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 OCCURRENCES = Short dump!

Former Member
0 Kudos
3,612

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

che_eky
Active Contributor
0 Kudos
815

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

12 REPLIES 12

former_member156446
Active Contributor
0 Kudos
815

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.

che_eky
Active Contributor
0 Kudos
816

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

Former Member
0 Kudos
815

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.

peter_ruiz2
Active Contributor
0 Kudos
815

Hi Barry,

Use CONDENSE

CONDENSE GW_CAMPAIGN_NAME NO-GAPS.

Regards,

Peter

asik_shameem
Active Contributor
0 Kudos
815

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.

Former Member
0 Kudos
815

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

Former Member
0 Kudos
815

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

Former Member
0 Kudos
815

.

Former Member
0 Kudos
815

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.

Former Member
0 Kudos
815

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!

che_eky
Active Contributor
0 Kudos
815

That is what I suggested. Glad it worked.

Che

Former Member
0 Kudos
815

your suggestion worked for 95% ;o]

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