Difference between two strings using CL/400, AS/400, COBOL/400

20 pts.
Tags:
AS/400
CL/400
COBOL/400
I am working on a requirement where in I need to find the numerical difference between two character strings. The two strings are 8 character long and can have spaces as values. The two strings are "from" and "to" fields. I will have to find out the last value used and then subtract it from the "to" field to get the remaining combinations possible.

For example From String = "0000" (8 Characters possible) To Strings = "4999R00" (8 Characters possible) Last Value used = "4999RZZ" Remaining combinations possible = 1 (4999R00)

I need to find the "Remaining combinations possible" value. I have taken this example just to show the conditions. I need to accomplish this either through CL400 or COBOL400 in AS400. Can anyone help me on this?

Thanks and Regards Sandeep



Software/Hardware used:
AS400, CL400, COBOL400
ASKED: April 26, 2011  10:10 AM
UPDATED: May 2, 2011  10:48 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

What I hear you say is that you have two 8 position fields that can contain any value. Does that include NULL X’00′ through X’FF’?
Or just A though Z plus 0 thorugh 9 plus blank?
If it is the 2nd option is what youmean, you could have up to 37*37*37*37*37*37*37*37 or 3,512,479,453,921 posibilities.
If it is the 1st option, then you possibilities would be 256 to the 8th power.
And now you want to list and count all the possibilities between the beginning string and the ending string.
Is this correct?

