Friday 26 April 2013

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:





1 comment: