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

Ascii value

Former Member
0 Likes
798

Hi Gurus,

I've a small requirement. I need to implement alogic where if the last digit of an order is 'a' then I have to change it as 'b'.

similarly if it is 'b' then we have to change it to 'c'. similarly I need to repeat this logic to all alphabets.

so if there would be any FM or logic to extract a number(like ascii value) for a particular character. Then I shall increment the value and convert back to alphabet and that is how I will change one alphabet to another.

Kindly let me know if there is any FM to convert a character into a number.

Thanks

Natasha.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
749

Hello All,

Use of SY-FDPOS, SY-ABCDE is definitely the simplest solution for getting the next letter.

But was thinking of a solution taking into account the ASCII value of the character, it goes something like this:

PARAMETER:
V_STR TYPE CHAR1 DEFAULT 'A'.

DATA:
V_ASCII TYPE I.

TRY.
    CALL METHOD CL_ABAP_CONV_OUT_CE=>UCCPI
      EXPORTING
        CHAR = V_STR
      RECEIVING
        UCCP = V_ASCII.
  CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
  CATCH CX_SY_CONVERSION_CODEPAGE .
  CATCH CX_PARAMETER_INVALID_RANGE .
ENDTRY.

WRITE: 'Input', 10 V_STR.

ADD 1 TO V_ASCII.

TRY.
    CALL METHOD CL_ABAP_CONV_IN_CE=>UCCPI
      EXPORTING
        UCCP = V_ASCII
      RECEIVING
        CHAR = V_STR.
  CATCH CX_SY_CONVERSION_CODEPAGE .
  CATCH CX_PARAMETER_INVALID_RANGE .
  CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
ENDTRY.

WRITE: / 'Output', 10 V_STR.

May be this is of some help.

BR,

Suhas

Hi Gurus,

I've a small requirement. I need to implement alogic where if the last digit of an order is 'a' then I have to change it as 'b'.

similarly if it is 'b' then we have to change it to 'c'. similarly I need to repeat this logic to all alphabets.

so if there would be any FM or logic to extract a number(like ascii value) for a particular character. Then I shall increment the value and convert back to alphabet and that is how I will change one alphabet to another.

Kindly let me know if there is any FM to convert a character into a number.

Thanks

Natasha.

4 REPLIES 4
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
749

Read only

Former Member
0 Likes
749

Hi

U can use something like this:

PARAMETERS: P_CHAR(1) TYPE C.

DATA: MY_CHAR   TYPE I,
      NEXT_CHAR TYPE I.

IF SY-ABCDE CS P_CHAR.
  MY_CHAR   = SY-FDPOS + 1.
  NEXT_CHAR = MY_CHAR + 1.

  WRITE: 'Next char:', SY-ABCDE+MY_CHAR(1), NEXT_CHAR.
ENDIF.

Max

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
750

Hello All,

Use of SY-FDPOS, SY-ABCDE is definitely the simplest solution for getting the next letter.

But was thinking of a solution taking into account the ASCII value of the character, it goes something like this:

PARAMETER:
V_STR TYPE CHAR1 DEFAULT 'A'.

DATA:
V_ASCII TYPE I.

TRY.
    CALL METHOD CL_ABAP_CONV_OUT_CE=>UCCPI
      EXPORTING
        CHAR = V_STR
      RECEIVING
        UCCP = V_ASCII.
  CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
  CATCH CX_SY_CONVERSION_CODEPAGE .
  CATCH CX_PARAMETER_INVALID_RANGE .
ENDTRY.

WRITE: 'Input', 10 V_STR.

ADD 1 TO V_ASCII.

TRY.
    CALL METHOD CL_ABAP_CONV_IN_CE=>UCCPI
      EXPORTING
        UCCP = V_ASCII
      RECEIVING
        CHAR = V_STR.
  CATCH CX_SY_CONVERSION_CODEPAGE .
  CATCH CX_PARAMETER_INVALID_RANGE .
  CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
ENDTRY.

WRITE: / 'Output', 10 V_STR.

May be this is of some help.

BR,

Suhas

Read only

venkat_o
Active Contributor
0 Likes
749

Hi Natasha, <li>Try this way.


REPORT zvenkat_notepad4.
DATA: g_position    TYPE i,
      g_next_letter TYPE c.
PARAMETERS p_given type char10 default '100000108k'.

START-OF-SELECTION.
  IF p_given+9(1) = 'Z'.
    WRITE 'A'.
  ELSE.
    FIND p_given+9(1) IN sy-abcde IGNORING CASE MATCH OFFSET g_position.
    g_position = g_position  + 1.
    g_next_letter = sy-abcde+g_position(1).
    WRITE / g_next_letter.
  ENDIF.
Thanks Venkat.O