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

converting Julian date(YYDDD) to YYYYMMDD format


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

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Tue Apr 11, 2006 6:20 pm
Reply with quote

Hi,

Please any one help me in converting a julian date of the format 'YYDDD' to 'MM/DD/YY'.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 11, 2006 7:17 pm
Reply with quote

mouli,

Check out these two functions

INTEGER-OF-DAY
DATE-OF-INTEGER

Dave
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Tue Apr 11, 2006 10:44 pm
Reply with quote

hy mouli,

just note: if you want to use these functions,
which are known as intrinsic functions and very useful.
you must use any higher level of cobol than vs cobol ii.
try any le-conform cobol compiler, i.e. cobol for mvs & vm,
cobol for os/390 & z/os, enterprise compiler for os/390 & z/os...

martin9
Back to top
View user's profile Send private message
mouli

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Wed Apr 12, 2006 4:13 pm
Reply with quote

Hi Dave,

Thanks for ur immediate response ....

I used those two intrinsic functions but it is giving some error ... i think data type missmatch i feel..

i coded as follows
WORKING STORAGE SECTION.
01 WS-JULIAN.
05 WS-JULIAN-YY PIC 9(2).
05 WS-JULIAN-YYDDD PIC 9(5).
01 WS-INTEGER PIC 9(7) VALUE ZEROES.
01 WS-YYYYMMDD PIC 9(8) VALUE ZEROES.
.....

PROCEDURE DIVISION.
...
.....

MOVE 20 TO WS-JULIAN-YY.
MOVE 06300 TO WS-JULIAN-YYDDD.
COMPUTE WS-INTEGER = INTEGER-OF-DAY(WS-JULIAN).
COMOUTE WS-YYYYMMDD = DAY-OF-INTEGER(WS-INTEGER).

DISPLAY WS-YYYYMMDD.


is there anything wrong in the data types or in coding .... don't ask what type of error u got bcz i tried so many ways ... pls help me.
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Wed Apr 12, 2006 4:17 pm
Reply with quote

hy mouli,

try to use the function as...

COMPUTE WS-INTEGER = FUNCTION INTEGER-OF-DAY(WS-JULIAN).

martin9
Back to top
View user's profile Send private message
mouli

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Wed Apr 12, 2006 4:41 pm
Reply with quote

Hi Martin,

Sorry .. i missed out FUNCTION in the mail... but i coded it in the program.

regards
mouli
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Wed Apr 12, 2006 5:04 pm
Reply with quote

hy mouli,

your variable WS-JULIAN is not an integer.
the group level is always a character field (string).

try it differently, using the correct pic clause...

INTEGER-OF-DAY

The INTEGER-OF-DAY function converts a date in the Gregorian calendar from
Julian date form (YYYYDDD) to integer date form.

The function type is integer.

The function result is a 7-digit integer.

+--- Format -------------------------------------------------------------+
! !
! >>--FUNCTION INTEGER-OF-DAY--(argument-1)--------------------------->< !
! !
+------------------------------------------------------------------------+

argument-1
Must be an integer of the form YYYYDDD whose value is obtained from
the calculation (YYYY * 1000) + DDD.

o YYYY represents the year in the Gregorian calendar. It must be an
integer greater than 1600, but not greater than 9999.

o DDD represents the day of the year. It must be a positive integer
less than 367, provided that it is valid for the year specified.

The INTDATE compiler option affects the starting date for the integer
date functions. For details, see the Enterprise COBOL Programming
Guide.

The returned value is an integer that is the number of days the date
represented by argument-1, succeeds December 31, 1600 in the Gregorian
calendar.


martin9
Back to top
View user's profile Send private message
mouli

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Wed Apr 12, 2006 5:30 pm
Reply with quote

Hi Martin,

i getting the following error..

"The current year was outside the 100-year window, 1900 through 1999, for program SAFSCAN1.From compile unit SAFSCAN1 at entry point SAFSCAN1 at compile unit offset +000005C4 at entry offset +000005C4 .....



regards
chandra
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Wed Apr 12, 2006 7:00 pm
Reply with quote

hy mouli,

which compiler are you using?

if it is enterprise cobol for z/os, note the following:

YEARWINDOW

Format: YEARWINDOW(base-year)

Default is: YEARWINDOW(1900)

Abbreviation is: YW

Use the YEARWINDOW option to specify the first year of the 100-year window
(the century window) to be applied to windowed date field processing by
the COBOL compiler.

base-year represents the first year of the 100-year window, and must be
specified as one of the following:

o An unsigned decimal number between 1900 and 1999.

This specifies the starting year of a fixed window. For example,
YEARWINDOW(1930) indicates a century window of 1930-2029.

o A negative integer from -1 through -99.

This indicates a sliding window, where the first year of the window is
calculated from the current run-time date. The number is subtracted
from the current year to give the starting year of the century window.
For example, YEARWINDOW(-80) indicates that the first year of the
century window is 80 years before the current year at the time the
program is run.

Usage notes

o The YEARWINDOW option has no effect unless the DATEPROC option is also
in effect.

o At run time, two conditions must be true:

- The century window must have its beginning year in the 1900s.

- The current year must lie within the century window for the
compilation unit.

