Showing posts with label ABAP Keywords. Show all posts
Showing posts with label ABAP Keywords. Show all posts

ABAP Tutorials for Beginners

Here is a Complete Guide of all the training manuals for SAP ABAP freshers. This is a organized set of all the documents which you need to learn from start to finish. The ABAP Tutorials are categorised sequentially from start to finish.

Download the Complete Tutorial from Rapidshare or Mediafire.

SAP ABAP Tutorial Contents

  1. ABAP Programming
  2. Dictionary
  3. Internal Tables
  4. ALV Grid Control
  5. SAP List Viewer
  6. Screen and Menu Painter
  7. BDC Concepts
  8. BDC Files
  9. BDC Recording
  10. BAPI Introduction & Programming
  11. Object Oriented Programming
  12. SAP Scripts/SmartForms
  13. Enhancements
  14. ALE Introduction/Programming/Steps
  15. EDI & IDOC
  16. IDOC Book
  17. LSMW Introduction & Steps
  18. Transport Management Systems
  19. Workflow

ABAP Keyword a day : ADD

ADD

Variants:
1. ADD n TO m.
2. ADD n1 THEN n2 UNTIL nz GIVING m.
3. ADD n1 THEN n2 UNTIL nz TO m.
4. ADD n1 THEN n2 UNTIL nz
…ACCORDING TO sel …GIVING m.
5. ADD n1 FROM m1 TO mz GIVING m.

Variant 1 ADD n TO m.

Effect Adds the contents of n to the contents of M and stores the result in m.
This is equivalent to: m = m + n.

Example
DATA: NUMBER TYPE I VALUE 3,

SUM TYPE I VALUE 5.
ADD NUMBER TO SUM.

The field SUM now contains 8, whilst the contents of the field NUMBER remains unchanged at 3.

Note The details about conversions and performance described under

COMPUTE are identical for ADD.

Note Runtime errors:
- BCD_BADDATA: P field contains incorrect BCD format.
- BCD_FIELD_OVERFLOW: Result field too small (type P).
– BCD_OVERFLOW: Overflow with arithmetic operation (type P.
- COMPUTE_INT_PLUS_OVERFLOW: Integer overflow when adding.

Related COMPUTE, ADD-CORRESPONDING.

Variant 2 ADD n1 THEN n2 UNTIL nz GIVING m.

Effect Adds the contents of the fields n1, n2, …, nz together and stores the result in m, where n1 is the first, n2 the second and nz the last of a sequence of fields the same distance apart. They can be either database fields or internal fields, but they must all have the same type and length.
This is equivalent to: m = n1 + n2 + … + nz.

Example

DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
SIX TYPE P VALUE 60,
END OF NUMBERS,

SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE GIVING SUM.

The field SUM now contains 150 but its initial value is unimportant. The fields within the field string NUMBERS remain unchanged.

Variant 3 ADD n1 THEN n2 UNTIL nz TO m.

Effect Calculates the total as in variant 2 but then adds it to the contents of the field m.
This is equivalent to: m = m + n1 + n2 + … + nz

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,

SUM TYPE I VALUE 1000.

ADD NUMBERS-ONE THEN NUMBERS-TWO UNTIL NUMBERS-FIVE TO SUM.

The field SUM now contains 1150.

Variant 4 ADD n1 THEN n2 UNTIL nz
…ACCORDING TO sel …GIVING m.

Parts marked with ” …” are interchangeable
Effect Calculates the total as in variants 2 and 3. In this case, however, the operands from a sequence of fields of the same type are restricted to a partial sequence by the selection
specification sel generated by SELECT-OPTIONS or RANGES. The partial sequence results from the indexes that satisfy the condition IN sel (see IF).

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000,

INDEX TYPE I.
RANGES SELECTION FOR INDEX.

SELECTION-SIGN = ‘I’.
SELECTION-OPTION = ‘BT’.

SELECTION-LOW = 2.
SELECTION-HIGH = 4.

APPEND SELECTION.

ADD NUMBERS-ONE THEN NUMBERS-TWO

UNTIL NUMBERS-FIVE
ACCORDING TO SELECTION

GIVING SUM.
SUM now contains 90. Only the component fields TWO to FOUR were selected from the field string NUMBERS and added together.

Variant 5 ADD n1 FROM m1 TO mz GIVING m.

Effect The field n1 must be the first in a sequence of consecutive fields of the same type. m1 and mz should contain the numbers of the first and last fields in this sequence to be added together (whether fixed or variable). The total is stored in m.

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
START TYPE I VALUE 2,
SUM TYPE I VALUE 1000.

ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.

The field SUM now contains 90.
Note Performance:
The details for conversion and performance specified for COMPUTE are equally valid for ADD.
The runtime required for adding two numbers of type I or F is about 2 msn (standardized microseconds), for type P it is roughly 8 msn.

Note Runtime errors:
Besides the runtime errors listed in variant 1, the error ADDF_INT_OVERFLOW can occur instead of COMPUTE_INT_PLUS_OVERFLOW in other variants.
ADD-CONDITIONAL is not an ABAP/4 key word (in R/3).

ABAP Tutorials for Beginners

Here is a Complete Guide of all the training manuals for SAP ABAP freshers. This is a organized set of all the documents which you need to learn from start to finish. The ABAP Tutorials are categorised sequentially from start to finish.

Download the Complete Tutorial from Rapidshare or Mediafire.

SAP ABAP Tutorial Contents

  1. ABAP Programming
  2. Dictionary
  3. Internal Tables
  4. ALV Grid Control
  5. SAP List Viewer
  6. Screen and Menu Painter
  7. BDC Concepts
  8. BDC Files
  9. BDC Recording
  10. BAPI Introduction & Programming
  11. Object Oriented Programming
  12. SAP Scripts/SmartForms
  13. Enhancements
  14. ALE Introduction/Programming/Steps
  15. EDI & IDOC
  16. IDOC Book
  17. LSMW Introduction & Steps
  18. Transport Management Systems
  19. Workflow

Authorization Object

Authorization Object are a group of fields used to check if an particular transaction/events/steps can be executed or not.

AUTHORITY-CHECK is the statement used in the ABAP program to perform the authorization check by passing a authorization object. All the relevant fields must be addressed or you have to use the keyword DUMMY to bypass the check and you can have a maximum of 10 fields defined in the authorization object.

To create the authorization object use the transaction SU21. Refer the ABAP Keywords to know more about it.

ABAP Keyword a day : ADD

ADD

Variants:
1. ADD n TO m.
2. ADD n1 THEN n2 UNTIL nz GIVING m.
3. ADD n1 THEN n2 UNTIL nz TO m.
4. ADD n1 THEN n2 UNTIL nz
…ACCORDING TO sel …GIVING m.
5. ADD n1 FROM m1 TO mz GIVING m.

Variant 1 ADD n TO m.

Effect Adds the contents of n to the contents of M and stores the result in m.
This is equivalent to: m = m + n.

Example
DATA: NUMBER TYPE I VALUE 3,

SUM TYPE I VALUE 5.
ADD NUMBER TO SUM.

The field SUM now contains 8, whilst the contents of the field NUMBER remains unchanged at 3.

Note The details about conversions and performance described under

COMPUTE are identical for ADD.

Note Runtime errors:
- BCD_BADDATA: P field contains incorrect BCD format.
- BCD_FIELD_OVERFLOW: Result field too small (type P).
– BCD_OVERFLOW: Overflow with arithmetic operation (type P.
- COMPUTE_INT_PLUS_OVERFLOW: Integer overflow when adding.

Related COMPUTE, ADD-CORRESPONDING.

Variant 2 ADD n1 THEN n2 UNTIL nz GIVING m.

Effect Adds the contents of the fields n1, n2, …, nz together and stores the result in m, where n1 is the first, n2 the second and nz the last of a sequence of fields the same distance apart. They can be either database fields or internal fields, but they must all have the same type and length.
This is equivalent to: m = n1 + n2 + … + nz.

Example

DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
SIX TYPE P VALUE 60,
END OF NUMBERS,

SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE GIVING SUM.

The field SUM now contains 150 but its initial value is unimportant. The fields within the field string NUMBERS remain unchanged.

Variant 3 ADD n1 THEN n2 UNTIL nz TO m.

Effect Calculates the total as in variant 2 but then adds it to the contents of the field m.
This is equivalent to: m = m + n1 + n2 + … + nz

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,

SUM TYPE I VALUE 1000.

ADD NUMBERS-ONE THEN NUMBERS-TWO UNTIL NUMBERS-FIVE TO SUM.

The field SUM now contains 1150.

Variant 4 ADD n1 THEN n2 UNTIL nz
…ACCORDING TO sel …GIVING m.

Parts marked with ” …” are interchangeable
Effect Calculates the total as in variants 2 and 3. In this case, however, the operands from a sequence of fields of the same type are restricted to a partial sequence by the selection
specification sel generated by SELECT-OPTIONS or RANGES. The partial sequence results from the indexes that satisfy the condition IN sel (see IF).

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000,

INDEX TYPE I.
RANGES SELECTION FOR INDEX.

SELECTION-SIGN = ‘I’.
SELECTION-OPTION = ‘BT’.

SELECTION-LOW = 2.
SELECTION-HIGH = 4.

APPEND SELECTION.

ADD NUMBERS-ONE THEN NUMBERS-TWO

UNTIL NUMBERS-FIVE
ACCORDING TO SELECTION

GIVING SUM.
SUM now contains 90. Only the component fields TWO to FOUR were selected from the field string NUMBERS and added together.

Variant 5 ADD n1 FROM m1 TO mz GIVING m.

Effect The field n1 must be the first in a sequence of consecutive fields of the same type. m1 and mz should contain the numbers of the first and last fields in this sequence to be added together (whether fixed or variable). The total is stored in m.

Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
START TYPE I VALUE 2,
SUM TYPE I VALUE 1000.

ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.

The field SUM now contains 90.
Note Performance:
The details for conversion and performance specified for COMPUTE are equally valid for ADD.
The runtime required for adding two numbers of type I or F is about 2 msn (standardized microseconds), for type P it is roughly 8 msn.

Note Runtime errors:
Besides the runtime errors listed in variant 1, the error ADDF_INT_OVERFLOW can occur instead of COMPUTE_INT_PLUS_OVERFLOW in other variants.
ADD-CONDITIONAL is not an ABAP/4 key word (in R/3).

ADD-CORRESPONDING : ABAP Keyword a day

ADD-CORRESPONDING

Basic form ADD-CORRESPONDING rec1 TO rec2.

Effect Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines. Searches for all sub-fields which occur both in rec1 and rec2 and then, for all relevant field pairs corresponding to the sub-fields ni, generates statements of the form

ADD rec1-ni TO rec2-ni.

The other fields remain unchanged. With complex structures, the complete names of the corresponding field pairs must be textually identical.

Example
DATA: BEGIN OF VECTOR,
X TYPE I,
Y TYPE I,
LENGTH TYPE I,
END OF VECTOR,
BEGIN OF CIRCLE,
VOLUME TYPE P
Y TYPE P,
RADIUS TYPE I,
X TYPE I,
END OF CIRCLE.


ADD-CORRESPONDING VECTOR TO CIRCLE.

The sub-fields X and Y occur in both the field strings VECTOR and CIRCLE. Therefore, the ADD-CORRESPONDING statement is equivalent to both the following statements:

ADD VECTOR-X TO CIRCLE-X.
ADD VECTOR-Y TO CIRCLE-Y.

Note All fields with the same name are added, whether numeric or not. The same conversions are performed as with ADD and similar runtime errors to those possible with ADD can also occur.

Related ADD-CORRESPONDING :

MOVE-CORRESPONDING
SUBTRACT-CORRESPONDING
MULTIPLY-CORRESPONDING
DIVIDE-CORRESPONDING

ADD-SELECTIVE is not an ABAP/4 key word (in R/3).

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).

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 STRUCTURE rec TO .
6. ASSIGN COMPONENT name OF STRUCTURE rec TO .

Variant 1
ASSIGN f TO .

Additions:
1. … TYPE typ
2. … DECIMALS dec
3. … LOCAL COPY OF …
Effect
Assigns the field f to the field symbol . The field symbol “points to” the contents of the field f at runtime, i.e. every change to the contents of f is reflected in and vice versa. If the field symbol is not typed (see FIELD-SYMBOLS), the field symbol adopts the type and atrributes of the field f at runtime, particularly the conversion exit. Otherwise, when the assignment is made, the system checks whether the type of the field f matches the type of the field symbol .

Note
With the ASSIGN statement, the offset and length specifications in field f (i.e. f+off, f+len or f+off(len)) have a special
meaning:
- They may be variable and thus not evaluated until runtime.
- The system does not check whether the selected area still lies within the field f.
- If an offset is specified, but no length, for the field f, the field symbol adopts the length of the field f.

Caution: also points to an area behind the field f. If you do not want this, the offset and length specifications can be in the form ASSIGN f+off(*) TO .. This means that the field symbol is set so that the field limits of f are not exceeded.
- In the ASSIGN statement, you can also use offset and length specifications to access field symbols, FORM and function parameters.
- Warning: If the effect of the ASSIGN statement is to assign parts of other fields beyond the limits of the field f, the changing of the contents via the field symbol may mean that the data written to these fields does not match the data type of these fields and thus later results in a runtime error.

Note
Since the ASSIGN statement does not set any return code value in the system field SY-SUBRC, subsequent program code should not read this field.

Example
DATA NAME(4) VALUE ‘JOHN’.
FIELD-SYMBOLS .
ASSIGN NAME TO .
WRITE .

Output: JOHN

Example
DATA: NAME(12) VALUE ‘JACKJOHNCARL’,
X(10) VALUE ‘XXXXXXXXXX’.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .

Output: JOHNCARLXXXX JOHNCARL

Example
DATA: NAME(12) VALUE ‘JACKJOHNCARL’,
X(10) VALUE ‘XXXXXXXXXX’.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .

Output: JOHNCARLXXXX JOHNCARL

Addition 1 … TYPE typ

Effect With untyped field symbols, allows you to change the current type of the field symbol to the type typ. The output length of the field symbol is corrected according to its type. With typed field symbols, this addition should only be used if the type of the field f does not match the type of the field symbol . The specified type type must be compatible with the type of the field symbol. Since no conversion can be performed (as with MOVE, the system must be able to interpret f as a field with this type type. The type specification is in the form of a literal or a field. At present, only system types (C, D, T, P, X, N, F, I or W) are allowed; you can also specify type ‘s’ for 2-byte integer fields with a sign and type ‘b’ for 1-byte integer fields without a sign (see also DESCRIBE FIELD).

Note
This statement results in a runtime error if the specified type is unknown or does not match the field to be assigned (due to a missing alignment or an inappropriate length).

Example
DATA LETTER TYPE C.
FIELD-SYMBOLS .
ASSIGN LETTER TO .

The field symbol has the type C and the output length 1.

ASSIGN LETTER TO TYPE ‘X’.

The field symbol has the type X and the output length 2.

Addition 2 … DECIMALS dec

Effect
This addition only makes sense when used with type P. The field symbol contains dec decimal places.

Example
Output sales in thousands:
DATA SALES_DEC2(10) TYPE P DECIMALS 2 VALUE 1234567.
FIELD-SYMBOLS .
ASSIGN SALES_DEC2 TO DECIMALS 5.
WRITE: / SALES_DEC2,
/ .

Output:
1,234,567.00
1,234.56700

Note
This statement results in a runtime error if the field symbol has a type other than P at runtime or the specified number of decimal places is not in the range 0 to 14.

Addition 3 … LOCAL COPY OF …

Effect
With LOCAL COPY OF, the ASSIGN statement can only be used in subroutines. This creates a copy of f which points to the field symbol.

Note
The field symbol must also be defined locally in the subroutine.

Example
DATA X(4) VALUE ‘Carl’.

PERFORM U.

FORM U.
FIELD-SYMBOLS .
ASSIGN LOCAL COPY OF X TO .
WRITE .
MOVE ‘John’ TO .
WRITE .
WRITE X.
ENDFORM.

Output: Carl John Carl

Variant 2 ASSIGN (f) TO .
Additions:
1. … TYPE typ
2. … DECIMALS dec
3. … LOCAL COPY OF …

Effect
Assigns the field whose name is stored in the field f to the field symbol.
The statement “ASSIGN (f)+off(len) TO ” is not allowed.

Notes
- The search for the field to be assigned is performed as follows:
1. If the statement is in a subroutine or function module, the system first searches in this modularization unit.
2. If the statement lies outside any such modularization units or if the field is not found there, the system searches for the field in the global data of the program.
3. If the field is not found there, the system searches in the table work areas of the main program of the current program group declared with TABLES

- The name of the field to be assigned can also be the name of a field symbol or formal parameter (or even a component of one of these, if the field symbol or the parameter has a structure).

- If the name of the field to be assigned is of the form “(program name)field name”, the system searches in the global fields of the program with the name “Program name”
for the field with the name “Field name”. However,it is only found if the program has already been loaded.

Warning:
This option is for internal use by specialists only. ncompatible changes or developments may occur at any time without warning or prior notice. The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field symbol.

Example
DATA: NAME(4) VALUE ‘XYZ’, XYZ VALUE ’5′.
FIELD-SYMBOLS .
ASSIGN (NAME) TO .
WRITE .
Output: 5

Addition 1 … TYPE typ
Addition 2 … DECIMALS dec
Addition 3 … LOCAL COPY OF …

Effect
See similar additions of variant 1.

Variant 3
ASSIGN TABLE FIELD (f) TO .

Effect
Identical to variant 2, except that the system searches for the field f only in the data in the current program group declared with TABLES. The return code value is set as follows:

SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field symbol.

Example
TABLES TRDIR.
DATA NAME(10) VALUE ‘TRDIR-NAME’.
FIELD-SYMBOLS .
MOVE ‘XYZ_PROG’ TO TRDIR-NAME.
ASSIGN TABLE FIELD (NAME) TO .
WRITE .

Output: XYZ_PROG

Example
TABLES T100.
T100-TEXT = ‘Global’.
PERFORM EXAMPLE.

FORM EXAMPLE.
DATA: BEGIN OF T100, TEXT(20) VALUE ‘LOCAL’, END OF T100,
NAME(30) VALUE ‘T100-TEXT’.
FIELD-SYMBOLS .
ASSIGN (NAME) TO .
WRITE .
ENDFORM.

Output: Local – although the global table field T100-TEXT has “global” contents. (This kind of name assignment of work fields is, of course, not recommended.)

Example
TABLES TRDIR.
DATA: F(8) VALUE ‘F_global’,
G(8) VALUE ‘G_global’.
MOVE ‘XYZ_PROG’ TO TRDIR-NAME.

PERFORM U.

FORM U.

DATA: F(8) VALUE ‘F_local’,
NAME(30) VALUE ‘F’.
FIELD-SYMBOLS .
ASSIGN (NAME) TO .
WRITE .
MOVE ‘G’ TO NAME.
ASSIGN (NAME) TO .
WRITE .

MOVE ‘TRDIR-NAME’ TO NAME.
ASSIGN (NAME) TO .
WRITE .
ENDFORM.

Output: F_local G_global XYZ_PROG

Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE ‘TFDIR-PNAME’.
FIELD-SYMBOLS .
MOVE ‘XYZ_PROG’ TO TRDIR-NAME.
PERFORM U(P1SUB).
ASSIGN (NAME) TO .
WRITE .
CALL FUNCTION ‘EXAMPLE’.
PROGRAM P1SUB.
TABLES TFDIR.

FORM U.
FIELD-SYMBOLS .

DATA NAME(30) VALUE ‘TRDIR-NAME’.
ASSIGN TABLE FIELD (NAME) TO .
WRITE .
MOVE ‘FCT_PROG’ TO TFDIR-PNAME.
ENDFORM.

FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE ‘TRDIR-NAME’.
FIELD-SYMBOLS .

ASSIGN (NAME) TO .
IF SY-SUBRC = 0.
WRITE .
ELSE.
WRITE / ‘TRDIR-NAME cannot be accessed’.
ENDIF.
ENDFUNCTION.

Output: XYZ_PROG FCT_PROG
TRDIR-NAME cannot be accessed

Example
TABLES TRDIR.
MOVE ‘XYZ_PROG’ to TRDIR-NAME.
PERFORM U USING TRDIR.
FORM U USING X STRUCTURE TRDIR.
FIELD-SYMBOLS .
DATA NAME(30) VALUE ‘X-NAME’.
ASSIGN (NAME) TO .
WRITE .
ENDFORM.

Output: XYZ_PROG

Variant 4
ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .

Additions:
1. … TYPE typ
2. … DECIMALS dec
Note
This statement is for internal use only. Incompatible changes or further developments may occur at any time without warning or notice.

Effect
Identical to variant 3, except that the system searches for the field whose name is in f steht only in the data in the program group of the main program declared with TABLES. However, the field symbol then points not directly to the found field, but to a copy of this field on theq value stack. This variant therefore ensures that any access to Dictionary fields of an external program group is read only and no changes
are made.

Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE ‘TFDIR-PNAME’.
FIELD-SYMBOLS .
MOVE ‘XYZ_PROG’ TO TRDIR-NAME.
CALL FUNCTION ‘EXAMPLE’.
FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE ‘TRDIR-NAME’.
FIELD-SYMBOLS .
ASSIGN LOCAL COPY OF MAIN
TABLE FIELD (NAME) TO .
IF SY-SUBRC = 0.
WRITE .
ELSE.
WRITE / ‘TRDIR-NAME cannot be accessed’.
ENDIF.
ENDFUNCTION.

Output: XYZ_PROG

Addition 1 … TYPE typ
Addition 2 … DECIMALS dec

Effect
See similar additions to variant 1.

Variant 5 ASSIGN COMPONENT idx OF STRUCTURE rec TO .
Variant 6 ASSIGN COMPONENT name OF STRUCTURE rec TO .

Additions:
1. … TYPE typ
2. … DECIMALS dec

Effect
If the field name or idx has the type C or if it is a field string with no internal table, it is treated as a component name. Otherwise, it is considered as a component number. The corresponding component of the field string rec is assigned to the field symbol . The return code value is set as follows:

SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field symbol.

Note
If idx has the value 0, the entire field string is assigned to the field symbol.

Example
PROGRAM P1MAIN.
DATA: BEGIN OF REC,
A VALUE ‘a’,
B VALUE ‘b’,
C VALUE ‘c’,
D VALUE ‘d’,
END OF REC,
CN(5) VALUE ‘D’.
FIELD-SYMBOLS .
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF
STRUCTURE REC TO .
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE .
ENDDO.

ASSIGN COMPONENT CN OF STRUCTURE REC TO .
WRITE .

Output: a b c d

Addition 1 … TYPE typ
Addition 2 … DECIMALS dec

Effect
See similar additions to variant 1.

Note
Runtime errors: Depending on the operands, the ASSIGN statement can cause runtime errors.

Note
Performance: For performance reasons, you are recommended to use typed field symbols. The runtime for a typed ASSIGN statement amounts to approx. 9 msn (standardized microseconds) against approx. 13 msn for an untyped ASSIGN statement.

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 fg.
Control break with internal tables
- AT NEW f.
- AT END OF f.
- AT FIRST.
- AT LAST.


AT – Events in lists

Variants

1. AT LINE-SELECTION.
2. AT USER-COMMAND.
3. AT PFn.
Variant 1
AT LINE-SELECTION.
Effect
Event in interactive reporting

This event is processed whenever the user chooses a valid line in the list (i.e. a line generated by statements such as WRITE , ULINE or SKIP ) with the cursor and presses the function key which has the function PICK in the interface definition.

This should normally be the function key F2 , because it has the same effect as double-clicking the mouse, or single-clicking in the case of a hotspot .
The processing for the event AT LINE-SELECTION usually generates further list output (the details list) which completely covers the current list display. If the latter is still visible (to aid user orientation), this may be due to the key word WINDOW .
In most cases, the information is from the selected line is used to retrieve more comprehensive information by direct reading. When displaying the original list, you store the key terms needed for this in the HIDE area of the output line.
Note
You can choose a line and start new processing even in the details lists.
The following system fields are useful for orientation purposes, since their values change with each interactive event executed.
SY-LSIND Index of list created by current event (basic list = 0, 1st details list = 1, …) SY-PFKEY Status of displayed list (SET PF-STATUS ) SY-LISEL Contents of selected line SY-LILLI Absolute number of this line in the displayed list SY-LISTI Index of this list – usually SY-LSIND – 1 (READ LINE ) SY-CUROW Last cursor position: Line in window SY-CUCOL Last cursor position: Column in window (GET CURSOR ) SY-CPAGE 1st displayed page of displayed list SY-STARO 1st displayed line of this page of displayed list SY-STACO 1st displayed column of displayed list (SCROLL LIST )
The system field SY-LSIND defines the line selection level (basic list: SY-LSIND = 0).
Example

DATA TEXT(20).

START-OF-SELECTION.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.

AT LINE-SELECTION.
CASE TEXT.
WHEN ‘List index’.
PERFORM WRITE_AND_HIDE USING ‘X’ SPACE.
WHEN ‘User command’.
PERFORM WRITE_AND_HIDE USING SPACE ‘X’.
WHEN OTHERS.
SUBTRACT 2 FROM SY-LSIND.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.
ENDCASE.
CLEAR TEXT.

FORM WRITE_AND_HIDE USING P_FLAG_LSIND P_FLAG_UCOMM.
WRITE / ‘SY-LSIND:’.
PERFORM WRITE_WITH_COLOR USING SY-LSIND P_FLAG_LSIND.
TEXT = ‘List index’.
HIDE TEXT.
WRITE / ‘SY-UCOMM:’.
PERFORM WRITE_WITH_COLOR USING SY-UCOMM P_FLAG_UCOMM.
TEXT = ‘User command’.
HIDE TEXT.
IF SY-LSIND > 0.
WRITE / ‘PICK here to go back one list level’.
ENDIF.
ENDFORM.

FORM WRITE_WITH_COLOR USING P_VALUE
P_FLAG_POSITIVE.
IF P_FLAG_POSITIVE = SPACE.
WRITE P_VALUE COLOR COL_NORMAL.
ELSE.
WRITE P_VALUE COLOR COL_POSITIVE.
ENDIF.
ENDFORM.

Depending on whether you choose the line at SY-LSIND or SY-UCOMM , the next details list contains the corresponding value with the color “positive”. If the line is chosen without HIDE information, the list level is reduced.
Variant 2
AT USER-COMMAND.
Effect
Event in interactive reporting

This event is executed whenever the user presses a function key in the list or makes an entry in the command field .

Some functions are executed directly by the system and thus cannot be processed by programs. These include:
PICK See variant AT LINE-SELECTION PFn See variant AT PFn /… System command %… System command PRI Print BACK Back RW Cancel P… Scroll function (e.g.: P+ , P- , PP+3 , PS– etc.)
Instead of this functions, you can use the SCROLL statement in programs.
Since many of these system functions begin with “P”, you should avoid using this letter to start your own function codes.
Otherwise, the effect is as for AT LINE-SELECTION ; also, the current function code is stored in the system field SY-UCOMM .
Example

DATA: NUMBER1 TYPE I VALUE 20,
NUMBER2 TYPE I VALUE 5,
RESULT TYPE I.

START-OF-SELECTION.
WRITE: / NUMBER1, ‘?’, NUMBER2.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN ‘ADD’.
RESULT = NUMBER1 + NUMBER2.
WHEN ‘SUBT’.
RESULT = NUMBER1 – NUMBER2.
WHEN ‘MULT’.
RESULT = NUMBER1 * NUMBER2.
WHEN ‘DIVI’.
RESULT = NUMBER1 / NUMBER2.
WHEN OTHERS.
WRITE ‘Unknown function code’.
EXIT.
ENDCASE.
WRITE: / ‘Result:’, RESULT.

After entry of a function code, the appropriate processing is performed under the event AT USER-COMMAND and the result is displayed in the details list.
Variant 3
AT PFn.
Effect
Event in interactive reporting

Here, n stands for a numeric value between 0 and 99.
This event is executed whenever the user presses a function key that contains the function code PFn in the interface definition. The default status for lists contains some of these functions.

Otherwise, the effect is as for the variant AT LINE-SELECTION . The cursor can be on any line.
Notes
To ensure that the chosen function is executed only for valid lines, you can check the current HIDE information. This variant should be used only for test or prototyping purposes, since the default status is not normally used. Instead, you should set a program-specific status with SET PF-STATUS . This should not contain any function codes beginning with ” PF “.
Example

DATA NUMBER LIKE SY-INDEX.

START-OF-SELECTION.
DO 9 TIMES.
WRITE: / ‘Row’, (2) SY-INDEX.
NUMBER = SY-INDEX.
HIDE NUMBER.
ENDDO.

AT PF8.
CHECK NOT NUMBER IS INITIAL.
WRITE: / ‘Cursor was in row’, (2) NUMBER.
CLEAR NUMBER.

AT – Events on selection screens

Basic form
AT SELECTION-SCREEN.
Additions

1. … ON psel
2. … ON END OF sel
3. … ON VALUE-REQUEST FOR psel_low_high .
4. … ON HELP-REQUEST FOR psel_low_high
5. … ON RADIOBUTTON GROUP radi
6. … ON BLOCK block
7. … OUTPUT
Effect
This event only makes sense in reports, i.e. in programs set to type 1 in the attributes. Type 1 programs are started via a logical database and always have a selection screen where the user can specify the database selections.
The event is processed when the selection screen has been processed (at the end of PAI ).
If an error message ( MESSAGE Emnr ) is sent during the event, all fields on the selection screen become ready for input.
After further user input, AT SELECTION-SCREEN is executed again.
Note
You should only perform very expensive checks with AT SELECTION-SCREEN if the program is then started (not every time the user presses ENTER). Here, you can read the system field SSCRFIELDS-UCOMM (provided a statement TABLES SSCRFIELDS exists). If the field has one of the values ‘ONLI’ (= Execute) or ‘PRIN’ (= Execute and Print), the report is then started, i.e. the selection screen is closed and the processing continues with START-OF-SELECTION . Remember that the selection screen (and thus also AT SELECTION-SCREE N ) is also processed in variant maintenance and with SUBMIT VIA JOB . You can determine which of these applies by calling the function module RS_SUBMIT_INFO .
Addition 1
… ON psel
Effect
This event is assigned to the selection screen fields corresponding to the report parameter or selection criterion psel .
If the report starts an error dialog at this point, precisely these fields become ready for input.
Addition 2
… ON END OF sel
Effect
For each selection criterion sel on the selection screen, you can call a further screen by pressing a pushbutton. On this screen, you can enter any number of single values and ranges for the selection criterion sel .
When this screen has been processed (i.e. at the end of PAI for this screen), the event AT SELECTION-SCREEN ON END OF sel is executed.
At this point, all the values entered are available in the internal table sel .
Addition 3
… ON VALUE-REQUEST FOR psel_low_high
Effect
With this addition, the field psel_low_high is either the name of a report parameter or of the form sel-LOW or sel-HIGH , where sel is the name of a selection criterion. The effect of this is twofold:
The pushbutton for F4 (Possible entries) appears beside the appropriate field.
When the user selects this pushbutton or presses F4 for the field, the event is executed. You can thus implement a self-programmed possible entries routine for the input/output fields of the selection screen. If the program contains such an event and the user presses F4 , the system processes this rather than displaying the check table or the fixed values of the Dictionary field – even if the report parameter or the selection option with LIKE or FOR points to a Dictionary field. You can, for example, use the CALL SCREEN statement to display a selection list of possible values. The contents of the field psel_low_high at the end of this processing block are copied to the appropriate input/output field.
This addition is only allowed with report-specific parameters (PARAMETERS ) or selection options (SELECT-OPTIONS ). For database-specific parameters or selection options, you can achieve the same effect by using the addition VALUE-REQUEST FOR … with the key word PARAMETERS or SELECT-OPTIONS in the include DBxyzSEL (where xyz = name of logical database). In this case, you must program the value help in the database program ERPDBxyz .
Addition 4
… ON HELP-REQUEST FOR psel_low_high
Effect
As with the addition ON VALUE-REQUEST the field psel_low_high is either the name of a report parameter or of the form sel-LOW or sel-HIGH , where sel is the name of a selection criterion. When the user presses F1 on the relevant field, the subsequent processing block is executed. You can thus implement a self-programmed help for the input/output fields of the selection screen. If the program contains such an event and the user presses F1 , the system processes this rather than displaying the documentation of the Dictionary field – even if the report parameter or the selection option with LIKE or FOR points to a Dictionary field.
This addition is only allowed with report-specific parameters (PARAMETERS ) or selection options (SELECT-OPTIONS ). For database-specific parameters or selection options, you can achieve the same effect by using the addition HELP-REQUEST FOR … with the key word PARAMETERS or SELECT-OPTIONS in the include DBxyzSEL (where xyz = name of logical database). In this case, you must program the help in the database program ERPDBxyz .
Addition 5
… ON RADIOBUTTON GROUP radi
Effect
This event is assigned to the radio button groups on the selection screen defined by PARAMETERS par RADIOBUTTON GROUP radi .
If the report starts an error dialog at this point, precisely these fields of the radio button group radi become ready for input again.
Addition 6
… ON BLOCK block
Effect
This event is assigned to the blocks on the selection screen defined by SELECTION-SCREEN BEGIN/END OF BLOCK block .
If the report starts an error dialog at this point, precisely these fields of the block block become ready for input again.
Note
In which sequence are the events AT SELECTION-SCREEN ON psel … , AT SELECTION-SCREEN ON RADIOBUTTON GROUP … , AT SELECTION-SCREEN ON BLOCK … , AT SELECTION-SCREEN processed?
The AT SELECTION-SCREEN ON psel … events assigned to the parameters or selection options are executed in the sequence they are declared in the program, i.e. in the sequence they appear on the selection screen.
The events assigned to the radio button groups are executed according to the first parameter of the radio button group.
The events assigned to the blocks are executed “from the inside to the outside”.
Example

SELECT-OPTIONS SEL0 FOR SY-TVAR0.

SELECTION-SCREEN BEGIN OF BLOCK BL0.
SELECT-OPTIONS SEL1 FOR SY-TVAR1.

SELECTION-SCREEN BEGIN OF BLOCK BL1.
PARAMETERS P0 RADIOBUTTON GROUP RADI.
PARAMETERS P1 RADIOBUTTON GROUP RADI.

SELECTION-SCREEN BEGIN OF BLOCK BL2.
PARAMETERS P3.
SELECTION-SCREEN END OF BLOCK BL2.

SELECT-OPTIONS SEL2 FOR SY-TVAR2.

SELECTION-SCREEN END OF BLOCK BL1.

SELECTION-SCREEN END OF BLOCK BL0.

Sequence:

AT SELECTION-SCREEN ON…
SEL0
SEL1
RADIOBUTTON GROUP RADI
P3
BLOCK BL2
SEL2
BLOCK BL1
BLOCK BL0

AT SELECTION-SCREEN is executed at the very end.

Addition 7
… OUTPUT
Effect
This event is executed at PBO of the selection screen every time the user presses ENTER – in contrast to INITIALIZATION . Therefore, this event is not suitable for setting selection screen default values. Also, since AT SELECTION-SCREEN OUTPUT is first executed after the variant is imported (if a variant is used) and after adopting any values specified under SUBMIT in the WITH clause, changing the report parameters or the selection options in AT SELECTION-SCREEN OUTPUT would destroy the specified values.
Here, however, you can use LOOP AT SCREEN or MODIFY SCREEN to change the input/output attributes of selection screen fields.
Example
Output all fields of the SELECT-OPTION NAME highlighted:

SELECT-OPTIONS NAME FOR SY-REPID MODIF ID XYZ.

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CHECK SCREEN-GROUP1 = ‘XYZ’.
SCREEN-INTENSIFIED = ’1′.
MODIFY SCREEN.
ENDLOOP.

The addition MODIF ID XYZ to the key word SELECT-OPTIONS assigns all fields of the selection option NAME to a group you can read in the field SCREEN-GROUP1 . At PBO of the selection screen, all these fields are then set to highlighted.

AT – Control break with extracts

Variants

1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
5. AT fg.
Effect
In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the end of a control group ( AT END OF , AT LAST ), there are two types of control level information between AT and ENDAT :

* If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER ), the field CNT(h) contains the number of control breaks in the (subordinate) control level h .

* For extracted number fields g (see also ABAP/4 number types ), the fields SUM(g) contain the relevant control totals.

Notes
The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur.
The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF , AT LAST ), not at the beginning ( AT FIRST , AT NEW ).
When calculating totals with SUM(g) , the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded.
You can also use special control break control structures with LOOP s on internal tables.
Variant 1
AT NEW f.
Variant 2
AT END OF f.
Effect
f is a field from the field group HEADER . The enclosed sequence of statements is executed if

