Copyright 2022 - BV TallVision IT

Here's a routine that shows ABAP/4 is not really 4GL. Sometimes it could be useful to add 1 to a character string.

Adding 1 to "B" would result in "C". The use of TRANSLATE can come in quite handy here.

This TRANSLATE statement changes every first (third, fifth) character into the second (fourth, sixth) character. This can be used to determine the next-higher character after the current one. Thus A => B, B => C and Z => A.

Data: lv_example type c length 6 value 'ABCXYZ'. 
write: / lv_example. 
write: / lv_example. 

The result:


Z to AA, AB, AC...

To elaborate on this example a little, here's a routine that adds 1 to a character string:

 constants: lc_ALPHABETH type string 
data: lv_Excel_column type c length 2. 

lv_Excel_Column = ' A'. "Space first, for the sorted sequence. 

TRANSLATE lv_Excel_Column+1(1) USING lc_ALPHABETH.
if lv_Excel_Column+1(1) = 'A'.
  TRANSLATE lv_Excel_Column+0(1) USING lc_ALPHABETH.

The above actions will lead to a series of characters A .. Z, then AA ... AZ then BA .. BZ then .... ZA .. ZZ and then AA again. Note, it won't switch back from ZZ to A, but from ZZ to AA. Thus the counter will reset at entry 702 (that's 26 + (26 * 26) ).