FIELD-SYMBOLS IN SAP&ABAP

Abdullah Dundar
5 min readJul 23, 2023

--

Hello everyone. I have prepared an article about field-symbols, which I have been in for a while, which is related to abap development and which is widely used in this world and should be understood well. so let’s get started.

These field-symbols in the ABAP programming language are similar to the pointers in C or C++ languages, but it would not be correct to say exactly the same.

If we look at the figure above, we see an array representing memory. The ‘LV_CHAR’ object stores address 1042 and has the value ‘B’. ‘LR_PTR’, on the other hand, can reach the value ‘B’ by referencing the address 1042. The ‘<LFS>’ value, on the other hand, is understood as another name for ‘LV_CHAR’. Changes made to ‘LV_CHAR’ are passed to ‘<LFS>’ and vice versa. Therefore, you can think of symbols as a de-referenced pointer.

One advantage of field-symbols over regular data objects is that they can be written globally. Generally typed field-symbols inherit the attributes of the data object they point to when an assignment is made at runtime. We can define field-symbols as any type, but this is not a recommended use, even it can be given as an example of bad use. Therefore, we need to determine the type as accurately as possible.

ASSIGNING DATA OBJECTS TO FIELD-SYMBOLS

Initially, no field-symbols is assigned to any data object. Therefore, to start using a field symbol, you must use the ASSIGN statement to bind it to a data object; otherwise, an error will occur if you try to access the field symbol at runtime.

We can also check if a field-symbol is assigned with the ‘IS ASSIGNED’ keyword.

STATIC ASSIGNMENTS

As we have mentioned before, it has a usage as seen in the example below. In static assignments, it is possible to make assignments by operating on the string value.

DYNAMIC ASSIGNMENTS

While developing the algorithm, sometimes we may not know the name of the value to be assigned, in this case, by typing a value in parentheses as in the image below, it sees this character string as the value to be assigned to the field sybmbole. A point to remember is that the ‘ASSIGN’ keyword can be used in dynamic as well as static.

WORKING WITH STRUCTURES

Above we worked with basic data types. So how can we work with structures? As seen in the example below, we can derive the field symbol from a structure and reach the values of that structure with the ( — ) operator.

sometimes you may know little or nothing about the build object you are working on. In these cases, you can use the ‘ASSIGN COMPONENT’ statement to dynamically iterate over the components of a particular structure.

WORKING WITH ITABS

Field-symbols can also be used in itabs. It can be used in loops and reads for tables in the same way. Perhaps the most powerful aspect of these symbols is to be able to access the rows of these tables one by one. Many developers nowadays use loops like below, but in this case there is a problem, in which case it is copied from itab to structure in each loop. This can be performance degrading for large tables.

The best way to loop these is to use field-symbols. Instead of copying the current row into a separate workspace using the INTO suffix of the LOOP statement, we assign the current row a type-compliant field-symbol using the ASSIGNING suffix of the LOOP statement. This technique avoids unnecessary duplication by simply assigning the <lfs_flight> field symbol a reference to the current line.

Also, this feature can be used when making a read table.

Casting Data Objects During the Assignment Process

In addition to ABAP assignments, it also allows the assignment of mixed data types with the CAST operation. The only requirement is that the length and alignment of the assigned data object must be compatible with the field symbol type.

Let’s consider the CAST operation with an example. In the following lines of code, the ‘lv_tstamp_raw’ variable is assigned a value as instant year, month, day, hour, minute, second, second. Then this value is set to ‘<lfs_timestamp>’ with CAST operation. Thus, type mismatch is avoided. The value ‘<lfs_timestamp>’ is assigned to the variable lv_time after it is filled. The last CAST operation is used to associate the variable ‘lv_tstamp_txt’ with a FIELD-SYMBOL of type ‘ly_timestamp’, ‘<lfs_generic>’. This operation is used to assign the value in ‘lv_tstamp_txt’ to the field symbol ‘<lfs_generic>’ and perform type conversion.

Thank you for reading. I hope I was able to explain the issue. If you like my article and want to be informed about my articles that I will share later, you can follow me. You can reach us via e-mail and LinkedIn.

--

--

Abdullah Dundar

I am Computer science engineer. I am currently developing SAP&ABAP and ı do things what ı enjoy.