Field Symbols - Syntax & Sample Program (SAP ABAP Keyword).


- In SAP, A field symbol can point to any data object.

- Field symbols can be created without any attributes or with a type specification. If a field symbol is created without attributes, it takes on the attributes of the field to which it is assigned. If a field symbol is assigned a type specification, the system verifies that the types of the field and field symbol are compatible.

- To declare a field symbol in SAP ABAP, use the statement

FIELD-SYMBOLS <FS>  [ <type> | STRUCTURE <S>  DEFAULT <WA> ].

Angle brackets (<>) are part of the syntax, which basically allows to distinguish the field symbols from the normal fields in the programs.

- The <type> addition is used to specify the type of a field symbol.

If there is no type specification it means the field symbol adopts all of the attributes of the data object.

TYPE ANY - Field symbol adopts all of the attributes of the data object.

TYPE C, N, P, or X - The field symbols points to data objects with type C, N, P, or X only.

TYPE TABLE - The field symbols points to data object which is a standard internal table.

TYPE ANY TABLE - The field symbols points to data object which is an internal table.


EXAMPLE - 1:

DATA: number TYPE I.

FIELD-SYMBOLS: <fs>,
<fs_1> TYPE I,
<fs_2> LIKE number.

number = 1.

ASSIGN : number to <fs>,
number to <fs_1>,
number to <fs_2>.

WRITE : / number , <fs>, <fs_1> , <fs_2>.
<fs> = 10.
WRITE : / number , <fs>, <fs_1> , <fs_2>.

OUTPUT:
  1         1         1        1
10        10       10      10

- ASSIGN statement associates a field to the field symbol when the program is executed. After successful assignment, there is no difference in using the field symbol or the field itself.


EXAMPLE - 2:

DATA: statement(20) TYPE c VALUE 'Rajan, how are you?',
number TYPE i VALUE 5.

DATA: BEGIN OF line1,
col1 TYPE f VALUE '2.2e+11',
col2 TYPE i VALUE '9876',
END OF line1.

DATA: line2 LIKE line1.

FIELD-SYMBOLS: <fs1> TYPE ANY, <fs2>  TYPE i.

ASSIGN statement TO <fs1> .
ASSIGN number TO <fs2> . "
DESCRIBE FIELD <fs1> LENGTH <fs2>.
WRITE: / <fs1>, 'has length', number.

OUTPUT:


Rajan, how are you? has length 20


EXAMPLE - 3.


Dynamic Assignment Of Partial Character Strings.


DATA: text(30) VALUE 'ANKUSHKUMAR'.
FIELD-SYMBOLS: <fs>.

ASSIGN text +2(5) to <fs>.

WRITE:/ 'TEXT = ', text.
WRITE:/ 'FIELD SYMBOL = ', <fs>.

<fs> = '9876543210'.


WRITE:/ 'FIELD SYMBOL = ', <fs>.

WRITE:/ 'TEXT = ', text.

OUTPUT:

TEXT = ANKUSHKUMAR
FIELD SYMBOL = KUSHK

FIELD SYMBOL = 98765
TEXT = AN98765UMAR.


ALSO READ:


- Elementary Data Types, Initial Values, Syntax & Properties.

- Type Conversion ( Char To Curr Type).

- Type Conversion ( Curr To Char Type).

- ELEMENTARY DATA TYPES - Initial Values, Syntax & Properties.

- FIELD SYMBOLS - Introduction, Syntax & Examples.

- PARAMETERS - Introduction, Syntax & Examples.

- SELECT-OPTIONS - Introduction, Syntax & Examples.

- SELECTION-SCREEN - Introduction, Syntax & Examples.

- SSCRFIELDS - The Screen Fields Table.

- ...Back To Index On Report Programming.



Your suggestions and comments are welcome in this section.


Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.