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

REPLACE ALL OCCURRENCES = Short dump!

Former Member
0 Likes
6,370

I am getting confused around the REPLACE ALL OCCURRENCES command..

basically..

I have a field that i need to convert to CAPS and replace the "spaces" with "_"

But my lack of abap skills = Short dump!

So this short dump hinted that the field was to blame as it was String (0).. so i thought i would move into the CHAR30 field as it would be no longer than 30 characters...


    MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.

        TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.
        REPLACE ALL OCCURRENCES OF SPACE IN GW_CAMPAIGN_NAME WITH '_'.

But this still results in the short dump:

Runtime Errors REPLACE_INFINITE_LOOP

Exception CX_SY_REPLACE_INFINITE_LOOP

Maybe i am missing something but the error said:

Ensure that the command "REPLACE ALL OCCURENCES OF ..." is not executed with a search string of length 0.

I am using the same command, but only for populating variables into a text string... that is replacing &1 rather than a space!

I did try the REGEX command i also found in keyword search but that resulted in a different short dump!

Am i missing something obvious??

1 ACCEPTED SOLUTION
Read only

che_eky
Active Contributor
0 Likes
3,573

Hi,

The following should work:

MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.

TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.

TRANSLATE GW_CAMPAIGN_NAME USING ' _'.

Note the space before the underscore above ' _', this should replace all occurrences of space with an underscore.

Che

I am getting confused around the REPLACE ALL OCCURRENCES command..

basically..

I have a field that i need to convert to CAPS and replace the "spaces" with "_"

But my lack of abap skills = Short dump!

So this short dump hinted that the field was to blame as it was String (0).. so i thought i would move into the CHAR30 field as it would be no longer than 30 characters...


    MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.

        TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.
        REPLACE ALL OCCURRENCES OF SPACE IN GW_CAMPAIGN_NAME WITH '_'.

But this still results in the short dump:

Runtime Errors REPLACE_INFINITE_LOOP

Exception CX_SY_REPLACE_INFINITE_LOOP

Maybe i am missing something but the error said:

Ensure that the command "REPLACE ALL OCCURENCES OF ..." is not executed with a search string of length 0.

I am using the same command, but only for populating variables into a text string... that is replacing &1 rather than a space!

I did try the REGEX command i also found in keyword search but that resulted in a different short dump!

Am i missing something obvious??

12 REPLIES 12
Read only

former_member156446
Active Contributor
0 Likes
3,573

try this :


data: c_space type space.

if not GW_CAMPAIGN_NAME is initial.
TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.
        REPLACE ALL OCCURRENCES OF c_SPACE IN GW_CAMPAIGN_NAME WITH '_'.
endif.

Read only

che_eky
Active Contributor
0 Likes
3,574

Hi,

The following should work:

MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.

TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.

TRANSLATE GW_CAMPAIGN_NAME USING ' _'.

Note the space before the underscore above ' _', this should replace all occurrences of space with an underscore.

Che

Read only

Former Member
0 Likes
3,573

you can see i define pattern with char2,so pattern = space + '_', try it

DATA: out       TYPE string VALUE 'DO you hear me!!!',
          pattern  TYPE char2 VALUE ' _'.
TRANSLATE out USING pattern.
WRITE out.

Read only

peter_ruiz2
Active Contributor
0 Likes
3,573

Hi Barry,

Use CONDENSE

CONDENSE GW_CAMPAIGN_NAME NO-GAPS.

Regards,

Peter

Read only

asik_shameem
Active Contributor
0 Likes
3,573

Hi

Try like this.

DATA: g_string TYPE char30 VALUE '     ABC  def       ',
      g_index  TYPE sy-index.

TRANSLATE g_string TO UPPER CASE.

DO 30 TIMES.

  g_index = sy-index - 1.

  IF g_string+g_index(1) = ' '.

    REPLACE space IN g_string+g_index(1) WITH '_'.

  ENDIF.

ENDDO.

BREAK-POINT.

Read only

Former Member
0 Likes
3,573

hello,

i hope this helps you ... as this solution is not so performing you can use this incase u still have the dump problem. in the while if i get any good solution i will reply back . just copy paste and try out.

data : wf_string type string value 'I am so sweet'.

data : wf_string_tmp type string .

data : itab type table of string.

data : wf_itab like line of itab.

split wf_string at wf_space into table itab.

loop at itab into wf_itab.

if sy-tabix EQ 1.

wf_string_tmp = wf_itab.

else.

concatenate wf_string_tmp wf_itab into wf_string_tmp separated by '_'.

endif.

endloop.

write : / wf_string_tmp.

--- Close the post once you get the solution

Read only

Former Member
0 Likes
3,573

Hi:

It seems ok just you should add few things like

if not GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME is initial.

MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.

TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.

REPLACE ALL OCCURRENCES OF SPACE IN GW_CAMPAIGN_NAME WITH '_'.

endif.

Regards

Shashi

Read only

Former Member
0 Likes
3,573

.

Read only

Former Member
0 Likes
3,573

see the following example

LOOP AT it_otfdata1 INTO wotfdata .

REPLACE ALL OCCURRENCE OF 'DUPLICATE' IN wotfdata-tdprintpar WITH 'ORIGINAL'.IF sy-subrc = 0.*

MODIFY it_otfdata1 FROM wotfdata INDEX sy-tabix TRANSPORTING tdprintpar.

ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
3,573

I changed the work area back to a String and then used the following:

    MOVE GS_SPECIFIC_CAMPAIGN-CAMPAIGN_NAME TO GW_CAMPAIGN_NAME.
    TRANSLATE GW_CAMPAIGN_NAME TO UPPER CASE.
    TRANSLATE GW_CAMPAIGN_NAME USING ' _'.

all done and working!

Some interesting ways of doing it though! thanks for you feedback!

Read only

che_eky
Active Contributor
0 Likes
3,573

That is what I suggested. Glad it worked.

Che

Read only

Former Member
0 Likes
3,573

your suggestion worked for 95% ;o]

I had to change the TEXT30 back to a String to remove the trailing ____________