Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Display date in various formats?

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Raje1002

New User


Joined: 21 Feb 2009
Posts: 11
Location: India

PostPosted: Sat Mar 07, 2009 2:14 pm    Post subject: Display date in various formats?
Reply with quote

Hi,

I am accepting the system date as shown below:

ACCEPT WS-DATE FROM DATE.

I am getting in the format DDMMYY.

Now I need to display the date in my file in the following formats.

DD/MM/YYY, DD/MM/YY, MM/DD/YY, MM/DD/YYYY, etc...

How can I achieve this?
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Mar 07, 2009 7:12 pm    Post subject:
Reply with quote

6.2.1.3 DATE, DATE YYYYMMDD, DAY, DAY YYYYDDD, DAY-OF-WEEK, and TIME
5.3.6 DATE FORMAT clause
Can you still edit in the slashes?
Otherwise 6.2.24 MOVE statement.....
Back to top
View user's profile Send private message
nkothako

Active User


Joined: 26 Nov 2008
Posts: 125
Location: chennai

PostPosted: Thu Mar 19, 2009 3:06 pm    Post subject: Display date in various formats?
Reply with quote

Example
Code:
IDENTIFICATION DIVISION.                           
PROGRAM-ID.    FILSTDY.                             
AUTHOR.        INTEL.                             
DATE-WRITTEN.  NOV 08 2006.                         
DATA DIVISION.                                     
WORKING-STORAGE SECTION.                           
01 WS-YY-MM-DD                    PIC 9(6).         
01 WS-YYYY-MM-DD                  PIC 9(8).         
01 WS-JULIAN-DAY                  PIC 9(5).         
01 WS-YYYY-DDD                    PIC 9(7).         
01 WS-DAY-OF-WEEK                 PIC 9(1).         
01 WS-TIME                        PIC 9(8).         
PROCEDURE DIVISION.                                 
MAIN-PARA.                                         
    ACCEPT WS-YY-MM-DD           FROM DATE.         
    ACCEPT WS-YYYY-MM-DD         FROM DATE.         
    ACCEPT WS-JULIAN-DAY         FROM DAY.         
    ACCEPT WS-YYYY-DDD           FROM DAY.         
    ACCEPT WS-DAY-OF-WEEK        FROM DAY-OF-WEEK. 

    ACCEPT WS-TIME               FROM TIME.       
                                                 
    DISPLAY 'WS-YY-MM-DD       ' WS-YY-MM-DD.     
    DISPLAY 'WS-YYYY-MM-DD     ' WS-YYYY-MM-DD.   
    DISPLAY 'WS-JULIAN-DAY     ' WS-JULIAN-DAY.   
    DISPLAY 'WS-YYYY-DDD       ' WS-YYYY-DDD.     
    DISPLAY 'WS-DAY-OF-WEEK    ' WS-DAY-OF-WEEK. 
    DISPLAY 'WS-TIME           ' WS-TIME.         
                                                 
      GOBACK.                                     



Out put :

Code:
WS-YY-MM-DD       090319            
WS-YYYY-MM-DD     00090319    << Why its populating wrong year 0009 instead of 2009
WS-JULIAN-DAY     09078   
WS-YYYY-DDD       0009078     << Why its populating wrong year 0009 instead of 2009
WS-DAY-OF-WEEK    4       
WS-TIME           02244948
   


and also how to use DATE FORMAT clause in the above code

Thanks alot in advance
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Mar 19, 2009 10:12 pm    Post subject:
Reply with quote

Hello,

You have named fields with different lengths, but used the same system field (i.e. DATE, DAY). Why would you believe the ACCEPT would accomodate this?

At the top of the page is a link to "IBM Manuals". Among them are multiple COBOL Language References for current mainframe compilers. Suggest you look in the manual for your version of the compiler and post back here if you fiind something that is not clear.

Post what you find that needs clarification and your question about it. Someone here should be able to clarify.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Mar 19, 2009 10:39 pm    Post subject:
Reply with quote

Quote:
Why its populating wrong year 0009 instead of 2009

