## 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

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

Thanks. We'll let you know when a new response is added.
• ```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
report
• 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
report
• `“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
report
• 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.

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.
```
report
• 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.
/--------------------------------------------------------------
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.

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.
```