Application Development and Automation 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: 
Read only

How to initialize the structure fields with the same value

Former Member
0 Likes
944

Hello Expert,

Suppose the structure S has more than 50 fields. I want to initial every field with the same value '/'. If I initialize the fields one by one by the statement: S-field = '/', I have to write more than 50 statements. It's time-consuming and the program is also urgly.

How can I initial the structure fields with value '/' by one or two statements?

Thnanks for help.

Best Regards, Johnny.

3 REPLIES 3
Read only

asik_shameem
Active Contributor
0 Likes
569

Hello Yongbo,

Just use field symbols to achieve this. Try something as below.

DATA: gs_makt TYPE makt.
FIELD-SYMBOLS: <gfs_field>.
CONSTANTS: gc_nodata TYPE c VALUE '/'.

CLEAR sy-subrc.
WHILE sy-subrc EQ 0.
  ASSIGN COMPONENT sy-index OF STRUCTURE gs_makt TO <gfs_field>.
  WRITE gc_nodata TO <gfs_field> LEFT-JUSTIFIED.
ENDWHILE.

Read only

karol_seman
Active Participant
0 Likes
569

field-symbols: <fs> type any.

do.
  assign component sy-index of structure S to <fs>.
  if sy-subrc NE 0.
    exit.
  endif.

  <fs> = '/'.
enddo.
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
569

field-symbols<fs>.
clear sy-subrc.
  WHILE sy-subrc EQ 0.
    ASSIGN COMPONENT sy-index OF STRUCTURE ST1 TO <fs>.
    WRITE '/' TO <fs> LEFT-JUSTIFIED.
  ENDWHILE.