2009 Nov 12 1:36 PM
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.
2009 Nov 12 2:11 PM
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.
2009 Nov 12 1:42 PM
2009 Nov 12 1:48 PM
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
2009 Nov 12 2:11 PM
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
2009 Nov 13 3:14 AM
Hi Natasha,
<li>Try this way.
Thanks
Venkat.O
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.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |