‎2007 Jun 13 9:33 AM
hi friends,..
in READ TABLE command what is the purpose of transporting and comparing?
give me the explanation wiith one program ?
thanks in advance
‎2007 Jun 13 9:37 AM
Hi
It's to READ a record of internal table, it's like SELECT SINGLE.
READ TABLE ITAB WITH KEY FIELD = 'A'.
It returns the first record of ITAB where the field FIELD has the value A.
Max
‎2007 Jun 13 9:39 AM
Hi Selva ,
Read statement is generally used to read data from internal table.
Now there can be a case where the internal table will have 10 to 20 feilds , but you want only a specific feilds from that the record you read , in such a case you use the TRANSPORTING addition and specify the feild whose value you actaully need , thus the advantage of this that you move only the feilds that are required to the varaible and not all the feilds of the table..
Comparing is used when you want to read the internal table based on a set of keys and once the line is selcted want to compare the value of some other fields with a set of values.
Regards,
Arun
‎2007 Jun 13 9:44 AM
Hi Selva,
Read table helps you to get a particular record in an internal table.
Here is the sample code:
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 2.
line-col2 = 3.
READ TABLE itab FROM line INTO line COMPARING col2.
WRITE: 'SY-SUBRC =', sy-subrc.
SKIP.
WRITE: / line-col1, line-col2.
Transporting :
If the addition TRANSPORTING NO FIELDS is used, the statement READ TABLE only checks whether the line that is being searched for exists, and fills the system field sy-subrc and sy-tabix. The system can then no longer access the content of the found fields.
PARAMETERS p_carrid TYPE scarr-carrid.
DATA: scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrid,
idx TYPE i.
SELECT *
FROM scarr
INTO TABLE scarr_tab.
READ TABLE scarr_tab
WITH TABLE KEY carrid = p_carrid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
idx = sy-tabix.
ENDIF.
Thanks,
Reward If Helpful.
‎2007 Jun 13 10:05 AM
Hi Selva,
<b>Syntax:</b>
READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f 2>...
|ALL FIELDS]
[TRANSPORTING <f1> <f 2> ...
|ALL FIELDS
|NO FIELDS].
If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a work area that is compatible with the line type of the relevant internal table.
If you use the COMPARING addition, the specified table fields <f i > of the structured line type are compared with the corresponding fields of the work area before being transported. If you use the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison.
If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without TRANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SY-SUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
<b>Example1:</b>
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 2. LINE-COL2 = 3.
READ TABLE ITAB FROM LINE INTO LINE COMPARING COL2.
WRITE: 'SY-SUBRC =', SY-SUBRC.
SKIP.
WRITE: / LINE-COL1, LINE-COL2.
The output is:
SY-SUBRC = 2
2 4
<b>Example2:</b>
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
CLEAR LINE.
READ TABLE ITAB WITH TABLE KEY COL1 = 3
INTO LINE TRANSPORTING COL2.
WRITE: 'SY-SUBRC =', SY-SUBRC,
/ 'SY-TABIX =', SY-TABIX.
SKIP.
WRITE: / LINE-COL1, LINE-COL2.
The output is:
SY-SUBRC = 0
SY-TABIX = 3
0 9
Regards,
Padmam.
‎2007 Jun 13 10:12 AM
hi,
<u><b>1.Read Table</b></u>
Read table doesn't allow ne operator.
It reads only one record...Either by index or key.
READ TABLE MY_TAB INDEX 1.
READ TABLE MY_TAB WITH KEY CODE = 'ATG'.
these are the results for SY-SUBRC checks after read table
SY-SUBRC = 0:
An entry was read.
SY-TABIX is set to the index of the entry.
SY-SUBRC = 2:
An entry was read.
SY-TABIX is set to the index of the entry. This return code can only occur when you use the COMPARING addition. For further detauls, refer to the COMPARING section of the additions
SY-SUBRC = 4:
No entry was read.
The value of SY-TABIX depends on the table type and whether the BINARY SEARCH addition was specified.
If the table is a SORTED TABLE or a table sorted in ascending order of the type STANDARD TABLE with the BINARY SEARCH addition, SY-TABIX refers to the next-highest index.
Otherwise, SY-TABIX is undefined.
SY-SUBRC = 8:
No entry was read.
This return code only occurs with a SORTED TABLE or a STANDARD TABLE with the BINARY SEARCH addition. SY-TABIX is set to the number of all entries plus 1.
Reading records with keys
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
Reading lines with Index
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm
<u><b>2.<u><b>Transporting</b></u></b></u>
suppose itab has fields
roll_num,name and age as field.
then,
read table itab with key rollnum = rl_num.
this will retuen all the 3 fields in the itab.
suppose we need only name.
if we use above synatx with out transporting, unneccesserly we are fetching roll_num and age
so use like this,
read table itab
with key rollnum = rl_num
transporting name.
now we get name only. so performance improved
always use transporting key word.
Regards
Anversha