2009 Jan 29 8:47 AM
Hi All,
I've create a dynamic table at runtime through the use of method create_dynamic_table and I want the dynamic table to be displayed in alv.
FM reuse_alv_grid_display wont accept the dynamic table since its not recognized as a table but as a reference only.
Any ideas?
Thanks in advance.
Tyken
2009 Jan 29 9:19 AM
Hi Friend,
You can display dynamic internal table in ALV, please find below code for guide:
*--------------------------------------
* CREATE DYNAMIC INTERNAL TABLE
* DATE: 28/05/2007 AUTHOR: LAHAKRI
*--------------------------------------
TYPE-POOLS: SLIS.
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IS_FCAT LIKE LINE OF IT_FCAT.
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
IS_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA: NEW_TABLE TYPE REF TO DATA.
DATA: NEW_LINE TYPE REF TO DATA.
* it should be standard table otherwise it will not work
FIELD-SYMBOLS: <L_TABLE> TYPE STANDARD TABLE,
<L_LINE> TYPE ANY,
<L_FIELD> TYPE ANY.
* Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
CHANGING
CT_FIELDCAT = IT_FCAT[].
* IAM TAKING ONLY FOUR 3 FIELDS FROM MARA TABLE FOR DISPLAY
LOOP AT IT_FCAT INTO IS_FCAT WHERE NOT REPTEXT_DDIC IS INITIAL.
MOVE-CORRESPONDING IS_FCAT TO IS_FIELDCAT.
IS_FIELDCAT-FIELDNAME = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_FIELD = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_TABLE = IS_FCAT-REF_TABNAME.
IF IS_FIELDCAT-FIELDNAME NE 'MANDT'.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDIF.
IF SY-TABIX = 3.
EXIT.
ENDIF.
ENDLOOP.
* EXTRA FIELD THAT YOU WILL KNOW IN RUN TIME ON SOME CONDITION
DO 1 TIMES.
IS_FIELDCAT-COL_POS = SY-INDEX + 4.
IS_FIELDCAT-FIELDNAME = 'GROUP1'.
IS_FIELDCAT-INTLEN = '10'.
IS_FIELDCAT-DATATYPE = 'CHAR'.
IS_FIELDCAT-INTTYPE = 'C'.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDDO.
* Create a new DYNAMIC INT TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = NEW_TABLE.
* Create a new Line with the same structure of the table.
ASSIGN NEW_TABLE->* TO <L_TABLE>.
CREATE DATA NEW_LINE LIKE LINE OF <L_TABLE>.
ASSIGN NEW_LINE->* TO <L_LINE>.
* FILL DATA..HARD CODING..YOU CAN FETCH IN A SEPARATE INT TABLE AND PASS
DO 4 TIMES.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <L_LINE> TO <L_FIELD>.
<L_FIELD> = '1-QA'.
ASSIGN COMPONENT 'GROUP1' OF STRUCTURE <L_LINE> TO <L_FIELD>.
<L_FIELD> = '1200'.
INSERT <L_LINE> INTO TABLE <L_TABLE>.
ENDDO.
* LIST OUTPUT
LOOP AT <L_TABLE> ASSIGNING <L_LINE>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <L_LINE> TO <L_FIELD>.
WRITE <L_FIELD>.
ASSIGN COMPONENT 'GROUP1' OF STRUCTURE <L_LINE> TO <L_FIELD>.
WRITE <L_FIELD>.
WRITE /.
ENDLOOP.
* TRANSFERRING TO COMAPTIBLE ALV DISPLAY STRUCTURE
CLEAR IT_FCAT[].
LOOP AT IT_FIELDCAT INTO IS_FIELDCAT.
MOVE-CORRESPONDING IS_FIELDCAT TO IS_FCAT.
APPEND IS_FCAT TO IT_FCAT.
ENDLOOP.
* DISPLAY IN ALV
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME =
* IS_LAYOUT =
IT_FIELDCAT = IT_FCAT
* 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
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = <L_TABLE>
* 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.
Hope it will help to solve the probelm.
Regards
Krishnendu
2009 Jan 29 9:19 AM
Hi Friend,
You can display dynamic internal table in ALV, please find below code for guide:
*--------------------------------------
* CREATE DYNAMIC INTERNAL TABLE
* DATE: 28/05/2007 AUTHOR: LAHAKRI
*--------------------------------------
TYPE-POOLS: SLIS.
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IS_FCAT LIKE LINE OF IT_FCAT.
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
IS_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA: NEW_TABLE TYPE REF TO DATA.
DATA: NEW_LINE TYPE REF TO DATA.
* it should be standard table otherwise it will not work
FIELD-SYMBOLS: <L_TABLE> TYPE STANDARD TABLE,
<L_LINE> TYPE ANY,
<L_FIELD> TYPE ANY.
* Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
CHANGING
CT_FIELDCAT = IT_FCAT[].
* IAM TAKING ONLY FOUR 3 FIELDS FROM MARA TABLE FOR DISPLAY
LOOP AT IT_FCAT INTO IS_FCAT WHERE NOT REPTEXT_DDIC IS INITIAL.
MOVE-CORRESPONDING IS_FCAT TO IS_FIELDCAT.
IS_FIELDCAT-FIELDNAME = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_FIELD = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_TABLE = IS_FCAT-REF_TABNAME.
IF IS_FIELDCAT-FIELDNAME NE 'MANDT'.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDIF.
IF SY-TABIX = 3.
EXIT.
ENDIF.
ENDLOOP.
* EXTRA FIELD THAT YOU WILL KNOW IN RUN TIME ON SOME CONDITION
DO 1 TIMES.
IS_FIELDCAT-COL_POS = SY-INDEX + 4.
IS_FIELDCAT-FIELDNAME = 'GROUP1'.
IS_FIELDCAT-INTLEN = '10'.
IS_FIELDCAT-DATATYPE = 'CHAR'.
IS_FIELDCAT-INTTYPE = 'C'.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDDO.
* Create a new DYNAMIC INT TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = NEW_TABLE.
* Create a new Line with the same structure of the table.
ASSIGN NEW_TABLE->* TO <L_TABLE>.
CREATE DATA NEW_LINE LIKE LINE OF <L_TABLE>.
ASSIGN NEW_LINE->* TO <L_LINE>.
* FILL DATA..HARD CODING..YOU CAN FETCH IN A SEPARATE INT TABLE AND PASS
DO 4 TIMES.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <L_LINE> TO <L_FIELD>.
<L_FIELD> = '1-QA'.
ASSIGN COMPONENT 'GROUP1' OF STRUCTURE <L_LINE> TO <L_FIELD>.
<L_FIELD> = '1200'.
INSERT <L_LINE> INTO TABLE <L_TABLE>.
ENDDO.
* LIST OUTPUT
LOOP AT <L_TABLE> ASSIGNING <L_LINE>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <L_LINE> TO <L_FIELD>.
WRITE <L_FIELD>.
ASSIGN COMPONENT 'GROUP1' OF STRUCTURE <L_LINE> TO <L_FIELD>.
WRITE <L_FIELD>.
WRITE /.
ENDLOOP.
* TRANSFERRING TO COMAPTIBLE ALV DISPLAY STRUCTURE
CLEAR IT_FCAT[].
LOOP AT IT_FIELDCAT INTO IS_FIELDCAT.
MOVE-CORRESPONDING IS_FIELDCAT TO IS_FCAT.
APPEND IS_FCAT TO IT_FCAT.
ENDLOOP.
* DISPLAY IN ALV
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME =
* IS_LAYOUT =
IT_FIELDCAT = IT_FCAT
* 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
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = <L_TABLE>
* 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.
Hope it will help to solve the probelm.
Regards
Krishnendu
2009 Jan 29 9:20 AM
Hi,
Try FIELD-SYMBOLS
use field-symbols for ur internal table u wil get that.....