Friday, March 11, 2011

ALV with all Events



*---------------------------------------------------------------------*
* Addon Function Name :
* Program ID          :
* Program Name        :
* Created By          :
* Created On          :
*----------------------------------------------------------------------*
* Process Outline
*
*----------------------------------------------------------------------*
* History of Changes
* Changed On   No.#  Changed By     Changed content
* ----------  ----  ------------   -------------------------------------
* YYYY/MM/DD  XXXX    XXXX          XXXXXXXX
*----------------------------------------------------------------------*

REPORT  ZTRPROG01 MESSAGE-ID 00 NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       TABLE
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       TYPE-POOLS
*----------------------------------------------------------------------*
TYPE-POOLS : SLIS.
*----------------------------------------------------------------------*
*       TYPE
*----------------------------------------------------------------------*
TYPES: BEGIN OF TYP_ALVOUT,
        WERKS       TYPE  EKPO-WERKS,
        WERKS_TXT   TYPE  T001W-NAME1,
        LGORT       TYPE  EKPO-LGORT,
        LGOBE       TYPE  T001L-LGOBE,
        MATKL       TYPE  EKPO-MATKL,
        WGBEZ       TYPE  T023T-WGBEZ,
        ERNAM       TYPE  EKKO-ERNAM,
        NAME_TEXT   TYPE  ADRP-NAME_TEXT,
        LIFNR       TYPE  EKKO-LIFNR,
        LIFNR_TXT   TYPE  LFA1-NAME1,
        MATNR       TYPE  EKPO-MATNR,
        TXZ01       TYPE  EKPO-TXZ01,
        EBELN       TYPE  EKKO-EBELN,
        EBELP       TYPE  EKPO-EBELP,
        RET_ITEM    TYPE  CHAR10,
        MENGE       TYPE  EKPO-MENGE,
        EINDT       TYPE  EKET-EINDT,
        ELIKZ       TYPE  EKPO-ELIKZ,
        MENGE1      TYPE  EKPO-MENGE,
        WEMNG       TYPE  EKET-WEMNG,
        OPENPO_QTY  TYPE  EKET-WEMNG,
        NETPR       TYPE  EKPO-NETPR,
        PEINH       TYPE  EKPO-PEINH,
        NETWR       TYPE  EKPO-NETWR,
        WAERS       TYPE  EKKO-WAERS,
        INCO2       TYPE  EKPO-INCO2,
        AEDAT       TYPE  EKKO-AEDAT,
        BUDAT_GR    TYPE  EKBE-BUDAT,
        MENGE_REC   TYPE  EKBE-MENGE,
        BUDAT_INV   TYPE  EKBE-BUDAT,
        WRBTR       TYPE  EKBE-WRBTR,
        WAERS_INV   TYPE  EKBE-WAERS,
        BELNR_GR    TYPE  EKBE-BELNR,
        BELNR_INV   TYPE  RBKP-BELNR,
        XBLNR       TYPE  EKBE-XBLNR,
        STOCK_ORDER TYPE  CHAR10,
        TR_DAT      TYPE  CHAR10,
        TR_LOCATION TYPE  CHAR10,
        GA_QTY      TYPE  EKBE-MENGE,
        OPENTR_QTY  TYPE  EKBE-MENGE,
        BSART       TYPE  EKKO-BSART,
        BATXT       TYPE  T161T-BATXT,
        EKGRP       TYPE  EKKO-EKGRP,
        EKGRP_NAME  TYPE  T024-EKGRP,
        MEINS       TYPE  MARA-MEINS,
        MSEHT       TYPE  T006A-MSEHT,
        BISMT       TYPE  MARA-BISMT,
        MFRPN       TYPE  MARA-MFRPN,
        MTART       TYPE  MARA-MTART,
        MTBEZ       TYPE  T134T-MTBEZ,
       END OF TYP_ALVOUT.
TYPES : BEGIN OF TYP_EKKO,
         EBELN      TYPE  EKKO-EBELN,
         BUKRS      TYPE  EKKO-BUKRS,
         ERNAM      TYPE  EKKO-ERNAM,
         LIFNR      TYPE  EKKO-LIFNR,
         AEDAT      TYPE  EKKO-AEDAT,
         BSART      TYPE  EKKO-BSART,
         EKGRP      TYPE  EKKO-EKGRP,
         WAERS      TYPE  EKKO-WAERS,
        END OF TYP_EKKO.
TYPES : BEGIN OF TYP_EKPO,
         EBELN      TYPE  EKKO-EBELN,
         EBELP      TYPE  EKPO-EBELP,
         TXZ01      TYPE  EKPO-TXZ01,
         MATNR      TYPE  EKPO-MATNR,
         WERKS      TYPE  EKPO-WERKS,
         LGORT      TYPE  EKPO-LGORT,
         MATKL      TYPE  EKPO-MATKL,
         MENGE      TYPE  EKPO-MENGE,
         NETPR      TYPE  EKPO-NETPR,
         PEINH      TYPE  EKPO-PEINH,
         NETWR      TYPE  EKPO-NETWR,
         ELIKZ      TYPE  EKPO-ELIKZ,
         INCO2      TYPE  EKPO-INCO2,
         RETPO      TYPE  EKPO-RETPO,
        END OF TYP_EKPO.
TYPES : BEGIN OF TYP_EKET,
         EBELN      TYPE  EKET-EBELN,
         EBELP      TYPE  EKET-EBELP,
         EINDT      TYPE  EKET-EINDT,
         WEMNG      TYPE  EKET-WEMNG,
        END OF TYP_EKET.
TYPES : BEGIN OF TYP_MARA,
         MATNR      TYPE MARA-MATNR,
         MTART      TYPE MARA-MTART,
         BISMT      TYPE MARA-BISMT,
         MEINS      TYPE MARA-MEINS,
         MFRPN      TYPE MARA-MFRPN,
        END OF TYP_MARA.
TYPES : BEGIN OF TYP_T001W,
         WERKS      TYPE T001W-WERKS,
         NAME1      TYPE T001W-NAME1,
        END OF TYP_T001W.
TYPES : BEGIN OF TYP_T001L,
         WERKS      TYPE T001L-WERKS,
         LGORT      TYPE T001L-LGORT,
         LGOBE      TYPE T001L-LGOBE,
        END OF TYP_T001L.
TYPES : BEGIN OF TYP_T023T,
         MATKL      TYPE T023T-MATKL,
         SPRAS      TYPE T023T-SPRAS,
         WGBEZ      TYPE T023T-WGBEZ,
        END OF TYP_T023T.
TYPES : BEGIN OF TYP_USR21,
         BNAME      TYPE USR21-BNAME,
         PERSNUMBER TYPE USR21-PERSNUMBER,
        END OF TYP_USR21.
TYPES : BEGIN OF TYP_ADRP,
         PERSNUMBER TYPE USR21-PERSNUMBER,
         NAME_TEXT  TYPE ADRP-NAME_TEXT,
        END OF TYP_ADRP.
TYPES : BEGIN OF TYP_LFA1,
         LIFNR      TYPE LFA1-LIFNR,
         NAME1      TYPE LFA1-NAME1,
        END OF TYP_LFA1.
TYPES : BEGIN OF TYP_T161T,
         BSART      TYPE T161T-BSART,
         SPRAS      TYPE T161T-SPRAS,
   BATXT      TYPE T161T-BATXT,
        END OF TYP_T161T.
TYPES : BEGIN OF TYP_T024,
         EKGRP      TYPE T024-EKGRP,
         NAME1      TYPE T024-EKGRP,
        END OF TYP_T024.
TYPES : BEGIN OF TYP_T006A,
         MSEHI      TYPE T006A-MSEHI,
         SPRAS      TYPE T006A-SPRAS,
         MSEHT      TYPE T006A-MSEHT,
        END OF TYP_T006A.
TYPES : BEGIN OF TYP_T134T,
         MTART      TYPE T134T-MTART,
         SPRAS      TYPE T134T-SPRAS,
         MTBEZ      TYPE T134T-MTBEZ,
        END OF TYP_T134T.
TYPES : BEGIN OF TYP_EKBE_GI,
         EBELN      TYPE EKBE-EBELN,
         EBELP      TYPE EKBE-EBELP,
         GJAHR      TYPE EKBE-GJAHR,
         BELNR      TYPE EKBE-BELNR,
            BUZEI      TYPE EKBE-BUZEI,
         BUDAT      TYPE EKBE-BUDAT,
         MENGE      TYPE EKBE-MENGE,
         SHKZG         TYPE EKBE-SHKZG,
         XBLNR      TYPE EKBE-XBLNR,
         CPUDT      TYPE EKBE-CPUDT,
        END OF TYP_EKBE_GI.
TYPES : BEGIN OF TYP_EKBE_INV,
         EBELN      TYPE EKBE-EBELN,
         EBELP      TYPE EKBE-EBELP,
         LFGJA      TYPE EKBE-LFGJA,
         LFBNR      TYPE EKBE-LFBNR,
         LFPOS      TYPE EKBE-LFPOS,
         GJAHR      TYPE EKBE-GJAHR,
         BELNR      TYPE EKBE-BELNR,
         BUDAT      TYPE EKBE-BUDAT,
         WRBTR      TYPE EKBE-WRBTR,
         WAERS      TYPE EKBE-WAERS,
         SHKZG         TYPE EKBE-SHKZG,
         CPUDT      TYPE EKBE-CPUDT,
        END OF TYP_EKBE_INV.
TYPES : BEGIN OF TYP_RBKP,
         BELNR      TYPE RBKP-BELNR,
         GJAHR      TYPE RBKP-GJAHR,
        END OF TYP_RBKP.
TYPES : BEGIN OF TYP_BKPF,
         BUKRS      TYPE BKPF-BUKRS,
         GJAHR      TYPE BKPF-GJAHR,
         CPUDT      TYPE BKPF-CPUDT,
         AWKEY      TYPE BKPF-AWKEY,
         KURSF      TYPE BKPF-KURSF,
         WAERS      TYPE BKPF-WAERS,
         HWAER      TYPE BKPF-HWAER,
        END OF TYP_BKPF.
TYPES : BEGIN OF TYP_EKPV,
         EBELN      TYPE EKPV-EBELN,
         EBELP      TYPE EKPV-EBELP,
         ABLAD      TYPE EKPV-ABLAD,
        END OF TYP_EKPV.
TYPES : BEGIN OF TYP_XBLNR,
         SIGN       TYPE CHAR1,
         OPTION     TYPE CHAR2,
         LOW        TYPE EKPV-ABLAD,
         HIGH       TYPE EKPV-ABLAD,
        END OF TYP_XBLNR.


*----------------------------------------------------------------------*
*       INTERNAL TABLE
*----------------------------------------------------------------------*
DATA: I_ALVOUT      TYPE STANDARD TABLE OF TYP_ALVOUT,
      I_EKKO        TYPE STANDARD TABLE OF TYP_EKKO,
      I_EKPO        TYPE STANDARD TABLE OF TYP_EKPO,
      I_EKPO_2      TYPE STANDARD TABLE OF TYP_EKPO,
      I_EKET        TYPE STANDARD TABLE OF TYP_EKET,
      I_EKET_2      TYPE STANDARD TABLE OF TYP_EKET,
      I_MARA        TYPE STANDARD TABLE OF TYP_MARA,
      I_T001W       TYPE STANDARD TABLE OF TYP_T001W,
      I_T001L       TYPE STANDARD TABLE OF TYP_T001L,
      I_T001L_2     TYPE STANDARD TABLE OF TYP_T001L,
      I_T023T       TYPE STANDARD TABLE OF TYP_T023T,
      I_USR21       TYPE STANDARD TABLE OF TYP_USR21,
      I_ADRP        TYPE STANDARD TABLE OF TYP_ADRP,
      I_LFA1        TYPE STANDARD TABLE OF TYP_LFA1,
      I_T161T       TYPE STANDARD TABLE OF TYP_T161T,
      I_T024        TYPE STANDARD TABLE OF TYP_T024,
      I_T006A       TYPE STANDARD TABLE OF TYP_T006A,
      I_T134T       TYPE STANDARD TABLE OF TYP_T134T,
      I_EKBE_GI     TYPE STANDARD TABLE OF TYP_EKBE_GI,
      I_EKBE_INV    TYPE STANDARD TABLE OF TYP_EKBE_INV,
      I_RBKP        TYPE STANDARD TABLE OF TYP_RBKP,
      I_BKPF        TYPE STANDARD TABLE OF TYP_BKPF,
      I_EKPV        TYPE STANDARD TABLE OF TYP_EKPV,
* Fieldcatalog structure
      I_FCAT        TYPE SLIS_T_FIELDCAT_ALV."SLIS_FILEDCAT_ALV,

*----------------------------------------------------------------------*
*       RANGES
*----------------------------------------------------------------------*
DATA: R_LFGJA       TYPE RANGE OF EKBE-LFGJA,
      R_LFGJA_LINE  LIKE LINE OF R_LFGJA.
DATA: R_LFBNR       TYPE RANGE OF EKBE-LFBNR,
      R_LFBNR_LINE  LIKE LINE OF R_LFBNR.
