‎2010 May 05 8:13 PM
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.
‎2010 May 05 8:21 PM
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.
‎2010 May 05 8:23 PM
field-symbols: <fs> type any.
do.
assign component sy-index of structure S to <fs>.
if sy-subrc NE 0.
exit.
endif.
<fs> = '/'.
enddo.
‎2010 May 05 8:25 PM
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.