How To USE FUNCTION MODULE 'REUSE_ALV_GRID_DISPLAY'

REUSE_ALV_GRID_DISPLAY  is function module which is used to display the output in grid format.

The input for this function module are two internal tables ie one internal table for data and another for internal table for about the fields. eg: 

TYPE-POOLS : SLIS. 
 DATA : BEGIN OF WA_T001, 
             BUKRS LIKE T001-BUKRS, 
             BUTXT LIKE T001-BUTXT, 
             ORT01 LIKE T001-ORT01, 
             END OF WA_T001, 
             IT_T001 LIKE TABLE OF WA_T001. 
 DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV, 
            WA_FCAT LIKE LINE OF IT_FCAT. 
 DATA : V_NAME LIKE  SY-REPID. 

 SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE IT_T001 UP TO 15 ROWS. V_NAME = SY-REPID.
 CALL FUCTION MODULE 'REUSE_ALV_FIELDCATLOG_MERGE. EXPORTING  I_CALBACK_PROGRAM =
 V_NAME I_INTERAL_TABNAME = 'WA_T001' I_INCLNAME = V_NAME CHANGING CT_FIELDCAT =
 IT_FCAT. 

 CALL FUNCTION MODULE "REUSE_ALV_GRID_DISPLAY" 
 EXPORTING 
 I_CALLBACK_PROGRAM = V_NAME 
 IT_FCAT = IT_FCAT. 
 TABLES 
     T_OUTTAB  = IT_T001 

 SY-REPID IS THE SYSTEM VARIABLE WHICH IS HAVING THE ABAP PROGRAM  
 OR CURRENT MAIN PROGRAM. 
*----- Sample Progam -----*
*----------------------------------------------------------------------*
***INCLUDE YRVR058_DEST_WISE_SUMMARY_DF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text      *-- Rajesh Vasudeva
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
  IF ITAB[] IS NOT  INITIAL.
    PERFORM F_APPEND_BLOCK.
  ELSE.
    MESSAGE 'Data not found for the selection
criteria' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.                    " display_data
*&---------------------------------------------------------------------*
*&      Form  f_append_block
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_APPEND_BLOCK .
  DATA : L_WA_SORT    TYPE SLIS_SORTINFO_ALV,   "For
sort
         L_WA_EVENTS  TYPE SLIS_ALV_EVENT.      "For
events

* Event (Top of List)
  CLEAR L_WA_EVENTS.
  L_WA_EVENTS-NAME = SLIS_EV_TOP_OF_LIST.
  L_WA_EVENTS-FORM = C_TOPOFPAGE.
  APPEND L_WA_EVENTS TO I_EVENTS_PART.

* Event (Top of Page)
  CLEAR L_WA_EVENTS.
  L_WA_EVENTS-NAME = SLIS_EV_TOP_OF_PAGE.
  L_WA_EVENTS-FORM = 'F_DISPLAY_HEADER_PARTA'(031).
  "f_display_header_part
  APPEND L_WA_EVENTS TO I_EVENTS_PART.

* Event (End of List)
  CLEAR L_WA_EVENTS.
  L_WA_EVENTS-NAME = SLIS_EV_END_OF_LIST.
  L_WA_EVENTS-FORM = C_END_OF_LIST.
  APPEND L_WA_EVENTS TO I_EVENTS_PART.

* Set Layout Zebra
  STRUCT_LAYOUT-ZEBRA          = 'X'.
  STRUCT_LAYOUT-NUMC_SUM       = 'X'.
  STRUCT_LAYOUT-TOTALS_TEXT    = 'TOTAL:'(032).

* set field catalog
  PERFORM F_FIELD_CATALOG_PART.
  ASSIGN ITAB[] TO <F_OUTTAB>.
  V_PART = 'A'.  "initiating list is A
  PERFORM F_DISPLAY_BLOCK USING STRUCT_LAYOUT
                               I_FIELD_CAT_PART[]
                               C_TAB
                               I_EVENTS_PART[]
                               I_SORT_PART[].

ENDFORM.                    " f_append_block

*&---------------------------------------------------------------------*
*&      Form  f_field_catalog_part
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_FIELD_CATALOG_PART .
  REFRESH I_FIELD_CAT_PART.
  CLEAR I_FIELD_CAT_PART.
  PERFORM F_CREATE_CATALOG USING :
*Month
C_TAB 'MONTH'  'MONTH'      SPACE 'L' 7
I_FIELD_CAT_PART[],
*OBD
*C_TAB 'VBELN'  'Delivery'      SPACE 'L' 12
I_FIELD_CAT_PART[],
*DATE
C_TAB 'WADAT_IST'  'Date'      SPACE 'L' 10
I_FIELD_CAT_PART[],
*Destination
C_TAB 'CITY1'  'Destination'      SPACE 'L' 25
I_FIELD_CAT_PART[],
*Qty By Road
C_TAB 'NTGEW_ROAD'  'Road Quantity'   SPACE 'R' 16
I_FIELD_CAT_PART[],
*Rail Qty
C_TAB 'NTGEW_RAIL'  'Rail Quantity'  SPACE 'R' 16 I_FIELD_CAT_PART[], 
*Total  Qty C_TAB 'TOT'  'Total Quantity'  SPACE 'R' 16 I_FIELD_CAT_PART[], *RR/Trk No.
  C_TAB 'EXTI2'  'Truck/RR No.' SPACE 'L' 17 I_FIELD_CAT_PART[].