* the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER ) and

* the field f or a superior sort criterion has a different value in the current LOOP line than in the prceding ( AT NEW ) or subsequent ( AT END OF ) record of the extract dataset.

Example

DATA: NAME(30),
SALES TYPE I.
FIELD-GROUPS: HEADER, INFOS.
INSERT: NAME INTO HEADER,
SALES INTO INFOS.

LOOP.
AT NEW NAME.
NEW-PAGE.
ENDAT.

AT END OF NAME.
WRITE: / NAME, SUM(SALES).
ENDAT.
ENDLOOP.

Notes
If the extract dataset is not sorted before processing with LOOP , no control level structure is defined and the statements following AT NEW or AT END OF are not executed.
Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF . This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order.
Variant 3
AT FIRST.
Variant 4
AT LAST.
Effect
Executes the relevant series of statements just once – either on the first loop pass (with AT FIRST ) or on the last loop pass (with AT LAST ).
Variant 5
AT fg.
Addition

… WITH fg1
Effect
This statement makes single record processing dependent on the type of extracted record.

The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record).
Addition
… WITH fg1
Effect
Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1 .

AT – Control break with internal tables

Variants

1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
Effect
In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

* All default key fields (on the right) are filled with “*” after the current control level key.

* All other fields (on the right) are set to their initial values after the current control level key.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.
Notes
When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.
If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.
With LOOP s on extracts, there are also special control break control structures you can use.
Note
Runtime errors

* SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1
AT NEW f.
Variant 2
AT END OF f.
Effect
f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.
Example

DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.

LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.

The AT statements refer to the field COMPANIES-NAME .
Notes
If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.
By defining an offset and/or length, you can further restrict control break criteria – regardless of whether they are specified statically or dynamically.
A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.
Note
Runtime errors

* AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.

* AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

* ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

Variant 3
AT FIRST.
Variant 4
AT LAST.
Effect
Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.
Example

DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.

LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: ‘Sum of all SALES:’,
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.

AUTHORITY-CHECK : ABAP Keyword a day

AUTHORITY-CHECK

Basic form
AUTHORITY-CHECK OBJECT object
ID name1 FIELD f1
ID name2 FIELD f2

ID name10 FIELD f10.

Effect
Explanation of IDs:
object Field which contains the name of the object for which the authorization is to be checked.
name1 … Fields which contain the names of the name10 authorization fields defined in the object.
f1 … Fields which contain the values for which the f10 authorization is to be checked.
AUTHORITY-CHECK checks for one object whether the user has an authorization that contains all values of f (see SAP authorization concept).
You must specify all authorizations for an object and a also a value for each ID (or DUMMY ).
The system checks the values for the ID s by AND-ing them together, i.e. all values must be part of an authorization assigned to the user.
If a user has several authorizations for an object, the values are OR-ed together. This means that if the CHECK finds all the specified values in one authorization, the user can proceed. Only if none of the authorizations for a user contains all the required values is the user rejected.
If the return code SY-SUBRC = 0, the user has the required authorization and may continue.

The return code is modified to suit the different error scenarios. The return code values have the following meaning:
4 User has no authorization in the SAP System for such an action. If necessary, change the user master record.
8 Too many parameters (fields, values). Maximum allowed is 10.
12 Specified object not maintained in the user master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match those of an authorization. Either the authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.

If the return code value is 8 or possibly 24, inform the person responsible for the program. If the return code value is 4, 12, 15 or 24, consult your system administrator if you think you should have the relevant authorization. In the case of errors 28 to 36, contact SAP, since authorizations have probably been destroyed.
Individual authorizations are assigned to users in their respective user profiles, i.e. they are grouped together in profiles which are stored in the user master record.
Note
Instead of ID name FIELD f , you can also write ID name DUMMY . This means that no check is performed for the field concerned.
The check can only be performed on CHAR fields. All other field types result in ‘unauthorized’.
Example
Check whether the user is authorized for a particular plant. In this case, the following authorization object applies:

Table OBJ : Definition of authorization object

M_EINF_WRK
ACTVT
WERKS

Here, M_EINF_WRK is the object name, whilst ACTVT and WERKS are authorization fields. For example, a user with the authorizations

M_EINF_WRK_BERECH1
ACTVT 01-03
WERKS 0001-0003 .

can display and change plants within the Purchasing and Materials Management areas.

Such a user would thus pass the checks

AUTHORITY-CHECK OBJECT ‘M_EINF_WRK’
ID ‘WERKS’ FIELD ’0002′
ID ‘ACTVT’ FIELD ’02′.

AUTHORITY-CHECK OBJECT ‘M_EINF_WRK’
ID ‘WERKS’ DUMMY
ID ‘ACTVT’ FIELD ’01′:

but would fail the check

AUTHORITY-CHECK OBJECT ‘M_EINF_WRK’
ID ‘WERKS’ FIELD ’0005′
ID ‘ACTVT’ FIELD ’04′.

To suppress unnecessary authorization checks or to carry out checks before the user has entered all the values, use DUMMY – as in this example. You can confirm the authorization later with another AUTHORITY-CHECK .

BACK: ABAP Keyword a day

BACK.

Effect
Returns output position to the first line of the current page after the TOP-OF-PAGE processing.
When used in connection with RESERVE x LINES , the statement returns the output position to the first output line after RESERVE .

Example
DATA: TOWN(10) VALUE ‘New York’,
CUSTOMER1(10) VALUE ‘Charly’,
CUSTOMER2(10) VALUE ‘Sam’,
SALES1 TYPE I VALUE 1100,
SALES2 TYPE I VALUE 2200.
RESERVE 2 LINES.
WRITE: TOWN, CUSTOMER1,
/ CUSTOMER2 UNDER CUSTOMER1.
BACK.
WRITE: 50 SALES1,
/ SALES2 UNDER SALES1.

Using the positioning in WRITE in column 50, data not yet output is not overwritten, but the sales volume is output after the customer names.

Notes
If you use a ‘/’ with the first WRITE after the BACK statement, this starts a (usually unwanted) new line. BACK in the TOP-OF-PAGE processing positions the cursor after the standard header. Subsequent WRITE statements also overwrite the lines output under TOP-OF-PAGE .

Note
Performance
The runtime required to execute a BACK statement is about 1 msn (standardized microseconds).

BREAK-POINT : ABAP Keyword a day

BREAK-POINT
Variants:

1. BREAK-POINT.
2. BREAK-POINT f.


Variant 1
BREAK-POINT.
Effect
The BREAK-POINT statement interrupts the processing and diverts the system to debugging mode. You can then display the contents of all the fields at runtime and also control the subsequent program flow.
If the system is unable to branch to debugging for some reason (due to a background job or update), it generates a system log message.
Note

* After the BREAK-POINT , the system automatically performs any restart in the database, if no COMMIT WORK was executed. Since debugging sometimes switches off COMMIT WORK , you should not place a BREAK-POINT statement in a SELECT loop.

* In the editor, you can also set a breakpoint dynamically without making any changes to the ABAP/4 program. These dynamic breakpoints are valid only for the current user in the current session.

Variant 2
BREAK-POINT f.
Effect
Behaves like variation 1, except that the field contents of f remain in the event of any system log messages.

CASE: ABAP Keyword a day

CASE

Basic form
CASE f.

Effect Case distinction.
Depending on the current contents of a field, this statement executes one of several alternative processing branches. The field whose contents determine how the subsequent processing is specified after CASE ; the individual processing branches are introduced by WHEN , followed by the value to be tested. The entire block is concluded by ENDCASE . The structure of the CASE statement is as follows:

CASE f.
WHEN f1.

WHEN f2.


ENDCASE.

On reaching such a CASE statement, the processor compares f with f1 .
If f = f1 , it executes the processing block between ” WHEN f1. ” and the next WHEN statement. If there are no further WHEN statements, it executes the processing block up to the ENDCASE statement and then continues with any subsequent processing.
If f <> f1 , the processor compares the field f2 in the next WHEN statement with f and proceeds as with f1 and so on.

Although f should be a variable, f1 can be a variable or a literal. For the comparison ” f = f1 “, the rules are the same as for IF .

There is a second variant of the WHEN statement:

WHEN OTHERS.
No more than one such WHEN statement is allowed within a CASE block. The ” WHEN OTHERS ” processing block is always concluded by ENDCASE , i.e. no further WHEN statements can follow.

The ” WHEN OTHERS ” processing block is executed only if none of the preceding WHEN blocks have been executed, i.e. if all previous comparisons (” f = … ) have returned a negative result.
Example

DATA: ONE TYPE I VALUE 1,
THREE TYPE P VALUE 3.
DO 5 TIMES.
CASE SY-INDEX.
WHEN ONE.
WRITE / ‘That is’.
WHEN 2.
WRITE ‘a’.
WHEN THREE.
WRITE ‘good’.
WRITE ‘example’.
WHEN OTHERS.
WRITE ‘!’.
ENDCASE.
ENDDO.

Output: ” That is a good example ! ! “
Notes
You can nest several CASE statements and even combine them with IF statements.
The statement ” WHEN: f1, f2. ” does not make sense. The example below shows that the block belonging to ” WHEN f1 ” is empty:

WHEN f1.
WHEN f2.
Related
IF , ELSEIF

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 form
CHECK logexp.
Effect
CHECK evaluates the subsequent logical expression . If it is true, the processing continues with the next statement.

In loop structures like

DO … ENDDO
WHILE … ENDWHILE
LOOP … ENDLOOP
SELECT … ENDSELECT

CHECK with a negative outcome terminates the current loop pass and goes back to the beginning of the loop to start the next pass, if there is one.

In structures like

FORM … ENDFORM
FUNCTION … ENDFUNCTION
MODULE … ENDMODULE
AT

CHECK with a negative outcome terminates the routine or modularization unit.

If CHECK is not in a loop or a routine or a modularization unit, a negative logical expression terminates the current event. In contrast, the statement REJECT terminates the current event, even from loops or subroutines.
Note
If a CHECK produces a negative result in a GET event , the GET events in subordinate tables of the logical database are not processed either.
Related CONTINUE , EXIT , REJECT , STOP

CHECK – special for reports with logical databases

Variants

1. CHECK sel.
2. CHECK SELECT-OPTIONS.
Variant 1
CHECK sel.
Effect
Checks the selection criterion requested by the statement SELECT-OPTIONS sel … .

This statement is equivalent to f IN sel , if sel was defined by SELECT-OPTIONS sel FOR f and can be used anywhere in logical expressions

If the result of this check is negative, the processing in this event is terminated and the GET events for any subordinate database tables are not processed either.

