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 table

Former Member
0 Kudos

In reading internal tables , there are some additions...

Comparing f1 f2 .... [All fields]

Transporting f1 f2.... [All fields]

Binary search...

What r the use of it?

Pls explain me with an example...

Points sure for helpful answers....

1 ACCEPTED SOLUTION

former_member189059
Active Contributor
0 Kudos

taken from SAP help.. your answer was there itself

The addition COMPARING compares the specified components comp1 comp2 ... (or the subareas or attributes thereof) in a found line before they are transported with the corresponding components of the work area. If ALL FIELDS is specified, all components are compared. If no NO FIELDS is specified, no components are compared. If the content of the compared components is identical, sy-subrc is set to 0. Otherwise it is set to 2. The found line is assigned to the work area independently of the result of the comparison.

If the addition TRANSPORTING is specified, only the specified components comp1 comp2 ... (and their subareas) in the found line are assigned to the corresponding components of the work area (or their subareas). If ALL FIELDS is specified, all the components are assigned.

COMPARING must be specified before TRANSPORTING. The components comp1 comp2 ... are specified according to the rules in the section Specifying Components. This is subject to the restriction that after TRANSPORTING, attributes of classes cannot be addressed using the object component selector, and after COMPARING, this is only possible as of release 6.10.

5 REPLIES 5

Former Member
0 Kudos

READ SAP Help.

People here are also going to paste the same !!

regards

Nishant

former_member189059
Active Contributor
0 Kudos

taken from SAP help.. your answer was there itself

The addition COMPARING compares the specified components comp1 comp2 ... (or the subareas or attributes thereof) in a found line before they are transported with the corresponding components of the work area. If ALL FIELDS is specified, all components are compared. If no NO FIELDS is specified, no components are compared. If the content of the compared components is identical, sy-subrc is set to 0. Otherwise it is set to 2. The found line is assigned to the work area independently of the result of the comparison.

If the addition TRANSPORTING is specified, only the specified components comp1 comp2 ... (and their subareas) in the found line are assigned to the corresponding components of the work area (or their subareas). If ALL FIELDS is specified, all the components are assigned.

COMPARING must be specified before TRANSPORTING. The components comp1 comp2 ... are specified according to the rules in the section Specifying Components. This is subject to the restriction that after TRANSPORTING, attributes of classes cannot be addressed using the object component selector, and after COMPARING, this is only possible as of release 6.10.

Former Member
0 Kudos

HI,

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 f1 ... fn 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, sy-subrc 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 f1 ... fn 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.

In both additions, you can also specify the fields f1 ... fn … dynamically using (n1) (n2)… as the contents of a field n1 ... nn. If n1 ... nn is empty when the statement is executed, it is ignored. You can also restrict all fields f1 ... fn to subfields by specifying offset and length.

<b>comparing:</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 list output is:

sy-subrc = 2

2 4

<b>transporting:</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 list output is:

sy-subrc= 0

sy-tabix = 3

0 9

rgds,

bharat.

Former Member
0 Kudos

Hi

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.

The addition COMPARING compares the specified components comp1 comp2 ... (or the subareas or attributes thereof) in a found line before they are transported with the corresponding components of the work area. If ALL FIELDS is specified, all components are compared. If no NO FIELDS is specified, no components are compared. If the content of the compared components is identical, sy-subrc is set to 0. Otherwise it is set to 2. The found line is assigned to the work area independently of the result of the comparison.