2005 Sep 23 2:10 AM
I have an internal table name declared in field I_DYN_TAB with me and I want to loop at this I_DYN_TAB.
( 4 example:
DATA: I_DYN_TAB(10) VALUE 'I_TAB'.
where I_TAB is my internal table with data in it.)
I already tried couple of things.
A. READ TABLE (I_DYN_TAB) WITH KEY I_DYN_TAB-FIELD1
but, it is not allowing me to read it dynamically this way.
B. LOOP AT (I_DYN_TAB). Again this is also not working.
Another option I tried is to create a field symbol for the internal table, which again is not useful or may be I am doing it wrong.
So if anybody can help me in solving this problem, it would be great.
Waiting for reply.
Regards
Arpit
2005 Sep 23 7:58 PM
Ok try this >
REPORT ZTEST .
DATA : BEGIN OF I_ITAB OCCURS 0,
TEST(5),
END OF I_ITAB.
DATA: I_DYN_TAB(10) VALUE 'I_ITAB[]'.
DATA: DTAB TYPE REF TO DATA.
FIELD-SYMBOLS : <ITAB> TYPE ANY TABLE ,
<WA> TYPE ANY.
I_ITAB-TEST = 'TEST'.
APPEND I_ITAB.
ASSIGN (I_DYN_TAB) TO <ITAB>.
LOOP AT <ITAB> ASSIGNING <WA>.
WRITE <WA>.
ENDLOOP.
2005 Sep 23 2:53 AM
hi, if your internal table is named 'I_TAB', do like following:
DATA: NEW_LINE TYPE REF TO DATA.
FIELD-SYMBOLS:<FS_1> TYPE ANY TABLE,
<FS_2>.
ASSIGN <b>I_TAB</b> TO <FS_1>.
CREATE DATA NEW_LINE LIKE LINE OF <FS_1>.
ASSIGN NEW_LINE->* TO <FS_2>.
LOOP AT <FS_1> ASSIGNING <FS_2>.
* add your handling logic here
ENDLOOP.
Hope it will be helpful
thanks
2005 Sep 23 6:33 PM
Hi Jhenglin,
Thanks for your reply....appreciate it.
But I_TAB is stored in I_DYN_TAB in a variable as I mentioned earlier so I dont think I can use your statement ASSIGN I_TAB TO <FS_1>.
Is there any other way.
Thanks and Regards,
Arpit.
2005 Sep 23 4:49 AM
U can use
ASSIGN COMPONENT...Eg:
FIELD-SYMBOLS: <dyn_field>,
<dyn_field1>,
<dyn_field2>,
<dyn_field3> TYPE ANY .
* Test when UOM, 'KMEIN' is '%'
* <b>ASSIGN COMPONENT 'KMEIN' OF STRUCTURE p_line1 TO <dyn_field1>.</b>
* ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field2>.
* ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field>.
* Test when Curr, 'KONWA' is '%'
ASSIGN COMPONENT 'KONWA' OF STRUCTURE p_line1 TO <dyn_field1>.
ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field2>.
ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field>.
IF <dyn_field1> = '%'.
<dyn_field> = <dyn_field2> / 10.
ENDIF.
if <dyn_field2> LE -1.
<dyn_field> = <dyn_field> * -1.
endif.
INSERT p_line1 INTO TABLE p_output1.Hope this helps.
2005 Sep 23 6:42 PM
Hi Judith,
Thanks for your quick response.
I think I cannot use assign component because my internal table name is dynamic and so I do not know till runtime which fields are present in the internal table.For e.g I have a set of code attached to a number of user exits. This code is a dynamic code which assigns itself the properties of all the internal tables that are transparent in the customer function exit and executes certain function.
Now I am not aware till runtime how many tables/workareas a user-exit has and I want to read the contents of the internal table available and perform my logic.
I hope I have made it clear about my requirement and will appreciate if you can help me .
Message was edited by: Arpit Gattani
2005 Sep 23 5:12 AM
2005 Sep 23 8:23 AM
Hi,
DATA: I_DYN_TAB(10) VALUE 'I_TAB'.
data: dtab type ref to data.
field-symbols: <itab> type any table,
<wa> type any.
assign (I_DYN_TAB) to <itab>.
loop at <itab> assigning <wa>.
endloop.
Svetlin
2005 Sep 23 6:55 PM
Hi Svetlin,
Thanks for your response.
But I have tried this code several times but the program gives a short dump saying " You attempted to assign a field to a typed field symbol,
but the field does not have the required type. ".
I believe we cannot assign a field to field symbol of type table.
Can you suggest something else.
Thanks and Regards,
Arpit
Message was edited by: Arpit Gattani
2005 Sep 23 7:58 PM
Ok try this >
REPORT ZTEST .
DATA : BEGIN OF I_ITAB OCCURS 0,
TEST(5),
END OF I_ITAB.
DATA: I_DYN_TAB(10) VALUE 'I_ITAB[]'.
DATA: DTAB TYPE REF TO DATA.
FIELD-SYMBOLS : <ITAB> TYPE ANY TABLE ,
<WA> TYPE ANY.
I_ITAB-TEST = 'TEST'.
APPEND I_ITAB.
ASSIGN (I_DYN_TAB) TO <ITAB>.
LOOP AT <ITAB> ASSIGNING <WA>.
WRITE <WA>.
ENDLOOP.
2005 Sep 23 8:18 PM
Hi Sanjay,
Thanks a lot. It worked absolutely fine.
Thanks,
Arpit