2006 Jun 27 7:56 PM
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
2006 Jun 27 7:59 PM
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
2006 Jun 27 7:59 PM
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
2006 Jun 27 7:59 PM
hi anyi,
read table itab with key id = t582s-id
c = t582s-text.
2006 Jun 27 8:04 PM
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
2006 Jun 27 8:06 PM
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
2006 Jun 27 8:10 PM
2006 Jun 27 8:20 PM
REPLY TO SRINIVAS ADAVI:
nope, this is very standard, like PA0000 kind of thing. Thanks a lot!
2006 Jun 27 8:24 PM
I didn't find it in this table in our system. That is why I asked.
2006 Jun 27 8:26 PM
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!
2006 Jun 27 8:36 PM
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
2006 Jun 27 8:41 PM
Not the code, I think the value for that specific one is not there.
2006 Jun 27 8:48 PM
Ae you sure you are passing in codes?
read table itab with key infotype = '9017'.
if sy-subrc = 0.
endifRegds
Manohar
2006 Jun 27 9:00 PM
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
2006 Jun 27 9:02 PM
2006 Jun 27 9:12 PM
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
2006 Jun 27 9:14 PM
2006 Jun 27 9:20 PM
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.
2006 Jun 27 9:20 PM
Err...Ok, I was pulling out the info type code (the 4-digit thing) from an internal table where a file was loaded into.
2006 Jun 27 8:02 PM
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.
2006 Jun 27 8:09 PM
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