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
…the last value used and then subtract it from the “to” field…
…to get the remaining combinations possible.
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
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
…to get the remaining combinations possible.
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
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.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.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.
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