09-25-2008 6:07 AM
HI EXPERTS,
Field1 = CAL_0000138171_XYZ
Hw to delete zeros between CAL_ and XYZ.
ie output should be FIELD1 = CAL_138171_XYZ.
if FIELD1 = 0000138171
I can use this SHIFT FIELD1 LEFT DELETING LEADING '0'.
But hw to do first one.
Please help me.
09-25-2008 6:14 AM
data: field1(30).
Field1 = 'CAL_0000138171_XYZ'.
data: a(4),
b(20),
c(10).
split field1 at '_' into a b c.
SHIFT b LEFT DELETING LEADING '0'.
Rajneesh Gupta
09-25-2008 6:10 AM
Hi,
Mostly it depends how u r getting that field.
Looking at ur field, heres one way how u can do it.
split the field at char "_". In the second segment of the field, u can give the shift command
shift <field_name> left deleting leading '0'.
Hope it works for you.
-Rajat
09-25-2008 6:19 AM
Hi use this code.
data:pp(10) type c .
replace all occurrences of '0' in pp with ' '.
09-25-2008 6:13 AM
hi,
use REPLACE ALL OCCURENCES OF '0' BY SPACE IN FIELD.
THEN CONDENSE NO-GAPS.
This should solve ur problem.
Rgds.,
subash
09-25-2008 6:13 AM
Field1 = CAL_0000138171_XYZ
use it
SPLIT FIELD1 AT _ INTO STR1 STR2 STR3.
STR2 = 0000138171.
THEN u can try shift & concatenate all fields again
09-25-2008 6:14 AM
data: field1(30).
Field1 = 'CAL_0000138171_XYZ'.
data: a(4),
b(20),
c(10).
split field1 at '_' into a b c.
SHIFT b LEFT DELETING LEADING '0'.
Rajneesh Gupta
09-25-2008 6:21 AM
Hi,
Probably u can make use of the code below.
do.
find '0' in field1.
if sy-subrc eq 0.
replace '0' with '' into field1.
else.
exit.
endif.
enddo.
CONDENSE field1 no-gaps.
write field1.
Regards,
Kiran
09-25-2008 6:21 AM
Hi,
plz do this way it will give intended output:
DATA: text TYPE string.
DATA: str1 TYPE string,
str2 TYPE string,
str3 TYPE string.
DATA: res TYPE string.
text = `CAL_0000138171_XYZ`.
SPLIT text AT '_' INTO: str1 str2 str3.
SHIFT str2 LEFT DELETING LEADING '0'.
CONCATENATE str1 str2 str3 INTO res SEPARATED BY '_'.
WRITE: res.
o/p : res = CAL_138171_XYZ.
thanx.
09-25-2008 6:23 AM
Hi,
Use Replace as follows,
Field1 = CAL_0000138171_XYZ
Replace All Occurences of '0' IN Field1 with ''.
Remember there is no space between single quotes in the With clause of the Replace statement.
Regards
KArthik D
09-25-2008 6:30 AM
Try to split the Field1 at _
try this code
DATA : field1 TYPE string VALUE 'CAL_0000138171_XYZ',
w(4) TYPE c,
e(4) TYPE c.
DATA : q(10) TYPE n.
SPLIT field1 AT '_' INTO w q e.
SHIFT q LEFT DELETING LEADING '0'.
CONCATENATE w q e INTO field1 SEPARATED BY '_'.
Write 😕 field1.
09-25-2008 6:36 AM
Hi ,
Variable = 'CAL_0000138171_XYZ'.
Replace All Occurences of '0' IN Variable with ''.
Write Variable.
Regards,
Sivappriya
09-25-2008 6:45 AM
Hi Experts,
Thanks to all.
I got the solutions but Replace All Occurences of '0' IN Field1
will not work bcz if any zeros inbetween numbers.
Thanks
Basu
09-25-2008 7:27 AM
Hi,
Actually you can use Replace as it is the easiest and efficient way to solve your requirement. But you need to utilize the REGEX addition, try as follows;
DATA field1 TYPE string.
field1 = 'CAL_0000138171_XYZ'.
WRITE : / 'Before Replace :' , field1.
REPLACE REGEX '_0*0' IN field1 WITH '_'.
WRITE : / 'After Replace :' , field1.
Output:
Before Replace : CAL_0000138171_XYZ
After Replace : CAL_138171_XYZ
This will be more efficient then SPLIT & SHIFT.
REPLACE REGEX '_0*0' IN field1 WITH '_'.
Regards
Karthik D