This variant of the CHECK statement should be used only if the logical database for the corresponding table does not support dynamic selections (see CHECK SELECT-OPTIONS ), or SELECT-OPTIONS with the addition NO DATABASE SELECTION . Otherwise, the relevant record is not read from the database and made available to the program.
Variant 2
CHECK SELECT-OPTIONS.
Effect
Called only after a GET event.
This statement checks all the selections for SELECT-OPTIONS where the reference field after FOR belongs to the current table dbtab (specified after GET . However, this applies only if the logical database for dbtab does not support dynamic selections . Otherwise, the selections are passed directly to the logical database (with the exception: addition ” NO DATABASE SELECTION ” to SELECT-OPTIONS ).

This variant of the CHECK statement only makes sense if the logical database does not support dynamic selections for the corresponding table or SELECT-OPTIONS are defined with the addition ” NO DATABASE SELECTION “.

You can determine from the ABAP/4 Development Workbench whether dynamic selections are defined and, if so, for which logical database tables by selecting Development -> Programming environ. -> Logical databases followed by Extras -> Dynamic selections .
Example
The logical database F1S of the demo flight reservation system contains the tables SPFLI with, and the table SFLIGHT without, dynamic selections.

TABLES:
SPFLI, SFLIGHT.

SELECT-OPTIONS:
SF_PRICE FOR SFLIGHT-PRICE,
SP_CARR FOR SPFLI-CARRID,
SP_FROM FOR SPFLI-CITYFROM NO DATABASE SELECTION,
SP_DEPT FOR SPFLI-DEPTIME.

Since dynamic selections are defined with the table SPFLI , but not with the table SFLIGHT , the following procedure applies:

GET SFLIGHT.
CHECK SELECT-OPTIONS.

This CHECK statement is equivalent to the following statement:

CHECK SF_PRICE.

With

GET SPFLI.
CHECK SELECT-OPTIONS.

the CHECK statement is equivalent to the following statement:

CHECK SP_FROM.

Note
With CHECK SELECT-OPTIONS , fields from superior tables in the database hierarchy are not (!) checked.
Note
Runtime errors

* CHECK_SELOPT_ILLEGAL_OPTION : Wrong ” OPTION ” in SELECT-OPTIONS or RANGES table

* CHECK_SELOPT_ILLEGAL_SIGN : Wrong ” SIGN ” in SELECT-OPTIONS or RANGES table

Related CONTINUE , EXIT , REJECT , STOP

CLEAR : ABAP Keyword a day

CLEAR

Basic form
CLEAR f.
Additions

1. … WITH g
2. … WITH NULL

Effect
Resets the contents of f to its initial value.

For predefined types (see DATA ), the following initial values are used:
Type C : ‘ … ‘ (blank character) Type N : ’00…0′ Type D : ’00000000′ Type T : ’000000′
Type I : 0 Type P : 0 Type F : 0.0E+00 Type X : 0
If f is a field string, each component field is reset to its initial value. If it is an internal table without a header line, the entire table is deleted together with all its entries. If, however, f is an internal table with a header line, only the sub-fields in the table header entry are reset to their initial values.
Example

DATA: TEXT(10) VALUE ‘Hello’,
NUMBER TYPE I VALUE 12345,
ROW(10) TYPE N VALUE ’1234567890′,
BEGIN OF PLAYER,
NAME(10) VALUE ‘John’,
TEL(8) TYPE N VALUE ’08154711′,
MONEY TYPE P VALUE 30000,
END OF PLAYER.

CLEAR: TEXT, NUMBER, PLAYER.

The field contents are now as follows:

ROW = ’1234567890′
TEXT = ‘ ‘
NUMBER = 0
PLAYER-NAME = ‘ ‘
PLAYER-TEL = ’00000000′
PLAYER-MONEY = 0
Notes
When CLEAR references an internal table itab with a header line, it only resets the sub-fields in the header entry to their initial values (as mentioned above). The individual table entries remain unchanged.
To delete the entire internal table together with all its entries, you can use CLEAR itab[] or REFRESH itab . Here, a Note is still required to explain how to manipulate tables with/without header lines.
Within a logical expression , you can use f IS INITIAL to check that the field f contains the initial value appropriate for its type.
Variables are normally initialized according to their type, even if the specification of an explicit initial value (addition ” … VALUE lit ” of the DATA statement) is missing. For this reason, it is not necessary to initialize variables again with CLEAR after defining them.
Addition 1
… WITH g
Effect
The field f is filled with the value of the first byte of the field g .
Addition 2
… WITH NULL
Effect
Fills the field with hexadecimal zeros.
Note
You should use this addition with particular care because the fields of most data types thus receive values which are really invalid.
Note
Performance
CLEAR requires about 3 msn (standardized microseconds) of runtime to process a field of type C with a length of 10 and about 2 msn to process a field of the type I. To delete an internal table with 15 fields, it needs about 5 msn.

CLOSE: ABAP Keyword a day

CLOSE
Basic form

1. CLOSE DATASET dsn.
2. CLOSE CURSOR c.

Basic form 1
CLOSE DATASET dsn.
Effect
Closes the file dsn , ignoring any errors which may occur. CLOSE is required only if you want to edit dsn several times. For further details, see the documentation for OPEN DATASET .
Basic form 2
CLOSE CURSOR c.
Effect
Closes the database cursor c . CLOSE CURSOR is only required if you want to read sets of database records several times with c . For further information, refer to the documentation on OPEN CURSOR and FETCH .

CLOSE CURSOR belongs to the Open SQL command set.

CNT : ABAP Keyword a day

CNT

Basic form
… CNT(h) …
Effect
CNT(h) is not a statement, but a field which is automatically created and filled by the system if f is a sub-field of an extract dataset .

CNT(h) can only be addressed from within a LOOP on a sorted extract.
Type Standard output length Output
C len left-justified
D 8 left-justified
F 22 right-justified
I 11 right-justified
N len left-justified
P 2*len or 2*len+1 right-justified
T 6 left-justified
X 2*len left-justified
sorted extract.

If h is a non-numeric field (see also ABAP/4 number types ) from the field group HEADER and part of the sort key of the extract dataset, the end of a control level (AT END OF , AT LAST ) is such that CNT(h) contains the number of different values which the field h has accepted in the group, i.e. the number of records in the group for which the field f has changed its value.
Related
SUM(g)

COLLECT : ABAP Keyword a day

COLLECT
Basic form
COLLECT [wa INTO] itab.
Addition
… SORTED BY f

Effect
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

After COLLECT , the system field SY-TABIX contains the index of the – existing or new – table entry with default key fields which match those of the entry to be processed.
Notes
COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that

* the internal table will actually be unique or compressed, as described above and
* COLLECT will run very efficiently.

If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.
Example
Compressed sales figures for each company

DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = ‘Duck’. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = ‘Tiger’. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = ‘Duck’. COMPANIES-SALES = 30.
COLLECT COMPANIES.

The table COMPANIES now has the following appearance:

NAME SALES
Duck 40
Tiger 20

Addition
… SORTED BY f
Effect
COLLECT … SORTED BY f is obsolete and should no longer be used. Use APPEND … SORTED BY f which has the same meaning.
Note
Performance

The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.

A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).
Note
Runtime errors

* COLLECT_OVERFLOW : Overflow in integer field when calculating totals.
* COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals.

Related APPEND , WRITE … TO , MODIFY , INSERT

COMMIT: ABAP Keyword a day

COMMIT
Basic form
COMMIT WORK.
Addition
… AND WAIT

Effect
Executes a database commit and thus closes a logical processing unit or Logical Unit of Work ( LUW ) (see also Transaction processing ). This means that

* all database changes are made irrevocable and cannot be reversed with ROLLBACK WORK and

* all database locks are released.

COMMIT WORK also

* calls the subroutines specified by PERFORM … ON COMMIT ,

* executes asynchronously any update requests (see CALL FUNCTION … IN UPDATE TASK ) specified in these subroutines or started just before,

* processes the function modules specified in CALL FUNCTION … IN BACKGROUND TASK ,

* cancels all existing locks (see SAP locking concept ) if no update requests exist,

* closes all open database cursors (see OPEN CURSOR ) and

* resets the time slice counter to 0.

COMMIT WORK belongs to the Open SQL command set.
Return code value
The SY-SUBRC is set to 0.
Notes
All subroutines called with PERFORM … ON COMMIT are processed in the LUW concluded by the COMMIT WORK command. All V1 update requests specified in CALL FUNCTION … IN UPDATE TASK are also executed in one LUW . When all V1 update requests have been successfully concluded, the V2 update requests (“update with start delayed”) are processed, each in one LUW . Parallel to this, the function modules specified in CALL FUNCTION … IN BACKGROUND TASK are each executed in one LUW per destination.
COMMIT WORK commands processed within CALL DIALOG processing

- execute a database commit (see above),
- close all open database cursors,
- reset the time slice counter and
- call the function modules specified by CALL FUNCTION IN
BACKGROUND TASK in the CALL DIALOG processing.

