Chain Statement

ABAP programming allows to concatenate consecutive statements with same keyword in the first part into a chain statement.

If any two or more statements started with same keywords coded consecutively together or one after the other, ABAP has a feasibility to combine them in a single statement. To combine two or more consecutive statements, colon (:) should be used after the keyword.

To concatenate sequence of statements, write the identical keyword only once and place a colon(:) immediately after keyword. After colon(:), write the remaining parts of the statements one after the other with a comma (,) separated. After all written, place a period (.) at the end of the statement.

Syntax –

ABAP_keyword : statements-comma-seperated.

For example, the declaration statement sequence shown below –

DATA v_a TYPE I.
DATA v_b TYPE P.

Chained statement –

DATA: v_a TYPE I, v_b TYPE P.

In the chain statement, after the colon the remaining parts of the statements are comma separated. We can write the statement like below –

DATA: v_a TYPE I, 
v_b TYPE P.

In a chain statement, the first part (before the colon) is not limited to the keyword of the statements. The identical part of all the statements can code before the colon(:).

For example, the processing statement sequence shown below –

SUM = SUM + 1.
SUM = SUM + 2.
SUM = SUM + 3.

Chain statement for the above –

SUM = SUM + : 1, 2, 3.

In the above example, “SUM = SUM + ” is the identical part of all the ABAP statements. So to make the chain statement for the above, write the common part first, next code colon(:) and then remaining part of statements comma separated.

Example –

Problem should be described here

Code –

*&---------------------------------------------------------------------*
*& Report  Z_COLON_NOTATION
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*

REPORT  Z_COLON_NOTATION.

* Displaying 'Hello ' on the output.
WRITE 'Hello '.

* Displaying 'World..!' on the same row of the output.
WRITE 'World..!'.

* Skipping next two lines on the output.
SKIP 2.

* Chained statement
WRITE : 'Hello ', 'World..!'.

Output –

Chained statement example output

Explaining Example –

In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.

WRITE ‘Hello ‘.
WRITE ‘World..!’.
– write output on the line 3 and 4. SKIP 2 – Inserts 2 empty line and places the cursor on 6th line.
WRITE : ‘Hello ‘, ‘World..!’ – Writes the output on the line 6. First two WRITE statements equal to third WRITE statement.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *