The Custom Statement keyword functions MIN and MAX should support Date or Character arguments for maximum configuration flexibility.
Issue
When a Custom Statement invokes the MIN/MAX keyword with Date or Character Operands, it returns the error message, “Operands in custom statement contains a non-numeric value.”
Use Case
Many use cases exist for extending the MIN/MAX functionality to Dates and Character values.
Here is an example of the MIN/MAX function used to return the earliest date a member is eligible for Normal Retirement:
This example also includes an assignment of Date Temporary to the final result, which will return the error message, “Error in assignment – incompatible types“, unless the fix for “Custom Statement Assignment from Character or Date Temporary Variable Fails” is implemented.
Solution
The Custom Statement module (PAPUCSTM) includes the logic for processing the MIN/MAX keyword function and can be updated to support Date and Character values with the following code changes.
Add new variables:
01 W-AREA-SAVE.
02 PRIOR-KEYWORD PIC X(10).
02 PRIOR-FUNCTION PIC X(10).
02 W-FUNCTION PIC X(10).
02 W-MAX-AMT PIC S9(9)V9(6) COMP-3.
02 W-MIN-AMT PIC S9(9)V9(6) COMP-3.
NOCLN 02 W-IN PIC X(1).
NOCLN 88 W-IN-YES VALUE 'Y'.
NOCLN 88 W-IN-NO VALUE 'N'.
NOCLN 02 W-IN-OPERAND-TYP PIC X(1).
NOCLN 88 W-IN-OPERAND-DEC VALUE 'N'.
NOCLN 88 W-IN-OPERAND-CHR VALUE 'C'.
02 W-IN-DEC PIC S9(9)V9(6).
02 W-IN-CHR PIC X(40).
02 W-TEMP-SUB PIC X(2).
02 W-TEMP-SUB-PIC REDEFINES W-TEMP-SUB
PIC 99.
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
02 W-MAX-DT PIC X(10).
02 W-MIN-DT PIC X(10).
02 W-MAX-CHR PIC X(10).
02 W-MIN-CHR PIC X(10).
* 05/20/2015 MWT - End Change. *
******************************************************************
COBOL – PAPUCSTM.cblUpdate JJ000-PROCESS-FUNCTION section:
******************************************************************
* *
JJ000-PROCESS-FUNCTION SECTION.
JJ000.
* *
******************************************************************
IF (PRIOR-KEYWORD NOT = 'ELSE' AND STMT-TRUE) OR
( PRIOR-KEYWORD = 'ELSE' AND STMT-FALSE)
IF KEYWORD OF CUSTM-ARRAY(CUSTM-IDX) = SPACES
MOVE PRIOR-FUNCTION TO W-FUNCTION
ELSE
MOVE KEYWORD OF CUSTM-ARRAY(CUSTM-IDX) TO W-FUNCTION
MOVE ZEROS TO W-MAX-AMT
MOVE 999999999.999999 TO W-MIN-AMT
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
MOVE '1900-01-01' TO W-MAX-DT
MOVE '2999-12-31' TO W-MIN-DT
MOVE '#' TO W-MAX-CHR
MOVE '~' TO W-MIN-CHR
* 05/20/2015 MWT - End Change. *
******************************************************************
SET W-IN-NO TO TRUE
IF KEYWORD OF CUSTM-ARRAY(CUSTM-IDX) = 'IN'
EVALUATE TRUE
WHEN OPERAND1-TYP-CHR OF CUSTM-ARRAY
(CUSTM-IDX)
MOVE OPERAND1-CHAR OF CUSTM-ARRAY
(CUSTM-IDX) TO W-IN-CHR
SET W-IN-OPERAND-CHR TO TRUE
WHEN OPERAND1-TYP-NUM OF CUSTM-ARRAY
(CUSTM-IDX)
MOVE OPERAND1-DEC OF CUSTM-ARRAY
(CUSTM-IDX) TO W-IN-DEC
SET W-IN-OPERAND-DEC TO TRUE
WHEN OPERAND1-TYP-DT OF CUSTM-ARRAY
(CUSTM-IDX)
MOVE OPERAND1-CHAR OF CUSTM-ARRAY
(CUSTM-IDX) TO W-IN-CHR
SET W-IN-OPERAND-CHR TO TRUE
END-EVALUATE
END-IF
END-IF
PERFORM JJ100-FUNCTION
END-IF
.
PROCESS-FUNCTION-EXIT. EXIT.
COBOL – PAPUCSTM.cblUpdate JJ200-MAX-FUNCTION section:
******************************************************************
* *
JJ200-MAX-FUNCTION SECTION.
JJ200.
* *
******************************************************************
IF OPERAND1-TYP OF CUSTM-ARRAY(CUSTM-IDX) > SPACES
IF NOT OPERAND1-TYP-NUM OF CUSTM-ARRAY
(CUSTM-IDX)
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
AND NOT OPERAND1-TYP-DT OF CUSTM-ARRAY
(CUSTM-IDX)
AND NOT OPERAND1-TYP-CHR OF CUSTM-ARRAY
(CUSTM-IDX)
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE 20 TO ERROR-NUM
MOVE 'JJ200-MAX-FUNCTION'
TO S-MSG-PGM-PARA
PERFORM SA000-ERROR-PROCESSING
ELSE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
AND OPERAND1-DATE OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-DT
MOVE OPERAND1-DATE OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-DT
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY(CUSTM-IDX)
AND OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-DT
MOVE OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-DT
END-IF
END-IF
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-CHR
MOVE OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-CHR
END-IF
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
IF OPERAND1-DEC OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-AMT
MOVE OPERAND1-DEC OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-AMT
END-IF
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
END-IF
END-IF
IF OPERAND2-TYP OF CUSTM-ARRAY(CUSTM-IDX) > SPACES
IF NOT OPERAND2-TYP-NUM OF CUSTM-ARRAY
(CUSTM-IDX)
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
AND NOT OPERAND2-TYP-DT OF CUSTM-ARRAY
(CUSTM-IDX)
AND NOT OPERAND2-TYP-CHR OF CUSTM-ARRAY
(CUSTM-IDX)
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE 20 TO ERROR-NUM
MOVE 'JJ200-MAX-FUNCTION'
TO S-MSG-PGM-PARA
PERFORM SA000-ERROR-PROCESSING
ELSE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
AND OPERAND2-DATE OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-DT
MOVE OPERAND2-DATE OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-DT
ELSE
IF OPERAND2-TYP-CHR OF CUSTM-ARRAY(CUSTM-IDX)
AND OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-DT
MOVE OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-DT
END-IF
END-IF
ELSE
IF OPERAND2-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX) >=
W-MAX-CHR
MOVE OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-CHR
END-IF
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
IF OPERAND2-DEC OF CUSTM-ARRAY(CUSTM-IDX) >
W-MAX-AMT
MOVE OPERAND2-DEC OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MAX-AMT
END-IF
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
END-IF
END-IF
IF ERROR-FLAG-NO AND
OPERATOR2 OF CUSTM-ARRAY(CUSTM-IDX) = '='
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
MOVE W-MAX-DT TO STMT-CHAR-VAR
EXPR-CHAR-VAR
SET ATTR-FLAG-DT TO TRUE
MOVE 'DATE' TO OPERAND3-PIC
OF CUSTM-ARRAY (CUSTM-IDX)
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
MOVE W-MAX-CHR TO STMT-CHAR-VAR
EXPR-CHAR-VAR
SET ATTR-FLAG-CHR TO TRUE
MOVE 'CHAR' TO OPERAND3-PIC
OF CUSTM-ARRAY (CUSTM-IDX)
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE W-MAX-AMT TO STMT-PIC-VAR
EXPR-PIC-VAR
SET ATTR-FLAG-NUM TO TRUE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE OPERAND3 OF CUSTM-ARRAY(CUSTM-IDX) TO
W-TEMP
IF W-TEMP-VAR-YES
PERFORM MA000-ASSIGN-TEMP
ELSE
PERFORM PA000-ASSIGN-ALIAS
END-IF
END-IF
.
MAX-FUNCTION-EXIT. EXIT.
COBOL – PAPUCSTM.cblUpdate JJ300-MIN-FUNCTION section:
******************************************************************
* *
JJ300-MIN-FUNCTION SECTION.
JJ300.
* *
******************************************************************
IF OPERAND1-TYP OF CUSTM-ARRAY(CUSTM-IDX) > SPACES
IF NOT OPERAND1-TYP-NUM OF CUSTM-ARRAY
(CUSTM-IDX)
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
AND NOT OPERAND1-TYP-DT OF CUSTM-ARRAY
(CUSTM-IDX)
AND NOT OPERAND1-TYP-CHR OF CUSTM-ARRAY
(CUSTM-IDX)
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE 20 TO ERROR-NUM
MOVE 'JJ300-MIN-FUNCTION'
TO S-MSG-PGM-PARA
PERFORM SA000-ERROR-PROCESSING
ELSE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
AND OPERAND1-DATE OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-DT
MOVE OPERAND1-DATE OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-DT
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY(CUSTM-IDX)
AND OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-DT
MOVE OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-DT
END-IF
END-IF
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-CHR
MOVE OPERAND1-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-CHR
END-IF
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
IF OPERAND1-DEC OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-AMT
MOVE OPERAND1-DEC OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-AMT
END-IF
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
END-IF
END-IF
IF OPERAND2-TYP OF CUSTM-ARRAY(CUSTM-IDX) > SPACES
IF NOT OPERAND2-TYP-NUM OF CUSTM-ARRAY
(CUSTM-IDX)
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
AND NOT OPERAND2-TYP-DT OF CUSTM-ARRAY
(CUSTM-IDX)
AND NOT OPERAND2-TYP-CHR OF CUSTM-ARRAY
(CUSTM-IDX)
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE 20 TO ERROR-NUM
MOVE 'JJ300-MIN-FUNCTION'
TO S-MSG-PGM-PARA
PERFORM SA000-ERROR-PROCESSING
ELSE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
AND OPERAND2-DATE OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-DT
MOVE OPERAND2-DATE OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-DT
ELSE
IF OPERAND2-TYP-CHR OF CUSTM-ARRAY(CUSTM-IDX)
AND OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-DT
MOVE OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-DT
END-IF
END-IF
ELSE
IF OPERAND2-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
IF OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-CHR
MOVE OPERAND2-CHAR OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-CHR
END-IF
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
IF OPERAND2-DEC OF CUSTM-ARRAY(CUSTM-IDX) <
W-MIN-AMT
MOVE OPERAND2-DEC OF CUSTM-ARRAY(CUSTM-IDX)
TO W-MIN-AMT
END-IF
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
END-IF
END-IF
IF ERROR-FLAG-NO AND
OPERATOR2 OF CUSTM-ARRAY(CUSTM-IDX) = '='
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
IF OPERAND1-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-DT OF CUSTM-ARRAY (CUSTM-IDX)
MOVE W-MIN-DT TO STMT-CHAR-VAR
EXPR-CHAR-VAR
SET ATTR-FLAG-DT TO TRUE
MOVE 'DATE' TO OPERAND3-PIC
OF CUSTM-ARRAY (CUSTM-IDX)
ELSE
IF OPERAND1-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
OR OPERAND2-TYP-CHR OF CUSTM-ARRAY (CUSTM-IDX)
MOVE W-MIN-CHR TO STMT-CHAR-VAR
EXPR-CHAR-VAR
SET ATTR-FLAG-CHR TO TRUE
MOVE 'CHAR' TO OPERAND3-PIC
OF CUSTM-ARRAY (CUSTM-IDX)
ELSE
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE W-MIN-AMT TO STMT-PIC-VAR
EXPR-PIC-VAR
SET ATTR-FLAG-NUM TO TRUE
******************************************************************
* 05/20/2015 MWT - Mark Tomsheck, PSPA Tech Inc. *
* DT-00020 PSPA Tech (DT) Modified Code *
* Extend MIN/MAX custom statement functionality *
* to dates and character values. *
* *
END-IF
END-IF
* 05/20/2015 MWT - End Change. *
******************************************************************
MOVE OPERAND3 OF CUSTM-ARRAY(CUSTM-IDX) TO
W-TEMP
IF W-TEMP-VAR-YES
PERFORM MA000-ASSIGN-TEMP
ELSE
PERFORM PA000-ASSIGN-ALIAS
END-IF
END-IF
.
MIN-FUNCTION-EXIT. EXIT.
COBOLWorkaround
A configuration workaround that uses IF/ELSEIF/ELSE logic might be an alternative to invoking the MIN/MAX keyword function for Date or Character values.
Resolution
After the proposed enhancement is coded and the COBOL compiled, the Custom Statement will resolve the MIN/MAX keyword function for Date or Character values without error.
Analysis
This issue has not been reported to Oracle. Whether it is a bug or enhancement could be debated.
Additional Resources
PeopleBooks does not indicate the MIN/MAX function will not work with Date or Character arguments. To learn more about the Custom Statement MIN/MAX function, see PeopleBooks.
Leave a Reply
You must be logged in to post a comment.