开放式阿尔法语序列功能

时间:2017-12-12 15:01:02

标签: function sequence openedge progress-4gl alphanumeric

我已创建此算法用于字母数字编号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

波多黎各

1 个答案:

答案 0 :(得分:0)

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

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个进行测试;您需要将其删除。