IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

converting Gregorian date to Integer of date - Error


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
hernikiten

New User


Joined: 08 Apr 2005
Posts: 23
Location: india

PostPosted: Fri Apr 24, 2009 11:22 am
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Apr 24, 2009 12:01 pm
Reply with quote

Hi,

Check this link on INTEGER-OF-DATE.
Back to top
View user's profile Send private message
hernikiten

New User


Joined: 08 Apr 2005
Posts: 23
Location: india

PostPosted: Fri Apr 24, 2009 5:54 pm
Reply with quote

I am conforming to the same data type. Still getting the same error.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 24, 2009 6:08 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 24, 2009 6:37 pm
Reply with quote

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
View user's profile Send private message
hernikiten

New User


Joined: 08 Apr 2005
Posts: 23
Location: india

PostPosted: Tue Apr 28, 2009 5:46 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Apr 28, 2009 8:07 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top