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: 

Regarding Logic for below statements

Former Member
0 Kudos

Hi,

What can be the logic for 2nd statement below:

1. Capture the user entered zip code in to a variable

2. Check the Variable[Code] if it is not 10 digits then

convert it into format ZZZZZ-XXXX by padding it with zeros.

EX: if user enters only 65549 convert it to 65549-0000

Thanks in advance.

Thanks,

Deep.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
REPORT ychatest.

PARAMETERS : p_value(10) default '65439'.

DATA : v_len TYPE i.
v_len = strlen( p_value ).

IF v_len NE 10.
  v_len = 10 - v_len - 1.
  CONCATENATE p_value '-' INTO p_value.
  DO v_len TIMES.
    CONCATENATE p_value '0' INTO p_value.
  ENDDO.
  WRITE : p_value.
ENDIF.
3 REPLIES 3

Former Member
0 Kudos
REPORT ychatest.

PARAMETERS : p_value(10) default '65439'.

DATA : v_len TYPE i.
v_len = strlen( p_value ).

IF v_len NE 10.
  v_len = 10 - v_len - 1.
  CONCATENATE p_value '-' INTO p_value.
  DO v_len TIMES.
    CONCATENATE p_value '0' INTO p_value.
  ENDDO.
  WRITE : p_value.
ENDIF.

graghavendra_sharma
Contributor
0 Kudos

Hi

Try out the following logic

data: n1(10) value '12345',

n2(11), i1 type i.

i1 = strlen( n1 ).

if i1 < 10.

concatenate n1 '-00000' into n2.

endif.

write: / i1, / n2.

former_member588853
Active Contributor
0 Kudos

HI,

let lv_bar has the value '65549'..

Now define

data: lv_len type i,

lv_len1 type i,

lv_char(10) type c.

lv_len = STRLEN( lv_bar).

if lv_len < 10.

lv_len1 = 10 - lv_len.

do lv_len1 times.

concatenate '0' to lv_char.

enddo.

CONCATENATE lv_bar '-' lv_char.

endif.