Skip to Content
author's profile photo Former Member
Former Member

How to create dynamic internal table

hi ,

i want to create dynamic internal table , for eg

if i am using this Function module means

REUSE_ALV_BLOCK_LIST_APPEND

i am calling this Fm inside the loop every tym if i have to pass another internal table in tables, can any one help me regards

loop at itab1.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IT_FIELDCAT = XFIELD

IS_LAYOUT = X_LAYOUT

I_TABNAME = 'XDATA'

IT_EVENTS = GT_XEVENTS

I_TEXT = TEXT-0B1

TABLES

T_OUTTAB = itab2

endloop.

for first record i have to pass itab2 then

second record i have to pass itab3 like that

can anyone help me regard this one.

regards,

siva kumar

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2007 at 04:12 AM

    Hi Siva,

    For ur requirement, the following code is suitable.

    field-symbols: <t_tab> type any.

    data: l_tabname(10) type c value 'itab',

    l_tabix type sy-tabix.

    loop at itab1.

    l_tabix = sy-tabix + 1.

    concatenate l_tabname l_tabix into l_tabname.

    <t_tab> = l_tabname.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    IT_FIELDCAT = XFIELD

    IS_LAYOUT = X_LAYOUT

    I_TABNAME = 'XDATA'

    IT_EVENTS = GT_XEVENTS

    I_TEXT = TEXT-0B1

    TABLES

    T_OUTTAB = <t_tab>

    endloop.

    Reward if helpful.

    -Prasanth

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 04:11 PM

    Hi Siva ,

    i think Field Symbols will do the trick for you.try dat.

    message edited

    shibu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 07:35 PM

    Hi Siva,

    You are already there!

    There is a FM to create field catalog for ALV from a field string or a structure in Dictionary. Try using FM REUSE_ALV_FIELDCATALOG_MERGE.

    If you have the fields available using which you want to dynamically create the internal table then this is the one to use. Refer to the FM Documentation also.

    Hope it helps.

    Sanjeev

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2007 at 03:52 AM

    Hi,

    I have posted a code for dynamic internal table the concept it...when record is greater than 5 append the values to other internal table( Perform 200_FILE_SPLIT ) ....

    I have used field symbols for this....paste this code and check out in debugger i think this would help you...

    REPORT ZDYNAMIC_INTERNAL_TABLE.

    TYPE-POOLS : ABAP.

    FIELD-SYMBOLS : <DYN_TABLE1> TYPE STANDARD TABLE,

    <DYN_TABLE2> TYPE STANDARD TABLE,

    <DYN_TABLE3> TYPE STANDARD TABLE,

    <DYN_WA>.

    DATA : DY_TABLE1 TYPE REF TO DATA,

    DY_TABLE2 TYPE REF TO DATA,

    DY_TABLE3 TYPE REF TO DATA,

    DY_LINE TYPE REF TO DATA,

    XFC TYPE LVC_S_FCAT,

    IFC TYPE LVC_T_FCAT,

    DY_TABLE TYPE REF TO data.

    DATA : BEGIN OF I_MARA OCCURS 0,

    MATNR LIKE MARA-MATNR,

    END OF I_MARA.

    DATA : IDETAILS TYPE ABAP_COMPDESCR_TAB,

    XDETAILS TYPE ABAP_COMPDESCR.

    DATA : REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR.

    DATA : INT TYPE I VALUE 1,

    INT1 TYPE I,

    INT3 TYPE I.

    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.

    PARAMETERS : P_FILE LIKE RLGRAP-FILENAME.

    SELECTION-SCREEN END OF BLOCK B1.

    &----


    *& AT SELECTION-SCREEN

    &----


    AT SELECTION-SCREEN

    ON VALUE-REQUEST FOR P_FILE.

    PERFORM GET_FILE USING P_FILE.

    &----


    *& START OF SELECTION

    &----


    START-OF-SELECTION.

    PERFORM 100_UPLOAD_INTERAL.

    PERFORM 150_GET_STRUCTURE.

    PERFORM 200_FILE_SPLIT.

    &----


    *& Form GET_FILE

    &----


    • GETTING FILE NAME FROM THE USER

    ----


    form GET_FILE using p_p_file.

    CALL FUNCTION 'WS_FILENAME_GET'

    EXPORTING

    MASK = ',All Files,..'

    IMPORTING

    FILENAME = P_FILE

    • RC =

    EXCEPTIONS

    INV_WINSYS = 1

    NO_BATCH = 2

    SELECTION_CANCEL = 3

    SELECTION_ERROR = 4

    OTHERS = 5

    .

    IF sy-subrc <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO.

    ENDIF.

    endform. " GET_FILE

    &----


    *& Form 100_UPLOAD_INTERAL

    &----


    • UPLOADING TO THE INTERNAL TABLE

    ----


    form 100_UPLOAD_INTERAL .

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = P_FILE

    FILETYPE = 'DAT'

    TABLES

    data_tab = I_MARA

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11

    .

    IF sy-subrc <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO.

    ENDIF.

    endform. " 100_UPLOAD_INTERAL

    &----


    *& Form 200_FILE_SPLIT

    &----


    • SPLITING UP THE INTERNAL TABLE DEPENDING ON THE

    • FILE SIZE AND LOADING TO NEW DYNAMIC INTERNAL TABLE

    ----


    form 200_FILE_SPLIT .

    DESCRIBE TABLE I_MARA.

    IF SY-SUBRC = 0.

    INT = SY-TFILL.

    IF INT > 5.

    INT1 = INT - 5.

    IF INT1 > 5 AND INT1 < 10.

    • CREATE <SYN_TABLE2> AND <SYN_TABLE3>

    PERFORM 300_DYNAMIC_TABLE.

    PERFORM 300_DYNAMIC_TABLE2.

    PERFORM 300_DYNAMIC_TABLE3.

    ASSIGN DY_TABLE1->* TO <DYN_TABLE1>.

    ASSIGN DY_TABLE2->* TO <DYN_TABLE2>.

    ASSIGN DY_TABLE3->* TO <DYN_TABLE3>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE1>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE2>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE3>.

    assign dy_line->* to <dyn_wa>.

    LOOP AT I_MARA INTO <DYN_WA>.

    IF SY-TABIX <= 5.

    APPEND <DYN_WA> TO <DYN_TABLE1>.

    ELSEIF SY-TABIX > 5 AND SY-TABIX <= 10.

    APPEND <DYN_WA> TO <DYN_TABLE2>.

    ELSEIF SY-TABIX > 10.

    APPEND <DYN_WA> TO <DYN_TABLE3>.

    ENDIF.

    ENDLOOP.

    ELSE.

    • CREATE <SYN_TABLE2>

    PERFORM 300_DYNAMIC_TABLE.

    PERFORM 300_DYNAMIC_TABLE2.

    ASSIGN DY_TABLE1->* TO <DYN_TABLE1>.

    ASSIGN DY_TABLE2->* TO <DYN_TABLE2>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE1>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE2>.

    assign dy_line->* to <dyn_wa>.

    LOOP AT I_MARA INTO <DYN_WA>.

    IF SY-TABIX <= 5.

    APPEND <DYN_WA> TO <DYN_TABLE1>.

    ELSEIF SY-TABIX > 5 AND SY-TABIX <= 10.

    APPEND <DYN_WA> TO <DYN_TABLE2>.

    ENDIF.

    ENDLOOP.

    ENDIF.

    ELSE.

    INT1 = 5.

    INT3 = 1.

    perform 300_dynamic_table.

    ASSIGN DY_TABLE1->* TO <DYN_TABLE1>.

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE1>.

    assign dy_line->* to <dyn_wa>.

    LOOP AT I_MARA INTO <DYN_WA>.

    APPEND <DYN_WA> TO <DYN_TABLE1>.

    ENDLOOP.

    ENDIF.

    ELSE.

    WRITE : 'FILE IS INVALID CHOOSE CORRECT FILE'.

    ENDIF.

    LOOP AT <DYN_TABLE1> INTO <DYN_WA>.

    WRITE : <DYN_WA>.

    ENDLOOP.

    endform. " 200_FILE_SPLIT

    &----


    *& Form 150_GET_STRUCTURE

    &----


    • GETTING STRUCTURE OF THE INTERNAL TABLE

    ----


    form 150_GET_STRUCTURE .

    REF_TABLE_DES ?=

    CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'MARA' ).

    IDETAILS[] = REF_TABLE_DES->COMPONENTS[].

    LOOP AT IDETAILS INTO XDETAILS where NAME = 'MATNR'.

    CLEAR XFC.

    XFC-FIELDNAME = XDETAILS-NAME.

    XFC-DATATYPE = XDETAILS-TYPE_KIND.

    XFC-INTTYPE = XDETAILS-TYPE_KIND.

    XFC-INTLEN = XDETAILS-length.

    XFC-DECIMALS = XDETAILS-DECIMALS.

    APPEND XFC TO IFC.

    ENDLOOP.

    endform. " 150_GET_STRUCTURE

    &----


    *& Form 300_dynamic_table

    &----


    • DYNAMIC TABLE STRUCTURE CREATION

    ----


    form 300_dynamic_table .

    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

    IT_FIELDCATALOG = IFC

    IMPORTING

    EP_TABLE = DY_TABLE1.

    endform. " 300_dynamic_table

    &----


    *& Form 300_DYNAMIC_TABLE2

    &----


    • text

    ----


    form 300_DYNAMIC_TABLE2 .

    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

    IT_FIELDCATALOG = IFC

    IMPORTING

    EP_TABLE = DY_TABLE2.

    endform. " 300_DYNAMIC_TABLE2

    &----


    *& Form 300_DYNAMIC_TABLE3

    &----


    • text

    ----


    form 300_DYNAMIC_TABLE3 .

    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

    IT_FIELDCATALOG = IFC

    IMPORTING

    EP_TABLE = DY_TABLE3.

    endform. " 300_DYNAMIC_TABLE3

    regards,

    Karthik

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.