Tuesday, 30 April 2013

ALV BLOCK LIST REPORT


*&---------------------------------------------------------------------*
*& Report  ZR_ALV_INETR_PO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_ALV_BLOCK_LIST.

TABLESEKKOEKPO,LFA1.
TYPE-POOLSSLIS.
TYPESBEGIN OF ST_EKKO,
     EBELN TYPE EKKO-EBELN,
     BUKRS TYPE EKKO-BUKRS,
     BSTYP TYPE EKKO-BSTYP,
     BSART TYPE EKKO-BSART,
     LIFNR TYPE EKKO-LIFNR,
     ERNAM TYPE EKKO-ERNAM,
     AEDAT TYPE EKKO-BEDAT,
      END OF ST_EKKO.

TYPESBEGIN OF ST_EKPO,
      EBELN TYPE EKPO-EBELN,
      EBELP TYPE EKPO-EBELP,
      MATNR TYPE EKPO-MATNR,
      MENGE TYPE EKPO-MENGE,
      NETPR TYPE EKPO-NETPR,
  END OF ST_EKPO.

DATAIT_EKKO TYPE TABLE OF ST_EKKO,
      IT_EKPO TYPE TABLE OF ST_EKPO,
      WA_EKKO TYPE ST_EKKO,
      WA_EKPO TYPE ST_EKPO.

DATAIT_FC1 TYPE SLIS_T_FIELDCAT_ALV,
      IT_FC2 TYPE SLIS_T_FIELDCAT_ALV,
      WA_FC1 TYPE SLIS_FIELDCAT_ALV,
      WA_FC2 TYPE SLIS_FIELDCAT_ALV.

DATAIT_EVENT TYPE SLIS_T_EVENT,
      V_TABNAME TYPE SLIS_TABNAME,
      S_LAYOUT TYPE SLIS_LAYOUT_ALV.


SELECT-OPTIONSS_EBELN FOR EKPO-EBELN.

PERFORM GETDATA.
PERFORM FIELDCAT1.
PERFORM FIELDCAT2.
PERFORM DISPLAY.

FORM GETDATA.
  SELECT EBELN EBELP MATNR MENGE NETPR FROM EKPO INTO TABLE IT_EKPO WHERE EBELN IN S_EBELN.
    SELECT EBELN BUKRS BSTYP BSART ERNAM AEDAT FROM EKKO INTO CORRESPONDING FIELDS OF TABLE IT_EKKO WHERE EBELN IN S_EBELN.
ENDFORM.

FORM FIELDCAT1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELN'.
  WA_FC1-SELTEXT_S 'PO DOC NO'.
  WA_FC1-COL_POS 1.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELP'.
  WA_FC1-SELTEXT_S 'PO DOC ITEM'.
  WA_FC1-COL_POS 2.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MATNR'.
  WA_FC1-SELTEXT_S 'MATERIAL NO'.
  WA_FC1-COL_POS 3.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MENGE'.
  WA_FC1-SELTEXT_S 'QUANTITY'.
  WA_FC1-COL_POS 4.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'NETPR'.
  WA_FC1-SELTEXT_S 'NET PRICE'.
  WA_FC1-COL_POS 5.
  APPEND WA_FC1 TO IT_FC1.

ENDFORM.


FORM FIELDCAT2.
  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'EBELN'.
  WA_FC2-SELTEXT_S 'PO DOC NO'.
  WA_FC2-COL_POS 1.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUKRS'.
  WA_FC2-SELTEXT_S 'COMPANY CODE'.
  WA_FC2-COL_POS 2.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUTYP'.
  WA_FC2-SELTEXT_S 'PO DOC CAT'.
  WA_FC2-COL_POS 3.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BSART'.
  WA_FC2-SELTEXT_S 'PO DOC TYPE'.
  WA_FC2-COL_POS 4.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
ENDFORM.

FORM DISPLAY.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             SY-REPID
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =
          .


V_TABNAME 'ITAB1'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        S_LAYOUT
    IT_FIELDCAT                      IT_FC1
    I_TABNAME                        V_TABNAME
    IT_EVENTS                        IT_EVENT
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_EKPO
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

V_TABNAME 'ITAB2'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        S_LAYOUT
    IT_FIELDCAT                      IT_FC2
    I_TABNAME                        V_TABNAME
    IT_EVENTS                        IT_EVENT
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_EKKO
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* 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.


RESULT:


ALV POPUP DISPLAY REPO

*&---------------------------------------------------------------------*
*& Report  ZR_ALV_POPUP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_ALV_POPUP.
TABLESVBAP.
TYPE-POOLSSLIS.

