Saturday, December 18, 2010
Fieldcatalog plays main role in ALV programming. Beginners when they are learning ALV, get struggle here.
Fieldcatalog in simple terms is a internal table which contains descriptions of the list output fields(usually a subset of the internal output table fields).A field catalog is required for every ALV list output.
- ALV without fieldcatalog(Need to pass table structures. Internally fieldcatalog is generated.
REPORT ZTEST_FIELDCAT1. "Without Fieldcatalog. DATA:I_MARD TYPE MARD OCCURS 0 WITH HEADER LINE. DATA:L_PROGRAM TYPE SY-REPID VALUE SY-REPID. START-OF-SELECTION. "Get data from MARD SELECT * FROM MARD INTO TABLE I_MARD UP TO 100 ROWS. " Call ALV function module and structure name instead of F CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = L_PROGRAM I_STRUCTURE_NAME = 'MARD' TABLES T_OUTTAB = I_MARD. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
- Automatic fieldcatalog generation -function module REUSE_ALV_FIELDCATALOG_MERGE.
REPORT ZTEST_FIELDCAT2. "Automatic Fieldcatalog Generation. DATA:I_MARD TYPE MARD OCCURS 0 WITH HEADER LINE. TYPE-POOLS:SLIS. DATA:I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV. DATA L_PROGRAM TYPE SY-REPID VALUE SY-REPID. SELECT * FROM MARD INTO TABLE I_MARD UP TO 100 ROWS. "Use function module create Fieldcat. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = L_PROGRAM I_STRUCTURE_NAME = 'MARD' I_INCLNAME = L_PROGRAM I_BYPASSING_BUFFER = 'X' CHANGING CT_FIELDCAT = I_FIELDCAT. 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 ALV Grid fm and pass fieldcatalog and data CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = L_PROGRAM IT_FIELDCAT = I_FIELDCAT TABLES T_OUTTAB = I_MARD. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
- Semi Automatic Fieldcatalog Generation - function module REUSE_ALV_FIELDCATALOG_MERGE
REPORT ZTEST_FIELDCAT3. "Semi Automatic Fieldcatalog Generation. DATA: BEGIN OF I_MARD OCCURS 0, MATNR LIKE MARD-MATNR, WERKS LIKE MARD-WERKS, LGORT LIKE MARD-LGORT, PSTAT LIKE MARD-PSTAT, END OF I_MARD. TYPE-POOLS:SLIS. DATA:I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV. SELECT MATNR WERKS LGORT PSTAT FROM MARD INTO CORRESPONDING FIELDS OF TABLE I_MARD UP TO 100 ROWS. "Use function module create Fieldcat. DATA:L_PROGRAM TYPE SY-REPID VALUE SY-REPID. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = L_PROGRAM I_INTERNAL_TABNAME = 'I_MARD' I_INCLNAME = L_PROGRAM I_BYPASSING_BUFFER = 'X' CHANGING CT_FIELDCAT = I_FIELDCAT. 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 ALV and pass fieldcatalog and data CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = L_PROGRAM IT_FIELDCAT = I_FIELDCAT TABLES T_OUTTAB = I_MARD. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
- Manually populating fieldcatag table
REPORT ZTEST_FIELDCAT4. "Fieldcatalog creation manually DATA: BEGIN OF I_MARD OCCURS 0, MATNR TYPE MARD-MATNR, WERKS TYPE MARD-WERKS, END OF I_MARD. TYPE-POOLS:SLIS. DATA:I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, W_FIELDCAT LIKE LINE OF I_FIELDCAT. DATA:L_PROGRAM TYPE SY-REPID VALUE SY-REPID. "Populate Fieldcatalog table W_FIELDCAT-FIELDNAME = 'MATNR'. W_FIELDCAT-TABNAME = 'I_MARD'. W_FIELDCAT-SELTEXT_M = 'Material No'. APPEND W_FIELDCAT TO I_FIELDCAT. CLEAR W_FIELDCAT. W_FIELDCAT-FIELDNAME = 'WERKS'. W_FIELDCAT-TABNAME = 'I_MARD'. W_FIELDCAT-SELTEXT_M = 'Plant'. APPEND W_FIELDCAT TO I_FIELDCAT. CLEAR W_FIELDCAT. SELECT MATNR WERKS FROM MARD INTO CORRESPONDING FIELDS OF TABLE I_MARD UP TO 100 ROWS. "Call ALV and pass fieldcatalog and data CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = L_PROGRAM IT_FIELDCAT = I_FIELDCAT TABLES T_OUTTAB = I_MARD. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
1)What is the main purpose of using "Field Catalog".
ReplyDelete2)when we should use "Semi Automatic Fieldcatalog Generation"
3)When we should use "Automatic fieldcatalog generation "
4)can we use Field Catalog for Field Enhancement in ALV?