DATA: R_LFPOS       TYPE RANGE OF EKBE-LFPOS,
      R_LFPOS_LINE  LIKE LINE OF R_LFPOS.
DATA: R_BUKRS       TYPE RANGE OF BKPF-BUKRS,
      R_BUKRS_LINE  LIKE LINE OF R_BUKRS.
DATA: R_AWKEY       TYPE RANGE OF BKPF-AWKEY,
      R_AWKEY_LINE  LIKE LINE OF R_AWKEY.
DATA: R_XBLNR       TYPE RANGE OF TYP_XBLNR,
      R_XBLNR_LINE  LIKE LINE OF R_XBLNR.

*----------------------------------------------------------------------*
*       STRUCTURE
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       WORKS
*----------------------------------------------------------------------*
DATA: WA_ALVOUT     TYPE TYP_ALVOUT,
      WA_EKKO       TYPE TYP_EKKO,
      WA_EKPO       TYPE TYP_EKPO,
      WA_EKET       TYPE TYP_EKET,
      WA_MARA       TYPE TYP_MARA,
      WA_T001W      TYPE TYP_T001W,
      WA_T001L      TYPE TYP_T001L,
      WA_T023T      TYPE TYP_T023T,
      WA_USR21      TYPE TYP_USR21,
      WA_ADRP       TYPE TYP_ADRP,
      WA_LFA1       TYPE TYP_LFA1,
      WA_T161T      TYPE TYP_T161T,
      WA_T024       TYPE TYP_T024,
      WA_T006A      TYPE TYP_T006A,
      WA_T134T      TYPE TYP_T134T,
      WA_EKBE_GI    TYPE TYP_EKBE_GI,
      WA_EKBE_INV   TYPE TYP_EKBE_INV,
      WA_RBKP       TYPE TYP_RBKP,
      WA_BKPF       TYPE TYP_BKPF,
      WA_EKPV       TYPE TYP_EKPV,
      WA_FCAT       TYPE SLIS_FIELDCAT_ALV, "SLIS_T_FILEDCAT_ALV.
      WA_LAYOUT     TYPE SLIS_LAYOUT_ALV.

*----------------------------------------------------------------------*
*       COUNTER
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       INDEX
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       FLAG
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       FIELD-SYMBOLS
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       DATA
*----------------------------------------------------------------------*
DATA: G_IHREZ       TYPE EKKO-IHREZ.
*----------------------------------------------------------------------*
*       TABLE CONTROL
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       TABSTRIP
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       CONSTANTS
*----------------------------------------------------------------------*
CONSTANTS: C_X      TYPE C VALUE 'X',
           C_E      TYPE C VALUE 'E',
           C_H      TYPE C VALUE 'H',
           C_I      TYPE C VALUE 'I',
           C_1      TYPE C VALUE '1',
           C_2      TYPE C VALUE '2',
           C_3      TYPE C VALUE '3',
           C_EQ     TYPE C VALUE 'EQ' LENGTH 2,
           C_JP     TYPE C VALUE 'JP' LENGTH 2,
           C_Z1     TYPE C VALUE 'Z1' LENGTH 2,
           C_Z2     TYPE C VALUE 'Z2' LENGTH 2,
           C_Z3     TYPE C VALUE 'Z3' LENGTH 2,
           C_Z4     TYPE C VALUE 'Z4' LENGTH 2,
           C_Z5     TYPE C VALUE 'Z5' LENGTH 2,
           C_RETURN TYPE C VALUE 'Return' LENGTH 6,
           C_RETURNJP
                    TYPE C VALUE '##' LENGTH 4,
           C_SPACE  TYPE C VALUE ' '.
*----------------------------------------------------------------------*
*       PARAMETERS
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_AEDAT FOR WA_ALVOUT-AEDAT MODIF ID S,
                S_WERKS FOR WA_ALVOUT-WERKS,
                S_MATKL FOR WA_ALVOUT-MATKL MODIF ID S,
                S_ERNAM FOR WA_ALVOUT-ERNAM,
                S_BSART FOR WA_ALVOUT-BSART,
                S_LGORT FOR WA_ALVOUT-LGORT,
                S_LIFNR FOR WA_ALVOUT-LIFNR,
                S_MTART FOR WA_ALVOUT-MTART,
                S_MATNR FOR WA_ALVOUT-MATNR,
                S_EBELN FOR WA_ALVOUT-EBELN,
                S_INCO2 FOR WA_ALVOUT-INCO2,
                S_IHREZ FOR G_IHREZ.
SELECTION-SCREEN SKIP 1.
PARAMETERS: RB_REM    RADIOBUTTON GROUP G1 USER-COMMAND SET DEFAULT 'X',
            RB_REMUN  RADIOBUTTON GROUP G1,
            RB_ALL    RADIOBUTTON GROUP G1.
*----------------------------------------------------------------------*
*       INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
*       AT SELECTION-SCREEN
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN.
*  IF RB_ALL = C_X
*    AND ( S_AEDAT IS INITIAL
*    OR S_MATKL IS INITIAL ).
*    MESSAGE E055(00).
*  ENDIF.
*----------------------------------------------------------------------*
*       AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF RB_ALL = C_X
      AND ( SCREEN-NAME = 'S_AEDAT-LOW'
      OR SCREEN-NAME = 'S_MATKL-LOW' ).
      SCREEN-REQUIRED = 2.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.
*----------------------------------------------------------------------*
*       START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Input check
  PERFORM F_INPUT_CHECK.
* 1-1
  PERFORM F_CHANGE_SBSART.
* 1-2
  PERFORM F_GET_DATA.
* 1-3
  PERFORM F_GET_EKBE_GI.
* 1-4
  PERFORM F_GET_DATA_2.
* 1-5
  PERFORM F_GET_DATA_3.
* SET DATA
  PERFORM F_SET_DATA.
* DISPLAY ALV
  PERFORM F_DISPLAY_ALV.

*----------------------------------------------------------------------*
*       END-OF-SELECTION
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       TOP-OF-PAGE
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*      AT LINE-SELECTION.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*       Subroutine
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  F_INPUT_CHECK
*&---------------------------------------------------------------------*
*       Input check
*----------------------------------------------------------------------*
FORM F_INPUT_CHECK .

  IF RB_ALL = C_X
    AND ( S_AEDAT IS INITIAL
    OR S_MATKL IS INITIAL ).
    MESSAGE S055(00) DISPLAY LIKE C_E.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_INPUT_CHECK
