SAP ABAP SYNTAX FOR ASSIGN PART TWO

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:

If the statement is in a subroutine or function module, the system first searches in this modularization unit. 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. 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. Incompatible 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.

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

Variant 4

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

Additions




1. ... TYPE typ
2. ... DECIMALS dec

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.

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.

No comments :

Post a Comment