SAP CHAINED STATEMENTS - Guide



Get Example source ABAP code based on a different SAP table
  



Chained Statements

ABAP_BACKGROUND
Successive ABAP statements that have the same starting part can be expressed in a chained statement. A chained statement consists of the identical starting part that is specified once and that is concluded by a colon (:). Behind this colon, the remaining parts are separated by commas (,). Only the last part is concluded with a period (.). During the syntax check and the compilation, a chained statement is handled like the respective sequence of individual ABAP statements, where the shared starting part is put in front of each remaining part. The identical starting parts are not restricted to the keyword.

ABAP_RULE
Only use chained statements where appropriate
Use chained statements mainly for declarations. They should always be used for related declarations of type TYPES BEGIN OF ... TYPES END OF ....

ABAP_DETAILS
The main motivation for using chained statements is to increase the readability of programs. Using chained statements correctly in d eclarations achieves this goal. In other statements, chained statements can actually decrease the readability or, in the worst case, result in incorrect program behavior. When using chained statements, only one statement at most should be specified per program line. Never span expressions or functional calls across multiple parts of chained statements.
Declarations
In complex declarations, chained statements can be used to improve readability. (However, if local declarations are too complex, this suggests an insufficient separation of tasks , and should not occur.) In particular, multiple chained statements can be used to group related declarations: DATA:
airplane TYPE REF TO cl_airplane,
airplane_attributes TYPE cl_airplane=>airplane_attributes.
DATA:
airport TYPE REF TO cl_airport,
airport_attributes TYPE cl_airport=>airport_attributes.
...
The grouping of declarative statements that semantically represent a composite statement is even more important. For example, the declaration of structured types and data objects in ABAP is done using individual statements, whose close relationship should be expressed by a chained statement: TYPES:
BEGIN OF file,
name TYPE string,
owner TYPE sy-uname,
creation_date TYPE timestamp,
END OF file.
For structures that copy components of another structure using the