*&---------------------------------------------------------------------*
*&      Form  F_CHANGE_SBSART
*&---------------------------------------------------------------------*
*       1-1
*----------------------------------------------------------------------*
FORM F_CHANGE_SBSART .

  S_BSART-SIGN   = C_E.
  S_BSART-OPTION = C_EQ.
  S_BSART-LOW    = C_Z1.
  APPEND S_BSART.
  S_BSART-LOW    = C_Z2.
  APPEND S_BSART.
  S_BSART-LOW    = C_Z3.
  APPEND S_BSART.
  S_BSART-LOW    = C_Z4.
  APPEND S_BSART.
  S_BSART-LOW    = C_Z5.
  APPEND S_BSART.

ENDFORM.                    " F_CHANGE_SBSART
*&---------------------------------------------------------------------*
*&      Form  F_GET_DATA
*&---------------------------------------------------------------------*
*       1-2
*----------------------------------------------------------------------*
FORM F_GET_DATA .

* DA001
  PERFORM F_GET_EKKO.

  IF RB_REM = C_X.
*   DA002
    PERFORM F_GET_EKPO USING C_1.
  ELSEIF RB_REMUN = C_X.
*   DA003
    PERFORM F_GET_EKPO USING C_2.
  ELSEIF RB_ALL = C_X.
*   DA004
    PERFORM F_GET_EKPO USING C_3.
  ENDIF.
* DA005
  PERFORM F_GET_EKET.
* DA010
  PERFORM F_GET_MARA.
* DA011
  PERFORM F_GET_T001W.
* DA012
  PERFORM F_GET_T001L.
* DA013
  PERFORM F_GET_T023T.
* DA014
  PERFORM F_GET_USR21.
* DA015
  PERFORM F_GET_ADRP.
* DA016
  PERFORM F_GET_LFA1.
* DA017
  PERFORM F_GET_T161T.
* DA018
  PERFORM F_GET_T024.
* DA019
  PERFORM F_GET_T006A.
* DA020
  PERFORM F_GET_T134T.


ENDFORM.                    " F_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKKO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKKO .

  SELECT EBELN
         BUKRS
         ERNAM
         LIFNR
         AEDAT
         BSART
         EKGRP
         WAERS FROM EKKO
         INTO TABLE I_EKKO
         WHERE AEDAT IN S_AEDAT
         AND   ERNAM IN S_ERNAM
         AND   BSART IN S_BSART
         AND   LIFNR IN S_LIFNR
         AND   EBELN IN S_EBELN
         AND   IHREZ IN S_IHREZ.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Purchasing Document Header'
                      'EKKO' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKKO
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKPO  USING    P_MODE TYPE C.

  CHECK NOT I_EKKO IS INITIAL.

  IF P_MODE = C_1.
    SELECT EBELN
           EBELP
           TXZ01
           MATNR
           WERKS
           LGORT
           MATKL
           MENGE
           NETPR
           PEINH
           NETWR
           ELIKZ
           INCO2
           RETPO  FROM EKPO
           INTO TABLE I_EKPO
           FOR ALL ENTRIES IN I_EKKO
           WHERE EBELN = I_EKKO-EBELN
           AND   LOEKZ = C_SPACE
           AND   ELIKZ = C_SPACE
           AND   WERKS = S_WERKS
           AND   MATKL = S_MATKL
           AND   LGORT = S_LGORT
           AND   MATNR = S_MATNR
           AND   INCO2 = S_INCO2.
  ELSEIF P_MODE = C_2.
    SELECT EBELN
           EBELP
           TXZ01
           MATNR
           WERKS
           LGORT
           MATKL
           MENGE
           NETPR
           PEINH
           NETWR
           ELIKZ
           INCO2
           RETPO  FROM EKPO
           INTO TABLE I_EKPO
           FOR ALL ENTRIES IN I_EKKO
           WHERE EBELN = I_EKKO-EBELN
           AND   LOEKZ = C_SPACE
           AND   ELIKZ = C_X
           AND   WERKS = S_WERKS
           AND   MATKL = S_MATKL
           AND   LGORT = S_LGORT
           AND   MATNR = S_MATNR
           AND   INCO2 = S_INCO2.
  ELSEIF P_MODE = C_3.
    SELECT EBELN
           EBELP
           TXZ01
           MATNR
           WERKS
           LGORT
           MATKL
           MENGE
           NETPR
           PEINH
           NETWR
           ELIKZ
           INCO2
           RETPO  FROM EKPO
           INTO TABLE I_EKPO
           FOR ALL ENTRIES IN I_EKKO
           WHERE EBELN = I_EKKO-EBELN
           AND   LOEKZ = C_SPACE
           AND   WERKS = S_WERKS
           AND   MATKL = S_MATKL
           AND   LGORT = S_LGORT
           AND   MATNR = S_MATNR
           AND   INCO2 = S_INCO2.
  ENDIF.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Purchasing Document Item'
                      'EKPO' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKPO
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKET .

  CHECK NOT I_EKPO IS INITIAL.

  SELECT EBELN
         EBELP
         EINDT
         WEMNG FROM EKET
         INTO TABLE I_EKET
         FOR ALL ENTRIES IN I_EKPO
         WHERE EBELN = I_EKPO-EBELN
         AND   EBELP = I_EKPO-EBELP.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Scheduling Agreement Schedule Lines'
                      'EKET' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKET
*&---------------------------------------------------------------------*
*&      Form  F_GET_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_MARA .

  DATA: LI_EKPO TYPE STANDARD TABLE OF TYP_EKPO.

  CHECK NOT I_EKPO IS INITIAL.
  APPEND LINES OF I_EKPO TO LI_EKPO.
  SORT LI_EKPO BY MATNR.
  DELETE ADJACENT DUPLICATES FROM LI_EKPO
                  COMPARING MATNR.
  SELECT MATNR
         MTART
         BISMT
         MEINS
         MFRPN FROM MARA
         INTO TABLE I_MARA
         FOR ALL ENTRIES IN LI_EKPO
         WHERE MATNR = LI_EKPO-MATNR
         AND   MTART IN S_MTART.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'General Material Data'
                      'MARA' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_MARA
*&---------------------------------------------------------------------*
*&      Form  F_GET_T001W
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T001W .

  DATA: LI_EKPO TYPE STANDARD TABLE OF TYP_EKPO.

  CHECK NOT I_EKPO IS INITIAL.
  APPEND LINES OF I_EKPO TO LI_EKPO.
  SORT LI_EKPO BY WERKS.
  DELETE ADJACENT DUPLICATES FROM LI_EKPO
                  COMPARING WERKS.
  SELECT WERKS
         NAME1 FROM T001W
         INTO TABLE I_T001W
         FOR ALL ENTRIES IN LI_EKPO
         WHERE WERKS = LI_EKPO-WERKS.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Plant Data'
                      'T001W' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T001W
*&---------------------------------------------------------------------*
*&      Form  F_GET_T001L
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T001L .

  DATA: LI_EKPO TYPE STANDARD TABLE OF TYP_EKPO.

  CHECK NOT I_EKPO IS INITIAL.
  APPEND LINES OF I_EKPO TO LI_EKPO.
  SORT LI_EKPO BY WERKS LGORT.
  DELETE ADJACENT DUPLICATES FROM LI_EKPO
                  COMPARING WERKS LGORT.
  SELECT WERKS
         LGORT
         LGOBE FROM T001L
         INTO TABLE I_T001L
         FOR ALL ENTRIES IN LI_EKPO
         WHERE WERKS = LI_EKPO-WERKS
         AND   LGORT = LI_EKPO-LGORT.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Storage Location Data'
                      'T001L' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T001L
*&---------------------------------------------------------------------*
*&      Form  F_GET_T023T
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T023T .

  DATA: LI_EKPO TYPE STANDARD TABLE OF TYP_EKPO.

  CHECK NOT I_EKPO IS INITIAL.
  APPEND LINES OF I_EKPO TO LI_EKPO.
  SORT LI_EKPO BY MATKL.
  DELETE ADJACENT DUPLICATES FROM LI_EKPO
                  COMPARING MATKL.
  SELECT MATKL
   SPRAS
         WGBEZ FROM T023T
         INTO TABLE I_T023T
         FOR ALL ENTRIES IN LI_EKPO
         WHERE MATKL = LI_EKPO-MATKL
         AND   SPRAS = SY-LANGU.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Material group'
                      'T023T' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T001L
*&---------------------------------------------------------------------*
*&      Form  F_GET_USR21
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_USR21 .

  DATA: LI_EKKO TYPE STANDARD TABLE OF TYP_EKKO.

  CHECK NOT I_EKKO IS INITIAL.
  APPEND LINES OF I_EKKO TO LI_EKKO.
  SORT LI_EKKO BY ERNAM.
  DELETE ADJACENT DUPLICATES FROM LI_EKKO
                  COMPARING ERNAM.
  SELECT BNAME
         PERSNUMBER FROM USR21
         INTO TABLE I_USR21
         FOR ALL ENTRIES IN LI_EKKO
         WHERE BNAME = LI_EKKO-ERNAM.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Created by'
                      'USR21' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T001L
*&---------------------------------------------------------------------*
*&      Form  F_GET_ADRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_ADRP .

  DATA: LI_USR21 TYPE STANDARD TABLE OF TYP_USR21.

  CHECK NOT I_USR21 IS INITIAL.
  APPEND LINES OF I_USR21 TO LI_USR21.
  SORT LI_USR21 BY PERSNUMBER.
  DELETE ADJACENT DUPLICATES FROM LI_USR21
                  COMPARING PERSNUMBER.
  SELECT PERSNUMBER
         NAME_TEXT FROM ADRP
         INTO TABLE I_ADRP
         FOR ALL ENTRIES IN LI_USR21
         WHERE PERSNUMBER = LI_USR21-PERSNUMBER.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Address'
                      'ADRP' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_ADRP
*&---------------------------------------------------------------------*
*&      Form  F_GET_LFA1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_LFA1 .

  DATA: LI_EKKO TYPE STANDARD TABLE OF TYP_EKKO.

  CHECK NOT I_EKKO IS INITIAL.
  APPEND LINES OF I_EKPO TO LI_EKKO.
  SORT LI_EKKO BY LIFNR.
  DELETE ADJACENT DUPLICATES FROM LI_EKKO
                  COMPARING LIFNR.
  SELECT LIFNR
         NAME1 FROM LFA1
         INTO TABLE I_LFA1
         FOR ALL ENTRIES IN LI_EKKO
         WHERE LIFNR = LI_EKKO-LIFNR.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'vENDOR'
                      'LFA1' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_LFA1
*&---------------------------------------------------------------------*
*&      Form  F_GET_T161T
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T161T .

  DATA: LI_EKKO TYPE STANDARD TABLE OF TYP_EKKO.

  CHECK NOT I_EKKO IS INITIAL.
  APPEND LINES OF I_EKKO TO LI_EKKO.
  SORT LI_EKKO BY BSART.
  DELETE ADJACENT DUPLICATES FROM LI_EKKO
                  COMPARING BSART.
  SELECT BSART
         SPRAS
         BATXT FROM T161T
         INTO TABLE I_T161T
         FOR ALL ENTRIES IN LI_EKKO
         WHERE BSART = LI_EKKO-BSART
         AND   SPRAS = SY-LANGU.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'ORDER TYPE'
                      'T161T' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T161T
*&---------------------------------------------------------------------*
*&      Form  F_GET_T024
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T024 .

  DATA: LI_EKKO TYPE STANDARD TABLE OF TYP_EKKO.

  CHECK NOT I_EKKO IS INITIAL.
  APPEND LINES OF I_EKKO TO LI_EKKO.
  SORT LI_EKKO BY EKGRP.
  DELETE ADJACENT DUPLICATES FROM LI_EKKO
                  COMPARING EKGRP.
  SELECT EKGRP
         EKNAM FROM T024
         INTO TABLE I_T024
         FOR ALL ENTRIES IN LI_EKKO
         WHERE EKGRP = LI_EKKO-EKGRP.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'PURCHASE GROUP'
                      'T024' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T024
*&---------------------------------------------------------------------*
*&      Form  F_GET_T006A
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T006A .

  DATA: LI_MARA TYPE STANDARD TABLE OF TYP_MARA.

  CHECK NOT I_MARA IS INITIAL.
  APPEND LINES OF I_MARA TO LI_MARA.
  SORT LI_MARA BY MEINS.
  DELETE ADJACENT DUPLICATES FROM LI_MARA
                  COMPARING MEINS.
  SELECT MSEHI
         SPRAS
         MSEHT FROM T006A
         INTO TABLE I_T006A
         FOR ALL ENTRIES IN LI_MARA
         WHERE MSEHI = LI_MARA-MEINS
         AND   SPRAS = SY-LANGU.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'UOM'
                      'T006A' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T006A