For example, if the current year is 2002, the DATEPROC option is in
effect, and you use the YEARWINDOW(1900) option, the program will
terminate with an error message.

martin9
Back to top
View user's profile Send private message
mouli

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Wed Apr 12, 2006 7:26 pm
Reply with quote

Hi martin,

we r using the "IBM COBOL for OS/390 & VM 2.2.2" compiler.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Apr 12, 2006 10:36 pm
Reply with quote

Hi mouli,

If you are having problems with the intrinsic functions, here is a simple subroutine what will perform the function you want.

Code:

 
 WORKING-STORAGE SECTION.                                       
                                                               
 01  MM-DD-TBL.                                                 
     05  MM-01                   PIC 9(3)   COMP-3 VALUE 0.     
     05  MM-02                   PIC 9(3)   COMP-3 VALUE 31.   
     05  MM-03                   PIC 9(3)   COMP-3 VALUE 59.   
     05  MM-04                   PIC 9(3)   COMP-3 VALUE 90.   
     05  MM-05                   PIC 9(3)   COMP-3 VALUE 120.   
     05  MM-06                   PIC 9(3)   COMP-3 VALUE 151.   
     05  MM-07                   PIC 9(3)   COMP-3 VALUE 181.   
     05  MM-08                   PIC 9(3)   COMP-3 VALUE 212.   
     05  MM-09                   PIC 9(3)   COMP-3 VALUE 243.   
     05  MM-10                   PIC 9(3)   COMP-3 VALUE 273.   
     05  MM-11                   PIC 9(3)   COMP-3 VALUE 304.   
     05  MM-12                   PIC 9(3)   COMP-3 VALUE 334.   
 01  MM-DD-TBL-R REDEFINES MM-DD-TBL.                           
     05  MM-DAYS                 OCCURS 12 TIMES               
                                 PIC 9(3)   COMP-3.             
 01  WS-AREA.                                                   
     05  WS-LEAP-YEAR            PIC S9(3)  COMP-3.             
         88 LEAP-YEAR                       VALUE 0.             
     05  WS-FIL9                 PIC S9(3)  COMP-3.               
                                                                 
 LINKAGE SECTION.                                                 
                                                                 
 01  DATE-YYDDD.                                                 
     05  YY                      PIC 99.                         
     05  DDD                     PIC 999.                         
 01  DATE-YYYYMMDD.                                               
     05  YYYY                    PIC 9999.                       
     05  MM                      PIC 99.                         
     05  DD                      PIC 99.                         
 01  WINDOW-YEAR                 PIC 99.                         
                                                                 
 PROCEDURE DIVISION USING DATE-YYDDD, DATE-YYYYMMDD, WINDOW-YEAR.
                                                                 
 PROGRAM-START.                                                   
                                                                 
*--- TEST FOR LEAP YEAR - REMAINDER = 0 = LEAP YEAR               
                                                               
     DIVIDE YY BY 4 GIVING WS-FIL9 REMAINDER WS-LEAP-YEAR.     
                                                               
*--- CORRECT MONTH-DAY VALUES FOR LEAP YEARS                   
                                                               
     IF LEAP-YEAR                                             
     THEN                                                     
         ADD +1                  TO MM-03                     
                                    MM-04                     
                                    MM-05                     
                                    MM-06                     
                                    MM-07                     
                                    MM-08                     
                                    MM-09                     
                                    MM-10                     
                                    MM-11                     
                                    MM-12                     
     END-IF.                                                   
                                                               
                                                       
*--- SET CENTURY YEAR AS PER WINDOW YEAR               
                                                       
     IF YY >= WINDOW-YEAR                               
     THEN                                               
         ADD 1900 TO YY GIVING YYYY                     
     ELSE                                               
         ADD 2000 TO YY GIVING YYYY                     
     END-IF.                                           
                                                       
*--- DETERMINE WHAT MONTH WE ARE IN                     
                                                       
     PERFORM                                           
       VARYING MM FROM 12 BY -1                         
       UNTIL MM-DAYS(MM) < DDD                         
     END-PERFORM.                                       
                                                       
*--- REMAINDER OF DDD IS DAYS WITHIN THE MONTH         
                                                       
                                                   
     SUBTRACT MM-DAYS(MM) FROM DDD GIVING DD.       
                                                   
*--- RESET MONTH-DAY VALUES FOR NEXT CALL           
                                                   
     IF LEAP-YEAR                                   
     THEN                                           
         SUBTRACT +1           FROM MM-03           
                                    MM-04           
                                    MM-05           
                                    MM-06           
                                    MM-07           
                                    MM-08           
                                    MM-09           
                                    MM-10           
                                    MM-11           
                                    MM-12           
     END-IF.                                       
                                       
     GOBACK.



Dave
Back to top
View user's profile Send private message
mouli

New User


Joined: 19 May 2005
Posts: 12
Location: kolkata

PostPosted: Thu Apr 13, 2006 1:21 pm
Reply with quote

Hi Dave,

Thank u very much for ur help .... Problem is solved.
I tried in both the ways(by using intrinsic functions and by using the code which u have sent) ..... both are working

Thank u once again to both 'Dave' and 'Martin' for showing intrest in solving the problem.

regards
mouli
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top