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

Get the next alphabet

vinotha_m
Participant
0 Kudos
2,075

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
Read only

Former Member
0 Kudos
905
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
Read only

Former Member
0 Kudos
905

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.

Read only

0 Kudos
905

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

Read only

Former Member
0 Kudos
905

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

Read only

Former Member
0 Kudos
906
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).
Read only

Former Member
0 Kudos
905

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.

Read only

Former Member
0 Kudos
905

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.