09-02-2007 5:41 PM
is read statement fetches one record or many records...explain with simple example
09-02-2007 6:03 PM
Hello balaji,
Read table command is used to read a single record at a time'
there are many syntax based on which read command be used
simple example
Scenario: you have an internal table INT_TAB (with header line) which has 5 records belonging to 5 different plants
Requirement: you need to get one record at a time which belongs to a particular plant..for instance consider you need a field "number" of the internal table
Solution:use the read statement
Eg:Read table int_tab with key plant = XXXX and date = sy-datum.
You can pass one or more keys based on your requirement
here you will get a single record in the header line of int_tab which satisfied the condition if sy-subrc after the read statement is zero and sy-subrc will not be zero if the read was a failure
so..
if sy-subrc = 0.
loc_variable = int_tab-number."you get your required condition
endif.
Hope it gave you some idea
Reward if helpful
Regards
Byju
09-02-2007 6:56 PM
Hello Balaji
The READ statement is used to read a <b>single </b>record or to check whether <b>at least a single</b> record is existing or not.
Example: itab lt_knb1 (of type KNB1) contains several customers
" Read single entry
READ TABLE lt_knb1 INTO ls_knb1
WITH KEY bukrs = '1000'
kunnr = '12345'.
If you have sorted your itab you can speed up the reading process by using:
SORT lt_knb1 BY bukrs kunnr.
READ TABLE lt_knb1 INTO ls_knb1
WITH KEY bukrs = '1000'
kunnr = '12345'
BINARY SEARCH.
Finally, if you just want to check for existance then use:
READ TABLE lt_knb1 TRANSPORTING NO FIELDS
WITH KEY bukrs = '1000'
kunnr = '12345'.
IF ( syst-subrc NE '0' ).
" no customer found for this company code...
ENDIF.
I highly recommend to make use of the TRANSPORTING NO FIELDS option because then is clear to everybody that you are just doing a check but are not interested in the actual customer data.
Regards
Uwe