SAP ABAP COMPUTE ADD COLLECT and APPEND
COMPUTE The COMPUTE statement is used to assign the result of the mathematical statement to a variable. The use of COMPUTE statement is optional. Please examine the following program.
d_num1 type i,
d_num2 type i.
COMPUTE d_result = d_num1 + d_num2.
is the same as
Note: If you want to add 2 numbers then it can also be done as follows in SAP ABAP.
COLLECT To Sum up the entries in the internal table you can use the COLLECT statement. The syntax is as shown below.
Please note that when using COLLECT you should ensure that all the fields that are not a part of the table key should be numeric. This means that fields that are not part of the table key should be either f,i or p.
Example
key(5) TYPE c,
num1(2) TYPE n,
num2 TYPE i,
END OF d_collect.
The result is as follows.
After first collect
First 20 30 >>>>> First 20 30 After Second Collect
First 20 15 >>>>> First 20 45 After Third Collect
Second 20 15 >>>>> First 20 45 Second 20 15
Please make a not that the first and the third COLLECT statements act as insertion statements and they just append the row to the table.
APPEND
The APPEND statement will just insert lines in the internal table. See the example given below.
Example:
key(5) TYPE c,
num1(2) TYPE n,
num2 TYPE i,
END OF d_append.
After first APPEND
First 20 30 >>>>> First 20 30 After Second APPEND
First 20 15 >>>>> First 20 30 First 20 15 After Third Collect
Second 20 15 >>>>> First 20 30 First 20 15 Second 20 15
No comments:
Post a Comment