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 leading Zero's

Former Member
0 Likes
743

Hi ,

one of my field var = 0000501

I want to display it like var = ****501

I want to replace all leading zero's with ' * ' .

Replace statement replaces all zeros with ' * ' & display var = ***51.

I want my output = ****501.

Plz help

Thanks in Advance

Sai

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
708

Hello

Try this snippet:


data: str1(10),
      x type i,
      y type i.
str1 = '0000501'.
x = strlen( str1 ).
shift str1 left deleting leading '0'.
y = strlen( str1 ).
x = x - y.
do x times.
  concatenate '*' str1 into str1.
enddo.
write str1.

6 REPLIES 6
Read only

Former Member
0 Likes
709

Hello

Try this snippet:


data: str1(10),
      x type i,
      y type i.
str1 = '0000501'.
x = strlen( str1 ).
shift str1 left deleting leading '0'.
y = strlen( str1 ).
x = x - y.
do x times.
  concatenate '*' str1 into str1.
enddo.
write str1.

Read only

0 Likes
708

thanks to all of u for there proper reply

Closing the thread

Sai

Read only

Former Member
0 Likes
708

Hi,

Try this simple code:


DATA value(7) TYPE c VALUE '0000501'.

DATA i TYPE i.

WHILE value+i(1) EQ '0'.
  value+i(1) = '*'.
  ADD 1 TO i.
ENDWHILE.

WRITE value.

Read only

Former Member
0 Likes
708

Hello,

Check this logic and modify if required according to your need.


data temp(7) type c.
data len type i.
data n type i.
temp = '0000501'.
len = strlen( temp ).
do len times.
  if temp+n(1) <> '0'.
    exit.
  else.
    replace '0' in temp+n(1) with '*' .
  endif.
  n = n + 1.
enddo.
write temp.

Hope this helps in solving your query.

Regards,

Sachin

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
708

How about something like this?

DATA: lv_init TYPE char07 VALUE '0000501'.
DATA: lv_conv TYPE char07.
DATA: lv_star TYPE char07 VALUE '*******'.
data: lv_outp type char07.
DATA: lv_init_l type i.
data: lv_conv_l type i.
data: lv_offset type i.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = lv_init
  IMPORTING
    output = lv_conv.

lv_init_l = strlen( lv_init ).
lv_conv_l = strlen( lv_conv ).
lv_offset = lv_init_l - lv_conv_l.
lv_outp = lv_star.
lv_outp+lv_offset(lv_conv_l) = lv_conv.

WRITE:/ lv_outp.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
708

hi.

i tried coding below .

FIELD-SYMBOLS : <fs> type c .

do .

off = sy-index - 1.

assign text+off(1) to <fs> .

if <fs> <> 0.

exit .

else.

replace SECTION offset off length 1 of text with '*' .

endif.

enddo.