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: 

alphanumeric serial number increment

Former Member
0 Kudos
1,496

Hi All,

Can anyone help me to increment an alphanumeric sequence.

For eq: 12B345A, should become 12B345B,12B345C...,12B345Z after Z it should take the second last character and inceremnt it, say 12B346A,12B346B,12B346C.........

Please let me know whether we can use some Function Modules for this operation or can anyone please help me with a pseudocode for the same.

Thanks in Advance,

Rijish

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
315

ARe positions 3 and 7 always the alpha characters, and the rest are always numeric?

Regards,

Rich Heilman

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
316

ARe positions 3 and 7 always the alpha characters, and the rest are always numeric?

Regards,

Rich Heilman

0 Kudos
315

Thanks Rich! (For ur quick reply).

Not necessary .The alphabets can be at any position.The sequence is less or equal to 18 !

0 Kudos
315

Try this Code:

data: v_str(7) type c,
      v_hx(1) type x,
      v_len type i,
      v_off type i.

field-symbols <fs>.

v_str = '12B345Z'.
write:/ 'Initial:', v_str.
v_len = strlen( v_str ).

v_off = v_len - 1.

do v_len times.

  if v_str+v_off(1) between 'A' and 'Z'.
    if v_str+v_off(1) lt 'Z'.
      assign v_str+v_off(1) to <fs> casting type x.
      add 1 to <fs>.
      exit.
    else.
      v_str+v_off(1) = 'A'.
    endif.
  elseif v_str+v_off(1) between '0' and '9'.
    if v_str+v_off(1) lt '9'.
      v_str+v_off(1) = v_str+v_off(1) + 1.
      exit.
    else.
      v_str+v_off(1) = '0'.
    endif.
  endif.
  v_off = v_off - 1.
enddo.

write:/ 'Final:', v_str.

Regards

Sridhar

0 Kudos
315

Hi Sridhar,

Thanks for the code, itz working perfect.....

Once again thanks for your help...

regards

rijish

0 Kudos
315

Its case sensitive?

Former Member
0 Kudos
315

Hi,

use below pseudo code logic

lv_data = strlen( string ).

lv_data1 = sy-abcde.

case string+0(lv_data)

when 'A'.

string+0(lv_data) = 'B'.

.....

when 'Z'.

lv_data = lv_data - 1.

string0(lv_data)= string0(lv_data) + 1.

endcase.

Regards

Amole

Former Member
0 Kudos
315

Rijish

What should happen when it reaches ...

12B346Z....

12B349Z...should the next be 12B350A or 12B34AA ?

Also in the case 12B999Z it should be followed by 12C000A or something else ???

Message was edited by: Anurag Bankley