DATE has the implicit PICTURE 9(6).
DATE YYYYMMDD has the implicit PICTURE 9(8).
DAY has the implicit PICTURE 9(5).
DAY YYYYDDD has the implicit PICTURE 9(7).

Understand now?
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Thu Mar 19, 2009 11:24 pm    Post subject:
Reply with quote

Also see INTRINSIC-FNCTN ie MOVE FUNCTION ... to ... that may be used in place of ACCEPT. CURRENT-DATE, DATE-OF-INTEGER, DATE-TO-YYYYMMDD, DATEVAL, DAY-OF-INTEGER, DAY-TO-YYYYDDD, INTEGER-OF-DATE, INTEGER-OF-DAY & YEARWINDOW.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Mar 20, 2009 2:59 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

You have named fields with different lengths, but used the same system field (i.e. DATE, DAY). Why would you believe the ACCEPT would accomodate this?
Not to digress too much, but I once worked with a version of Univac COBOL where the system date was stored as MMDDYYDDD. Accepting into a 6-character field would move in the left-most 6 characters, and into a 5-character field would move in the right-most 5 characters. icon_smile.gif
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 20, 2009 3:42 am    Post subject: Reply to: Display date in various formats?
Reply with quote

What version of COBOL do you have?

If it's a minimum of COBOL/370 (early 90's), then FUNCTIONS would be the best choice.

Otherwise, if it's either OS/VS COBOL or VS COBOL II, check with your system's people to determine whether LE (Language Environment) is active in your LPAR.

If it is, then you can use Callable Service routine CEELOCT to obtain the current date, with a Gregorian format of CCYYMMDD followed by Callable Service routine CEEDATE (using the lilian days obtained from CEELOCT) to obtain the current date, with a Julian format of CCYYDDD.

Each ACCEPT will cause a CALL (BALR) to a run-time module (a total of four), whereas, if you use Intrinsic FUNCTIONS, then three CALLS would be generated or lastly, if you use Callable Service routine's, then the number of CALLS would only be two.

So, you have several choices to ponder....

Regards,
Back to top
View user's profile Send private message
Raje1002

New User


Joined: 21 Feb 2009
Posts: 11
Location: India

PostPosted: Tue Mar 24, 2009 1:18 pm    Post subject:
Reply with quote

Hei thanks to all for your replies..
Back to top
View user's profile Send private message
Jose Villafranca

New User


Joined: 12 Nov 2008
Posts: 4
Location: Monterrey

PostPosted: Thu Apr 02, 2009 2:41 am    Post subject:
Reply with quote

Code:


IDENTIFICATION DIVISION.                           
PROGRAM-ID.    FILSTDY.                             
AUTHOR.        INTEL.                             
DATE-WRITTEN.  NOV 08 2006.                         
DATA DIVISION.                                     
WORKING-STORAGE SECTION.                           
01 WS-DATE.
   05 YYYY             PIC X(4).
   05 MM               PIC X(2).
   05 DD               PIC X(2).

01 WS-MM-DD-YYYY .   
   05 MM               PIC X(2).
   05 FILLER          PIC X(1) VALUE '/'.
   05 DD               PIC X(2). 
   05 FILLER          PIC X(1) VALUE '/'.
   05 YYYY             PIC X(4). 
   
PROCEDURE DIVISION.                                 
MAIN-PARA.                                         
    ACCEPT WS-DATE FROM DATE YYYYMMDD.         
    MOVE CORRESPONDING WS-DATE TO  WS-MM-DD-YYYY
    DISPLAY 'MM/DD/YYYY:' WS-MM-DD-YYYY
                                                   
      GOBACK. 


And so on...
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Apr 02, 2009 2:57 am    Post subject:
Reply with quote

I usually dislike the CORRESPONDING option of MOVE, but it comes in very handy when manipulating dates as Jose's example shows.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts display the sign only if the value is... useit DFSORT/ICETOOL 3 Wed Oct 04, 2017 5:53 pm
No new posts Compare yesterday's date to the one o... migusd SYNCSORT 11 Fri Sep 22, 2017 11:35 pm
No new posts Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm
No new posts Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts DB2 NULL Values display V S Amarendra Reddy DB2 3 Thu Sep 07, 2017 6:59 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us