SAP-&EWM은 트랜잭션 코드/SCWM/GRPI를 통해 DN을 생성합니다.

6510 단어 EWMabap
FUNCTION zewm_fm_dn_create_grpi.
*"----------------------------------------------------------------------
*"*"    :
*"  IMPORTING
*"     VALUE(IS_DATA) TYPE  ZEWM_S_DN_CREATE_FB
*"  EXPORTING
*"     VALUE(EV_MSG) TYPE  BAPI_MSG
*"     VALUE(EV_SEVERITY) TYPE  BAPI_MTYPE
*"     VALUE(EV_DOCID) TYPE  /SCDL/DL_DOCID
*"     VALUE(EV_ITEMID) TYPE  /SCDL/DL_ITEMID
*"----------------------------------------------------------------------

  DATA: lo_log             TYPE REF TO /scwm/cl_log,
        lo_controller      TYPE REF TO /scmb/cl_controller,
        lo_tm              TYPE REF TO object,
        lo_gr_sp           TYPE REF TO /scwm/cl_gr_sp,
        lo_adapter_handler TYPE REF TO /scwm/cl_dlv_handler_adapter,
        lt_outrecords      TYPE TABLE OF /scwm/s_gr_egr,
        lt_inkeys          TYPE TABLE OF index,
        lt_ibd             TYPE TABLE OF /scwm/s_gr_ibd,
        lt_selection       TYPE /scmb/t_sp_selection,
        lt_return_codes    TYPE /scdl/t_sp_return_code,
        lt_key_egr         TYPE /scdl/t_sp_k_item,
        lv_message         TYPE string,
        lv_rejected        TYPE boole_d,
        lv_failed          TYPE boole_d,
        lv_pa_execute      TYPE /scdl/dl_docid,
        lv_inparam         TYPE char4.

*   
  CLEAR: ev_msg, ev_severity, ev_docid, ev_itemid.

*       
  CREATE OBJECT lo_log.
  lo_log->init( ).

  CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
    EXPORTING
      input        = is_data-matnr
    IMPORTING
      output       = is_data-matnr
    EXCEPTIONS
      length_error = 1
      OTHERS       = 2.

  SELECT SINGLE *
    FROM /scdl/db_proci_i
    INTO @DATA(ls_i)
   WHERE productno = @is_data-matnr
     AND doccat = 'EGR'.

  SELECT SINGLE scuguid
    FROM /scwm/t300_md
   WHERE lgnum = @is_data-lgnum
    INTO @DATA(lv_locationid_wh_h).

*     ,Init
  TRY.
      lo_controller = /scmb/cl_controller=>get_instance( ).
      lo_controller->initialize( io_tm = lo_tm iv_classid = '' ).
      CREATE OBJECT lo_adapter_handler.
*       lo_adapter_handler->mo_msg_handler->set_log_save_data(
*         EXPORTING iv_subobject = /scwm/if_gr_c=>sc_tcode_int_prod ).
      CREATE OBJECT lo_gr_sp
        EXPORTING
          io_handler = lo_adapter_handler.
  ENDTRY.

  CLEAR:lt_selection,lv_failed,lt_outrecords,lt_key_egr.

*     
  lt_selection = VALUE #( ( fieldname = '/SCWM/PRODIND_PRDI_H' sign = 'I' option = 'EQ'  low = 'D')
                          ( fieldname = 'LOCATIONID_WH_H'      sign = 'I' option = 'EQ'  low = lv_locationid_wh_h )
                          ( fieldname = 'PRODUCTNO_I'          sign = 'I' option = 'EQ'  low = is_data-matnr ) ).

  lo_gr_sp->/scmb/if_sp_query~execute(" Query      
            EXPORTING
              inkeys     = lt_inkeys
              query      = '/SCWM/QUERY_EGR'
              inparam    = lv_inparam
              selections = lt_selection
            IMPORTING
              outrecords = lt_outrecords
              rejected   = lv_failed ).

  IF lt_outrecords IS INITIAL OR lv_failed IS NOT INITIAL.
    ev_msg = '      ,   '.
    ev_severity = 'E'.
    RETURN.
  ENDIF.

  APPEND VALUE #( docid = ls_i-docid itemid = ls_i-itemid ) TO lt_key_egr.

  lo_gr_sp->/scmb/if_sp_action~execute(  " Query    
            EXPORTING
               aspect       = '/SCWM/ASP_GR_EGR'
               inkeys       = lt_key_egr
               action       = 'ACT_MARK_SELECTION'
            IMPORTING
               outrecords   = lt_outrecords
               rejected     = lv_failed
               return_codes = lt_return_codes ).

  IF lv_failed IS INITIAL.     " Execute
    lo_gr_sp->/scmb/if_sp_action~execute("('EXECUTE')
              EXPORTING
                aspect       = '/SCWM/ASP_GR_EGR'
                inkeys       = lt_key_egr
                action       = 'ACT_COPY_EGR2IBD'
                inparam      = lv_pa_execute
              IMPORTING
                outrecords   = lt_outrecords
                rejected     = lv_failed
                return_codes = lt_return_codes ).
  ENDIF.

  IF lv_failed IS INITIAL.      " Query    DN
    lo_gr_sp->/scmb/if_sp_action~execute(
              EXPORTING
                aspect       = '/SCWM/ASP_GRPREP_IBD'
                inkeys       = lt_key_egr
                action       = 'ACT_DISPLAY_COPIED_EGR'
                inparam      = lv_inparam
              IMPORTING
                outrecords   = lt_ibd
                rejected     = lv_failed
                return_codes = lt_return_codes ).
  ENDIF.

  IF lv_failed IS INITIAL.
    lo_gr_sp->/scmb/if_sp_transaction~before_save(
              IMPORTING
                rejected = lv_rejected ).

    IF lv_rejected = abap_true.
      lv_failed = abap_true.
      MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
            INTO lv_message.
      ev_msg = lv_message.
      ev_severity = 'E'.
      RETURN.
    ENDIF.

  ENDIF.

  IF lv_failed IS INITIAL.
    lo_gr_sp->/scmb/if_sp_transaction~save(" Save->     DN
              IMPORTING
                rejected = lv_rejected ).

    IF lv_rejected = abap_true.
      lv_failed = abap_true.
      MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
            INTO lv_message.
      ev_msg = lv_message.
      ev_severity = 'E'.
      RETURN.
    ENDIF.

  ENDIF.

  IF lv_failed IS INITIAL.

    COMMIT WORK AND WAIT.
    lo_gr_sp->/scmb/if_sp_transaction~cleanup(
              EXPORTING
                reason = /scmb/if_sp_transaction=>sc_cleanup_commit ).

    /scwm/cl_tm=>cleanup( iv_reason = /scmb/if_sp_transaction=>sc_cleanup_commit ).
    ev_msg = '       '.
    ev_severity = 'S'.

    READ TABLE lt_ibd INTO DATA(ls_ibd) INDEX 1.
    IF sy-subrc = 0.
      ev_docid = ls_ibd-docid.
      ev_itemid = ls_ibd-itemid.
    ENDIF.

  ELSE.

    ROLLBACK WORK.
    lo_gr_sp->/scmb/if_sp_transaction~cleanup(
              EXPORTING
                reason = /scmb/if_sp_transaction=>sc_cleanup_end ).

    /scwm/cl_tm=>cleanup( ).
    ev_msg = '       '.
    ev_severity = 'E'.
    RETURN.

  ENDIF. 
  
ENDFUNCTION.

좋은 웹페이지 즐겨찾기