设为首页收藏本站

SAP Best Business Solution

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 489|回复: 0

Alpha Numeric Number Range (0000 to ZZZZ)

[复制链接]

24

主题

24

帖子

204

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
204
发表于 2018-5-29 14:13:07 | 显示全部楼层 |阅读模式
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.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



QQ|Archiver|手机版|小黑屋|www.sapbbs.com    

GMT+8, 2018-12-17 18:52 , Processed in 1.058000 second(s), 30 queries .

声明:本站严禁任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!

本站内容由网友原创或转载,如果侵犯了您的合法权益,请及时联系处理!© admin@sapbbs.com

快速回复 返回顶部 返回列表