*&---------------------------------------------------------------------*
*&      Form  F_GET_T134T
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T134T .

  DATA: LI_MARA TYPE STANDARD TABLE OF TYP_MARA.

  CHECK NOT I_MARA IS INITIAL.
  APPEND LINES OF I_MARA TO LI_MARA.
  SORT LI_MARA BY MTART.
  DELETE ADJACENT DUPLICATES FROM LI_MARA
                  COMPARING MTART.
  SELECT MTART
         SPRAS
         MTBEZ FROM T134T
         INTO TABLE I_T134T
         FOR ALL ENTRIES IN LI_MARA
         WHERE MTART = LI_MARA-MTART
         AND   SPRAS = SY-LANGU.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'MATERIAL TYPE'
                      'T134T' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T134T
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKBE_GI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKBE_GI .

  CHECK NOT I_EKPO IS INITIAL.

  SELECT EBELN
         EBELP
         GJAHR
         BELNR
         BUZEI
         BUDAT
         MENGE
         SHKZG
         XBLNR
         CPUDT FROM EKBE
         INTO TABLE I_EKBE_GI
         FOR ALL ENTRIES IN I_EKPO
         WHERE EBELN = I_EKPO-EBELN
         AND   EBELP = I_EKPO-EBELP
         AND   VGABE = C_1.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'History per Purchasing Document'
                      'EKBE' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKBE_GI
*&---------------------------------------------------------------------*
*&      Form  F_GET_DATA_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_DATA_2 .

* DA007
  PERFORM F_GET_EKBE_INV.
* DA008
  PERFORM F_GET_RBKP.
* DA009
  PERFORM F_GET_BKPF.

ENDFORM.                    " F_GET_DATA_2
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKBE_INV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKBE_INV .

  CHECK NOT I_EKPO IS INITIAL.

  R_LFGJA_LINE-SIGN   = C_I.
  R_LFGJA_LINE-OPTION = C_EQ.
  LOOP AT I_EKBE_GI INTO WA_EKBE_GI.
    R_LFGJA_LINE-LOW = WA_EKBE_GI-GJAHR.
    APPEND R_LFGJA_LINE TO R_LFGJA.
    CLEAR R_LFGJA_LINE-LOW.
  ENDLOOP.

  R_LFBNR_LINE-SIGN   = C_I.
  R_LFBNR_LINE-OPTION = C_EQ.
  LOOP AT I_EKBE_GI INTO WA_EKBE_GI.
    R_LFBNR_LINE-LOW = WA_EKBE_GI-BELNR.
    APPEND R_LFBNR_LINE TO R_LFBNR.
    CLEAR R_LFBNR_LINE-LOW.
  ENDLOOP.

  R_LFPOS_LINE-SIGN   = C_I.
  R_LFPOS_LINE-OPTION = C_EQ.
  LOOP AT I_EKBE_GI INTO WA_EKBE_GI.
    R_LFPOS_LINE-LOW = WA_EKBE_GI-BUZEI.
    APPEND R_LFPOS_LINE TO R_LFPOS.
    CLEAR R_LFPOS_LINE-LOW.
  ENDLOOP.

  SELECT EBELN
         EBELP
         LFGJA
         LFBNR
         LFPOS
         GJAHR
         BELNR
         BUDAT
         WRBTR
         WAERS
         SHKZG
         CPUDT FROM EKBE
         INTO TABLE I_EKBE_INV
         FOR ALL ENTRIES IN I_EKPO
         WHERE EBELN = I_EKPO-EBELN
         AND   EBELP = I_EKPO-EBELP
         AND   VGABE = C_2
         AND   LFGJA IN R_LFGJA
         AND   LFBNR IN R_LFBNR
         AND   LFPOS IN R_LFPOS.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'History per Purchasing Document'
                      'EKBE' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKBE_INV
*&---------------------------------------------------------------------*
*&      Form  F_GET_RBKP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_RBKP .

  CHECK NOT I_EKBE_GI IS INITIAL.

  SELECT BELNR
         GJAHR
         FROM RBKP
         INTO TABLE I_RBKP
         FOR ALL ENTRIES IN I_EKBE_GI
         WHERE BELNR = I_EKBE_GI-BELNR
         AND   GJAHR = I_EKBE_GI-GJAHR.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Document Header: Invoice Receipt'
                      'RBKP' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_RBKP
*&---------------------------------------------------------------------*
*&      Form  F_GET_BKPF
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_BKPF .

  DATA: LI_EKKO TYPE STANDARD TABLE OF TYP_EKKO.

  CHECK NOT I_EKBE_GI IS INITIAL.

  APPEND LINES OF I_EKKO TO LI_EKKO.
  SORT LI_EKKO BY BUKRS.
  DELETE ADJACENT DUPLICATES FROM LI_EKKO
                  COMPARING BUKRS.
  R_BUKRS_LINE-SIGN   = C_I.
  R_BUKRS_LINE-OPTION = C_EQ.
  LOOP AT LI_EKKO INTO WA_EKKO.
    R_BUKRS_LINE-LOW = WA_EKKO-BUKRS.
    APPEND R_BUKRS_LINE TO R_BUKRS.
    CLEAR R_BUKRS_LINE-LOW.
  ENDLOOP.

  R_AWKEY_LINE-SIGN   = C_I.
  R_AWKEY_LINE-OPTION = C_EQ.
  LOOP AT I_EKBE_GI INTO WA_EKBE_GI.
    CONCATENATE WA_EKBE_GI-BELNR WA_EKBE_GI-GJAHR
                INTO R_AWKEY_LINE-LOW.
    APPEND R_AWKEY_LINE TO R_AWKEY.
    CLEAR R_AWKEY_LINE-LOW.
  ENDLOOP.

  SELECT BUKRS
         GJAHR
         CPUDT
         AWKEY
         KURSF
         WAERS
         HWAER FROM BKPF
         INTO TABLE I_BKPF
         FOR ALL ENTRIES IN I_EKBE_GI
         WHERE BUKRS IN R_BUKRS
         AND   GJAHR = I_EKBE_GI-GJAHR
         AND   CPUDT = I_EKBE_GI-CPUDT
         AND   AWKEY IN R_AWKEY.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Accounting Document Header'
                      'BKPF' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_BKPF
*&---------------------------------------------------------------------*
*&      Form  F_GET_DATA_3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_DATA_3 .

* DA021
  PERFORM F_GET_EKPV.
* DA022
  PERFORM F_GET_EKET_2.
* DA023
  PERFORM F_GET_EKPO_2.
* DA024
  PERFORM F_GET_T001L_2.

