10-07-2008 3:33 PM
Hi Guyz,
LOOP AT gt_data INTO gs_data FROM 2.
REFRESH:gt_columns.
gs_data = gt_data-line.
SPLIT gs_data AT '|' INTO TABLE gt_columns.
READ TABLE gt_columns INDEX 1 ASSIGNING <fs_data>.
gt_tab-client = <fs_data>.
im reading the data using above read statement , iam doing it 11 times coz i know there is 11 entries (sy-tabix = 11)..but i dont wanna hardcode that bit after index..how can i do it?..plz advise
thanks
Edited by: Julius Bussche on Oct 7, 2008 6:00 PM
10-07-2008 4:32 PM
so for the question why cant i use loop.
here i have splitted 1 record
for eg:
SPLIT gs_data AT '|' INTO TABLE gt_columns.
so in the gt _columns table
i have
1.400
2.1111
3.aaaaa
4.32
5.00010
.
.
.
11.abcd
and here
READ TABLE gt_columns INDEX 1 ASSIGNING <fs_data>.
gt_tab-client = <fs_data>.
READ TABLE gt_columns INDEX 2 ASSIGNING <fs_data>.
gt_tab-asd = <fs_data>.
....
READ TABLE gt_columns INDEX 11 ASSIGNING <fs_data>.
gt_tab-wsd = <fs_data>.
hope you all understand what i mean
thanks
10-07-2008 3:35 PM
Hi ,
Use the v_tabix = sy-tabix.
READ TABLE gt_columns INDEX v_tabix ASSIGNING <fs_data>.
Regards,
Bharani
10-07-2008 3:35 PM
10-07-2008 3:35 PM
Can't you use
READ TABLE gt_columns INDEX sy-index ASSIGNING <fs_data>.
-Aman
10-07-2008 3:37 PM
10-07-2008 3:39 PM
thanks for your replies...
i got 11 entries in the table..
so im doing as read index 1....read index 2 ...read index 11..
now can i do it anyother way with no hardcoding bit after index so that i can read it dynamically one by one .
reg
10-07-2008 3:44 PM
DO 11 TIMES.
READ TABLE ... INDEX sy-index. "sy-index will go from 1 to 11
...
ENDDO.
10-07-2008 3:45 PM
LOOP AT gt_data INTO gs_data FROM 2.
REFRESH:gt_columns.
gs_data = gt_data-line.
SPLIT gs_data AT '|' INTO TABLE gt_columns.
LOOP AT gt_columns ASSIGNING <fs_data>.
if sy-tabix gt '11'.
exit.
endif.
Your stuff
ENDLOOP.
10-07-2008 3:46 PM
10-07-2008 3:50 PM
You can try this....
DESCRIBE TABLE ITAB LINES L_COUNT.
LOOP AT ITAB from t_index to l_count.
....................
ENDLOOP.
10-07-2008 3:50 PM
>
> I'd like to know why you can't use a LOOP.
>
> Rob
probably he has read your blog entry about nested LOOPs...
10-07-2008 3:55 PM
If you really really really really don;t want to loop at gt_columns:
do.
read table gt_columns index sy-index assigning <fs_data>.
if sy-subrc eq 0.
* Do your stuff: high five!!! dance naked!!!
else.
exit.
endif.
enddo.
10-07-2008 3:56 PM
>
> probably he has read your blog entry about nested LOOPs...
Oh yeah - never thought of that! (10 points to the first person that can name the song that came from.)
Seriously - reading the table eleven times or looping through it won't make much difference.
Rob
10-07-2008 4:32 PM
so for the question why cant i use loop.
here i have splitted 1 record
for eg:
SPLIT gs_data AT '|' INTO TABLE gt_columns.
so in the gt _columns table
i have
1.400
2.1111
3.aaaaa
4.32
5.00010
.
.
.
11.abcd
and here
READ TABLE gt_columns INDEX 1 ASSIGNING <fs_data>.
gt_tab-client = <fs_data>.
READ TABLE gt_columns INDEX 2 ASSIGNING <fs_data>.
gt_tab-asd = <fs_data>.
....
READ TABLE gt_columns INDEX 11 ASSIGNING <fs_data>.
gt_tab-wsd = <fs_data>.
hope you all understand what i mean
thanks
10-07-2008 4:38 PM
I see, but the problem is not LOOP vs. READ TABLE here...
The question is now, if in the target table the fields are in the same order, then in the source. If gt_tab is built up in the same sequence, like the source (that means client is the fierst field, asd is the second....wsd is the last), if yes than you can code like:
FIELD-SYMBOLS : <fs_target> TYPE ANY.
DO 11 TIMES.
READ TABLE gt_columns INDEX sy-index ASSIGNING <fs_data>.
ASSIGN COMPONENT sy-index OF structure gt_tab TO <fs_target>.
<fs_target> = <fs_data>.
ENDDO.
(sorry Rob, it still READ TABLE
One more thing: Can't you replace the whole thing with only:
SPLIT gs_data AT '|' INTO gt_tab-client, gt_tab-asd, ... , gt_tab-wsd.
???