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: 

Deleting Zeros

former_member575017
Participant
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

12 REPLIES 12

Former Member
0 Kudos

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

0 Kudos

Hi use this code.

data:pp(10) type c .

replace all occurrences of '0' in pp with ' '.

Former Member
0 Kudos

hi,

use REPLACE ALL OCCURENCES OF '0' BY SPACE IN FIELD.

THEN CONDENSE NO-GAPS.

This should solve ur problem.

Rgds.,

subash

former_member329859
Participant
0 Kudos

Field1 = CAL_0000138171_XYZ

use it

SPLIT FIELD1 AT _ INTO STR1 STR2 STR3.

STR2 = 0000138171.

THEN u can try shift & concatenate all fields again

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

former_member585060
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Hi ,

Variable = 'CAL_0000138171_XYZ'.

Replace All Occurences of '0' IN Variable with ''.

Write Variable.

Regards,

Sivappriya

former_member575017
Participant
0 Kudos

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

0 Kudos

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