Application Development 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... the rules about meaningfull subject titles please

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

14 REPLIES 14

P561888
Active Contributor
0 Kudos

Hi ,

Use the v_tabix = sy-tabix.

READ TABLE gt_columns INDEX v_tabix ASSIGNING <fs_data>.

Regards,

Bharani

Former Member
0 Kudos
LOOP AT gt_columns ASSIGNING <fs_data>.

* do your stuff

ENDLOOP.

Former Member
0 Kudos

Can't you use

READ TABLE gt_columns INDEX sy-index ASSIGNING <fs_data>.

-Aman

Former Member
0 Kudos

LOOP??

Rob

Former Member
0 Kudos

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

0 Kudos
DO 11 TIMES.
READ TABLE ... INDEX sy-index. "sy-index will go from 1 to 11
...
ENDDO.

0 Kudos

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.

0 Kudos

I'd like to know why you can't use a LOOP.

Rob

0 Kudos

You can try this....

DESCRIBE TABLE ITAB LINES L_COUNT.
LOOP AT ITAB from t_index to l_count.
  ....................
ENDLOOP.

0 Kudos

>

> I'd like to know why you can't use a LOOP.

>

> Rob

probably he has read your blog entry about nested LOOPs...

0 Kudos

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.

0 Kudos

>

> 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

Former Member
0 Kudos

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

0 Kudos

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.

???