Register Login

PO ALV Interactive Report

Updated May 18, 2018

TYPE-POOLS SLIS.
TABLES:EKKO,"PURCHASE DOCUMENT HEADER
       EKPO,"PURCHASE DOCUMENT ITEM
       EKBE."PURCHASE DOCUMENT HISTORY
**************************************END OF TABLES DECLARATION*****************************************************



*******************************************TYPES DECLARATION*****************************************************
                           "TYPES DECLARATION FOR THE PURCHASE DOCUMENT HEADER
TYPES: BEGIN OF TY_EKKO,
       EBELN TYPE EBELN,"PURCHASE ORDER NO
       AEDAT TYPE ERDAT,"PURCHASE ORDER DATE
       END OF TY_EKKO.

                           "TYPES DECLARATION OF THE PURCHASE DOCUMENT HISTORY
TYPES: BEGIN OF TY_EKBE,
       EBELN TYPE EBELN,"PURCHASE ORDER NO
       WESBS TYPE WESBS,"GOODS RECEIPT
       BWART TYPE BWART,"MOVEMENT TYPE
       BELNR TYPE MBLNR,"MATERIAL DOC NUMBER
       BUDAT TYPE BUDAT,"POSTING DATE
       MENGE TYPE MENGE_D,"QUANTITY
       LSMNG TYPE LSMNG,"BASIC UNIT OF MEASURE
       END OF TY_EKBE.
                              "TYPES DECLARATION OF THE PURCHASE DOCUMENT ITEM
TYPES: BEGIN OF TY_EKPO,
       EBELN TYPE EBELN,         "  Purchasing Document Number
       EBELP TYPE EBELP,         "  Item Number of Purchasing Document
       MENGE TYPE BSTMG,         "  Purchase Order Quantity
       TXZ01 TYPE TXZ01,         "  Short Text
       END OF TY_EKPO.


TYPES : BEGIN OF TY_BASIC,
        EBELN TYPE EBELN,         "  Purchasing Document Number
        EBELP TYPE EBELP,         "  Item Number of Purchasing Document
       WESBS TYPE WESBS,         "GOODS RECEIPT
       BWART TYPE BWART,         "MOVEMENT TYPE
       BELNR TYPE MBLNR,         "MATERIAL DOC NUMBER
       BUDAT TYPE BUDAT,         "POSTING DATE
       MENGE TYPE MENGE_D,       "QUANTITY
       LSMNG TYPE LSMNG,         "BASIC UNIT OF MEASURE
       END OF TY_BASIC.


****************************************end of types declaration***********************************************
DATA : IS_FCAT TYPE SLIS_FIELDCAT_ALV,
       IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
       IS_FCAT1 TYPE SLIS_FIELDCAT_ALV,
       IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV.
*******************************************STRUCUTURE DECLARATION*************************************************

DATA:IS_EKPO TYPE TY_EKPO,      "STRUCURE DECLARATION FOR PURCHASE ORDER HEADER
     IS_EKKO TYPE TY_EKKO,     "STRUCURE DECLARATION FOR PURCHASE ORDER ITEM
     IS_EKBE TYPE TY_EKBE,      "STRUCURE DECLARATION FOR PURCHASE ORDER HISTORY
     IS_BASIC TYPE TY_BASIC.
    

****************************************END OF STRUCUTRE DECLARATION***********************************************

***************************************INTERNAL TABLE DECLARATION***************************************************

DATA: IT_EKPO TYPE STANDARD TABLE OF TY_EKPO,
      IT_EKKO TYPE STANDARD TABLE OF TY_EKKO,
      IT_EKBE TYPE STANDARD TABLE OF TY_EKBE,
      IT_BASIC TYPE STANDARD TABLE OF TY_BASIC.
     


*************************************END OF INTERNAL TABLE DECLARATION*******************************************

*************************************SELECTION SCREEN DECLARATION**********************************************
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:  S_EBELN FOR EKKO-EBELN,
                 S_BEDAT FOR EKKO-BEDAT  .
SELECTION-SCREEN: END OF BLOCK B1.

PERFORM F_FETCH_DATA.
PERFORM F_FIELD_CAT.
PERFORM F_DISPLAY.

*&---------------------------------------------------------------------*
*&      Form  F_FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*


FORM F_FETCH_DATA .
SELECT EBELN FROM EKKO INTO TABLE IT_EKKO
      WHERE EBELN IN S_EBELN AND
            BEDAT IN S_BEDAT.

      IF IT_EKKO[] IS NOT INITIAL.
        SELECT EBELN EBELP MENGE TXZ01 FROM EKPO INTO TABLE
                      IT_EKPO
          FOR ALL ENTRIES IN IT_EKKO WHERE EBELN = IT_EKKO-EBELN.
      ENDIF.

      ENDFORM.


    FORM F_FIELD_CAT.

    IS_FCAT-FIELDNAME = 'EBELN'.
    IS_FCAT-TABNAME = 'IT_FCAT'.
    IS_FCAT-COL_POS = 1.
    IS_FCAT-SELTEXT_M = 'Purchasing Number'.
*    IS_FCAT-EMPHASIZE = 'C510'.
    APPEND IS_FCAT TO IT_FCAT.
    CLEAR IS_FCAT.

    IS_FCAT-FIELDNAME = 'EBELP'.
    IS_FCAT-TABNAME = 'IT_FCAT'.
    IS_FCAT-COL_POS = 2.
    IS_FCAT-SELTEXT_M = 'Item Number'.
*    IS_FCAT-EMPHASIZE = 'C610'.
    APPEND IS_FCAT TO IT_FCAT.
    CLEAR IS_FCAT.

    IS_FCAT-FIELDNAME = 'TXZ01'.
    IS_FCAT-TABNAME = 'IT_FCAT'.
    IS_FCAT-COL_POS = 3.
    IS_FCAT-SELTEXT_M = 'Short text'.