DATABEGIN OF IT_VBAP OCCURS 10,
     VBELN TYPE VBAP-VBELN,
     POSNR TYPE VBAP-VBELN,
     END OF IT_VBAP.
DATAFC TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

PARAMETERSP_VBELN TYPE VBAP-VBELN.

SELECT FROM VBAP INTO CORRESPONDING FIELDS OF TABLE IT_VBAP WHERE VBELN P_VBELN.

PERFORM FIELDCAT.
PERFORM DISPLAY.

*&---------------------------------------------------------------------*
*&      Form  fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FIELDCAT.

  FC-FIELDNAME 'VBELN'.
  FC-SELTEXT_L 'salse doc no'.
  APPEND FC.
  CLEAR FC.

  FC-FIELDNAME 'POSNR'.
  FC-SELTEXT_L 'salse doc ITEM'.
  APPEND FC.
  CLEAR FC.

ENDFORM.                    "fieldcat

*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM DISPLAY.
  CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
    EXPORTING
*     I_TITLE                       =
*     I_SELECTION                   = 'X'
*     I_ALLOW_NO_SELECTION          =
     I_ZEBRA                       'X'
*     I_SCREEN_START_COLUMN         = 0
*     I_SCREEN_START_LINE           = 0
*     I_SCREEN_END_COLUMN           = 0
*     I_SCREEN_END_LINE             = 0
*     I_CHECKBOX_FIELDNAME          =
*     I_LINEMARK_FIELDNAME          =
*     I_SCROLL_TO_SEL_LINE          = 'X'
      I_TABNAME                     'IT_VBAP'
*     I_STRUCTURE_NAME              =
     IT_FIELDCAT                   FC[]
*     IT_EXCLUDING                  =
*     I_CALLBACK_PROGRAM            =
*     I_CALLBACK_USER_COMMAND       =
*     IS_PRIVATE                    =
*   IMPORTING
*     ES_SELFIELD                   =
*     E_EXIT                        =
    TABLES
      T_OUTTAB                      IT_VBAP
*   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.                    "DISPLAY


RESULT:



Friday, 26 April 2013

ALV Interactive report 3 list

                       
*&---------------------------------------------------------------------*
*& Report  ZR_ALV_INETR_PO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_ALV_INETR_PO_3LIST.

TABLESEKKOEKPO,LFA1.
TYPE-POOLSSLIS.
TYPESBEGIN OF ST_EKKO,
     EBELN TYPE EKKO-EBELN,
     BUKRS TYPE EKKO-BUKRS,
     BSTYP TYPE EKKO-BSTYP,
     BSART TYPE EKKO-BSART,
     LIFNR TYPE EKKO-LIFNR,
     ERNAM TYPE EKKO-ERNAM,
     AEDAT TYPE EKKO-BEDAT,
      END OF ST_EKKO.

TYPESBEGIN OF ST_EKPO,
      EBELN TYPE EKPO-EBELN,
      EBELP TYPE EKPO-EBELP,
      MATNR TYPE EKPO-MATNR,
      MENGE TYPE EKPO-MENGE,
      NETPR TYPE EKPO-NETPR,
  END OF ST_EKPO.

DATAIT_EKKO TYPE TABLE OF ST_EKKO,
      IT_EKPO TYPE TABLE OF ST_EKPO,
      WA_EKKO TYPE ST_EKKO,
      WA_EKPO TYPE ST_EKPO.

DATAIT_FC1 TYPE SLIS_T_FIELDCAT_ALV,
      IT_FC2 TYPE SLIS_T_FIELDCAT_ALV,
      WA_FC1 TYPE SLIS_FIELDCAT_ALV,
      WA_FC2 TYPE SLIS_FIELDCAT_ALV.

