Alpha Numeric Number Range (0000 to ZZZZ)

Alpha Numeric Number Range (0000 to ZZZZ)


Skip to end of metadata
Go to start of metadata

Author: Abhishek Jolly
Submitted: 12.01.2009

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.


Method Name : GET_NEXT_ALPHA_CODE

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值