Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP

Go down

Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP

Post  Admin on Fri Apr 27, 2012 11:00 am

*&---------------------------------------------------------------------*
*& 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.

Admin
Admin

Posts : 92
Join date : 2012-01-26

http://mysaplab.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum