Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Declaring multiple dynamic internal tables

Former Member
0 Likes
1,223

Hi,

I'm trying to use function REUSE_ALV_BLOCK_LIST_APPEND to show multiple ALV's on a page. I however need to run this function multiple times, each time with a different internal tables (the number of these tables is never the same). What is the best method to declare a varying amount of internal tables?

I've searched the forum but couldn't find what I wanted. If you could point me to a link or in the right direction that would be great.


CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    it_fieldcat                = it_alvfc
    is_layout                  = gp_layout
    i_tabname                  = 'GT_GETDATA'
    it_events                  = gt_alv_event
  TABLES
    t_outtab                   = <dyn_table>
  EXCEPTIONS
    program_error              = 1
    maximum_of_appends_reached = 2
    OTHERS                     = 3.

First run of FM: <dyn_table> refers to certain data

second run: <dyn_table> refers to new data

third run <dyn_table> refers to different data again

Thanks

Edited by: Hin Lai on Dec 22, 2010 9:15 PM

Edited by: Hin Lai on Dec 22, 2010 9:17 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
860

Hi,

I would suggest you to follow as below. Here you need to create dynamic internal table names in a pattern like

<dyn_table_1>, <dyn_table_2> and <dyn_table_3>.........etc. One more i didnpt check for syntax errors for below code.

I am pointing you to provide a possibility. I used this approach for condition type value search for any given codition type access sequense and context.

DATA : L_TMPREF TYPE REF TO DATA.

1. Determine how many table to show variable LV_NO.

2. DO LV_NO TIMES.

concatenate '<dyn_table_' LV_NO '>' into LV_NAME.

CREATE DATA L_TMPREF LIKE (LV_NAME).

ASSIGN L_TMPREF->* TO <FS_TAB>.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

it_fieldcat = it_alvfc

is_layout = gp_layout

i_tabname = LV_NAME

it_events = gt_alv_event

TABLES

t_outtab = <FS_TAB>.

EXCEPTIONS

program_error = 1

maximum_of_appends_reached = 2

OTHERS = 3.

ENDDO.

4 REPLIES 4
Read only

Former Member
0 Likes
861

Hi,

I would suggest you to follow as below. Here you need to create dynamic internal table names in a pattern like

<dyn_table_1>, <dyn_table_2> and <dyn_table_3>.........etc. One more i didnpt check for syntax errors for below code.

I am pointing you to provide a possibility. I used this approach for condition type value search for any given codition type access sequense and context.

DATA : L_TMPREF TYPE REF TO DATA.

1. Determine how many table to show variable LV_NO.

2. DO LV_NO TIMES.

concatenate '<dyn_table_' LV_NO '>' into LV_NAME.

CREATE DATA L_TMPREF LIKE (LV_NAME).

ASSIGN L_TMPREF->* TO <FS_TAB>.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

it_fieldcat = it_alvfc

is_layout = gp_layout

i_tabname = LV_NAME

it_events = gt_alv_event

TABLES

t_outtab = <FS_TAB>.

EXCEPTIONS

program_error = 1

maximum_of_appends_reached = 2

OTHERS = 3.

ENDDO.

Read only

former_member186491
Contributor
0 Likes
860

Hi Hin Lai,

You can achieve that by using one temporary and one final FIELD-SYMBOL.

Suppose, you have fixed scenarios and countings of ITAB, then, you can make use of CASE-ENDCASE otherwise IF-ENDIF would be used.

Now, Just based on business condition, pass your ITAB in temporary Field-Symbol and finally assign those values in Final Field-Symbol within the Condition-Block made by IF / CASE. Do remember to flush the values out before assigning.

This Final Field-Symbol can be passed in FM for ALV.

That's it. Hope this would serve your purpose.

Thanks.

Kumar Saurav.

Read only

0 Likes
860

Kumar Saurav: I dont have fixed scenarios, I am able to find out how many internal tables I will need to declare dynamically though.

Srinivas: I've tried your idea and have come up with this.


  DATA: lv_dyn_tab  TYPE string,
        l_tmpref    TYPE REF TO data.
  FIELD-SYMBOLS: <fs1>, <fs2>, <fs3>.

LOOP AT gt_getdata.

    ASSIGN COMPONENT  'BLNCE'  OF STRUCTURE <dyn_wa> TO <fs1>.
    <fs1> =  gt_getdata-blnce.

    ASSIGN COMPONENT  'BELNR'  OF STRUCTURE <dyn_wa> TO <fs2>.
    <fs2> =  gt_getdata-belnr.

*   Append to the dynamic internal table
    CONCATENATE '<dyn_table_' gv_grp_counter '>' INTO lv_dyn_tab.
    CREATE DATA l_tmpref LIKE lv_dyn_tab.
    APPEND <dyn_wa> TO l_tmpref.

  ENDLOOP.

The problem here is that I cannot append to l_tmpref since it is not an internal table. How can I get around this?

The other section of my code is this:


  DO lv_no TIMES.

*   Create dynamic internal table and assign to FS
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_fldcat
      IMPORTING
        ep_table        = new_table.

    ASSIGN new_table->* TO <dyn_table>.

*   Create dynamic work area and assign to FS
    CREATE DATA new_line LIKE LINE OF <dyn_table>.
    ASSIGN new_line->* TO <dyn_wa>.

  ENDDO.

How could I make this work?

Thanks

Read only

0 Likes
860

I am still searching for an answer if anyone has any suggestions.

Thanks,