Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Pointers in ABAP

VB09104
Active Participant
0 Kudos

hello all,

can any one plz tell me what are pointers in ABAP n how they can be used in report?

thanks for help.

regards,

vikas

1 ACCEPTED SOLUTION

Former Member
0 Kudos

in ABAP Pointers call as Field symbols and see the example programs :

REPORT CHAP2401.

  • Defining a Field Symbol

FIELD-SYMBOLS <FS>.

  • Variable for later use

DATA FIELD VALUE 'X'.

  • Assigning a field to a Field Symbol

ASSIGN FIELD TO <FS>.

  • Using a Field Symbol which has an assigned field

WRITE <FS>.

Another one :

REPORT zfield_symbols .

TYPES: BEGIN OF t_p0121,

pernr TYPE pa0121-pernr,

rfp01 TYPE pa0121-rfp01,

rfp02 TYPE pa0121-rfp02,

rfp03 TYPE pa0121-rfp03,

rfp04 TYPE pa0121-rfp04,

END OF t_p0121.

DATA: it_p0121 TYPE STANDARD TABLE OF t_p0121 INITIAL SIZE 0,

wa_p0121 TYPE t_p0121.

DATA: gd_index TYPE string,

gd_rfp0 TYPE string.

FIELD-SYMBOLS: <fs1>, <fs2>.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

SELECT pernr

rfp01

rfp02

rfp03

rfp04

UP TO 10 ROWS

FROM pa0121

INTO TABLE it_p0121.

************************************************************************

*End-of-selection.

END-OF-SELECTION.

WA_P0121-RFP01 = '1234'.

CONCATENATE 'WA_P0121-RFP01' gd_index INTO gd_rfp0.

  • Now watch how the values change as you loop around the table fields

LOOP AT it_p0121 INTO wa_p0121.

write:/.

write:/ wa_p0121-pernr.

CLEAR: gd_index.

DO.

gd_index = gd_index + 1.

CONCATENATE 'WA_P0121-RFP0' gd_index INTO gd_rfp0.

  • assign with brackets

ASSIGN (gd_rfp0) TO <fs1>. "assigns the value of field name contained in variable

  • fs1 value would be the value of the field WA_P0121-RFP01..21

  • i.e. if index 1 and WA_P0121-RFP01 = 1234 then fs1 would = 1234

  • assign without brackets

ASSIGN gd_rfp0 TO <fs2>. " assigns the exact value contained in the field

  • fs1 value would literally be the same as the field WA_P0121-RFP01..21

  • i.e. if index 1 then fs2 would = 'WA_P0121-RFP01'

  • index 2 then fs2 would = 'WA_P0121-RFP02' etc...

  • you may also notice that once assigned any change made to the field gd_rfp0

  • is instantly reflected in the field symbol (fs2) so technically you could perform

  • the assign command once outside of the loop, but i have left it here to aid

  • readability.

write:/ <fs2>, <fs1>.

IF gd_index GE 21. "exit once last field has been read

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

Thanks

Seshu

4 REPLIES 4

Former Member
0 Kudos

in ABAP Pointers call as Field symbols and see the example programs :

REPORT CHAP2401.

  • Defining a Field Symbol

FIELD-SYMBOLS <FS>.

  • Variable for later use

DATA FIELD VALUE 'X'.

  • Assigning a field to a Field Symbol

ASSIGN FIELD TO <FS>.

  • Using a Field Symbol which has an assigned field

WRITE <FS>.

Another one :

REPORT zfield_symbols .

TYPES: BEGIN OF t_p0121,

pernr TYPE pa0121-pernr,

rfp01 TYPE pa0121-rfp01,

rfp02 TYPE pa0121-rfp02,

rfp03 TYPE pa0121-rfp03,

rfp04 TYPE pa0121-rfp04,

END OF t_p0121.

DATA: it_p0121 TYPE STANDARD TABLE OF t_p0121 INITIAL SIZE 0,

wa_p0121 TYPE t_p0121.

DATA: gd_index TYPE string,

gd_rfp0 TYPE string.

