VinceCoder
9/18/2019 - 11:57 AM

EXIT: ME51N - EBKN ed EBAN

Exit che scatta al salvataggio del documento.

In tale exit rispetto all'equivalente 005 permette anche di reperire campi della EBKN (ad esempio KOSTL e PRCTR), cosa che la BADI ME_PROCESS_REQ_CUST

*&---------------------------------------------------------------------*
*&  Include           ZXM02U12
*&---------------------------------------------------------------------*

*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(IM_REQ_HEADER) TYPE REF TO  IF_PURCHASE_REQUISITION
*"     REFERENCE(IM_T_EBAN) TYPE  MEREQ_T_EBAN
*"     REFERENCE(IM_T_EBKN) TYPE  MEREQ_T_EBKN
*"     REFERENCE(IM_T_EBAN_PERS) TYPE  MEREQ_T_EBAN
*"     REFERENCE(IM_T_EBKN_PERS) TYPE  MEREQ_T_EBKN
*"  EXPORTING
*"     REFERENCE(EX_MESSAGES) TYPE  MEREQ_T_BAPIRET2
*"  EXCEPTIONS
*"      ERROR_MESSAGES
*"----------------------------------------------------------------------

DATA: lv_kostl TYPE cobl-kostl.
DATA: lt_t_ebkn TYPE mereq_t_ebkn.
DATA: lt_message TYPE mereq_t_bapiret2.
DATA: ls_message LIKE LINE OF lt_message.

lt_t_ebkn = im_t_ebkn.
CLEAR lv_kostl.

LOOP AT lt_t_ebkn ASSIGNING FIELD-SYMBOL(<lfs_ebkn>).

  DATA: lv_bukrs  TYPE t001k-bukrs,
        lv_prctr  TYPE ebkn-prctr,
        lf_banfn  LIKE eban-banfn_cs,
        lr_profit TYPE RANGE OF ebkn-prctr.

  READ TABLE im_t_eban ASSIGNING FIELD-SYMBOL(<lfs_eban>) INDEX sy-tabix.

  SELECT SINGLE bukrs INTO lv_bukrs FROM t001k WHERE bwkey EQ <lfs_eban>-werks.

  SELECT COUNT(*) FROM zco_utprofit WHERE bukrs EQ lv_bukrs.

  IF sy-subrc EQ 0.

    SELECT prctr_l AS low prctr_h AS high
      FROM zco_utprofit
      INTO TABLE lr_profit
      WHERE bukrs EQ lv_bukrs
      AND   ernam EQ sy-uname.

    LOOP AT lr_profit ASSIGNING FIELD-SYMBOL(<lfs_range>).
      <lfs_range>-sign = 'I'.
      IF <lfs_range>-low IS NOT INITIAL
      AND <lfs_range>-high IS NOT INITIAL.
        <lfs_range>-option = 'BT'.
        CONTINUE.
      ENDIF.
      <lfs_range>-option = 'EQ'.
    ENDLOOP.

    IF <lfs_ebkn>-prctr NOT IN lr_profit
    OR lr_profit IS INITIAL.
*            MESSAGE e060(zsd) WITH sy-uname lv_prctr DISPLAY LIKE 'I'. *viian 13.09.2019 15:29:24
      MESSAGE i060(zsd) WITH sy-uname <lfs_ebkn>-prctr INTO ls_message-message. "DISPLAY LIKE 'E' "lv_prctr DISPLAY LIKE 'I'.  "viian 13.09.2019 15:29:24
      ls_message-type = 'E'.
      ls_message-id = 'ZSD'.
      ls_message-number = 060.
      ls_message-message_v2 = <lfs_ebkn>-prctr.
      APPEND ls_message TO ex_messages.
    ENDIF.

  ENDIF.

  EXIT.

ENDLOOP.