Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Page 1 of 1
Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
*&---------------------------------------------------------------------*
*& Report Z_SUKS_DYNAMIC_ITAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SUKS_DYNAMIC_ITAB.
DATA: TY_DTRF TYPE REF TO DATA,
ALVF_CAT TYPE TABLE OF LVC_S_FCAT,
LS_ALV_CAT LIKE LINE OF ALVF_CAT.
TYPES: TABNAME LIKE DCOBJDEF-NAME.
PARAMETER: P_TBNAME TYPE TABNAME.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE DNTAB.
DATA: END OF ITAB.
DATA: NEW_LINE TYPE REF TO DATA.
FIELD-SYMBOLS : <F_FS> TYPE TABLE.
REFRESH ITAB.
"Using NAMETAB_GET to get the tablename structure
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
LANGU = SY-LANGU
TABNAME = P_TBNAME
TABLES
NAMETAB = ITAB
EXCEPTIONS
NO_TEXTS_FOUND = 1.
LOOP AT ITAB .
LS_ALV_CAT-FIELDNAME = ITAB-FIELDNAME.
LS_ALV_CAT-REF_TABLE = P_TBNAME.
LS_ALV_CAT-REF_FIELD = ITAB-FIELDNAME.
APPEND LS_ALV_CAT TO ALVF_CAT.
ENDLOOP.
*Using function CREATE_DYNAMIC_TABLE to create the internal table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING IT_FIELDCATALOG = ALVF_CAT
IMPORTING EP_TABLE = TY_DTRF .
ASSIGN TY_DTRF->* TO <F_FS>.
"Select for the transparent table into the internal table
SELECT * FROM (P_TBNAME) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* 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 = P_TBNAME
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* 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 = <F_FS>
* 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.
*& Report Z_SUKS_DYNAMIC_ITAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SUKS_DYNAMIC_ITAB.
DATA: TY_DTRF TYPE REF TO DATA,
ALVF_CAT TYPE TABLE OF LVC_S_FCAT,
LS_ALV_CAT LIKE LINE OF ALVF_CAT.
TYPES: TABNAME LIKE DCOBJDEF-NAME.
PARAMETER: P_TBNAME TYPE TABNAME.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE DNTAB.
DATA: END OF ITAB.
DATA: NEW_LINE TYPE REF TO DATA.
FIELD-SYMBOLS : <F_FS> TYPE TABLE.
REFRESH ITAB.
"Using NAMETAB_GET to get the tablename structure
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
LANGU = SY-LANGU
TABNAME = P_TBNAME
TABLES
NAMETAB = ITAB
EXCEPTIONS
NO_TEXTS_FOUND = 1.
LOOP AT ITAB .
LS_ALV_CAT-FIELDNAME = ITAB-FIELDNAME.
LS_ALV_CAT-REF_TABLE = P_TBNAME.
LS_ALV_CAT-REF_FIELD = ITAB-FIELDNAME.
APPEND LS_ALV_CAT TO ALVF_CAT.
ENDLOOP.
*Using function CREATE_DYNAMIC_TABLE to create the internal table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING IT_FIELDCATALOG = ALVF_CAT
IMPORTING EP_TABLE = TY_DTRF .
ASSIGN TY_DTRF->* TO <F_FS>.
"Select for the transparent table into the internal table
SELECT * FROM (P_TBNAME) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* 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 = P_TBNAME
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* 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 = <F_FS>
* 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.
Similar topics
» Creating table type in ABAP
» What are internal tables? How do you get the number of lines in an internal table?
» Hashed Internal Table in SAP
» What is occurs in internal table?
» Passing internal table as method parameter
» What are internal tables? How do you get the number of lines in an internal table?
» Hashed Internal Table in SAP
» What is occurs in internal table?
» Passing internal table as method parameter
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP