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

Increment CHAR variable

Former Member
0 Likes
4,348

Hi,

I'm a beginner in ABAP and I have a question..

Is possible increment a char variable?

for example I have varible:

R001 and i want increment this variable till RZZZ..

There is some solution or some function that i could use to do this?

Thanks so much.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,326

You could split the variable into a character and numeric variable, increment the number and then re-combine.

Rob

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,326

Yes, you can do that, but you will have to code for it, there is no function to do something like that.

REgards,.

Rich Heilman

Read only

Former Member
0 Likes
2,326

Hi,

Looks Interesting........Even if you want to Increase.....it can be from 001 to 999, but the way you want looks different.

Anyway...Increment is only posible with the Var of type I, P & F.

So you can have an increment by these varaibles and later on you can assign the same to a CHAR variable.

Read only

Former Member
0 Likes
2,327

You could split the variable into a character and numeric variable, increment the number and then re-combine.

Rob

Read only

matt
Active Contributor
0 Likes
2,326

I wrote exactly that using TRANSLATE

TRANSLATE single_digit USING '0112233445566778899AABB..Z0'

when the single_digit is equal to 0, after the translate we know to do a carry-one to the next digit.

matt

Read only

0 Likes
2,326

Nice work Matthew, just what I needed...thx mate

3-char counter increment from 000, 001, 002...00A, 010,....ZZZ

CONSTANTS:

   c_transl  type text100 value

             '0112233445566778899AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ0'.


TRANSLATE hlp+2(1USING c_transl.

   IF hlp+2(1) = '0'.

     TRANSLATE hlp+1(1USING c_transl.

     IF hlp+1(1) = '0'.

       TRANSLATE hlp+0(1USING c_transl.

     ENDIF.

   ENDIF.

Read only

MarcinPciak
Active Contributor
0 Likes
2,326

Hi,

In regards to increment form A to Z you may check ASCII number starting from A - 65, then in a loop increament your decimal and change it back to the letter. Then concatenate it to the string. Something like this:


data: i type i,   "first loop index
        j type i,   "second loop
       k type i value 65,   "third one
       ascii type c,
your_string(4) type c calue 'R000'.

do 3 times.   "three position in string

"first work on incrementation of numbers from 0 to 9
do 9 times.
your_string+i(1) = j.  "work on each position of the string (externall loop index i indicates which position you are working on)
write your_string.
j = j + 1.   " 0 - 9
enddo.

do 25 times. "A - 65 , Z - 90  in ASCII (90-65 = 25)
"here change ASCII code to char 
ascii = k.
your_string+i(1) = ascii.
write your_string.
k = k + 1.
enddo.

enddo.

It should work, at least logic:)

Cheers

M.

Read only

former_member156446
Active Contributor
0 Likes
2,326

Hi check this

DATA: lv_gltgb(4) TYPE c.
DATA: lv_gltgb1(3) TYPE n.
MOVE 'R000' TO lv_gltgb.

lv_gltgb1 = lv_gltgb+1(3).

DO 5 TIMES.
  lv_gltgb1 = lv_gltgb1 + 1.

  CONCATENATE lv_gltgb+0(1) lv_gltgb1 into lv_gltgb.
  WRITE:/ lv_gltgb.
ENDDO.

Read only

0 Likes
2,326

Hi,

The combination 001 to ZZZ will have 46655 sequence numbers with the following sequence ranges

ie


001       999
01A       99Z
0A0       0Z9
0AA       0ZZ
1A0       9Z9
1AA       9ZZ
A01       Z99
A0A       Z9Z
AA0       ZZ9
AAA       ZZZ

a®

Read only

0 Likes
2,326
DATA: lv_gltgb(4) TYPE c.
DATA: lv_gltgb1(1) TYPE c.
DATA: lv_gltgb2(1) TYPE c.
DATA: lv_cnt TYPE sy-index.
MOVE 'R001' TO lv_gltgb.

DO 26 TIMES.

  lv_gltgb2 = sy-abcde+lv_cnt(1).
  lv_cnt = sy-index .

  CONCATENATE lv_gltgb+0(1) lv_gltgb2 lv_gltgb2 lv_gltgb2 INTO lv_gltgb.
  WRITE:/ lv_gltgb.
ENDDO.

outoput:

RAAA
RBBB
RCCC
RDDD
REEE
RFFF
RGGG
RHHH
RIII
RJJJ
RKKK
RLLL
RMMM
RNNN
ROOO
RPPP
RQQQ
RRRR
RSSS
RTTT
RUUU
RVVV
RWWW
RXXX
RYYY
RZZZ

Read only

0 Likes
2,326

Hi,

please find starting & ending sequence numbers from R000 RZZZ

000 001 002 003 004 005 006 007 008 009 00A 00B 00C 00D 00E 00F 00G 00H 00I 00J 00K 00L 00M 00N

00O 00P 00Q 00R 00S 00T 00U 00V 00W 00X 00Y 00Z 010 011 012 013 014 015 016 017 018 019 020 021

022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045

046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069

070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093

094 095 096 097 098 099 01A 01B 01C 01D 01E 01F 01G 01H 01I 01J 01K 01L 01M 01N 01O 01P 01Q 01R

01S 01T 01U 01V 01W 01X 01Y 01Z 02A 02B 02C 02D 02E 02F 02G 02H 02I 02J 02K 02L 02M 02N 02O 02P

.....

....

.....

ZUM ZUN ZUO ZUP ZUQ ZUR ZUS ZUT ZUU ZUV ZUW ZUX ZUY ZUZ ZVA ZVB ZVC ZVD ZVE ZVF ZVG ZVH ZVI ZVJ

ZVK ZVL ZVM ZVN ZVO ZVP ZVQ ZVR ZVS ZVT ZVU ZVV ZVW ZVX ZVY ZVZ ZWA ZWB ZWC ZWD ZWE ZWF ZWG ZWH

ZWI ZWJ ZWK ZWL ZWM ZWN ZWO ZWP ZWQ ZWR ZWS ZWT ZWU ZWV ZWW ZWX ZWY ZWZ ZXA ZXB ZXC ZXD ZXE ZXF

ZXG ZXH ZXI ZXJ ZXK ZXL ZXM ZXN ZXO ZXP ZXQ ZXR ZXS ZXT ZXU ZXV ZXW ZXX ZXY ZXZ ZYA ZYB ZYC ZYD

ZYE ZYF ZYG ZYH ZYI ZYJ ZYK ZYL ZYM ZYN ZYO ZYP ZYQ ZYR ZYS ZYT ZYU ZYV ZYW ZYX ZYY ZYZ ZZA ZZB

ZZC ZZD ZZE ZZF ZZG ZZH ZZI ZZJ ZZK ZZL ZZM ZZN ZZO ZZP ZZQ ZZR ZZS ZZT ZZU ZZV ZZW ZZX ZZY ZZZ

My suggestion will be create a custom table and keep all possible combination numbers in it and use this table

a®