ENDFORM.                    " f_field_catalog_part

*&---------------------------------------------------------------------*
*&      Form  f_DISPLAY_block
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_STRUCT_LAYOUT  text
*      -->P_I_FIELD_CAT_PART[]  text
*      -->P_C_TAB  text
*      -->P_I_EVENTS_PART[]  text
*      -->P_I_SORT_PART[]  text
*----------------------------------------------------------------------*
FORM F_DISPLAY_BLOCK  USING  FP_LAYOUT         TYPE
SLIS_LAYOUT_ALV
                             FP_I_FCAT         TYPE
SLIS_T_FIELDCAT_ALV
                             VALUE(FP_TABNAME) TYPE
ANY
                             FP_I_EVENTS       TYPE
SLIS_T_EVENT
                             FP_I_SORT         TYPE
SLIS_T_SORTINFO_ALV.
  DATA: V_REPID  TYPE SYREPID,                  
"current Program id
        C_SAVE       TYPE CHAR1 VALUE 'A'.      
"variant save
  V_REPID = SY-REPID.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
*CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = V_REPID
      IS_LAYOUT          = FP_LAYOUT
      IT_FIELDCAT        = FP_I_FCAT[]
      IT_SORT            = FP_I_SORT[]
      I_SAVE             = C_SAVE             "variant
save
      IT_EVENTS          = FP_I_EVENTS[]
    TABLES
      T_OUTTAB           = <F_OUTTAB>
    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_block
*&---------------------------------------------------------------------*
*&      Form  f_create_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_C_TAB  text
*      -->P_0085   text
*      -->P_0086   text
*      -->P_SPACE  text
*      -->P_0088   text
*      -->P_5      text
*      -->P_I_FIELD_CAT_PART[]  text
*----------------------------------------------------------------------*
FORM F_CREATE_CATALOG  USING  FP_I_TABNAME   TYPE
SLIS_TABNAME
                              FP_I_FIELDNAME TYPE SLIS_FIELDNAME
                              FP_I_SELTEXT   TYPE
SCRTEXT_L
                              FP_I_DOSUM     TYPE
CHAR1
                              FP_I_JUST      TYPE C
                              FP_I_OUTPUTLEN TYPE
OUTPUTLEN
                              FP_I_FCAT      TYPE
SLIS_T_FIELDCAT_ALV.

* Record for field catalog
  DATA: L_REC_FCAT TYPE SLIS_FIELDCAT_ALV.

  L_REC_FCAT-TABNAME   = FP_I_TABNAME.
  L_REC_FCAT-FIELDNAME = FP_I_FIELDNAME.
  L_REC_FCAT-SELTEXT_L = FP_I_SELTEXT.
  L_REC_FCAT-DO_SUM    = 'X'.
*l_rec_fcat-do_sum    = ' '.
  L_REC_FCAT-JUST      = FP_I_JUST.
  L_REC_FCAT-OUTPUTLEN = FP_I_OUTPUTLEN.
  L_REC_FCAT-DECIMALS_OUT = '2'.
  L_REC_FCAT-KEY          = '1'.


  APPEND L_REC_FCAT TO FP_I_FCAT.
ENDFORM.                    " f_create_catalog

***********************************************************************
*      Subroutines for Headings
***********************************************************************

*&---------------------------------------------------------------------*
*&      Form  f_display_header_partA
*&---------------------------------------------------------------------*
*       Display header for report for Part A
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE .
  SKIP 1.
  WRITE:/25 ' Name of Company ',80 'RUN DATE' ,
SY-DATUM.
*  SKIP 1.
*  WRITE:/60 'RUN DATE' , SY-DATUM.
  SKIP 1.
  DATA: YR(4) TYPE N,
         FIN_PRD(10) TYPE C.
  IF S_DTABF-LOW+4(2) LT '04'.
    YR = S_DTABF-LOW+0(4) - 1.
    CONCATENATE YR '-' S_DTABF-LOW+2(2) INTO FIN_PRD.
  ELSE.
    YR = S_DTABF-LOW+0(4) + 1.
    CONCATENATE S_DTABF-LOW+0(4) '-' YR+2(2) INTO
FIN_PRD.
  ENDIF.
  WRITE:/5 'DETAILS OF THE MONTH/DATE WISE DESPATCHES
MADE BY ROAD/RAIL DURING THE YEAR ' , FIN_PRD  .
  SKIP 1.
*  WRITE :/ 'SALES OFFICE : ' , P_SALES,' ' , RNAME.
*  SKIP 1.
ENDFORM.                    " DISPLAY_DATA

Related:

ABAP Books List
ABAP/4 Certification, Programming and Object Oriented Programming Books

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.