Field symbol- Pointer concept implemented in SAP - Sap 4 All

Latest

Please enter your email and get the updates in your inbox.

Friday, 17 June 2016

Field symbol- Pointer concept implemented in SAP

In SAP, the memory pointer concept which is used in many programming languages is implemented through what is known as field symbol. Filed symbol acts as a memory buffer and do not reserve any physical data field for the contents. Instead it references directly and point to the contents.

The syntax for the field symbol declaration is as below:

FIELD-SYMBOLS [|STRUCTURE  DEFAULT "wa" ]
Following are the features of the field symbol:
1. Field symbols are identified from other variables by the use of the angle brackets.

2. Again, it’s not necessary to provide the specifications at the time of declaration.

3. In case, the type is mentioned, the field symbol and data object type compatibility can be checked with the use of ASSIGN statement.

4. The field symbol has the important property of inheriting all the technical characteristics of the assigned field in case the data type is not declared.

5. Data operations can be done on the field symbols as in the case of variables and data constants.

6. One field symbol can be assigned to another. This helps in addressing parts of fields.

So where exactly is the advantage of using field symbols over the variables and constants?
Well the answer to this lies mostly in the programming algorithms. Complex data operations which involve many constants and variables create a bit of strain on the physical addresses and memory. They could potentially impact on the available memory and things available. This is exactly where field symbols come to usage. They can consume very less memory and give better results without much strain on the memory and hardware available. The only disadvantage is we should careful with the programming techniques using field symbols. Its important to unassign a field symbol before exiting from program. As they say, with great powers, comes great responsibilities. So is the case with field symbols.

Type declaration that are usually  used are:


·         TYPE D,F,I or T(Elementary type declarations)
·         TYPE(The TYPES declared in the program or based on tables types)
·         TYPE REF to (Type based on reference variable)
·         TYPE LINE of (reference to line of internal table or dictionary table )
·         LIKE (Like another field symbol)


Its always a good practice to create a field symbol which is meaningful to its type.

For example,<fs_likp> looks more meaningful when referenced to LIKP table.It makes readers and users understand the code much better.

Different ways to use field symbol[code snippets]
·         Assigning a field symbol
        <fs_likp> type likp
          LOOP at i_likp ASSIGNING <fs_likp>
·         Using as a work area
           Append intitial line to i_likp ASSIGNING <fs_likp>.
·          Reading a interntal table using field symbol

                   READ  table i_likp ASSIGNING<fs_LIKP>
                   WITH KEY BELNR EQ ‘234567’
                    IF  SY_SUBRC EQ 0.
                    MOVE <fs_likp>  TO .
                    ENDIF.
·         Using a field symbol in loop
          LOOP AT i_likp ASSIGNING<fs_likp>
         IF <fs_likp> EQ  c_belnr
         MOVE <fs_likp>  TO

·           Unassigning/Destructing a field symbol

                 UNASSIGN <fs_likp> (this is to be done after all the computations and usage of field symbol are done.Part of best practices in abap programming)

You can also check demo programs in SAP.One of the sample programs provided for same by SAP R/3 is DEMO_FIELD_SYMBOLS_ASSIGN_COMP.

No comments:

Post a Comment