Alpha Numeric Number Range (0000 to ZZZZ) Skip to end of metadata
Go to start of metadata Author: Abhishek Jolly Description The code snippet given below is for generating alpha numeric number range starting from 0000 till ZZZZ. The number range will be incremented in the following sequence 0000, 0001, 0002, 0003.....0009, 000A, 000B, 000C ..... 000Z, 0010, 0011, 0012....0019, 001A, 001B.....001Z, 0020 and so on. The Code Snippet is in the form of a method which taken Input as the current number and generates the next number in sequence as Output.
Importing Parameter : ALPHA_CURRENT ( Type Char 4 ) Exporting Parameter : APLHA_NEW ( Type Char 4 ) Error rendering macro 'code': Invalid value specified for parameter 'lang'FUNCTION ZGET_NEXT_ALPHA_CODE_FOR_10065. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" REFERENCE(ALPHA_CURRENT) TYPE CHAR4 *" EXPORTING *" REFERENCE(ALPHA_NEW) TYPE CHAR4 *" TABLES *" IT_EXCLUDE STRUCTURE LINE OPTIONAL *" CHANGING *" REFERENCE(SUFFIX) TYPE CHAR2 DEFAULT 'AA' *"---------------------------------------------------------------------- * Types declaration TYPES : BEGIN OF TY_ALPHA, CODE1 TYPE CHAR1, CODE2 TYPE NUM2, END OF TY_ALPHA. "Type for Mapping table : 1 character to 2 character code " 0,00 1,01 ..... 9,09 A,10 B,11....Y,34 Z,35 * Internal Tables declaration DATA: TB_ALPHA TYPE STANDARD TABLE OF TY_ALPHA. * Work Areas declaration DATA: WA_ALPHA LIKE LINE OF TB_ALPHA. DATA: WF_COUNT TYPE I, WF_OFFSET TYPE I, WF_1_CURRENT TYPE CHAR1 , WF_2_CURRENT TYPE CHAR1, WF_3_CURRENT TYPE CHAR1, WF_4_CURRENT TYPE CHAR1, WF_1_NEW TYPE NUM2, WF_2_NEW TYPE NUM2, WF_3_NEW TYPE NUM2, WF_4_NEW TYPE NUM2. *populating internal table with 1 to 2 character mapping. WF_COUNT = 0. WF_OFFSET = 0. DO 36 TIMES. WA_ALPHA-CODE2 = WF_COUNT. IF WF_COUNT <= 9 . WA_ALPHA-CODE1 = WF_COUNT. ELSE. WA_ALPHA-CODE1 = SY-ABCDE+WF_OFFSET(1). WF_OFFSET = WF_OFFSET + 1. ENDIF. WF_COUNT = WF_COUNT + 1. APPEND WA_ALPHA TO TB_ALPHA. CLEAR WA_ALPHA. ENDDO. * Break the Current number into 4 characters and get the corresponding 2 digit code for each character WF_4_CURRENT = ALPHA_CURRENT+0(1). WF_3_CURRENT = ALPHA_CURRENT+1(1). WF_2_CURRENT = ALPHA_CURRENT+2(1). WF_1_CURRENT = ALPHA_CURRENT+3(1). *read the mapping table and get the 2 digit code. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE1 = WF_1_CURRENT . IF SY-SUBRC = 0. WF_1_NEW = WA_ALPHA-CODE2. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE1 = WF_2_CURRENT . IF SY-SUBRC = 0. WF_2_NEW = WA_ALPHA-CODE2. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE1 = WF_3_CURRENT . IF SY-SUBRC = 0. WF_3_NEW = WA_ALPHA-CODE2. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE1 = WF_4_CURRENT . IF SY-SUBRC = 0. WF_4_NEW = WA_ALPHA-CODE2. ENDIF. * Increment the last character and based on the carry forward increment the next character by 1 IF WF_1_NEW < 35. WF_1_NEW = WF_1_NEW + 1. ELSE. WF_1_NEW = 0. WF_2_NEW = WF_2_NEW + 1. IF WF_2_NEW > 35. WF_2_NEW = 0. WF_3_NEW = WF_3_NEW + 1. IF WF_3_NEW > 35. WF_3_NEW = 0. WF_4_NEW = WF_4_NEW + 1. ENDIF. ENDIF. ENDIF. * Do the reverse. Get the 1 digit code for each 2 digit code. * Read the mapping table and get 1 character code. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE2 = WF_1_NEW. IF SY-SUBRC = 0. WF_1_CURRENT = WA_ALPHA-CODE1. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE2 = WF_2_NEW . IF SY-SUBRC = 0. WF_2_CURRENT = WA_ALPHA-CODE1. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE2 = WF_3_NEW . IF SY-SUBRC = 0. WF_3_CURRENT = WA_ALPHA-CODE1. ENDIF. READ TABLE TB_ALPHA INTO WA_ALPHA WITH KEY CODE2 = WF_4_NEW . IF SY-SUBRC = 0. WF_4_CURRENT = WA_ALPHA-CODE1. ENDIF. * Concatenate the 4 characters into the field APLHA_NEW parameter CONCATENATE WF_4_CURRENT WF_3_CURRENT WF_2_CURRENT WF_1_CURRENT INTO ALPHA_NEW. ENDFUNCTION. |
Alpha Numeric Number Range (0000 to ZZZZ)
最新推荐文章于 2023-02-17 20:53:47 发布