ABAP EWM PRDO交货单过账

Posted 想发财的小夏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP EWM PRDO交货单过账相关的知识,希望对你有一定的参考价值。

/N/SCWM/PRDO 交货单过账

FUNCTION zewm_post_pdo.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IV_LGNUM) TYPE  /SCWM/LGNUM
*"     VALUE(IV_DOCID) TYPE  /SCDL/DL_DOCID
*"  EXPORTING
*"     VALUE(ET_BAPIRET) TYPE  BAPIRETTAB
*"     VALUE(EV_SEVERITY) TYPE  BAPI_MTYPE
*"----------------------------------------------------------------------
  DATA:
    lo_sp_out         TYPE REF TO /scwm/cl_sp_prd_out,
    lo_ctrl           TYPE REF TO /scmb/cl_controller,
    lo_dlvhd          TYPE REF TO /scwm/cl_dlv_handler_adapter,
    lo_aspect         TYPE REF TO /scmb/if_mh_aspect,
    lt_field_mpapping TYPE /scmb/t_field_mapping,
    lt_aspect         TYPE /scmb/t_aspect,
    lt_docid_in       TYPE /scdl/t_sp_k_head,
    lt_docid_post     TYPE /scdl/t_sp_k_head,
    ls_dfval          TYPE /scmb/s_default_values_det,
    ls_dyndt          TYPE /scmb/s_dynpro_data,
    ls_dftdt          TYPE /scmb/s_default_values,
    lv_rejct          TYPE boole_d,
    lt_retcd          TYPE /scdl/t_sp_return_code,
    lv_msg            TYPE bapi_msg.

  DEFINE dlv_register_aspect. 

    CALL METHOD lo_dlvhd->mo_msg_handler->register_aspect
    EXPORTING
      iv_aspect             = &1
      io_aspect             = lo_aspect
      iv_structure          = &2
      it_field_mapping      = lt_field_mpapping
      it_aspect_composition = lt_aspect.

  END-OF-DEFINITION.

  CLEAR:lt_docid_in,ls_dftdt.

  lt_docid_in = VALUE #( ( docid = iv_docid ) ).

  ls_dftdt-t_details = VALUE #( ( v_fieldname = 'LGNUM' v_mandatory = abap_true v_memoryid = '/SCWM/LGN' )
                                ( v_fieldname = 'SHIPPING_OFFICE' )
                                ( v_fieldname = 'ENTITLED' ) ).

  ls_dftdt-v_identifier = '/SCWM/PRDO'.
  ls_dftdt-v_values_structure = '/SCWM/S_SP_DEFAULT'.
  ls_dftdt-v_extended = abap_true.

  " Initialization
  CALL METHOD /scmb/cl_controller=>get_instance
    RECEIVING
      eo_controller = lo_ctrl.

  CALL METHOD lo_ctrl->initialize
    EXPORTING
      io_tm = lo_ctrl.

  CREATE OBJECT lo_dlvhd.
  dlv_register_aspect:
  '/SCWM/S_SP_A_HEAD        ' '/SCDL/S_SP_K_HEAD        ',
  '/SCDL/S_SP_A_HEAD        ' '/SCDL/S_SP_A_HEAD        '. 

  IF lo_sp_out IS NOT BOUND.

    CREATE OBJECT lo_sp_out
      EXPORTING
        io_attribute_handler = lo_dlvhd
        io_message_handler   = lo_dlvhd
        iv_mode              = /scdl/cl_sp=>sc_mode_classic.

  ENDIF.

  SET PARAMETER ID '/SCWM/LGN' FIELD iv_lgnum.
  /scmb/cl_base=>set_process_data( io_attribute_handler     = lo_dlvhd->mo_attr_handler
                                   io_service_provider      = lo_sp_out
                                   io_message_handler       = lo_dlvhd->mo_msg_handler
                                   is_dynpro_data           = ls_dyndt
                                   is_default_values        = ls_dftdt
                                   iv_disable_standard_save = abap_true ).

  /scmb/cl_base=>end_of_initialization( iv_no_message_display = abap_true ).

*  FREE:lt_docid_post.
  MOVE-CORRESPONDING lt_docid_in TO lt_docid_post.
*  APPEND VALUE #( docid = iv_docid ) TO lt_docid_post.

  " LOCKS
  lo_sp_out->lock(
    EXPORTING
      inkeys       = lt_docid_post
      aspect       = '/SCWM/S_SP_A_HEAD'
      lockmode     = /scdl/if_sp1_locking=>sc_exclusive_lock
    IMPORTING
      rejected     = lv_rejct
      return_codes = lt_retcd ).

  IF lv_rejct EQ 'X'."锁定失败
    et_bapiret = VALUE #( ( type = 'E' id = '00' number = '398' message_v1 = '锁定失败' ) ).
    ev_severity = 'E'.
    RETURN.
  ENDIF.

  " EXECUTE
  CALL METHOD lo_sp_out->('EXECUTE')
    EXPORTING
      aspect   = '/SCWM/S_SP_A_HEAD'
      inkeys   = lt_docid_post
      action   = '/SCWM/ACT_POST_GM'
    IMPORTING
      rejected = lv_rejct.

  IF lv_rejct EQ 'X'. "过账失败
    CLEAR: lv_msg.
    MESSAGE ID sy-msgid TYPE sy-msgty
     NUMBER sy-msgno
       WITH sy-msgv1
            sy-msgv2
            sy-msgv3
            sy-msgv4
       INTO lv_msg.
    et_bapiret = VALUE #( ( type = 'E' id = '00' number = '398' message_v1 = lv_msg ) ).
    ev_severity = 'E'.
    RETURN.
  ENDIF.

  CALL METHOD lo_sp_out->/scmb/if_sp_transaction~before_save " BEFORE SAVE
    IMPORTING
      rejected = lv_rejct.

  IF lv_rejct EQ 'X'."保存前失败
    et_bapiret = VALUE #( ( type = 'E' id = '00' number = '398' message_v1 = '保存前失败' ) ).
    ev_severity = 'E'.
    RETURN.
  ENDIF.

  CALL METHOD lo_sp_out->/scmb/if_sp_transaction~save      " SAVE
    EXPORTING
      synchronously = space
    IMPORTING
      rejected      = lv_rejct.

  IF lv_rejct EQ 'X'."保存失败
    et_bapiret = VALUE #( ( type = 'E' id = '00' number = '398' message_v1 = '保存失败' ) ).
    ev_severity = 'E'.
    RETURN.
  ENDIF.

  et_bapiret = VALUE #( ( type = 'S' id = '00' number = '398' message_v1 = '过账成功' ) ).
  ev_severity = 'S'.
  COMMIT WORK AND WAIT.

ENDFUNCTION.

以上是关于ABAP EWM PRDO交货单过账的主要内容,如果未能解决你的问题,请参考以下文章

ABAP EWM PRDI交货单过账

ABAP EWM PRDI交货单过账

ABAP EWM PRDI交货单过账

交货单过账后 过账日期

EWM PRDI交货单取消

交货单过账报错