ABAP排序启用字母排序 99过后是AA AB AC ... ZZ
*&---------------------------------------------------------------------*
*& Form frm_get_increment_alpha
*&---------------------------------------------------------------------*
*& 获取下一字母流水
*&---------------------------------------------------------------------*
FORM frm_get_increment_alpha CHANGING cv_position TYPE i
cv_alpha TYPE string.
DATA: lv_offset TYPE i,
lt_character_tab TYPE STANDARD TABLE OF char1.
FIELD-SYMBOLS <char> TYPE char1.
* Split changing parameter alpha into a table of single characters to facilitate substring handling
CALL FUNCTION 'SWA_STRING_TO_TABLE'
EXPORTING
character_string = cv_alpha
line_size = 1
IMPORTING
character_table = lt_character_tab
EXCEPTIONS
OTHERS = 0.
IF cv_position IS INITIAL.
ADD 1 TO cv_position.
ENDIF.
READ TABLE lt_character_tab ASSIGNING <char> INDEX cv_position.
CHECK <char> IS ASSIGNED.
* An initial character is incremented to 'A'
IF <char> IS INITIAL.
<char> = sy-abcde(1). " A
* Reconstitute changing parameter alpha from the character table
CALL FUNCTION 'SWA_STRING_FROM_TABLE'
EXPORTING
character_table = lt_character_tab
IMPORTING
character_string = cv_alpha
EXCEPTIONS
OTHERS = 0.
EXIT. " we're done
ELSEIF <char> CN sy-abcde.
RAISE non_alpha.
ENDIF. " <char>
* Increment the alphabetic counter string
CASE <char>.
WHEN sy-abcde+25(1). " Z
* Roll Z back to A at the current cv_position
<char> = sy-abcde(1). " A
* Reconstitute changing parameter cv_alpha from the character table
CALL FUNCTION 'SWA_STRING_FROM_TABLE'
EXPORTING
character_table = lt_character_tab
IMPORTING
character_string = cv_alpha
EXCEPTIONS
OTHERS = 0.
** Increment the left-adjacent position by recursively calling this method
IF cv_position GT 1.
cv_position = cv_position - 1.
PERFORM frm_get_increment_alpha CHANGING cv_position cv_alpha.
ENDIF.
WHEN OTHERS. " A-Y
* Increment the current alphabetic character
FIND <char> IN sy-abcde IGNORING CASE MATCH OFFSET lv_offset.
ADD 1 TO lv_offset.
<char> = sy-abcde+lv_offset(1).
* Reconstitute changing parameter alpha from the character table
CALL FUNCTION 'SWA_STRING_FROM_TABLE'
EXPORTING
character_table = lt_character_tab
IMPORTING
character_string = cv_alpha
EXCEPTIONS
OTHERS = 0.
ENDCASE. " <char>
ENDFORM.