ENDFORM.                    " F_GET_DATA_3
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKPV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKPV .

  CHECK NOT I_EKBE_GI IS INITIAL.

  R_XBLNR_LINE-SIGN   = C_I.
  R_XBLNR_LINE-OPTION = C_EQ.
  LOOP AT I_EKBE_GI INTO WA_EKBE_GI.
    R_XBLNR_LINE-LOW = WA_EKBE_GI-XBLNR.
    APPEND R_XBLNR_LINE TO R_XBLNR.
  ENDLOOP.

  SELECT EBELN
         EBELP
         ABLAD FROM EKPV
         INTO TABLE I_EKPV
         WHERE ABLAD IN R_XBLNR.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Shipping Data For STO Document Item'
                      'EKPV' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKPV
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKET_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKET_2 .

  CHECK NOT I_EKPV IS INITIAL.

  SELECT EBELN
         EBELP
         EINDT
         WEMNG FROM EKET
         INTO TABLE I_EKET_2
         FOR ALL ENTRIES IN I_EKPV
         WHERE EBELN = I_EKPV-EBELN
         AND   EBELP = I_EKPV-EBELP.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Scheduling Agreement Schedule Lines'
                      'EKET' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKET_2
*&---------------------------------------------------------------------*
*&      Form  F_GET_EKPO_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_EKPO_2 .

  CHECK NOT I_EKPV IS INITIAL.

  SELECT EBELN
         EBELP
         WERKS
         LGORT FROM EKPO
         INTO CORRESPONDING FIELDS OF TABLE I_EKPO_2
         FOR ALL ENTRIES IN I_EKPV
         WHERE EBELN = I_EKPV-EBELN
         AND   EBELP = I_EKPV-EBELP.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'PURCHASE LINE ITEM'
                      'EKPO' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_EKPO_2
*&---------------------------------------------------------------------*
*&      Form  F_GET_T001L_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_GET_T001L_2 .

  DATA: LI_EKPO_2 TYPE STANDARD TABLE OF TYP_EKPO.

  CHECK NOT I_EKPO_2 IS INITIAL.
  APPEND LINES OF I_EKPO_2 TO LI_EKPO_2.
  SORT LI_EKPO_2 BY WERKS LGORT.
  DELETE ADJACENT DUPLICATES FROM LI_EKPO_2
                  COMPARING WERKS LGORT.
  SELECT WERKS
         LGORT
         LGOBE FROM T001L
         INTO TABLE I_T001L_2
         FOR ALL ENTRIES IN LI_EKPO_2
         WHERE WERKS = LI_EKPO_2-WERKS
         AND   LGORT = LI_EKPO_2-LGORT.
  IF SY-SUBRC <> 0.
    MESSAGE S040 DISPLAY LIKE C_E
                 WITH 'Storage Location Data'
                      'T001L' .
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " F_GET_T001L_2
*&---------------------------------------------------------------------*
*&      Form  F_SET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_SET_DATA .

  DATA : L_WEMNG TYPE TYP_EKET-WEMNG,
         L_MENGE TYPE TYP_EKBE_GI-MENGE,
         L_AWKEY TYPE TYP_BKPF-AWKEY.

  SORT I_EKET BY EINDT.

  LOOP AT I_EKPO INTO WA_EKPO.

    CLEAR WA_EKKO.
    READ TABLE I_EKKO INTO WA_EKKO
               WITH KEY EBELN = WA_EKPO-EBELN.
    IF SY-SUBRC = 0.
      WA_ALVOUT-EBELN = WA_EKKO-EBELN.
      WA_ALVOUT-BSART = WA_EKKO-BSART.
      WA_ALVOUT-ERNAM = WA_EKKO-ERNAM.
      WA_ALVOUT-LIFNR = WA_EKKO-LIFNR.
      WA_ALVOUT-WAERS = WA_EKKO-WAERS.
      WA_ALVOUT-AEDAT = WA_EKKO-AEDAT.
      WA_ALVOUT-EKGRP = WA_EKKO-EKGRP.
*     EKPO
      WA_ALVOUT-EBELP = WA_EKPO-EBELP.
      WA_ALVOUT-WERKS = WA_EKPO-WERKS.
      WA_ALVOUT-LGORT = WA_EKPO-LGORT.
      WA_ALVOUT-MATKL = WA_EKPO-MATKL.
      WA_ALVOUT-MATNR = WA_EKPO-MATNR.
      WA_ALVOUT-TXZ01 = WA_EKPO-TXZ01.
      WA_ALVOUT-MENGE = WA_EKPO-MENGE.
      WA_ALVOUT-ELIKZ = WA_EKPO-ELIKZ.
      WA_ALVOUT-MENGE1 = WA_EKPO-MENGE.
      WA_ALVOUT-NETPR = WA_EKPO-NETPR.
      WA_ALVOUT-PEINH = WA_EKPO-PEINH.
      WA_ALVOUT-NETWR = WA_EKPO-NETWR.
      WA_ALVOUT-INCO2 = WA_EKPO-INCO2.
    ENDIF.
    IF WA_EKPO-RETPO = C_X
      AND SY-LANGU = C_JP.
      WA_ALVOUT-RET_ITEM = C_RETURNJP.
    ELSEIF WA_EKPO-RETPO = C_X.
      WA_ALVOUT-RET_ITEM = C_RETURN.
    ENDIF.

    CLEAR: WA_EKET,
           L_WEMNG.
    LOOP AT I_EKET INTO WA_EKET
            WHERE EBELN = WA_EKPO-EBELN
            AND   EBELP = WA_EKPO-EBELP.
      L_WEMNG = L_WEMNG + WA_EKET-WEMNG.
    ENDLOOP.
    IF SY-SUBRC = 0.
      WA_ALVOUT-EINDT = WA_EKET-EINDT.
      WA_ALVOUT-WEMNG = L_WEMNG.
    ENDIF.

    CLEAR: WA_EKBE_GI,
           L_MENGE.
    LOOP AT I_EKBE_GI INTO WA_EKBE_GI
            WHERE EBELN = WA_EKPO-EBELN
            AND   EBELP = WA_EKPO-EBELP.
      L_MENGE = L_MENGE + WA_EKBE_GI-MENGE.
    ENDLOOP.
    IF SY-SUBRC = 0.
      WA_ALVOUT-BUDAT_GR  = WA_EKBE_GI-BUDAT.
      IF WA_EKBE_GI-SHKZG = C_H.
        L_MENGE = L_MENGE * -1.
      ENDIF.
      WA_ALVOUT-MENGE_REC = L_MENGE.
      WA_ALVOUT-BUDAT_INV = WA_EKBE_GI-BUDAT.
*      WA_ALVOUT-WRBTR     = WA_EKBE_GI-WRBTR.
*      WA_ALVOUT-WAERS_INV = WA_EKBE_GI-WAERS.
      WA_ALVOUT-BELNR_GR  = WA_EKBE_GI-BELNR.
      WA_ALVOUT-XBLNR     = WA_EKBE_GI-XBLNR.
    ENDIF.

    CLEAR: WA_EKBE_INV.
    READ TABLE I_EKBE_INV INTO WA_EKBE_INV
            WITH KEY EBELN = WA_EKPO-EBELN
                     EBELP = WA_EKPO-EBELP
                     LFGJA = WA_EKBE_GI-GJAHR
                     LFBNR = WA_EKBE_GI-BELNR
                     LFPOS = WA_EKBE_GI-BUZEI.
    IF SY-SUBRC = 0.
      WA_ALVOUT-BUDAT_INV = WA_EKBE_INV-BUDAT.
      WA_ALVOUT-WRBTR     = WA_EKBE_INV-WRBTR.
      WA_ALVOUT-WAERS_INV = WA_EKBE_INV-WAERS.
    ENDIF.

    CLEAR WA_RBKP.
    READ TABLE I_RBKP INTO WA_RBKP
               WITH KEY BELNR = WA_EKBE_GI-BELNR
                        GJAHR = WA_EKBE_GI-GJAHR.
    IF SY-SUBRC = 0.
      CONTINUE.
    ENDIF.

    CONCATENATE WA_EKBE_GI-BELNR WA_EKBE_GI-GJAHR
                INTO L_AWKEY.
    CLEAR WA_BKPF.
    READ TABLE I_BKPF INTO WA_BKPF
               WITH KEY BUKRS = WA_EKKO-BUKRS
                        GJAHR = WA_EKBE_GI-GJAHR
                        CPUDT = WA_EKBE_GI-CPUDT
                        AWKEY = L_AWKEY.
    IF SY-SUBRC = 0.

    ENDIF.



  ENDLOOP.

ENDFORM.                    " F_SET_DATA
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_DISPLAY_ALV .

* FIELDCATLOG CREATION
  PERFORM F_CREATE_FCAT.
* ALV DISPLAY
  PERFORM F_ALV_OUT.

ENDFORM.                    " F_DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  F_CREATE_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_CREATE_FCAT .

  DEFINE FIELDCAT.
    WA_FCAT-FIELDNAME = &1.
    WA_FCAT-TABNAME   = &2.
    WA_FCAT-SELTEXT_L = &3.
*    WA_FCAT-NO_OUT    = &4.
    WA_FCAT-COL_POS   = &4.
    APPEND WA_FCAT TO I_FCAT.
    CLEAR WA_FCAT.
  END-OF-DEFINITION.
  FIELDCAT : 'WERKS'         'I_ALVOUT' TEXT-001 '1',
             'WERKS_TXT'  'I_ALVOUT' TEXT-002 '2',
             'LGORT'      'I_ALVOUT' TEXT-003 '3',
             'LGOBE'      'I_ALVOUT' TEXT-004 '4',
             'MATKL'      'I_ALVOUT' TEXT-005 '5',
             'WGBEZ'      'I_ALVOUT' TEXT-006 '6',
             'ERNAM'      'I_ALVOUT' TEXT-007 '7',
             'NAME_TEXT'  'I_ALVOUT' TEXT-008 '8',
             'LIFNR'      'I_ALVOUT' TEXT-009 '9',
             'LIFNR_TXT'  'I_ALVOUT' TEXT-010 '10',
             'MATNR'      'I_ALVOUT' TEXT-011 '11',
             'TXZ01'      'I_ALVOUT' TEXT-012 '12',
             'EBELN'      'I_ALVOUT' TEXT-013 '13',
             'EBELP'      'I_ALVOUT' TEXT-014 '14',
             'RET_ITEM'   'I_ALVOUT' TEXT-015 '15',
             'MENGE'      'I_ALVOUT' TEXT-016 '16',
             'EINDT'      'I_ALVOUT' TEXT-017 '17',
             'ELIKZ'      'I_ALVOUT' TEXT-018 '18',
             'MENGE1'     'I_ALVOUT' TEXT-019 '19',
             'WEMNG'      'I_ALVOUT' TEXT-020 '20',
             'OPENPO_QTY' 'I_ALVOUT' TEXT-021 '21',
             'NETPR'      'I_ALVOUT' TEXT-022 '22',
             'PEINH'      'I_ALVOUT' TEXT-023 '23',
             'NETWR'      'I_ALVOUT' TEXT-024 '24',
             'WAERS'      'I_ALVOUT' TEXT-025 '25',
             'INCO2'      'I_ALVOUT' TEXT-026 '26',
             'AEDAT'      'I_ALVOUT' TEXT-027 '27',
             'BUDAT_GR'   'I_ALVOUT' TEXT-028 '28',
             'MENGE_REC'  'I_ALVOUT' TEXT-029 '29',
             'BUDAT_INV'  'I_ALVOUT' TEXT-030 '30',
             'WRBTR'      'I_ALVOUT' TEXT-031 '31',
             'WAERS_INV'  'I_ALVOUT' TEXT-032 '32',
             'BELNR_GR'   'I_ALVOUT' TEXT-033 '33',
             'BELNR_INV'  'I_ALVOUT' TEXT-034 '34',
             'XBLNR'      'I_ALVOUT' TEXT-035 '35',
             'STOCK_ORDER' 'I_ALVOUT' TEXT-036 '36',
             'TR_DAT'     'I_ALVOUT' TEXT-037 '37',
             'TR_LOCATION' 'I_ALVOUT' TEXT-038 '38',
             'GA_QTY'     'I_ALVOUT' TEXT-039 '39',
             'OPENTR_QTY' 'I_ALVOUT' TEXT-040 '40',
             'BSART'      'I_ALVOUT' TEXT-041 '41',
             'BATXT'      'I_ALVOUT' TEXT-042 '42',
             'EKGRP'      'I_ALVOUT' TEXT-043 '43',
             'EKGRP_NAME' 'I_ALVOUT' TEXT-044 '44',
             'MEINS'      'I_ALVOUT' TEXT-045 '45',
             'MSEHT'      'I_ALVOUT' TEXT-046 '46',
             'BISMT'      'I_ALVOUT' TEXT-047 '47',
             'MFRPN'      'I_ALVOUT' TEXT-048 '48',
             'MTART'      'I_ALVOUT' TEXT-049 '49',
             'MTBEZ'      'I_ALVOUT' TEXT-050 '50'.
ENDFORM.                    " F_CREATE_FCAT
*&---------------------------------------------------------------------*
*&      Form  F_ALV_OUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_ALV_OUT .

  WA_LAYOUT-COLWIDTH_OPTIMIZE = C_X.

* ALV DISPLAY
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      IS_LAYOUT     = WA_LAYOUT
      IT_FIELDCAT   = I_FCAT
      I_SAVE        = 'X'
    TABLES
      T_OUTTAB      = I_ALVOUT
    EXCEPTIONS
      PROGRAM_ERROR = 1
      OTHERS        = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " F_ALV_OUT

2 comments: