APPEND: ABAP Keyword a day
APPEND
Variants:
1. APPEND [wa TO|INITIAL LINE TO] itab.
2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
3. APPEND [wa TO] itab SORTED BY f.
Variant 1
APPEND [wa TO|INITIAL LINE TO] itab.
Appends a new line to the end of the internal table itab. If you specify wa TO, the new line is taken from the contents of the explicitly specified work area wa.
If you use INITIAL LINE TO, a line filled with the correct value for the type is added. If the specification before itab is omitted, the new line is taken from the internal tbale itab. After the APPEND, the system field SY-TABIX contains the index
of the newly added table entry.
Examples
Generate a list with customer numbers:
TABLES SCUSTOM.
DATA: CUSTOMER LIKE SCUSTOM-ID OCCURS 0.
APPEND SCUSTOM-ID TO CUSTOMER.
Append a blank line or a line with its initial value to the above list:
APPEND INITIAL LINE TO CUSTOMER
Generate a compressed list with plane data
PARAMETERS: SEATS_LO LIKE SAPLANE-SEATSMAX DEFAULT 30,
SEATS_HI LIKE SAPLANE-SEATSMAX DEFAULT 50.
DATA: PLANE LIKE SAPLANE OCCURS 0,
PLANE_NEEDED LIKE SAPLANE WITH HEADER LINE.
LOOP AT PLANE INTO PLANE_NEEDED
WHERE SEATSMAX BETWEEN SEATS_LO AND SEATS_HI.
APPEND PLANE_NEEDED.
ENDLOOP.
Notes Performance:
1. When using internal tables with a header line, avoid unnecessary assignments to the header line. Whenever possible, use statements which have an explicit work area.
For example, “APPEND wa TO itab.” is approximately twice as fast as “itab = wa. APPEND itab.”. The same applies to COLLECT and INSERT.
2. In contrast to COLLECT, APPEND does not check whether an entry with the same default key exists. Therefore, it is considerably faster than COLLECT. If the COLLECT logic is not needed or lines with an identical default key cannot occur in a particular situation, you should always use APPEND instead of COLLECT.
3. The runtime required for APPEND increases with the line width of the table and depends on the number of fields. Appending an entry to an internal table with a width of 111 bytes takes about 9 msn (standardized microseconds).
4. To append an internal table to another internal table, you should use the variant APPEND LINES OF … which is 3 to 4 times faster than using a LOOP to process the source table and append the entries line-by-line to the target table.
Variant 2
APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
Effect Appends the internal table itab1 or an extract from itab1 to the end of the internal table itab2. By specifying FROM idx1 or TO idx2 you can restrict the line area taken from the source table itab1. If there is no FROM specification, it begins with the first line of itab1. If there is no TO specification, it ends with the last line of itab1. This means that the complete table is appended if neither a FROM nor a TO is specified.
After the APPEND, the system field SY-TABIX contains the index of the last table entry appended, i.e. the total number of entries from both tables.
Note By comparing the values of SY-TABIX before and after the APPEND statement, you can determine how many lines were appended to the table.
Example Merge two tables with whole numbers:
DATA: ITAB1 TYPE I OCCURS 100,
ITAB2 TYPE I OCCURS 100.
APPEND 2 TO ITAB1.
APPEND 3 TO ITAB1.
APPEND 5 TO ITAB1.
APPEND 7 TO ITAB1.
APPEND 3 TO ITAB2.
APPEND INITIAL LINE TO ITAB2.
APPEND LINES OF ITAB1 FROM 2 TO 20 TO ITAB2.
The table ITAB2 now contains five lines with the values 3, 0, 3, 5 and 7.
Note Performance:
This variant is 3 to 4 times faster than using a LOOP to process the source table and append the entries line-by-line to the target table.
Variant 3
APPEND [wa TO] itab SORTED BY f.
Effect Inserts the new entry into table and re-sorts the table by the sub-field f in descending order. This only makes sense if the table was sorted beforehand. When the number of table entries reaches the OCCURS parameter value, the last entry is deleted if the value f of a new entry is greater (particularly suitable for ranked lists). You can only sort by one sub-field.
If you specify wa TO, the new line is taken from the contents of the explicitly specified work area wa. Otherwise, it comes from the header line of the internal table itab.
Example
DATA: BEGIN OF COMPANIES OCCURS 3,
NAME(10), SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = ‘big’.
COMPANIES-SALES = 90.
APPEND COMPANIES.
COMPANIES-NAME = ‘small’.
COMPANIES-SALES = 10.
APPEND COMPANIES.
COMPANIES-NAME = ‘too small’.
COMPANIES-SALES = 5.
APPEND COMPANIES.
COMPANIES-NAME = ‘middle’.
COMPANIES-SALES = 50.
APPEND COMPANIES SORTED BY SALES.
The table now has three (-> OCCURS 3) entries. The line with the contents ‘too small’ in the sub-field NAME is deleted from the table because the entry for ‘middle’ has a greater value in
the sub-field SALES. This entry now appears in the second table line (after ‘big’ and before ‘small’).
Notes
1. Whenever an internal table is processed with APPEND SORTED BY, it should always be filled in this way.
2. If you specify APPEND with the parameter SORTED BY, the system always searches the entire table. Therefore, it is sometimes better to create the table with a simple APPEND
and then use SORT to sort in descending ot ascending order afterwards. You can also sort in ascending order by first determining the insert position with READ TABLE itab WITH KEY f = itab-f BINARY SEARCH and then by inserting the new entry into the table (perhaps read SY-SUBRC beforehand) with INSERT itab INDEX SY-TABIX. However, you should be aware that, in such cases, the table may contain more entries than specified in the OCCURS
parameter.
3. If several lines with an identical value f are added, lines added later are treated as smaller, i.e. they are inserted after existing lines with the same value f.
4. If you use APPEND … SORTED BY f with an explicitly specified work area, this must be compatible with the line type of the internal table.
5. If the sort criterion f is not known until runtime, you can use SORTED BY (name) to specify it dynamically as the contents of the field name. If name is blank at runtime or contains an invalid component name, a runtime error occurs.
6. Regardless of whether you specify it statically or dynamically, you can restrict the sort criterion f further by defining an offset and/or length.
Related
COLLECT itab, INSERT itab, SELECT / FETCH NEXT CURSOR … INTO/APPENDING TABLE itab, MODIFY itab, WRITE f TO itab INDEX idx, SORT itab, READ TABLE itab, LOOP AT itab, DELETE itab
ASS-RPERF is not an ABAP/4 key word (in R/3).
———————
ABAPer, mail: abap.community@gmail.com http://www.erpdb.info
If you like this post, you may as well like these too:
- AT : ABAP Keyword a day AT Events in lists- AT LINE-SELECTION.- AT USER-COMMAND.- AT PFn.Events on selection screens- AT SELECTION-SCREEN.Control break with extracts- AT NEW f.- AT END OF f.- AT FIRST.- AT LAST.- AT...
- GET: ABAP Keyword a day GET: Event keyword for defining event blocks for reporting events. GET <node> [FIELDS <fi> <f 2>...]. GET node LATE [FIELDS f1 f2 ...]. Only occurs in executable programs. When the...
- DO : ABAP Keyword a day DO Variants 1. DO. 2. DO n TIMES. Variant 1 DO. Addition … VARYING f FROM f1 NEXT f2 Effect Repeats the processing enclosed by the DO and ENDDO statements...
- ASSIGN: ABAP Keyword a day ASSIGN Variants:1. ASSIGN f TO .2. ASSIGN (f) TO .3. ASSIGN TABLE FIELD (f) TO .4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .5. ASSIGN COMPONENT idx OF...
- FORM: ABAP Keyword a day FORM: Defines a subroutine. Syntax FORM [USING ... [VALUE(][)] [TYPE |LIKE ]„. ] [CHANGING... [VALUE(][)] [TYPE |LIKE ]„. ]. Introduces a subroutine. The USING and CHANGING additions define the subroutine’s...
- FETCH : ABAP Keyword a day FETCH Basic form FETCH NEXT CURSOR c target. Effect Uses the cursor c to read the next line or lines from the dataset of a database table determined by OPEN...
- EXPORT : ABAP Keyword a day EXPORT 1 2 3 4 *Export data - EXPORT obj1 ... objn TO MEMORY. - EXPORT obj1 ... objn TO DATABASE dbtab(ar) ID key. - EXPORT obj1 ... objn TO...
- DIVIDE : ABAP Keyword a day DIVIDE Basic form DIVIDE n1 BY n2. Effect Divides the contents of n1 by n2 and places the result in n1 . This is equivalent to: n1 = n1 /...
- DESCRIBE : ABAP Keyword a day DESCRIBE Return attributes of a field - DESCRIBE FIELD f. Return attributes of an internal table - DESCRIBE TABLE itab. Determine distance between two fields - DESCRIBE DISTANCE BETWEEN f1...
- DATA : ABAP Keyword a day DATA Variants1. DATA f.2. DATA f(len).3. DATA: BEGIN OF rec,…END OF rec.4. DATA: BEGIN OF itab OCCURS n,…END OF itab.5. DATA: BEGIN OF COMMON PART c,…END OF COMMON PART.EffectDefines global...
- CONTINUE: ABAP Keyword a day CONTINUE Basic formCONTINUE.EffectWithin loop structures like * DO … ENDDO* WHILE … ENDWHILE* LOOP … ENDLOOP* SELECT … ENDSELECTCONTINUE terminates the current loop pass, returns the processing to the beginning...
- CONCATENATE : ABAP Keyword a day CONCATENATE Basic form CONCATENATE f1 … fn INTO g. Addition … SEPARATED BY h Effect Places the fields f1 to fn after g . With the fields fi (1 <=...
- COMPUTE: ABAP Keyword a day COMPUTEBasic formCOMPUTE n = arithexp.EffectEvaluates the arithmetic expression arithexp and places the result in the field n .Allows use of the four basic calculation types + , – , *...
- CHECK : ABAP Keyword a day CHECK Within loops and events- CHECK logexp.Special for reports with logical databases- CHECK sel.- CHECK SELECT-OPTIONS. CHECK – within loops Basic formCHECK logexp.EffectCHECK evaluates the subsequent logical expression . If...
- GET PARAMETER: ABAP Keyword a day GET PARAMETER Gets an SPA/GPA parameters. Syntax GET PARAMETER ID <pid> FIELD <field_name>. Writes the value of the SPA/GPA parameter <pid> from the user-specific SAP memory into the variable <f>....



















For some reason only fifty percent of the post is being scene, is it my online browser or the site?