Discuss This Question: 8  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    From = "0000    " (4 trailing blanks)
    To = "4999R00 " (1 trailing blank)
    
    LastUsed = "4999RZZ " (1 trailing blank)
    ...the last value used and then subtract it from the "to" field...
    "4999R00 " minus "4999RZZ "
    ...to get the remaining combinations possible.
    Remaining combinations possible = 1 (4999R00)
    It looks like you have values that may be numeric in the first four positions, and alphabetic and numeric in the last four positions. There are 26 alphabetic characters possible, plus ten digits (0-9), plus a blank. That implies that each of the last four positions can have 37 different values. The "To" string gives an upper limit on the characters that can be used in each position. Your example "To" string has a trailing blank, so that restricts the last position from having a character greater than a blank in the eighth position. Am I understanding it so far? What OS version are you running under? Tom
    125,585 pointsBadges:
    report
  • Pgsdeb
    Tom I am using V6R1 version of AS400. As for the "from" and "to" fields, I have only given an example of what the values can be. There is no restrictions on the number of characters or numerals that you can put in the "from" and "to" strings. The only restriction is that "from field should be less than "to" field. Sandeep
    20 pointsBadges:
    report
  • TomLiotta
    “4999R00 ” minus “4999RZZ “
    …to get the remaining combinations possible.
    Remaining combinations possible = 1 (4999R00)
    Can you explain why there is only one combination left? Why aren't 4999R0A, 4999R0B, 4999R0Z, 4999R0A1, 4999R0g5 and many other possible combinations still available? Tom
    125,585 pointsBadges:
    report
  • NullFields
    Hi, Hope this works. I'm including the source of a COBOL program that will calculate the number of values between to base-36 strings. It should be easy to convert it to a base-37 that you need. Also, it assumes only a 4 character string, but that should be easy to convert as well:
    PIC  9(018).
          /--------------------------------------------------------------
           PROCEDURE DIVISION USING LS-WORD
                                    LS-RETURN-BASE-VALUE.
           HOUSKEEPING.
          ***
          *** Find the length of the input variable.
          ***   start with basic length of 4.
    
               MOVE LS-WORD TO INPUT-WORD.
               MOVE +4 TO INPUT-WORD-LENGTH.
    
           MAINLINE.
          *
    
               PERFORM VARYING NTH-POSITION
                 FROM INPUT-WORD-LENGTH BY -1
                 UNTIL NTH-POSITION < 1
    
                 SET BASE-IX TO 1
                 SEARCH BASE-INTEGER
                   AT END
                     GO TO END-OF-JOB
                   WHEN BASE-CHAR(BASE-IX) =
                        INPUT-WORD(NTH-POSITION:1)
                     MOVE BASE-VALUE(BASE-IX) TO CHAR-CALC-VALUE
                 END-SEARCH
    
                 COMPUTE WORD-BASE-VALUE =
                           WORD-BASE-VALUE +
                           CHAR-CALC-VALUE *
                           (36 ** (INPUT-WORD-LENGTH - NTH-POSITION ))
    
               END-PERFORM.
    
    
           END-OF-JOB.
    
               MOVE WORD-BASE-VALUE TO LS-RETURN-BASE-VALUE.
               DISPLAY 'RETURN VALUE: ' LS-RETURN-BASE-VALUE.
               GOBACK.    
    
    880 pointsBadges:
    report
  • NullFields
    Let me try that again, some of the code did not get included:
           IDENTIFICATION DIVISION.
           PROGRAM-ID.    TESTGETBAS.
           AUTHOR.            nullfields.
           DATE-WRITTEN.
           DATE-COMPILED.
          /
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           SPECIAL-NAMES.        LOCAL-DATA IS LOCAL-DATA-AREA.
           INPUT-OUTPUT SECTION.
           FILE-CONTROL.
          *
           DATA DIVISION.
           FILE SECTION.
          /--------------------------------------------------------------
           WORKING-STORAGE SECTION.
    
           LOCAL-STORAGE SECTION.
           01  INPUT-WORD            PIC  X(04)   VALUE SPACES.
           01  INPUT-WORD-LENGTH     PIC  9(05)   VALUE ZEROES.
           01  CHAR-CALC-VALUE       PIC  9(02)   VALUE ZEROES.
           01  NTH-POSITION          PIC  9(02)   VALUE ZEROES.
    
           01  WORD-SUBSCRIPT        PIC  9(01)   VALUE 1.
    
           01  BASE-LOOKUP-AREA.
               05 BASE-DECODE-ARRAY.
                  10 FILLER          PIC X(018) VALUE '000101202303404505'.
                  10 FILLER          PIC X(018) VALUE '606707808909A10B11'.
                  10 FILLER          PIC X(018) VALUE 'C12D13E14F15G16H17'.
                  10 FILLER          PIC X(018) VALUE 'I18J19K20L21M22N23'.
                  10 FILLER          PIC X(018) VALUE 'O24P25Q26R27S28T29'.
                  10 FILLER          PIC X(018) VALUE 'U30V31W32X33Y34Z35'.
               05 BASE-INTEGER REDEFINES BASE-DECODE-ARRAY
                                 OCCURS 36 TIMES
                                 INDEXED BY BASE-IX.
                  10 BASE-CHAR       PIC  X(01).
                  10 BASE-VALUE      PIC  9(02).
    
           01  WORD-BASE-VALUE       PIC  9(18) VALUE ZEROES.
          /--------------------------------------------------------------
           LINKAGE SECTION.
           01  LS-WORD               PIC  X(004).
           01  LS-RETURN-BASE-VALUE  PIC  9(018).
          /--------------------------------------------------------------
           PROCEDURE DIVISION USING LS-WORD
                                    LS-RETURN-BASE-VALUE.
           HOUSKEEPING.
          ***
          *** Find the length of the input variable.
          ***   start with basic length of 4.
    
               MOVE LS-WORD TO INPUT-WORD.
               MOVE +4 TO INPUT-WORD-LENGTH.
    
           MAINLINE.
          *
    
               PERFORM VARYING NTH-POSITION
                 FROM INPUT-WORD-LENGTH BY -1
                 UNTIL NTH-POSITION < 1
    
                 SET BASE-IX TO 1
                 SEARCH BASE-INTEGER
                   AT END
                     GO TO END-OF-JOB
                   WHEN BASE-CHAR(BASE-IX) =
                        INPUT-WORD(NTH-POSITION:1)
                     MOVE BASE-VALUE(BASE-IX) TO CHAR-CALC-VALUE
                 END-SEARCH
    
                 COMPUTE WORD-BASE-VALUE =
                           WORD-BASE-VALUE +
                           CHAR-CALC-VALUE *
                           (36 ** (INPUT-WORD-LENGTH - NTH-POSITION ))
    
               END-PERFORM.
    
    
           END-OF-JOB.
    
               MOVE WORD-BASE-VALUE TO LS-RETURN-BASE-VALUE.
               DISPLAY 'RETURN VALUE: ' LS-RETURN-BASE-VALUE.
               GOBACK. 
    
    880 pointsBadges:
    report
  • NullFields
    One other note about the code I posted. Each call you provide a string. It converts it to a number. To get the difference between the two strings, you would need to call it two times and get the difference between the values returned from each call. The sequence of the characters is determined by the array defined in working storage. If you needed 0-9 to be greater then A-Z, then you would need to change the array.
    880 pointsBadges:
    report
  • TomLiotta
    The only restriction is that “from field should be less than “to” field. If that is true, then this must be false: Remaining combinations possible = 1 (4999R00) Both of those can't be true at the same time. There are many combinations between "4999R00 " and "4999RZZ ". It is not just '1' combination remaining. I gave a few examples of other possible values. We need to know why those values must be excluded before we can suggest useful algorithms that will work. Please explain why "4999R0Z " isn't available between "4999R00 " and "4999RZZ ". Tom
    125,585 pointsBadges:
    report
  • Pgsdeb
    [...] 9. TomLiotta, NullFields, and CharlieBrowne were all over a member’s inquiry about the difference between two strings using CL/400, AS/400, and COBOL/400. [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following