Comparing SAP ABAP Field symbols and data reference with Pointers in C

Field symbols resemble pointers in C but there is one main difference: you can use field symbols only to access the values present in them but not the memory address. Similar to a pointer in actual implementation, a field symbol stores the memory address of the variable that was assigned to it. You can see the data held by the variable but you cannot fetch the memory address. Similar to a pointer, if you make changes to data referenced by field symbol, it changes the value at the original location too.

Data references also resemble pointers at a high level. You can access memory address in this case. You can compare two data references to verify whether both of them refer to the same memory location. However, you cannot use increment or decrement operations on the memory address, unlike pointers in C. Memory allocation can be done dynamically in this case if you use the CREATE DATA command.

Key Differences Overview

C Pointers ? Access memory address ? Access values ? Increment/decrement ? Pointer arithmetic ? Manual memory mgmt Field Symbols ? Cannot access address ? Access values only ? No arithmetic ? Type checking ? Automatic memory Data References ? Can access address ? Access values ? No arithmetic ? Reference comparison ? CREATE DATA support

Example Comparison

Here's how similar operations look in C pointers versus ABAP field symbols and data references ?

" ABAP Field Symbol
FIELD-SYMBOLS: <fs_var> TYPE i.
DATA: lv_number TYPE i VALUE 10.

ASSIGN lv_number TO <fs_var>.
<fs_var> = 20.  " Changes lv_number to 20

" ABAP Data Reference
DATA: lr_data TYPE REF TO i.
CREATE DATA lr_data.
lr_data->* = 30.  " Assign value through reference
// C Pointer equivalent
#include <stdio.h>
#include <stdlib.h>

int main() {
    int number = 10;
    int *ptr = &number;
    
    *ptr = 20;  // Changes number to 20
    printf("Value: %d, Address: %p<br>", *ptr, (void*)ptr);
    
    // Dynamic allocation
    int *dyn_ptr = (int*)malloc(sizeof(int));
    *dyn_ptr = 30;
    printf("Dynamic value: %d<br>", *dyn_ptr);
    free(dyn_ptr);
    
    return 0;
}

The output of the above C code is ?

Value: 20, Address: 0x7fff5fbff6ac
Dynamic value: 30

Conclusion

While ABAP field symbols and data references provide pointer-like functionality, they offer safer memory management compared to C pointers by restricting direct address manipulation and providing automatic memory handling.

Updated on: 2026-03-13T18:04:43+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements