OPENEDGE 字母数字序列函数

Posted

技术标签:

【中文标题】OPENEDGE 字母数字序列函数【英文标题】:OPENEDGE ALPHANUMERIC SEQUENCE FUNCTION 【发布时间】:2017-12-12 15:01:01 【问题描述】:

我已经为字母数字编号 en PROGRESS OPENEDGE 创建了这个算法。我看到的问题是它完全是连续的,当序列增长时它会变得更慢。我想看看是否有办法重新排列函数,这样无论输入参数上给出哪个数字都会有效。

代码如下:

/* LOAN-ORDER-FUNCTION.i */

DEF VAR i-NUMBER-IN AS INT.
DEF VAR o-order AS CHAR.

DEF VAR cnt AS INTEGER.


DEF VAR NUMERAL AS INTEGER.
DEF VAR CODE-OUT AS CHAR FORMAT "X(5)".

DEF VAR LETTERs1 AS CHAR EXTENT 24 
        INITIAL ["A","B","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z"].

DEF VAR LETTERs2 AS CHAR EXTENT 26 
        INITIAL ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"].



FUNCTION BIG-NUMBER RETURNS CHAR (INPUT COMPANY AS CHAR, INPUT  NUMBER-IN AS INTEGER):

DEF VAR LETTER1 AS integer INITIAL 1 .
DEF VAR LETTER2 AS INTEGER INITIAL 1 .
DEF VAR LETTER3 AS INTEGER INITIAL 1 .

DEF VAR i AS integer INITIAL 1 NO-UNDO.
DEF VAR j AS integer INITIAL 1  NO-UNDO.
DEF VAR k AS integer INITIAL 1  NO-UNDO.

DEF VAR CODIGO AS CHAR.

DEF VAR in-letter2 AS INT NO-UNDO.
DEF VAR in-letter1 AS INT NO-UNDO.

    CNT = 0.

    IF NUMBER-IN < 100000 THEN
       RETURN COMPANY + STRING(NUMBER-IN,"99999").

    REPEAT LETTER1 = 1 TO 24:

        DO i = 0 TO 9999:

            CODIGO = COMPANY + LETTERS1[LETTER1] + string(i,"9999").

            IF CNT  + 100000 = NUMBER-IN THEN
               RETURN CODIGO.

            cnt = cnt + 1.
        END.

        DO i = 0 TO 999:
            CODIGO = COMPANY + LETTERS1[LETTER1] + LETTERS1[LETTER2] + string(i,"999").

            IF CNT  + 100000 = NUMBER-IN THEN
               RETURN CODIGO.

            cnt = cnt + 1.
        END.

        DO letter2 = 1 TO 26:
            DO letter3 = 1 TO 26:
                DO i = 0 TO 99:

                    CODIGO = COMPANY + LETTERS1[LETTER1] + LETTERS2[LETTER2] + LETTERS2[LETTER3] + string(i,"99").

                    IF CNT  + 100000 = NUMBER-IN THEN
                       RETURN CODIGO.

                    cnt = cnt + 1.
                END.
            END.
        END.

        ASSIGN letter2 = 1
               letter3 = 1.

    END.

END FUNCTION.


FUNCTION BIG-TO-NUMBER RETURNS INTEGER (INPUT codigo-in AS CHAR):

DEF VAR LETTER1 AS integer INITIAL 1 .
DEF VAR LETTER2 AS INTEGER INITIAL 1 .
DEF VAR LETTER3 AS INTEGER INITIAL 1 .

DEF VAR i AS integer INITIAL 1 NO-UNDO.
DEF VAR j AS integer INITIAL 1  NO-UNDO.
DEF VAR k AS integer INITIAL 1  NO-UNDO.

DEF VAR codigo AS CHAR.

    CNT = 0.

    IF codigo-in < "AA0000" THEN
       RETURN integer(SUBSTRING(codigo-in, 2)).

    REPEAT LETTER1 = 1 TO 24:

        DO i = 0 TO 9999:

            CODIGO = COMPANY + LETTERS1[LETTER1] + string(i,"9999").

            IF CODIGO  = codigo-IN THEN
               RETURN CNT  + 100000.

            cnt = cnt + 1.
        END.

        DO i = 0 TO 999:

            CODIGO = COMPANY + LETTERS1[LETTER1] + LETTERS1[LETTER2] + string(i,"999").

            IF CODIGO  = codigo-IN THEN
               RETURN CNT  + 100000.

            cnt = cnt + 1.
        END.

        DO letter2 = 1 TO 26:
            DO letter3 = 1 TO 26:

                DO i = 0 TO 99:
                    CODIGO = COMPANY + LETTERS1[LETTER1] + LETTERS2[LETTER2] + LETTERS2[LETTER3] + string(i,"99").

                    IF CODIGO  = codigo-IN THEN
                       RETURN CNT  + 100000.

                    cnt = cnt + 1.
                END.
            END.
        END.

        ASSIGN letter2 = 1
               letter3 = 1.
    END.



END FUNCTION.

提前感谢您的时间和精力,

雨果

hugoyamil@yahoo.com

波多黎各

【问题讨论】:

如果你想让它快速抛弃字母,只使用 int64。这将允许您使用内置序列。另外一个由多个实体(公司+序列)组成的字段是违反规范化的,很可能导致下游数据质量问题。 0。您的示例无法编译 - 1. 这将有助于添加一些预期的输入和输出值 2. 所以您真的在使用蛮力方法来获取数字?!?!?阅读 ASC 和 CHR 函数的作用。 好的,这是因为它作为包含文件运行,请在顶部添加 DEF VAR COMPANY 作为 CHAR 首字母“A”。 @tom Bascom @Stefan Drissen 向发票功能添加其他 var def var in-data 作为 int64 不可撤销。 def var iter as integer no-undo。最后让输入或生成数字重复:设置数据。 display big-number(company,in-data) big-to-number(big-number(company,in-data). end. 或者可能重复 iter = 123456 到 234567: display big-number(company,iter) big -to-number(big-number(company,iter)).end. 【参考方案1】:

您可以尝试下面的代码来生成字母数字序列(短、快、简单),

DEFINE VARIABLE chText      AS CHARACTER   NO-UNDO.
DEFINE VARIABLE inLoop1     AS INTEGER     NO-UNDO.
DEFINE VARIABLE inLoop2     AS INTEGER     NO-UNDO.
DEFINE VARIABLE inLength    AS INTEGER     NO-UNDO.

DEFINE VARIABLE chLetter    AS CHARACTER   NO-UNDO. 
DEFINE VARIABLE loNext      AS LOGICAL     NO-UNDO. 

SET chtext FORMAT "X(15)".
inLength = LENGTH(chtext).

DO inLoop1 = 1 TO 1000:
MESSAGE chtext
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

DO inLoop2 = 1 TO inLength:
    chLetter = SUBSTRING(chtext, (inLength + 1 - inLoop2), 1).

    IF chLetter = "Z" THEN 
        ASSIGN chtext = SUBSTRING(chtext,1,(inLength - inLoop2))  + STRING(CHR(ASC(chLetter) - 25)) + SUBSTRING(chtext,(inLength + 2 - inLoop2)) 
               loNext = TRUE.
    ELSE IF chLetter = "9" THEN 
        ASSIGN chtext = SUBSTRING(chtext,1,(inLength - inLoop2))  + STRING(CHR(ASC(chLetter) - 9))  + SUBSTRING(chtext,(inLength + 2 - inLoop2)) 
               loNext = TRUE.
    ELSE
        ASSIGN chtext = SUBSTRING(chtext,1,(inLength - inLoop2)) + STRING(CHR(ASC(chLetter) + 1))   + SUBSTRING(chtext,(inLength + 2 - inLoop2))
               loNext = FALSE.

    IF NOT loNext THEN
        LEAVE.
    END.
END.

将其放入您的函数中并传递序列字段的值。 我使用do循环创建了1000个进行测试;你需要删除它。

【讨论】:

以上是关于OPENEDGE 字母数字序列函数的主要内容,如果未能解决你的问题,请参考以下文章

怎样用Excel随机函数rand()生成随机数字和大写字母,能自动产生4位混合的

excel 如何自动生成32位的大写字母跟数字组合的随机序列,类似于验证码的那种随机的

使用Java8函数式编程 生成字母序列

假定输入的字符中只包含字母和“ * ”号。编写一个函数fun,该函数的功能是将字符串中前导“ *

正则校验字母数字特殊字符的函数

excel单元格编号有字母有数字怎么让后面的数字增加,