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

String length

Former Member
0 Likes
1,384

Hi Friends-

I need a help in writing this logic my req is one field of 8 numbers i have to fill and if the value is less then 8 digit then i have to fill the rest area with ' 0' how i can do that becz am not sure the coming value can be 3 or 4 or 5 in length but max it shd be 8 and rest area before that value shd fill with Zero's

eg if this is the coming value 709240 then it should be 00709240 before updating in table

Pls suggest

Regards

Smeeta

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,286

u simply use ,

CONVERSION_EXIT_ALPHA_INPUT.

Function module CONVERSION_EXIT_ALPHA_INPUT

Import parameters Value

INPUT 12 *use ur variable here

Export parameters Value

OUTPUT 00000012

10 REPLIES 10
Read only

Former Member
0 Likes
1,286

Hi,

Take a variable of type n and move it into that.

Ex:

data:

w_num(8) type n,

w_int type i.

w_int = 12.

w_num = w_int.

now, w_num will have 00000012 in it.

Ram

Read only

Former Member
0 Likes
1,286

hi,

you can use a variable of lenght 8 and type numeric.

or u can use

CONVERSION_EXIT_ALPHA_INPUT

thanks

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,286

Hi,

Refer:

CONVERSION_EXIT_ALPHA_INPUT -


It is used to add the 0(Zero) at the begining of the value. You dont require to add zero manually for any variable.

CONVERSION_EXIT_ALPHA_OUTPUT -


It is used to Remove 0(Zero) from the Begining of the value. You dont require to remove Zero manually for any variable. Just call this Function Module and it will automatically removes zero from the begining.

Or you can use PACK and UNPACK...

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
1,287

u simply use ,

CONVERSION_EXIT_ALPHA_INPUT.

Function module CONVERSION_EXIT_ALPHA_INPUT

Import parameters Value

INPUT 12 *use ur variable here

Export parameters Value

OUTPUT 00000012

Read only

awin_prabhu
Active Contributor
0 Likes
1,286

Hi Meeta,

Check this logic.

REPORT ztest.

DATA: num(8) TYPE c,

l TYPE i.

num = '1234'.

l = STRLEN( num ).

CASE l.

WHEN '1'.

DO 7 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '2'.

DO 6 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '3'.

DO 5 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '4'.

DO 4 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '5'.

DO 3 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '6'.

DO 2 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

WHEN '7'.

DO 1 TIMES.

CONCATENATE '0' num INTO num.

ENDDO.

ENDCASE.

WRITE:/ num.

Thanks.

Edited by: Sap Fan on Apr 9, 2009 6:07 AM

Read only

Former Member
0 Likes
1,286

Hi Txs for quick turn ,

But even if we take w_int as n it will give correct answer ,

data : w_num(8) type n,

w_int(8) type n.

clear w_int.

w_int = 12.

w_num = w_int.

now, w_num will have 00000012 in it.

But when am passing in my program one field employee number and both field has type numc 8 only

but still for few pernrs it will not fill with Zeros don't know why ?

wa_709-pernr = wa_2-pernr.

pls suggest any clue for this.

Regards

Smeeta

Read only

0 Likes
1,286

Hi Meera,

Use FM CONVERSION_EXIT_ALPHA_INPUT

and for its input parameter, use a variable of CHAR type and size 8.

data: v_field(8) type c.

and then pass it to above Function Module.

This will resolve your problem.

Regards,

Nitin.

Read only

0 Likes
1,286

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = w_num

  • IMPORTING

  • OUTPUT = w_int .

try this.

Read only

Former Member
0 Likes
1,286

Hi,

You can use the below logic. Let say the filed on which you want to add Zeroes is L_FLD and its value is 1234.

Report Test1.

DATA var1(8) TYPE c.

DATA len TYPE i.

DATA l_fld TYPE i VALUE 1234.

DATA rest TYPE i.

DATA var2(8) TYPE c VALUE '00000000'.

var1 = l_fld.

CONDENSE var1 NO-GAPS.

len = STRLEN( var1 ).

IF len <> 8.

rest = 8 - len.

CONCATENATE var2+0(rest) var1 INTO var1.

CONDENSE var1.

WRITE var1.

ENDIF.

Regards,

Rajneesh

Read only

Former Member
0 Likes
1,286

Conversion_exit_alpha_input

this function module might not work for numc.

What you can do instead is

len = 8 - strlen( wa-pernr ).

Temp = '00000000'.

Concatenate temp+0(len) wa-pernr into wa-pernr.

regards,

lalit mohan gupta.