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

number convert

Former Member
0 Likes
1,431

hi,

if want to convert posnr from 500001 to 000010, 500002 to 000020 and so on what can i do?

i need to loop through an internal table for this and how do i know when it meets 500001 until maybe 500100 as i need to convert it to 000010 to 001000.

thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,397

Lets do a little math, if the number always starts with 5.

data: posnr(6) type n value '500001'.

posnr = posnr - 500000.
posnr = posnr * 10.

Regards,

Rich Heilman

8 REPLIES 8
Read only

Former Member
0 Likes
1,397

Hi,

Check this.

DATA: i_posnr LIKE vbap-posnr VALUE '500001',
      o_posnr LIKE vbap-posnr.

o_posnr = ( i_posnr - 500000 ) * 10.

You can write the below given statement inside you loop.

o_posnr = ( i_posnr - 500000 ) * 10.

Regards,

RS

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,398

Lets do a little math, if the number always starts with 5.

data: posnr(6) type n value '500001'.

posnr = posnr - 500000.
posnr = posnr * 10.

Regards,

Rich Heilman

Read only

0 Likes
1,397

hi,

let say i already have the number until 000040. i need to continue and start from 000050 for 500001.

i need to loop to check until which number it stops and continue with this 500001 as 000050.

how should i do so?

thanks

points already awarded

Read only

0 Likes
1,397

Hi,

In that case your code would be like this.

*----------------------------------------------------------------------*
*----------------------------------------------------------------------*

DATA: i_posnr LIKE vbap-posnr VALUE '500001',
      o_posnr LIKE vbap-posnr.

DATA: l_posnr LIKE vbap-posnr VALUE '000040'.

o_posnr = ( i_posnr - 500000 ) * 10.

o_posnr = o_posnr + l_posnr.

*----------------------------------------------------------------------*
*----------------------------------------------------------------------*

So, if you are looping the internal table, then write these statments in loop. Here l_posnr holds the starting line item number, let's say 000040

o_posnr = ( i_posnr - 500000 ) * 10.
o_posnr = o_posnr + l_posnr.

Let me know if you have any question.

Regards,

RS

Read only

0 Likes
1,397

hi,

how do i know it stops at 000040 before i convert the 5series to continue as 000050.

thanks

Read only

0 Likes
1,397

Hi,

you do not need to know anything.

See,

o_posnr = ( i_posnr - 500000 ) * 10.

always gives '000010' saying your internal table always start from 500001. That means o_posnr always has value '000010' to begin with.

Now, let say you have already reached to '000040' before converting 5 series nos. Let's say whatever current line item number you have is store in variable l_posnr.

So, now o_posnr = '000010' and l_posnr = '000040'.

When you do <b>o_posnr = o_posnr + l_posnr.</b>, it will give you '000050'. Which you want/

Now, say you already have l_posnr = '000100'. In that case you should start with '000110'. Now based on my formula above, o_posnr begin with '000010'

So, o_posnr = o_posnr + l_posnr means ( 000010 + 000100 ) = 000110.

Let me know if you still have any question.

Regards,

RS

Read only

0 Likes
1,397

hi,

points given again. i will test it out.

i will close the thread when ok.

thanks

Read only

Former Member
0 Likes
1,397

Hi,

This works for u. Check out this sample code :

DATA : i TYPE i,

j TYPE i.

DATA : BEGIN OF itab OCCURS 0,

text TYPE string,

END OF itab.

i = 1.

DO 100 TIMES.

itab-text = 500000 + i.

APPEND itab.

i = i + 1.

ENDDO.

CLEAR i.

LOOP AT itab.

i = 0.

i = i + 1.

WHILE itab-text+i(1) EQ '0'.

i = i + 1.

ENDWHILE.

j = itab-text+i.

j = j * 10.

WRITE 😕 j, itab-text+i.

ENDLOOP.

-Please reward if it's helpful.