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

Loop on a table choosed dynamically

Former Member
0 Likes
526

Hi,

I'm trying to create a LOOP on an internal table, but the name of this table will only be knwon at runtime.

I tried a few thins but didn't work !!

How can I do that.


FIELD-SYMBOLS : <MY_TABLE> TYPE STANDARD TABLE.
DATA : l_inttab TYPE char64.

CONCATENATE 'T_'
            T_TABPB-TABNAME
            INTO l_inttab.
ASSIGN (l_inttab) TO <MY_TABLE>.
            
LOOP AT <MY_TABLE>.
*...        
ENDLOOP.

When i try this code, i've got an error that says i'ts impossible because i don't have a header line.

What do i have to change ?

Thanks for your help.

nb : of course all the possibles names for my internal table are declared with their type.

3 REPLIES 3
Read only

Former Member
0 Likes
500

Hi Heldere

field-symbols: <my_header_line> type any.

try with

LOOP AT <MY_TABLE> into <my_header_line>.

endloop.

bye

enzo

Message was edited by: Enzo Porcasi

Read only

Former Member
0 Likes
500

Hi Helder,

1. simple loop won't work.

2. we have to use something like this :

LOOP AT <dyntable> ASSIGNING <dynline>.

3. use this code (just copy paste)

it will give u all details on how

to use the field value in the table.

REPORT abc.

*----


COMPULSORY

FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.

FIELD-SYMBOLS: <dynline> TYPE ANY.

DATA: lt TYPE lvc_t_fcat.

DATA: ls TYPE lvc_s_fcat.

FIELD-SYMBOLS: <fld> TYPE ANY.

DATA : fldname(50) TYPE c.

*----


FIELD LIST

ls-fieldname = 'LIFNR'.

APPEND ls TO lt.

ls-fieldname = 'LAND1'.

APPEND ls TO lt.

ls-fieldname = 'NAME1'.

APPEND ls TO lt.

*----


PERFORM

PERFORM mydyntable USING lt.

*----


SELECT

SELECT * FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE <dyntable>.

*----


DISPLAY

LOOP AT <dyntable> ASSIGNING <dynline>.

fldname = '<DYNLINE>-LIFNR'.

ASSIGN (fldname) TO <fld>.

WRITE 😕 <fld>.

fldname = '<DYNLINE>-LAND1'.

ASSIGN (fldname) TO <fld>.

WRITE : <fld>.

fldname = '<DYNLINE>-NAME1'.

ASSIGN (fldname) TO <fld>.

WRITE : <fld>.

ENDLOOP.

BREAK-POINT.

*----


  • FORM

*----


FORM mydyntable USING lt TYPE lvc_t_fcat .

*----


Create Dyn Table From FC

FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

FIELD-SYMBOLS: <fs_1>.

FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.

DATA: lt_data TYPE REF TO data.

ASSIGN lt_data TO <fs_data>.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt

IMPORTING

ep_table = <fs_data>

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

*----


Assign Dyn Table To Field Sumbol

ASSIGN <fs_data>->* TO <fs_1>.

ASSIGN <fs_1> TO <fs_2>.

ASSIGN <fs_1> TO <dyntable>.

ENDFORM. "MYDYNTABLE

regards,

amit m.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
500

Hi,

MOdify your code as follows.It works for me.Kindly reward points by clicking the star on the left of reply,if it helps.

FIELD-SYMBOLS : <MY_TABLE> TYPE ANY TABLE.

DATA : l_inttab TYPE char64.

data itab type standard table of pa0001.

data wa type pa0001.

select * from pa0001 into table itab.

l_inttab = 'itab'.

ASSIGN (l_inttab) TO <MY_TABLE>.

LOOP AT <MY_TABLE> into wa.

write 😕 wa-pernr.

ENDLOOP.