Additions for Output With READ TABLE

Extras:

1. ... INTO wa

2a. ... ASSIGNING <fs>

2b. ... REFERENCE INTO dref

3a. ... COMPARING f1 f2 ...

3b. ... COMPARING ALL FIELDS

4a. ... TRANSPORTING f1 f2 ...

4b. ... TRANSPORTING NO FIELDS

Addition 1

... INTO wa

Effect

If the system finds an appropriate entry, it uses the specified work area wa as the output area. If the table has a header line, you can omit the addition, since the header line is then used as the output area.

Addition 2a

... ASSIGNING <fs>

Effect

If a corresponding entry is found, the field symbol <fs> is assigned to the entry. This saves the cost of copying the contents in comparison to the first addition. However, this addition does involve table administration costs, and it is therefore only worthwile for lines longer than around 300 bytes. (Example: When you delete a line of a table to which a field symbol is pointing, an UNASSIGN is required for the field symbol.)

Note

The field symbol <fs> accesses the internal table directly. The key components of a table with the type SORTED or HASHED must not be changed in this way, since this could invalidate the sort order of the table. For this reason, all modifying operations on the key fiedls of these kinds of tables (such as MODIFY, MOVE, CLEAR), and all potential modifying operations (such as when the table has been passed as a CHANGING parameter) result in a runtime error.

Addition 2b

... REFERENCE INTO dref

Effect

If a suitable entry is found, the system returns the reference to that line in dref. Otherwise, the data reference dref remains unchanged. Since the reference can be used to directly manipulate the contents of the internal table, the same restrictions apply as to the ASSIGNING addition.

Addition 3a

... COMPARING f1 f2 ...

Effect

If the system find an entry, the system compares the subfields f1, f2, ... with the corresponding fields of the work area before they are transported into it.

The return value SY-SUBRC indicates whether any values were found that correspond to the search, and, if so, the result of the comparison:

SY-SUBRC = 0:
Entry found, field contents identical
SY-SUBRC = 2:
Entry found, field contents different
SY-SUBRC > 2:
No entry found

If you want to instruct the system not to compare any fields (which is the default in any case), you can use the COMPARING NO FIELDS addition.

Notes

  1. If you use COMPARING with a specific work area, the work area must be compatible with the line type of the internal table.
  2. If a comparison criterion is not known until runtime, you can specify it dynamically as the contents of the name field in COMPARING ... (name) .... If name is empty at runtime, the system ignores the comparison. If name contains an invalid component name, the system triggers a runtime error.


  3. You can further restrict comparison criteria (whether static or dynamic) by specifying length or offset.


  4. If you use the obsolete first variant READ TABLE itab (without specifying key or index), it is only worth using the COMPARING f1 f2 ... addition if fields f1, f2, ... are not part of the read key (that is, when f1, f2, ... are numeric fields (types I, F, P)).


Addition 3b

... COMPARING ALL FIELDS

Effect

This is the same as addition 3a, except that the system compares all fields.

Addition 4a

... TRANSPORTING f1 f2 ...

Effect

If the system finds an entry, it does not transfer all of the subfields (default) into the work area, but only the specified fields f1 f2 ...; the other subfields remain unchanged.

If you want to specify that all fields should be transported (the default), you can use the TRANSPORTING ALL FIELDS addition.

Notes

  1. If you use TRANSPORTING f1 f2 ... with an explicitly specified output area, this must be compatible with the line type of the internal table.


  2. If you do not know a particular transport field until runtime, you can specify it dynamically in the contents of the field name in TRANSPORTING ... (name) .... If name is empty at runtime, the system ignores the transport criterion. If name contains an invalid component name, the system triggers a runtime error.

  3. You can restrict transport fields, whether static or dynamic, further by specifying offset or length.

  4. If you combine the " COMPARING" and "TRANSPORTING" additions, "COMPARING" must come before "TRANSPORTING".

Addition 4b

... TRANSPORTING NO FIELDS

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Redundant work areas not allowed.

Effect

The output area of the internal table is not changed at all. The only purpose of the READ TABLE statement is to set the values of SY-SUBRC and SY-TABIX.
Additional help

Processing Internal Tables