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

Confused with the read table statement

Former Member
0 Likes
1,942

Hello there,

I am very confused with the READ TABLE statement now, say if I have an internal table like T582S, the infotype table, and I would like to pull out a particular record, identified by the infotype ID, and assign the description of the infotype to a variable type c, how can I do that? Thanks a lot!

Regards,

Anyi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,909

hi anyi,

read table itab with key id = t582s-id

c = t582s-text.

Hello there,

I am very confused with the READ TABLE statement now, say if I have an internal table like T582S, the infotype table, and I would like to pull out a particular record, identified by the infotype ID, and assign the description of the infotype to a variable type c, how can I do that? Thanks a lot!

Regards,

Anyi

19 REPLIES 19
Read only

Former Member
0 Likes
1,909

hi ZHU,

do this way and relate it to your requirement

i.e,

read table itab with key <field> = <tab-field>.

if sy-subrc = 0.

do something.

endif

Read only

Former Member
0 Likes
1,910

hi anyi,

read table itab with key id = t582s-id

c = t582s-text.

Read only

0 Likes
1,909

You can do it just like this. Make sure to use the Language key also.



report  zrich_0005.

data: it582s type table of t582s.
data: xt582s type t582s.

data: the_text type t582s-itext.

select * into table it582s from t582s.

read table it582s into xt582s with key sprsl = sy-langu
                                       infty = '0002'.

if sy-subrc = 0.
  the_text = xt582s-itext.
endif.

write:/ the_text.

Regards,

Rich Heilman

Read only

0 Likes
1,909

mm...I am not sure what is going on but I can not get subrc <> 0 even though I keyed in an infotype of name 9017 (which I suppose there is no such infotype there, in T582S).. Any suggestions?

Anyi

Read only

0 Likes
1,909

That is what it looks like. Is this a custom infotype?

Read only

0 Likes
1,909

REPLY TO SRINIVAS ADAVI:

nope, this is very standard, like PA0000 kind of thing. Thanks a lot!

Read only

0 Likes
1,909

I didn't find it in this table in our system. That is why I asked.

Read only

0 Likes
1,909

mm...I am not sure, I have never ever worked on any other SAP system before... probably you are right. But any suggestions on how to resolve the problem, I think PA0000 is also OK if you do not have T582S. Thanks!

Read only

0 Likes
1,909

What is the issue? Is this code not working?



report  zrich_0005.

data: it582s type table of t582s.
data: xt582s type t582s.

data: the_text type t582s-itext.

select * into table it582s from t582s.

* Check for Infotype PA0002 (0002)
read table it582s into xt582s with key sprsl = sy-langu
                                       infty = '0002'.

if sy-subrc = 0.
  the_text = xt582s-itext.
endif.

write:/ the_text.



Regards,

Rich Heilman

Read only

0 Likes
1,909

Not the code, I think the value for that specific one is not there.

Read only

0 Likes
1,909

Ae you sure you are passing in codes?

read table itab with key infotype = '9017'.
      if sy-subrc = 0.
      endif

Regds

Manohar

Read only

0 Likes
1,909

I am not, actually, and I am still trying to figure that one out, getting a little bit desparate on that one...but I am still trying

Read only

0 Likes
1,909

A record for infortype 9017 does not exist in table t582s in my system. It looks like it has all of the standard ones.

Regards,

Rich Heilman

Read only

0 Likes
1,909

Ok, I know what happened to this one guys, I forgot to increment the index of the internal table, so in essense, I was just reading the first row of my internal table again and again, I thought the looping statement will automatically increment the row, but apparently that did not do so. Thanks a lot to all the replies!

Anyi

Read only

0 Likes
1,909

? Why are you useing an INDEX for this READ statement? Don't you need to compare the infotype value?

Regards,

Rich Heilman

Read only

0 Likes
1,909

Inside the loop at an internal table, the current record index is stored in SY-TABIX. You can use that as long as you use it before any other loop or read of an internal table.

Read only

0 Likes
1,909

Err...Ok, I was pulling out the info type code (the 4-digit thing) from an internal table where a file was loaded into.

Read only

Former Member
0 Likes
1,909

When you do a READ TABLE, you are reading the entire record matching the criteria. So you can move the individual field value into your variable if the READ is successful.


DATA: s_t582s LIKE t582s,
      v_text  like t582s-itext.

READ TABLE i_582s INTO s_582s WITH KEY sprsl = sy-langu
                                       infty = 'xxx'.
IF sy-subrc = 0.
  v_text = s_t582s-itext.
ENDIF.

Read only

Former Member
0 Likes
1,909

The READ statement will return only one record (the first one it encounters). It's more efficient to use it with the binary serach option.


sort itab by sprsl infty.
read table itab with key
  infty = infotype_id
  binary search.
if sy-subrc = 0.
*Process the record
endif.

Rob