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: 

Field Symbols

Former Member
0 Kudos

What is ment by following statements?

ASSIGN A INCREMENT B TO <FS>.

ASSIGN A INCREMENT <FS1> TO <FS2>.

ASSIGN <FS1> INCREMENT <FS2> TO <FS3>.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Increments the field symbol <fs>, starting from f, by n times the length of f. You cannot use offset/length addressing in f. If the system cannot assign f to the field symbol - that is, if it addresses an invalid memory area - the field symbol remains unchanged and sy-subrc is set to 4.

SY-SUBRC = 0:

The field was assigned successfully.

SY-SUBRC = 4:

The field was not assigned successfully. the field symbol

remains unchanged

Example

DATA: cf(26) TYPE c VALUE 'abcdefghijklmnopqrstuvwxyz'.

FIELD-SYMBOLS: <fs> TYPE c.

ASSIGN cf(2) TO <fs>.

DO 5 TIMES.

WRITE <fs>.

ASSIGN <fs> INCREMENT 3 TO <fs>.

ENDDO.

In this example, the field symbol points to the first two characters of the field cf. Then in each loop pass, the field symbol is incremented 3 times 2 characters. The system then displays the result: ab gh mn st yz.

Example

TYPES: BEGIN OF comp,

f1 TYPE string,

f2 TYPE i,

END OF comp.

DATA: BEGIN OF stru,

k1 TYPE comp,

k2 TYPE comp,

k3 TYPE comp,

k4 TYPE comp,

END OF stru.

FIELD-SYMBOLS: TYPE comp.

ASSIGN stru-k1 TO RANGE stru.

DO 4 TIMES.

...

ASSIGN INCREMENT 1 TO .

ENDDO.

This example shows you how to edit a sequence of identically-typed sub-structures in a loop.

Source SAP Help,

Regards,

Amit

1 REPLY 1

Former Member
0 Kudos

Hi,

Increments the field symbol <fs>, starting from f, by n times the length of f. You cannot use offset/length addressing in f. If the system cannot assign f to the field symbol - that is, if it addresses an invalid memory area - the field symbol remains unchanged and sy-subrc is set to 4.

SY-SUBRC = 0:

The field was assigned successfully.

SY-SUBRC = 4:

The field was not assigned successfully. the field symbol

remains unchanged

Example

DATA: cf(26) TYPE c VALUE 'abcdefghijklmnopqrstuvwxyz'.

FIELD-SYMBOLS: <fs> TYPE c.

ASSIGN cf(2) TO <fs>.

DO 5 TIMES.

WRITE <fs>.

ASSIGN <fs> INCREMENT 3 TO <fs>.

ENDDO.

In this example, the field symbol points to the first two characters of the field cf. Then in each loop pass, the field symbol is incremented 3 times 2 characters. The system then displays the result: ab gh mn st yz.

Example

TYPES: BEGIN OF comp,

f1 TYPE string,

f2 TYPE i,

END OF comp.

DATA: BEGIN OF stru,

k1 TYPE comp,

k2 TYPE comp,

k3 TYPE comp,

k4 TYPE comp,

END OF stru.

FIELD-SYMBOLS: TYPE comp.

ASSIGN stru-k1 TO RANGE stru.

DO 4 TIMES.

...

ASSIGN INCREMENT 1 TO .

ENDDO.

This example shows you how to edit a sequence of identically-typed sub-structures in a loop.

Source SAP Help,

Regards,

Amit