However, subroutines and function modules called with PERFORM … ON COMMIT or CALL FUNCTION … IN UPDATE TASK in the CALL DIALOG processing are not executed in the calling transaction until a COMMIT WORK occurs.
Since COMMIT WORK closes all open database cursors, any attempt to continue a SELECT loop after a COMMIT WORK results in a runtime error. For the same reason, a FETCH after a COMMIT WORK on the now closed cursors also produces a runtime error. You must therefore ensure that any open cursors are no longer used after the COMMIT WORK .
With batch input and CALL TRANSACTION … USING , COMMIT WORK successfully concludes the processing.
Addition
… AND WAIT
Effect
The addition … AND WAIT makes the program wait until the type V1 updates have been completed.

The return code value is set as follows:

SY-SUBRC = 0 The update was successfully performed.
SY-SUBRC <> 0 The update could not be successfully performed.
Note
Runtime errors

* COMMIT_IN_PERFORM_ON_COMMIT : COMMIT WORK is not allowed in a FORM callled with PERFORM … ON COMMIT .

* COMMIT_IN_POSTING : COMMIT WORK is not allowed in the update task.

COMMUNICATION : ABAP Keywords a day

COMMUNICATION

Variants

1. COMMUNICATION INIT DESTINATION dest ID id.
2. COMMUNICATION ALLOCATE ID id.
3. COMMUNICATION ACCEPT ID id.
4. COMMUNICATION SEND ID id BUFFER f.
5. COMMUNICATION RECEIVE ID id
…BUFFER f
…DATAINFO d
…STATUSINFO s.
6. COMMUNICATION DEALLOCATE ID id.


The COMMUNICATION statement allows you to develop applications which perform direct program-to-program communication. The basis for this is CPI-C (Common Programming Interface – Coummunication), defined by IBM within the context of SAA standards as a standardized communications interface. The COMMUNICATION statement provides the essential parameters for implementing simple communication. Its starter set covers the following functionality:
Establishing a connection Accepting a communication Sending data Receiving data Closing a connection
The other essential part of such a communication is an ABAP/4 program containing a FORM routine which is executed when the connection has been established. This program may be in an R/3 System or an R/2> System. Here, you should be aware that the application programs themselves declare a protocol. In particular, logon to the partner SAP System must be performed in the calling program. The partner programs must also manage different character sets, e.g. ASCII – EBCDIC themselves. A facility known as the Remote Function Call ( RFC ) has now been developed to save users from having to deal with these problems. External programs (e.g. a program written in C on a UNIX workstation) can also be used as partner programs. For this purpose, SAP provides a platform-specific development library. For more detailed information about communication in the SAP System, you can refer to the manual
SAP Communication: Programming
Further information about communication can be found in any of the following literature:

IBM SAA
Common Programming Interface
Communication Reference
SC 26-4399

X/Open Developers’ Specification CPI-C
X/Open Company Ltd.
ISBN 1 872630 02 2
Variant 1
COMMUNICATION INIT DESTINATION dest ID id.
Addition
… RETURNCODE rc
Effect
Initializes a program-to-program connection.

The partner system is specified in the dest field. You can use any name you like, but it must be entered in the connection table TXCOM and can be no more than 8 characters long. This entry in TXCOM determines to which physical system a connection is established using the symbolic name of the target system.

In the field id , the system assigns an eight-character ID number of type C to the connection. The system field SY-SUBRC contains an appropriate return code value.
All return codes can be read using their symbolic names. For this purpose, you can use the program RSCPICDF which contains these names and can be included, if required.
Addition
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Variant 2
COMMUNICATION ALLOCATE ID id.
Addition
As for variant 1.
Effect
Sets up a program-to-program connection. The call must immediately follow COMMUNICATION INIT .
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Variant 3
COMMUNICATION ACCEPT ID id.
Addition
As for variant 1.
Effect
Accepts a connection requested by the partner program. id is a field of type C which is 8 characters long and contains the ID of the accepted connection after a successful call.
Example

FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.

Variant 4
COMMUNICATION SEND ID id BUFFER f.
Additions
1. … RETURNCODE rc
2. … LENGTH len
Effect
Sends data to the partner program. The data is stored in the field f which follows the key word parameter BUFFER . It is sent in the full length of the field f . If the partner program is part of a system which has a different character set, you must perform an appropriate conversion yourself. To do this, use the TRANSLATE statement.
Addition 1
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Addition 2
… LENGTH leng
Effect
Sends the contents of the field f to the partner program in the specified length.
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE
CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
RECORD = ‘The quick brown fox jumps over the lazy dog’.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Since the length is specified explicitly in this example, only the part ‘ The quick brown fox ‘ is transferred from the contents of the field RECORD .
Variant 5
COMMUNICATION RECEIVE ID id …BUFFER f …DATAINFO d …STATUSINFO s.
Additions
1. … RETURNCODE rc
2. … LENGTH leng
3. … RECEIVED m
4. … HOLD
Effect
Receives data in the field f . If no length is explicitly defined, the amount of data accepted depends on the length of the field. The fields d and s contain information about the receive process. You can address the contents of these using symbolic names in the include program RSCPICDF . The field d indicates whether the data was received in its entirety. The status field s informs the RECEIVE user of the status of the program. Here, it is important to know whether the program is in receive status or send status. It is, for example, not possible to send data if the program is in receive status.
For more detailed information about these protocol questions, refer to the manuals listed above.
Addition 1
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Addition 2
… LENGTH leng
Effect
Receives data only in the specified length leng .
Addition 3
… RECEIVED m
Effect
After the call, m contains the number of bytes received by the partner program.
Addition 4
… HOLD
Effect
Normally, data is received asynchronously, i.e. the system performs a rollout. However, this may not be desirable if, for example, the data is received in a SELECT loop, the database cursor is lost due to the rollout and the loop is terminated. To prevent a rollout, you can use the addition HOLD . Then, the SAP process waits until the data has been received and is thus available for use by other users.
Note
The fields d , s and m which contain information about the outcome of the call must be of type X with length 4.
Example

FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
INCLUDE RSCPICDF.

COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.

COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.

Variant 6
COMMUNICATION DEALLOCATE ID id.
Addition

As for variant 1
Effect
Severs connection and releases all resources.
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
DEST TYPE DESTINATION VALUE ‘C00′.

DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.

INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
RECORD = ‘The quick brown fox jumps over the lazy dog’.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION DEALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Note
The above examples illustrate the basic functionality of the key words. However, the example program can only have an external system as partner. If the partner is an SAP System, the calling program must first logon to the SAP System and receive an acknowledgement. Only then can you begin to transmit the actual data. When logging on to an R2 System and an R3 System, the logon data must be converted to EBCDIC . All user data should be converted according to the partner system. This is in the concluding example of an R/3 – R/2 connection.
Example

PROGRAM ZCPICTST.
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.

DATA: BEGIN OF CONNECT_STRING,
REQID(4) VALUE ‘CONN’,
TYPE(4) VALUE ‘CPIC’,
MODE(4) VALUE ’1 ‘,
MANDT(3) VALUE ’000′,
NAME(12) VALUE ‘CPICUSER’,
PASSW(8) VALUE ‘CPIC’,
LANGU(1) VALUE ‘D’,
KORRV(1),
REPORT(8) VALUE ‘ZCPICTST’,
FORM(30) VALUE ‘CPIC_EXAMPLE’,
END OF CONNECT_STRING.

DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘R2-SYST’,
CPIC_RC TYPE RETURN_CODE,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.

DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

* Convert logon data to EBCDIC
TRANSLATE CONNECT_STRING TO CODE PAGE ’0100′.
COMMUNICATION SEND ID CONVID BUFFER CONNECT_STRING.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
* Receive acknowledgement of logon
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
DATAINFO DINFO
STATUSINFO SINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION RECEIVE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
* Convert acknowledgement to ASCII
TRANSLATE RECORD FROM CODE PAGE ’0100′.

* Now begin user-specific data exchange
RECORD = ‘The quick brown fox jumps over the lazy dog’.

* Depending on the partner system, convert to another
* character set
TRANSLATE RECORD TO CODE PAGE ’0100′.

COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION DEALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

PROGRAM ZCPICTST.
INCLUDE RSCPICDF.
* The receiving procedure in the relevant partner program follows
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.

COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK AND CPIC_RC NE CM_DEALLOCATED_NORMAL.
EXIT.
ENDIF.
ENDFORM.