Problem solve Get help with specific problems with your technologies, process and projects.

Date arithmetic in COBOL

I have your book "DB2 Developers Guide" 4th edition -- excellent by the way but like others, I am having trouble with date arithmetic.

I understand that date durations have to be decimal 8, I have coded:
INTO :WS-TEMP-DAYS                           
FROM VSREGS     (vsregs is our 'nothing' table)   
And, I am getting the message in the precompile DSNH312I UNDEFINED OR UNUSABLE HOST VARIABLE "WS-TEMP-DAYS."

WS-TEMP-DAYS is defined as PIC 9(8) in COBOL. I have also tried PIC 9(8) COMP-2, PIC 9(8) COMP-3 WS-DT-RCVD is defined as PIC X(10) and has the CCYY-MM-DD format date in it.

So my question is, what is decimal 8 in COBOL?
Well, the first problem is that the DAYS function converts the date into an integer representation. So, you are subtracting one integer from another and the result will be an integer.

You should define the host variable as PIC S9(9) COMP.

Good luck.

Editor's note: Do you agree with this expert's response? If you have more to share, post it in one of our .VO7aaqqaAFk.0@/search390>discussion forums.

This was last published in November 2003

Dig Deeper on IBM DB2 management

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.