*    IS_FCAT-EMPHASIZE = 'C401'.
    APPEND IS_FCAT TO IT_FCAT.
    CLEAR IS_FCAT.


    IS_FCAT-FIELDNAME = 'MENGE'.
    IS_FCAT-TABNAME = 'IT_FCAT'.
    IS_FCAT-COL_POS = 4.
    IS_FCAT-SELTEXT_M = 'Quantity'.
*    IS_FCAT-EMPHASIZE = 'C201'.
    APPEND IS_FCAT TO IT_FCAT.
    CLEAR IS_FCAT.

    ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                = 'ZBC2_TRG05_PRG16'
*   I_CALLBACK_PF_STATUS_SET          = ' '
   I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
   IT_FIELDCAT                       = IT_FCAT[]
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          = IT_EKPO[]
* 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_DISPLAY

FORM USER_COMMAND USING  UCOMMAND LIKE SY-UCOMM USER_FIELD TYPE SLIS_SELFIELD.
  DATA D_EBELN TYPE EKKO-EBELN.
  D_EBELN = USER_FIELD-VALUE.

  IF IT_EKKO[] IS NOT INITIAL.
        SELECT EBELN EBELP MENGE TXZ01 FROM EKPO INTO TABLE
         IT_EKPO FOR ALL ENTRIES IN IT_EKKO WHERE EBELN = IT_EKKO-EBELN.
      ENDIF.

      IF IT_EKKO[] IS NOT INITIAL.
        SELECT EBELN WESBS BWART BELNR BUDAT MENGE LSMNG FROM EKBE
          INTO TABLE IT_EKBE FOR ALL ENTRIES IN IT_EKPO
          WHERE EBELN = IT_EKPO-EBELN AND
                EBELP = IT_EKPO-EBELP.
      ENDIF.
     LOOP AT IT_EKPO INTO IS_EKPO WHERE EBELN = D_EBELN.


  IS_BASIC-EBELN = IS_EKPO-EBELN.
        IS_BASIC-EBELP = IS_EKPO-EBELP.
        IS_BASIC-TXZ01 = IS_EKPO-TXZ01.
        IF SY-SUBRC = 0.

        READ TABLE IT_EKBE INTO IS_EKBE WITH KEY EBELN = IS_EKPO-EBELN.

      IS_BASIC-WESBS = IS_EKBE-WESBS.
      IS_BASIC-BWART = IS_EKBE-BWART.
      IS_BASIC-BELNR = IS_EKBE-BELNR.
      IS_BASIC-BUDAT = IS_EKBE-BUDAT.
      IS_BASIC-MENGE = IS_EKBE-MENGE.
      IS_BASIC-LSMNG = IS_EKBE-LSMNG.

        APPEND IS_BASIC TO IT_BASIC.
        CLEAR : IS_BASIC.
        ENDIF.
      ENDLOOP.
      CLEAR D_EBELN.

*&---------------------------------------------------------------------*
*&      Form  D_FIELD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
*FORM D_FIELD_CAT .

   IS_FCAT1-FIELDNAME = 'EBELN'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 1.
    IS_FCAT1-SELTEXT_M = 'Purchasing Number'.
*    IS_FCAT-EMPHASIZE = 'C510'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'EBELP'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 2.
    IS_FCAT1-SELTEXT_M = 'Item Number'.
*    IS_FCAT-EMPHASIZE = 'C610'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'TXZ01'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 3.
    IS_FCAT1-SELTEXT_M = 'Short text'.
*    IS_FCAT-EMPHASIZE = 'C401'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'WESBS'.
    IS_FCAT1-TABNAME = 'IT_FCAT'.
    IS_FCAT1-COL_POS = 4.
    IS_FCAT1-SELTEXT_M = 'Goos Receipt'.
*    IS_FCAT-EMPHASIZE = 'C510'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'BWART'.
    IS_FCAT1-TABNAME = 'IT_FCAT11'.
    IS_FCAT1-COL_POS = 5.
    IS_FCAT1-SELTEXT_M = 'Movement Type'.
*    IS_FCAT-EMPHASIZE = 'C610'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'BELNR'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 6.
    IS_FCAT1-SELTEXT_M = 'Mat Doc No'.
*    IS_FCAT-EMPHASIZE = 'C610'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'BUDAT'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 7.
    IS_FCAT1-SELTEXT_M = 'Posting Date'.
*    IS_FCAT-EMPHASIZE = 'C610'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.

    IS_FCAT1-FIELDNAME = 'MENGE'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 8.
    IS_FCAT1-SELTEXT_M = 'Quantity'.
*    IS_FCAT-EMPHASIZE = 'C201'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT.

     IS_FCAT1-FIELDNAME = 'LSMNG'.
    IS_FCAT1-TABNAME = 'IT_FCAT1'.
    IS_FCAT1-COL_POS = 9.
    IS_FCAT1-SELTEXT_M = 'Unit'.
*    IS_FCAT-EMPHASIZE = 'C310'.
    APPEND IS_FCAT1 TO IT_FCAT1.
    CLEAR IS_FCAT1.
*ENDFORM.                    " D_FIELD_CAT
*&---------------------------------------------------------------------*
*&      Form  D_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
*FORM D_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                = 'ZBC2_TRG05_PRG16'
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
   IT_FIELDCAT                       = IT_FCAT1[]
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          = IT_BASIC[]
* 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.
REFRESH :IT_BASIC,IT_FCAT1.

ENDFORM.                    " D_DISPLAY
 


×