FIELD-SYMBOLS: <fs1>, <fs2>.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

SELECT pernr

rfp01

rfp02

rfp03

rfp04

UP TO 10 ROWS

FROM pa0121

INTO TABLE it_p0121.

************************************************************************

*End-of-selection.

END-OF-SELECTION.

WA_P0121-RFP01 = '1234'.

CONCATENATE 'WA_P0121-RFP01' gd_index INTO gd_rfp0.

  • Now watch how the values change as you loop around the table fields

LOOP AT it_p0121 INTO wa_p0121.

write:/.

write:/ wa_p0121-pernr.

CLEAR: gd_index.

DO.

gd_index = gd_index + 1.

CONCATENATE 'WA_P0121-RFP0' gd_index INTO gd_rfp0.

  • assign with brackets

ASSIGN (gd_rfp0) TO <fs1>. "assigns the value of field name contained in variable

  • fs1 value would be the value of the field WA_P0121-RFP01..21

  • i.e. if index 1 and WA_P0121-RFP01 = 1234 then fs1 would = 1234

  • assign without brackets

ASSIGN gd_rfp0 TO <fs2>. " assigns the exact value contained in the field

  • fs1 value would literally be the same as the field WA_P0121-RFP01..21

  • i.e. if index 1 then fs2 would = 'WA_P0121-RFP01'

  • index 2 then fs2 would = 'WA_P0121-RFP02' etc...

  • you may also notice that once assigned any change made to the field gd_rfp0

  • is instantly reflected in the field symbol (fs2) so technically you could perform

  • the assign command once outside of the loop, but i have left it here to aid

  • readability.

write:/ <fs2>, <fs1>.

IF gd_index GE 21. "exit once last field has been read

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

Thanks

Seshu

Former Member
0 Kudos

HI,

there is no concept of pointer in abap.

here we have a concept called field-symbols.these fields are same as like pointers in other languages.

<b>ex1:</b>

DATA: BEGIN OF LINE OCCURS 0,

COL1 TYPE I VALUE '11',

COL2 TYPE I VALUE '22',

COL3 TYPE I VALUE '33',

END OF LINE.

DATA COMP(5) VALUE 'COL2'.

FIELD-SYMBOLS: <F1>, <F2>, <F3>.

ASSIGN LINE TO <F1>.

ASSIGN COMP TO <F2>.

DO 3 TIMES.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.

WRITE <F3>.

ENDDO.

ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.

WRITE / <F3>.

<b>ex2:</b>

data:var1(10) value 'var2'.

data:var2(10) value 'var3'.

data:var3(10) value 'var4'.

data:var4(10) value 'output'.

field-symbols:<fs> type any.

field-symbols:<fs1> type any.

field-symbols:<fs2> type any.

assign (var1) to <fs>.

assign (<fs>) to <fs1>.

assign (<fs1>) to <fs2>.

write:/ <fs>, / <fs1>,/ <fs2>.

<b>reward if helpful</b>

rgds,

bharat.

Former Member
0 Kudos

Hi vikas

we use pointers to point address of variable . So you can use the data of variable by pointing address to the variable .

The good thing for pointer is you need not to keep data in your variable .

Example

DATA NAME(4) VALUE 'JOHN'.

FIELD-SYMBOLS <F> TYPE ANY.

ASSIGN NAME TO <F>.

WRITE <F>.

Output: JOHN

Example

DATA: NAME(12) VALUE 'JACKJOHNCARL',

X(10) VALUE 'XXXXXXXXXX'.

FIELD-SYMBOLS <F> TYPE ANY.

ASSIGN NAME+4 TO <F>.

WRITE <F>.

ASSIGN NAME+4(*) TO <F>.

WRITE <F>.

Output: JOHNCARLXXXX JOHNCARL

Regards

Wiboon

Former Member
0 Kudos

Hi Vikas,

The FIELD SYMBOLS used in ABAP are the pointers.. when we assign some field to a field symbol, the field symbol points to the memory location of the field..

And if we make any change in the field symboil value, the new values is reflected in the field too..

Thanks and Best Regards,

Vikas Bittera.