Search
Search

# Logic to add 1 from 01 until 99, then go to A1->Z9

I have a requirement add 1 to the line no. whenever I add a record to the table. I have to search the table for the highest line number saved and add 1 to it. The trick is that when I get to 99, the next line number should be A1, and then A2 until A9. When I get to A9 I should go to B1, etc. until Z9.

How can I accomplish this?

##### Former Memberreplied

Hi

DATA: BEGIN OF ITAB OCCURS 0,

KEY(2) TYPE C,

END   OF ITAB.

DATA: NUM_CHECK TYPE I.

DATA: NUM2(2) TYPE N.

DATA: NUM(1) TYPE N.

DATA: OFFSET TYPE I.

PARAMETERS: P_TIMES TYPE I.

DO P_TIMES TIMES.

SORT ITAB BY KEY DESCENDING.

IF SY-SUBRC <> 0.

ITAB-KEY = '01'.

ELSE.

IF ITAB-KEY CO '0123456789'.

MOVE ITAB-KEY TO NUM_CHECK.

IF NUM_CHECK < 99.

NUM_CHECK = NUM_CHECK + 1.

MOVE NUM_CHECK TO NUM2.

MOVE NUM2      TO ITAB-KEY.

ELSE.

ITAB-KEY = 'A1'.

ENDIF.

ELSE.

MOVE ITAB-KEY+1 TO NUM.

IF NUM < 9.

NUM = NUM + 1.

ITAB-KEY+1(1) = NUM.

ELSE.

OFFSET = OFFSET + 1.

ITAB-KEY(1) = SY-ABCDE+OFFSET(1).

ITAB-KEY+1(1) = '1'.

ENDIF.

ENDIF.

ENDIF.

APPEND ITAB.

ENDDO.

SORT ITAB BY KEY.

LOOP AT ITAB.

WRITE: / ITAB-KEY.

ENDLOOP.

Max

0 View this answer in context
View more on this topic or