View previous topic :: View next topic
|
Author |
Message |
hernikiten
New User
Joined: 08 Apr 2005 Posts: 23 Location: india
|
|
|
|
Hi
I am trying to convert a Gregorian date to integer date using this statement.
Code: |
COMPUTE WS-INTEGER-DT = FUNCTION INTEGER-OF-DATE(WS-GREGORIAN-DATE). |
The datatypes are
Code: |
WS-GREGORIAN-DATE PIC 9(08) **its in YYYYMMDD format
WS-INTEGER-DT PIC S9(09) usage comp |
I am getting the compilation error
Function argument "WS-GREGORIAN-DATE" did not have the correct type for function "INTEGER-OF-DATE". The statement was discarded.
Please advice.
Thanks
Edited: Please use BBcode when You post some code/error, that's rather readable, Thanks... Anuj |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
Back to top |
|
|
hernikiten
New User
Joined: 08 Apr 2005 Posts: 23 Location: india
|
|
|
|
I am conforming to the same data type. Still getting the same error. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL Language Reference says
Quote: |
7.1.18 INTEGER-OF-DATE
The INTEGER-OF-DATE function converts a date in the Gregorian calendar from standard date form (YYYYMMDD) to integer date form.
The function type is integer.
The function result is a seven-digit integer with a range from 1 to 3,067,671. |
Now just how exactly do you think a 7-digit integer (which implies USAGE DISPLAY) will fit into a COMP field? Your problem isn't the argument doesn't conform -- your output variable doesn't conform. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Okay, now that I've had a chance to get on the mainframe and test, I find it takes the COMP field just fine. Another day, another thing learned.
Code: |
05 WS-GREGORIAN-DATE PIC 9(08) VALUE 20090424.
05 WS-INTEGER-DT PIC S9(09) USAGE COMP .
05 WS-INT-DT PIC S9(09).
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
COMPUTE WS-INTEGER-DT = FUNCTION
INTEGER-OF-DATE (WS-GREGORIAN-DATE) .
COMPUTE WS-INT-DT = FUNCTION
INTEGER-OF-DATE (WS-GREGORIAN-DATE) .
DISPLAY 'WS-INTEGER-DT = ' WS-INTEGER-DT.
DISPLAY 'WS-INT-DT = ' WS-INT-DT. |
produces
Code: |
WS-INTEGER-DT = 0000149133
WS-INT-DT = 00014913C |
so if you're getting a compile error you are doing something wrong in your program. What does the full declaration for the variables look like (01 right on down)? |
|
Back to top |
|
|
hernikiten
New User
Joined: 08 Apr 2005 Posts: 23 Location: india
|
|
|
|
It was happening due to sublevels in gregorian date.
01 Gregorian
02 greg-yyyy pic 9(04)
02 greg-mm pic 9(02)
02 greg-dd pic 9(02)
It must be an elementary item. To use a group variable ON SIZE ERROR clause is required.
Sorry didn't mention it earlier.n |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Well, I'm glad you got it resolved.
Hopefully, this is a lesson -- do not ever post your interpretation of what's going on -- if you'd posted the actual variables involved instead of saying WS-GREGORIAN-DATE was an elementary item, we probably could have solved it much quicker. Definitely with less confusion! |
|
Back to top |
|
|
|