Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  READ TABLE itab →  READ TABLE - result 

READ TABLE - transport_options

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


 ... [COMPARING { {
comp1 comp2 ...}|{ALL FIELDS}|{NO FIELDS} }] 
    [TRANSPORTING { { comp1 comp2 ...}|{ALL FIELDS} }] ...

Effect

The addition COMPARING compares the specified components comp1 comp2 ... (or the subareas or attributes) in a found row 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 row 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 row 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.


Example

The READ statement uses a WHILE loop to read all rows of the table sflight_tab one after the other using the primary table index in the work area sflight_wa. Only fields that are also in the output are transported. The COMPARING addition is used to select all flights in which no seats have yet been booked.

DATA: sflight_tab TYPE SORTED TABLE OF sflight 
                  WITH UNIQUE KEY carrid connid fldate, 
      sflight_wa  LIKE LINE OF sflight_tab, 
     output      TYPE TABLE OF string WITH EMPTY KEY. 

DATA subrc TYPE sy-subrc. 

SELECT * 
       FROM sflight 
       WHERE carrid = 'LH' 
       INTO TABLE @sflight_tab. 

subrc = sy-subrc. 
WHILE subrc = 0. 
  sflight_wa-seatsocc = 0. 
  READ TABLE sflight_tab 
       INDEX sy-index 
       INTO sflight_wa COMPARING seatsocc 
                      TRANSPORTING carrid 
                                   connid 
                                   fldate 
                                   seatsocc. 
  CASE sy-subrc. 
    WHEN 0. 
      APPEND |{ sflight_wa-carrid } { sflight_wa-connid } { 
                sflight_wa-fldate } { sflight_wa-seatsocc } <----!| 
        TO output. 
      subrc = sy-subrc. 
    WHEN 2. 
      APPEND |{ sflight_wa-carrid } { sflight_wa-connid } { 
                sflight_wa-fldate } { sflight_wa-seatsocc }| 
        TO output. 
      subrc = 0. 
    WHEN 4 OR 8. 
      EXIT. 
  ENDCASE. 
ENDWHILE. 
cl_demo_output=>display( output ).