2009 Mar 19 11:00 PM
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??
2009 Mar 19 11:26 PM
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
2009 Mar 19 11:20 PM
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.
2009 Mar 19 11:26 PM
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
2009 Mar 20 2:15 AM
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.
2009 Mar 20 2:41 AM
Hi Barry,
Use CONDENSE
CONDENSE GW_CAMPAIGN_NAME NO-GAPS.
Regards,
Peter
2009 Mar 20 4:30 AM
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.
2009 Mar 20 4:57 AM
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
2009 Mar 20 5:01 AM
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
2009 Mar 20 6:12 AM
2009 Mar 20 6:15 AM
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.
2009 Mar 20 9:01 AM
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!
2009 Mar 20 10:12 AM
2009 Mar 20 12:53 PM
your suggestion worked for 95% ;o]
I had to change the TEXT30 back to a String to remove the trailing ____________