ABAP-交货冲销

FUNCTION zsd_fm_43 .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_VBELN_DN) LIKE  LIKP-VBELN
*"     VALUE(I_BUDAT) LIKE  SY-DATLO
*"  EXPORTING
*"     VALUE(STATUS) TYPE  C
*"     VALUE(MESSAGE) TYPE  CHAR200
*"----------------------------------------------------------------------
  DATA: ident     LIKE sy-uzeit.
  DATA: lt_mesgx LIKE STANDARD TABLE OF mesg WITH HEADER LINE,
        lt_mesg  TYPE tsmesg,
        ls_mesg  TYPE smesg.
  CLEAR lt_mesg[].



  DATA: lf_user        TYPE symsgv,
        lf_enqueue_arg LIKE seqg3-garg,                     "n_1662694
        lt_enqueue     LIKE seqg3 OCCURS WITH HEADER LINE.

  CLEAR:lf_user,lf_enqueue_arg,lt_enqueue,lt_enqueue[].
  CONCATENATE sy-mandt i_vbeln_dn INTO lf_enqueue_arg.
  CALL FUNCTION 'ENQUEUE_READ'
    EXPORTING
      gclient               = sy-mandt
      gname                 'LIKP'
      garg                  = lf_enqueue_arg
      guname                '*'
    TABLES
      enq                   = lt_enqueue
    EXCEPTIONS
      communication_failure 1
      system_failure        2
      OTHERS                3.
  READ TABLE lt_enqueue INDEX 1.
  IF sy-subrc 0.
    status  'E'.
    WRITE lt_enqueue-guname TO lf_user.                     "^_n_1662694
    MESSAGE e046(vlWITH i_vbeln_dn lf_user INTO message.
    EXIT.
  ENDIF.

  CALL FUNCTION 'MESSAGES_INITIALIZE'    "消息初始化
    EXPORTING
      i_identification = ident
    IMPORTING
      e_identification = ident
    EXCEPTIONS
      OTHERS           0.
  CALL FUNCTION 'MESSAGES_ACTIVE'      "激活消息
    EXCEPTIONS
      OTHERS 1.

  CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
    EXPORTING
      i_vbeln                   = i_vbeln_dn
      i_budat                   = i_budat
      i_tcode                   'VL09'
      i_vbtyp                   'J'
    TABLES
      t_mesg                    = lt_mesgx
    EXCEPTIONS
      error_reverse_goods_issue 1
      OTHERS                    2.
  IF sy-subrc =  0.
    COMMIT WORK AND WAIT.
    status  'S'.
    message '冲销成功'.
  ELSE.
    status  'E'.

    ROLLBACK WORK.

    CALL FUNCTION 'MESSAGES_GIVE'     "获取消息
      TABLES
        t_mesg = lt_mesg.
    LOOP AT lt_mesg INTO ls_mesg.
      IF ls_mesg-msgty IS INITIAL.
        ls_mesg-msgty 'S'.
      ENDIF.
      MESSAGE ID ls_mesg-arbgb TYPE ls_mesg-msgty NUMBER ls_mesg-txtnr
      WITH ls_mesg-msgv1 ls_mesg-msgv2 ls_mesg-msgv3 ls_mesg-msgv4 INTO message.
    ENDLOOP.
  ENDIF.

  CALL FUNCTION 'MESSAGES_INITIALIZE'
    EXPORTING
      i_identification = ident
    IMPORTING
      e_identification = ident
    EXCEPTIONS
      OTHERS           0.                                 "^_n_720286

  CALL FUNCTION 'MESSAGES_STOP'"释放消息

ENDFUNCTION.

posted @ 2021-11-29 12:58  東東東東  阅读(213)  评论(0编辑  收藏  举报