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: 

Get the next alphabet

vinotha_m
Participant
0 Kudos

I have a requirement...where if the string contains 'A'.

I have to get the next letter..that is 'B....

How to do this

1 ACCEPTED SOLUTION

Former Member
0 Kudos
PARAMETERS char TYPE c DEFAULT 'A'.
DATA cnt TYPE i.
SEARCH sy-abcde FOR char IN CHARACTER MODE.

cnt = sy-fdpos + 1.
IF cnt GE 26.
 cnt  = 0.
ENDIF.
WRITE sy-abcde+cnt(1).
6 REPLIES 6

former_member181962
Active Contributor
0 Kudos

Cook your own logic:

using case statement

case character.

when 'A'.

Next_alphabet = 'B'.

when 'B'.

Next_alphabet = 'C'.

.

.

..

.

.....

.

when 'Z'.

Next_alphabet = 'A'.

endcase.

0 Kudos

data: abcd type sy-abcde.

data: source_string(1) .

data: moff type i ,

mlen type i ,

next_alpha(1) .

move: sy-abcde to abcd .

source_string = 'G' .

find source_string in abcd MATCH OFFSET moff MATCH LENGTH mlen.

if sy-subrc eq 0.

moff = moff + 1 .

next_alpha = abcd+moff(1) .

endif .

Regards

Raja

Former Member
0 Kudos

Hi vinotha,

you can use sy-ABCDE.

it contains all the alphabets in series..

just check the input and give the next one from it..

regards

satesh

Former Member
0 Kudos
PARAMETERS char TYPE c DEFAULT 'A'.
DATA cnt TYPE i.
SEARCH sy-abcde FOR char IN CHARACTER MODE.

cnt = sy-fdpos + 1.
IF cnt GE 26.
 cnt  = 0.
ENDIF.
WRITE sy-abcde+cnt(1).

Former Member
0 Kudos

Hi vinotha,

1. simple.

(we have to make use of the field

sy-abcde

sy-fdpos

)

2. just copy paste in new program

it will give A----


>B

B----


>C

.

.

.

Z----


> A

3.

REPORT abc.

PARAMETERS: : a(1) TYPE c DEFAULT 'A'.

DATA : b(1) TYPE c.

PERFORM getnext USING a b.

*----


WRITE 😕 b.

*----


  • INDEPENDENT FORM

*----


FORM getnext USING oldval newval.

DATA : chr TYPE c.

DATA : pos TYPE i.

chr = oldval.

IF sy-abcde CS chr.

sy-fdpos = sy-fdpos + 1.

<b> IF sy-fdpos > 25.

sy-fdpos = 0.

ENDIF.</b>

newval = sy-abcde+sy-fdpos(1).

ENDIF.

ENDFORM. "

regards,

amit m.

Former Member
0 Kudos

U can use the following code.. it goes in cyclic way if u don't need this u can comment that part.

data: nxt(1).

parameter chr(1).

search sy-abcde for chr.

if sy-subrc = 0.

if sy-fdpos <> 25.

sy-fdpos = sy-fdpos + 1.

else.

sy-fdpos = 0.

endif.

nxt = sy-abcde+sy-fdpos(1).

write : nxt.

else.

write : 'Last Char'.

endif.