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: 

replace all ocurrences in a loop with space and structure

AJeB
Participant
387

hi i have a structure with 70 fields and in each field i need to replace some characters to space i tried this code

sample
in structure if check i check in debug
each field has length of 19

field1 = this is field1 test
field2 = test this is field2
field3 = test this is field3
etc....
code

do 70 times.<br>    replace all occurences of 'test' in lv_header with space.<br>enddo.

the problem is if i put the lv_header only

the field value become
field1 = this is field1 this
field2 = is field2 this is f
field3 = ield3

i can't put something like this -> lv_header-field1 / lv_header-field2 etc,... in replace all occurences because there are 70 fields needed to replace

how i can replace the fields value inside a loop? is my code correct or there is an additional code for this?

1 ACCEPTED SOLUTION

jens_michaelsen
Participant
340

You can try it with something like this

DO 70 TIMES. 
ASSIGN COMPONENT sy-index OF STRUCTURE my_workarea TO <my_field_symbol>. "my_field_symbol Type any 
IF sy-subrc NE 0. 
CONTINUE. 
ENDIF. 
REPLACE ALL OCCURENCES OF 'test' IN <my_field_symbol> WITH space. 
ENDDO. 
5 REPLIES 5

jens_michaelsen
Participant
341

You can try it with something like this

DO 70 TIMES. 
ASSIGN COMPONENT sy-index OF STRUCTURE my_workarea TO <my_field_symbol>. "my_field_symbol Type any 
IF sy-subrc NE 0. 
CONTINUE. 
ENDIF. 
REPLACE ALL OCCURENCES OF 'test' IN <my_field_symbol> WITH space. 
ENDDO. 

0 Kudos
340

Is there a reason to use CONTINUE instead of EXIT?

340

Tomorrow I was a litle bit tired, you are right: EXIT is better than CONTINUE

Sandra_Rossi
Active Contributor
340

The term "workarea" is a term used in the ABAP documentation to name few placeholders in some ABAP statements where "workarea" can represent anything, not only structures. For instance, READ TABLE itab INTO workarea, workarea can be anything (structure, scalar/elementary, internal table, etc.)

You can say "structure" or "structured variable" instead.

AJeB
Participant
0 Kudos
340

thanks sandra.rossi