ABAP:ME21N状态栏添加自定义按钮

SE38:LMEGUICJL---->代码增强点

ENHANCEMENT 1  Z_SEND_PO_TO_OA.    "active version
IF im_fcode = 'OA'.

  DATA: ls_return TYPE zscomm03,
        lv_bsart  TYPE ekko-bsart.
  DATA: lv_status TYPE zshr0004,
        ls_ekko TYPE ekko.

  CLEAR im_fcode.

  DATA: wa_ebeln TYPE ebeln.
  DATA: wa_bukrs TYPE bukrs.
  DATA: lv_flag.

  IF sy-tcode = 'ME21N'.
    GET PARAMETER ID 'BES' FIELD wa_ebeln.
    SELECT SINGLE bukrs INTO wa_bukrs FROM ekko WHERE ebeln = wa_ebeln.
  ELSE.
    DATA: field(50).
    FIELD-SYMBOLS: <dbcnt> TYPE any.
    field = '(SAPLMEGUI)MEPO_TOPLINE-EBELN'.
    ASSIGN (field) TO <dbcnt>.
    wa_ebeln = <dbcnt>.

    SELECT SINGLE bukrs INTO wa_bukrs FROM ekko WHERE ebeln = wa_ebeln.

  ENDIF.

  IF wa_ebeln IS INITIAL.
    IF sy-langu = 'E'.
      MESSAGE w001(00) WITH 'Po not found, please check the data!'DISPLAY LIKE 'W'.
    ELSE.
      MESSAGE w001(00) WITH '未找到PO,请检查数据!'DISPLAY LIKE 'W'.
    ENDIF.
  ENDIF.

  CHECK wa_ebeln IS NOT INITIAL.

  IF sy-mandt = '320' OR sy-mandt = '620' OR sy-mandt = '820'.

    SELECT SINGLE bsart
      FROM ekko
      INTO lv_bsart
     WHERE ebeln = wa_ebeln.

    IF lv_bsart = 'NB' OR lv_bsart = 'FNB' OR lv_bsart = 'ZNBS' OR lv_bsart = 'GDZC' OR lv_bsart = 'GXWX' OR lv_bsart = 'LXCG'.
      SELECT SINGLE * INTO ls_ekko FROM ekko WHERE ebeln = wa_ebeln.
      IF ls_ekko-frgzu IS NOT INITIAL AND ls_ekko-frggr = 'P1' AND ls_ekko-frgsx = 'P1'.
        MESSAGE  '采购订单已审批,请勿发送OA' TYPE 'E'.
      ENDIF.
      CALL FUNCTION 'ZFMMM_PO_SEND'
        EXPORTING
          iv_ifid   = '003'
          iv_ebeln  = wa_ebeln
        IMPORTING
          es_return = ls_return.
      IF ls_return-type <> 'W'.
        lv_status-code    = ls_return-type.
        lv_status-message = ls_return-message.
      ENDIF.
    ENDIF.

  ELSE.

    DATA: lr_bukrs TYPE RANGE OF bukrs,
          ls_bukrs LIKE LINE OF lr_bukrs,
          lr_ebeln TYPE RANGE OF ebeln,
          ls_ebeln LIKE LINE OF lr_ebeln.

    CLEAR:lr_bukrs[],lr_bukrs,ls_bukrs,lr_ebeln[],lr_ebeln,ls_ebeln.

    ls_bukrs-sign = 'I'.
    ls_bukrs-option = 'EQ'.
    ls_bukrs-low = wa_bukrs.
    APPEND ls_bukrs TO lr_bukrs.

    ls_ebeln-sign = 'I'.
    ls_ebeln-option = 'EQ'.
    ls_ebeln-low = wa_ebeln.
    APPEND ls_ebeln TO lr_ebeln.

    EXPORT oa_flag = 'X' TO MEMORY ID zpo_send_oa_memory_id=>oa_flag.

    SUBMIT zmmi0004
      WITH s_bukrs IN lr_bukrs
      WITH s_ebeln IN lr_ebeln
      AND RETURN.


    IMPORT oa_return TO lv_status FROM MEMORY ID zpo_send_oa_memory_id=>oa_stauts.

    FREE MEMORY ID zpo_send_oa_memory_id=>oa_stauts.

  ENDIF.

  IF lv_status-code = 'E'.
    MESSAGE s001(00) WITH lv_status-message DISPLAY LIKE 'W'.
  ELSEIF lv_status-code = 'S'.
    IF sy-langu = 'E'.
      MESSAGE s001(00) WITH 'Po sent OA successfully!'DISPLAY LIKE 'S'.
    ELSE.
      MESSAGE s001(00) WITH 'PO 发送 OA 成功!'DISPLAY LIKE 'S'.
    ENDIF.
  ELSE.
    DATA l_ekko LIKE ekko.

    CLEAR l_ekko.

    SELECT SINGLE * INTO l_ekko FROM ekko WHERE ebeln = wa_ebeln.
    IF l_ekko-frgzu IS NOT INITIAL AND l_ekko-frggr = 'P1' AND l_ekko-frgsx = 'P1'.
      IF sy-langu = 'E'.
        MESSAGE s001(00) WITH 'Po has been sent to OA, no need to re execute!'DISPLAY LIKE 'S'.
      ELSE.
        MESSAGE s001(00) WITH 'PO已经发送 OA,不需要重新执行!'DISPLAY LIKE 'S'.
      ENDIF.
    ELSEIF l_ekko-frgzu IS INITIAL.
      IF sy-langu = 'E'.
        MESSAGE s001(00) WITH 'Po does not need to be sent to OA for approval!'DISPLAY LIKE 'S'.
      ELSE.
        MESSAGE s001(00) WITH 'PO不需要发送OA审批!'DISPLAY LIKE 'S'.
      ENDIF.
    ELSE.
      IF sy-langu = 'E'.
        MESSAGE s001(00) WITH 'The Po has been approved and does not need to be sent to OA for approval!'DISPLAY LIKE 'S'.
      ELSE.
        MESSAGE s001(00) WITH 'PO已经审批通过,不需要发送OA审批!'DISPLAY LIKE 'S'.
      ENDIF.
    ENDIF.
  ENDIF.

ENDIF.
ENDENHANCEMENT.

 

posted @ 2024-02-18 16:29  阿胖的阿多  阅读(164)  评论(0编辑  收藏  举报