Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATE SUBTRACTION 1

Status
Not open for further replies.

krimhild

Technical User
Jul 25, 2001
7
US
I am getting the error message 'ARGUMENT OF FUNCTION INTEGER-OF-DATE MUST BE TYPE INTEGER' when I compile my subprogram. I am trying to find the number of days difference between two dates. Here is my subprogram:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CUR-DATE.
05 WS-CUR-YEAR PIC 9999.
05 WS-CUR-MONTH PIC 99.
05 WS-CUR-DAY PIC 99.

01 WS-START-DATE.
05 WS-START-YEAR.
10 WS-START-CENTURY PIC 99.
10 WS-START-END PIC 99.
05 WS-START-MONTH PIC 99.
05 WS-START-DAY PIC 99.


LINKAGE SECTION.
COPY DATESTMP.

PROCEDURE DIVISION USING DATE-ARGUMENTS.

000-MAIN.
MOVE FUNCTION CURRENT-DATE (1:8) TO WS-CUR-DATE.
PERFORM 200-GET-CENTURY.
PERFORM 300-FORMAT-CURRENT-DATE.
PERFORM 400-FIND-DAYS-DIFF.
PERFORM 500-FORMAT-DATE
EXIT PROGRAM.


200-GET-CENTURY.
IF SUB-START-YEAR > 90
MOVE 19 TO WS-START-CENTURY
ELSE
MOVE 20 TO WS-START-CENTURY
END-IF.

300-FORMAT-CURRENT-DATE.
MOVE SUB-START-MONTH TO WS-START-MONTH
MOVE SUB-START-DAY TO WS-START-DAY
MOVE SUB-START-YEAR TO WS-START-END.

400-FIND-DAYS-DIFF.

COMPUTE DAYS-DIFFERENCE =
FUNCTION INTEGER-OF-DATE(WS-CUR-DATE)
- FUNCTION INTEGER-OF-DATE(WS-START-DATE).

500-FORMAT-DATE.
MOVE WS-CUR-MONTH TO SUB-CUR-MONTH
MOVE WS-CUR-DAY TO SUB-CUR-DAY
MOVE WS-CUR-YEAR TO SUB-CUR-YEAR.

My copybook 'DATESTMP' is as follows:
01 DATE-ARGUMENTS.
05 SUB-CUR-DATE.
10 SUB-CUR-MONTH PIC 99.
10 SUB-CUR-DAY PIC 99.
10 SUB-CUR-YEAR PIC 9999.
05 SUB-START-DATE.
10 SUB-START-MONTH PIC 99.
10 SUB-START-DAY PIC 99.
10 SUB-START-YEAR PIC 99.
05 DAYS-DIFFERENCE PIC 9999.

Thanks if anyone can help.
 
You are using group names for your function arguments. Group names are, by definition, alphanumeric. Redefine the group names as PIC 9(08), and use the redifinitions as the arguments for the function.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
I changed the program to this and it compiles correctly. When I execute the main program it has the error message:
'function integer-of-date error, argument value is invalid pgm=currdate'

DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CUR-DATE PIC 9(8).

01 WS-START-DATE.
05 WS-START-YEAR.
10 WS-START-CENTURY PIC 99.
10 WS-START-END PIC 99.
05 WS-START-MONTH PIC 99.
05 WS-START-DAY PIC 99.

01 FUNC-START-DATE REDEFINES WS-START-DATE PIC 9(8).


LINKAGE SECTION.
COPY DATESTMP.

PROCEDURE DIVISION USING DATE-ARGUMENTS.

000-MAIN.
MOVE FUNCTION CURRENT-DATE (1:8) TO WS-CUR-DATE.
PERFORM 200-GET-CENTURY.
PERFORM 300-FORMAT-CURRENT-DATE.
PERFORM 400-FIND-DAYS-DIFF.
PERFORM 500-FORMAT-DATE
EXIT PROGRAM.


200-GET-CENTURY.
IF SUB-START-YEAR > 90
MOVE 19 TO WS-START-CENTURY
ELSE
MOVE 20 TO WS-START-CENTURY
END-IF.

300-FORMAT-CURRENT-DATE.
MOVE SUB-START-MONTH TO WS-START-MONTH
MOVE SUB-START-DAY TO WS-START-DAY
MOVE SUB-START-YEAR TO WS-START-END.

400-FIND-DAYS-DIFF.

COMPUTE DAYS-DIFFERENCE =
FUNCTION INTEGER-OF-DATE(WS-CUR-DATE)
- FUNCTION INTEGER-OF-DATE(FUNC-START-DATE).

500-FORMAT-DATE.
MOVE WS-CUR-DATE TO SUB-CUR-DATE.
 
Do a display on WS-CUR-DATE and FUNC-START-DATE. Make sure your data is good. (CUR-date looks OK, but START-DATE is coming from another program.

Your code looks good... let's look at the data!

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
Thank you very much. You are a great help. I was not moving my the start date to the right field before transferring it. One more question. I want to call the subprogram and just return the current date without executing the rest of the program. It is for the header of a report and the header writes before the first start date is read. So really just the 500-format-date needs to be executed along with the current-date function. Once again you are a big help.
 
I noticed this piece of code right away:

000-MAIN.
MOVE FUNCTION CURRENT-DATE (1:8) TO WS-CUR-DATE.

As I recall, CURRENT-DATE, as the result of your function, would be numeric. Or else has to be defined as numeric. Therefore, employing a reference modification (1:8) to reference the first 8 bytes of data would give you a compile error because this sort of coding is normally used on alphanumeric (PIC X) fields, not numeric fields.

You might have to move the result of your function to a PIC X field, then do the reference modification.

As for skipping part of the program when certain results happen: In your mainline (000-MAIN), when you want to branch off to the end and skip part of the processing, use a conditional statement for performing the rest of the paragraphs i.e.

PERFORM 200-GET-CENTURY.
PERFORM 300-FORMAT-CURRENT-DATE.
IF CURRENT-DATE > ZEROES [or some other condition]
CONTINUE
ELSE
PERFORM 400-FIND-DAYS-DIFF
PERFORM 500-FORMAT-DATE
END-IF.

EXIT PROGRAM.

Hope this helps, Nina Too
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top