DATAIT_LH1 TYPE SLIS_T_LISTHEADER,
      IT_LH2 TYPE SLIS_T_LISTHEADER,
      WA_LH1 TYPE SLIS_LISTHEADER,
      WA_LH2 TYPE SLIS_LISTHEADER,
      LINE TYPE I,
      LINE1(10TYPE C,
      T_LINE LIKE WA_LH1-INFO.

SELECT-OPTIONSS_EBELN FOR EKPO-EBELN.

PERFORM GETDATA1.
PERFORM FIELDCAT1.
PERFORM DISPLAY1.

FORM GETDATA1.
  SELECT EBELN EBELP MATNR MENGE NETPR FROM EKPO INTO TABLE IT_EKPO WHERE EBELN IN S_EBELN.
ENDFORM.

FORM FIELDCAT1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELN'.
  WA_FC1-SELTEXT_S 'PO DOC NO'.
  WA_FC1-COL_POS 1.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELP'.
  WA_FC1-SELTEXT_S 'PO DOC ITEM'.
  WA_FC1-COL_POS 2.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MATNR'.
  WA_FC1-SELTEXT_S 'MATERIAL NO'.
  WA_FC1-COL_POS 3.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MENGE'.
  WA_FC1-SELTEXT_S 'QUANTITY'.
  WA_FC1-COL_POS 4.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'NETPR'.
  WA_FC1-SELTEXT_S 'NET PRICE'.
  WA_FC1-COL_POS 5.
  APPEND WA_FC1 TO IT_FC1.

ENDFORM.

FORM TOP_OF_PAGE1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'H'.
  WA_LH1-INFO 'PURCHASE ORDER ITEM DATA'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'S'.
  WA_LH1-KEY 'DATE:'.
  CONCATENATE SY-DATUM+6(2SY-DATUM+4(2SY-DATUM(4INTO WA_LH1-INFO SEPARATED BY '/'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  DESCRIBE TABLE IT_EKPO LINES LINE.
  LINE1 LINE.
  CONCATENATE 'TOTAL NO OF RECORD SELECTED' LINE1 INTO T_LINE SEPARATED BY SPACE.
  WA_LH1-TYP 'A'.
  WA_LH1-INFO T_LINE.
  APPEND WA_LH1 TO IT_LH1.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY       IT_LH1.

REFRESH IT_LH1.
CLEARWA_LH1.
ENDFORM.

FORM DISPLAY1.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
     I_CALLBACK_PROGRAM                SY-REPID
     I_CALLBACK_USER_COMMAND           'USER_COMMAND'
     I_CALLBACK_TOP_OF_PAGE            'TOP_OF_PAGE1'
     I_BACKGROUND_ID                   'ALV_BACKGROUND'
     IT_FIELDCAT                       IT_FC1
    TABLES
      T_OUTTAB                          IT_EKPO .
ENDFORM.

form  USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELF TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN '&IC1'.
      READ TABLE IT_EKPO INTO WA_EKPO INDEX RS_SELF-TABINDEX.
      PERFORM FIELDCAT2.
      PERFORM GETDATA2.
      PERFORM DISPLAY2.
  ENDCASE.
ENDFORM.

FORM GETDATA2.
  SELECT EBELN BUKRS BSTYP BSART ERNAM AEDAT FROM EKKO INTO CORRESPONDING FIELDS OF TABLE IT_EKKO WHERE EBELN WA_EKPO-EBELN.
ENDFORM.

FORM FIELDCAT2.
  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'EBELN'.
  WA_FC2-SELTEXT_S 'PO DOC NO'.
  WA_FC2-COL_POS 1.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUKRS'.
  WA_FC2-SELTEXT_S 'COMPANY CODE'.
  WA_FC2-COL_POS 2.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUTYP'.
  WA_FC2-SELTEXT_S 'PO DOC CAT'.
  WA_FC2-COL_POS 3.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BSART'.
  WA_FC2-SELTEXT_S 'PO DOC TYPE'.
  WA_FC2-COL_POS 4.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
ENDFORM.

FORM DISPLAY2.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                SY-REPID
   I_CALLBACK_USER_COMMAND           'USER_COMMAND2'
   I_CALLBACK_TOP_OF_PAGE            'TOP_OF_PAGE2'
   IT_FIELDCAT                       IT_FC2
  TABLES
    T_OUTTAB                          IT_EKKO.

CLEARWA_FC2.
REFRESH IT_FC2.
ENDFORM.

FORM TOP_OF_PAGE2.

  CLEAR WA_LH1.
  WA_LH1-TYP 'H'.
  WA_LH1-INFO 'PURCHASE ORDER HEADER DATA'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'S'.
  WA_LH1-KEY 'DATE:'.
  CONCATENATE SY-DATUM+6(2SY-DATUM+4(2SY-DATUM(4INTO WA_LH1-INFO SEPARATED BY '/'.
  APPEND WA_LH1 TO IT_LH1.

  CLEARWA_LH1,LINE,LINE1,T_LINE.
  DESCRIBE TABLE IT_EKKO LINES LINE.
  LINE1 LINE.
  CONCATENATE 'TOTAL NO OF RECORD SELECTED' LINE1 INTO T_LINE SEPARATED BY SPACE.
  WA_LH1-TYP 'A'.
  WA_LH1-INFO T_LINE.
  APPEND WA_LH1 TO IT_LH1.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY       IT_LH1.

REFRESH IT_LH1.
CLEARWA_LH1.
ENDFORM.

FORM USER_COMMAND2 USING R_UCOMM2 LIKE SY-UCOMM RS_SELF2 TYPE SLIS_SELFIELD.
  READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELF2-TABINDEX.

  PERFORM FIELDCAT3.
  PERFORM DISPLAY3.

ENDFORM.

FORM FIELDCAT3.
CLEARWA_FC2,IT_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'ERNAM'.
  WA_FC2-SELTEXT_S 'ENTER BY NAME'.
  WA_FC2-COL_POS 1.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'AEDAT'.
  WA_FC2-SELTEXT_S 'CREATED DATE'.
  WA_FC2-COL_POS 2.
  APPEND WA_FC2 TO IT_FC2.

ENDFORM.

FORM DISPLAY3.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     I_GRID_TITLE                      'VENDER DETAILS'
     IT_FIELDCAT                       IT_FC2
   TABLES
     T_OUTTAB                          IT_EKKO
            .
    CLEARWA_FC2.
  REFRESH IT_FC2.
ENDFORM.

RESULT:

  Basic list
 Secondary list 1
Secondary list 2

ALV INTERACTIVE REPORT WITH HEADER

  PURCHASE ORDER ALV
*&---------------------------------------------------------------------*
*& Report  ZR_ALV_INETR_PO
*&
*&---------------------------------------------------------------------*
*&  PURCHASE ORDER ALV REPORT
*&
*&---------------------------------------------------------------------*

REPORT  ZR_ALV_INETR_PO.

TABLESEKKOEKPO,LFA1.
TYPE-POOLSSLIS.
TYPESBEGIN OF ST_EKKO,
               EBELN TYPE EKKO-EBELN,
               BUKRS TYPE EKKO-BUKRS,
               BSTYP TYPE EKKO-BSTYP,
               BSART TYPE EKKO-BSART,
             END OF ST_EKKO.

TYPESBEGIN OF ST_EKPO,
               EBELN TYPE EKPO-EBELN,
               EBELP TYPE EKPO-EBELP,
               MATNR TYPE EKPO-MATNR,
               MENGE TYPE EKPO-MENGE,
               NETPR TYPE EKPO-NETPR,
             END OF ST_EKPO.

DATAIT_EKKO TYPE TABLE OF ST_EKKO,
            IT_EKPO TYPE TABLE OF ST_EKPO,
            WA_EKKO TYPE ST_EKKO,
            WA_EKPO TYPE ST_EKPO.

DATAIT_FC1 TYPE SLIS_T_FIELDCAT_ALV,
            IT_FC2 TYPE SLIS_T_FIELDCAT_ALV,
           WA_FC1 TYPE SLIS_FIELDCAT_ALV,
           WA_FC2 TYPE SLIS_FIELDCAT_ALV.

DATAIT_LH1 TYPE SLIS_T_LISTHEADER,
            IT_LH2 TYPE SLIS_T_LISTHEADER,
           WA_LH1 TYPE SLIS_LISTHEADER,
           WA_LH2 TYPE SLIS_LISTHEADER,
           LINE TYPE I,
           LINE1(10TYPE C,
          T_LINE LIKE WA_LH1-INFO.

SELECT-OPTIONSS_EBELN FOR EKPO-EBELN.

PERFORM GETDATA1.
PERFORM FIELDCAT1.
*PERFORM HEADER1.
PERFORM DISPLAY1.

FORM GETDATA1.
  SELECT EBELN EBELP MATNR MENGE NETPR FROM EKPO INTO TABLE IT_EKPO WHERE EBELN IN S_EBELN.
ENDFORM.

FORM FIELDCAT1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELN'.
  WA_FC1-SELTEXT_S 'PO DOC NO'.
  WA_FC1-COL_POS 1.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'EBELP'.
  WA_FC1-SELTEXT_S 'PO DOC ITEM'.
  WA_FC1-COL_POS 2.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MATNR'.
  WA_FC1-SELTEXT_S 'MATERIAL NO'.
  WA_FC1-COL_POS 3.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'MENGE'.
  WA_FC1-SELTEXT_S 'QUANTITY'.
  WA_FC1-COL_POS 4.
  APPEND WA_FC1 TO IT_FC1.

  CLEARWA_FC1.
  WA_FC1-TABNAME 'IT_EKPO'.
  WA_FC1-FIELDNAME 'NETPR'.
  WA_FC1-SELTEXT_S 'NET PRICE'.
  WA_FC1-COL_POS 5.
  APPEND WA_FC1 TO IT_FC1.

ENDFORM.

FORM TOP_OF_PAGE1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'H'.
  WA_LH1-INFO 'PURCHASE ORDER ITEM DATA'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'S'.
  WA_LH1-KEY 'DATE:'.
  CONCATENATE SY-DATUM+6(2SY-DATUM+4(2SY-DATUM(4INTO WA_LH1-INFO SEPARATED BY '/'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  DESCRIBE TABLE IT_EKPO LINES LINE.
  LINE1 LINE.
  CONCATENATE 'TOTAL NO OF RECORD SELECTED' LINE1 INTO T_LINE SEPARATED BY SPACE.
  WA_LH1-TYP 'A'.
  WA_LH1-INFO T_LINE.
  APPEND WA_LH1 TO IT_LH1.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY       IT_LH1
     I_LOGO                   'MAPPLE LOGO'
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .

REFRESH IT_LH1.
CLEARWA_LH1.
ENDFORM.

FORM DISPLAY1.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     I_CALLBACK_PROGRAM                SY-REPID
*     I_CALLBACK_PF_STATUS_SET          = ' '
     I_CALLBACK_USER_COMMAND           'USER_COMMAND'
     I_CALLBACK_TOP_OF_PAGE            'TOP_OF_PAGE1'
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
     I_BACKGROUND_ID                   'ALV_BACKGROUND'
*     I_GRID_TITLE                      = 'PURCHAS ORDER DETAILS'
*     I_GRID_SETTINGS                   =
*     IS_LAYOUT                         =
     IT_FIELDCAT                       IT_FC1
*     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.

form  USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELF TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN '&IC1'.
      READ TABLE IT_EKPO INTO WA_EKPO INDEX RS_SELF-TABINDEX.
      PERFORM FIELDCAT2.
      PERFORM GETDATA2.
      PERFORM DISPLAY2.
  ENDCASE.
ENDFORM.

FORM GETDATA2.
  SELECT EBELN BUKRS BSTYP BSART FROM EKKO INTO TABLE IT_EKKO WHERE EBELN WA_EKPO-EBELN.
ENDFORM.

FORM FIELDCAT2.
  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'EBELN'.
  WA_FC2-SELTEXT_S 'PO DOC NO'.
  WA_FC2-COL_POS 1.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUKRS'.
  WA_FC2-SELTEXT_S 'COMPANY CODE'.
  WA_FC2-COL_POS 2.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BUTYP'.
  WA_FC2-SELTEXT_S 'PO DOC CAT'.
  WA_FC2-COL_POS 3.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
  WA_FC2-TABNAME 'IT_EKKO'.
  WA_FC2-FIELDNAME 'BSART'.
  WA_FC2-SELTEXT_S 'PO DOC TYPE'.
  WA_FC2-COL_POS 4.
  APPEND WA_FC2 TO IT_FC2.

  CLEARWA_FC2.
ENDFORM.

FORM DISPLAY2.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                SY-REPID
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
   I_CALLBACK_TOP_OF_PAGE            'TOP_OF_PAGE2'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      = 'PO ITEM DETAILS'
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
   IT_FIELDCAT                       IT_FC2
*   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_EKKO
* 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.

CLEARWA_FC2.
REFRESH IT_FC2.
ENDFORM.

FORM TOP_OF_PAGE2.

  CLEAR WA_LH1.
  WA_LH1-TYP 'H'.
  WA_LH1-INFO 'PURCHASE ORDER HEADER DATA'.
  APPEND WA_LH1 TO IT_LH1.

  CLEAR WA_LH1.
  WA_LH1-TYP 'S'.
  WA_LH1-KEY 'DATE:'.
  CONCATENATE SY-DATUM+6(2SY-DATUM+4(2SY-DATUM(4INTO WA_LH1-INFO SEPARATED BY '/'.
  APPEND WA_LH1 TO IT_LH1.

  CLEARWA_LH1,LINE,LINE1,T_LINE.
  DESCRIBE TABLE IT_EKKO LINES LINE.
  LINE1 LINE.
  CONCATENATE 'TOTAL NO OF RECORD SELECTED' LINE1 INTO T_LINE SEPARATED BY SPACE.
  WA_LH1-TYP 'A'.
  WA_LH1-INFO T_LINE.
  APPEND WA_LH1 TO IT_LH1.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY       IT_LH1.
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .

REFRESH IT_LH1.
CLEARWA_LH1.
ENDFORM.


RESULT: