Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to convert date from one format to other in Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Mon Dec 15, 2008 4:02 pm    Post subject: How to convert date from one format to other in Cobol
Reply with quote

Hi i need to convert date in format (say) 01/01/09 (dd/mm/yy) to
01/Jan/09 using array/table in cobol. If there is any other way to do this that will be additional advantage.
Back to top
View user's profile Send private message

ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Mon Dec 15, 2008 5:30 pm    Post subject:
Reply with quote

There are some nice date services in Language Environment Callable Services.

O.
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Mon Dec 15, 2008 5:34 pm    Post subject: Reply to: How to convert date from one format to other in Co
Reply with quote

actually i dont want to use date function . want to write a code for that
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: Mon Dec 15, 2008 11:30 pm    Post subject:
Reply with quote

Hello,


Quote:
want to write a code for that

Ok. Go for it icon_wink.gif

Quote:
If there is any other way to do this that will be additional advantage
If you clarify this, someone may have a suggestion. It is not clear what you are asking.

To reformat dates, you may need an array or a series of IFs. . .
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Dec 16, 2008 1:39 am    Post subject:
Reply with quote

Hi Rupesh,

Here's a copybook I use for date processing. I have a leap year routine laying around somewhere. If you're interested I'll take a look.

Code:
1     /
      *===============================================================
      *==================    END OF MOMTH TABLE    ===================
      *===============================================================
      *    NOTE: THIS IS A GENERALIZED TABLE TO BE USED FOR DATE     *
      *          MANIPULATION. EACH ENTRY CONTAINS THE NAME OF THE   *
      *          MONTH AND THE NUMBER OF DAYS IN EACH MONTH AND ITS  *
      *          IMMEDIATE NEIGHBORS. THE JAN-PREV-EOM FIELD CON-    *
      *          TAINS THE NUMBER OF DAYS IN THE PREVIOUS DECEMBER.  *
      *          THE DEC-NEXT-EOM FIELD CONTAINS THE NUMBER OF DAYS  *
      *          IN THE NEXT JANUARY.                                *
      *
      *          IN LEAP YEARS THE USER MUST INCREMENT THE FOLLOWING *
      *          FIELDS BY ONE:                                      *
      *                         JAN-NEXT-EOM-VAL                     *
      *                         FEB-EOM-VAL                          *
      *                         MAR-PREV-EOM-VAL                     *
      *===============================================================

       01  END-OF-MONTH-VALUES.
      *========================
           05  JAN-VALUES.
               10  JAN-NAME                PIC X(009) VALUE
               'JANUARY'.
               10  JAN-EOM-VAL             PIC 9(002) VALUE 31.
               10  JAN-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  JAN-NEXT-EOM-VAL        PIC 9(002) VALUE 28.
           05  FEB-VALUES.
               10  FEB-NAME                PIC X(009) VALUE
               'FEBRUARY'.
               10  FEB-EOM-VAL             PIC 9(002) VALUE 28.
               10  FEB-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  FEB-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  MAR-VALUES.
               10  MAR-NAME                PIC X(009) VALUE
               'MARCH'.
               10  MAR-EOM-VAL             PIC 9(002) VALUE 31.
               10  MAR-PREV-EOM-VAL        PIC 9(002) VALUE 28.
               10  MAR-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  APR-VALUES.
               10  APR-NAME                PIC X(009) VALUE
               'APRIL'.
               10  APR-EOM-VAL             PIC 9(002) VALUE 30.
               10  APR-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  APR-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  MAY-VALUES.
               10  MAY-NAME                PIC X(009) VALUE
               'MAY'.
               10  MAY-EOM-VAL             PIC 9(002) VALUE 31.
               10  MAY-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  MAY-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  JUN-VALUES.
               10  JUN-NAME                PIC X(009) VALUE
               'JUNE'.
               10  JUN-EOM-VAL             PIC 9(002) VALUE 30.
               10  JUN-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  JUN-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  JUL-VALUES.
               10  JUL-NAME                PIC X(009) VALUE
               'JULY'.
               10  JUL-EOM-VAL             PIC 9(002) VALUE 31.
               10  JUL-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  JUL-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  AUG-VALUES.
               10  AUG-NAME                PIC X(009) VALUE
               'AUGUST'.
               10  AUG-EOM-VAL             PIC 9(002) VALUE 31.
               10  AUG-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  AUG-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  SEP-VALUES.
               10  SEP-NAME                PIC X(009) VALUE
               'SEPTEMBER'.
               10  SEP-EOM-VAL             PIC 9(002) VALUE 30.
               10  SEP-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  SEP-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  OCT-VALUES.
               10  OCT-NAME                PIC X(009) VALUE
               'OCTOBER'.
               10  OCT-EOM-VAL             PIC 9(002) VALUE 31.
               10  OCT-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  OCT-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  NOV-VALUES.
               10  NOV-NAME                PIC X(009) VALUE
               'NOVEMBER'.
               10  NOV-EOM-VAL             PIC 9(002) VALUE 30.
               10  NOV-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  NOV-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  DEC-VALUES.
               10  DEC-NAME                PIC X(009) VALUE
               'DECEMBER'.
               10  DEC-EOM-VAL             PIC 9(002) VALUE 31.
               10  DEC-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  DEC-NEXT-EOM-VAL        PIC 9(002) VALUE 31.

       01  EOM-TABLE REDEFINES
           END-OF-MONTH-VALUES.
           05  ET-MONTHLY-ENTRY     OCCURS 012  TIMES.
               10  ET-MONTH-NAME           PIC X(009).
               10  ET-EOM                  PIC 9(002).
               10  ET-PREV-EOM             PIC 9(002).
               10  ET-NEXT-EOM             PIC 9(002).
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 16, 2008 1:59 am    Post subject:
Reply with quote

Quote:
To reformat dates, you may need an array or a series of IFs. . .
Dick: I'd probably use EVALUATE to simplify the logic.
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: Tue Dec 16, 2008 4:24 am    Post subject:
Reply with quote

Hi Robert,

Quote:
I'd probably use EVALUATE to simplify the logic.
Yup, but if using a function was not acceptable, i wasn't sure if anything but the simplest instructions should be used. . . icon_confused.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Dec 16, 2008 6:21 am    Post subject:
Reply with quote

I'd use a subscripted MOVE from the copybook using the MM as the subscript.
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: Tue Dec 16, 2008 7:42 am    Post subject: Reply to: How to convert date from one format to other in Co
Reply with quote

Works for me icon_smile.gif

i'm easy. . . icon_cool.gif
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Tue Dec 16, 2008 3:39 pm    Post subject: Reply to: How to convert date from one format to other in Co
Reply with quote

jack i got it .. can you provide me with subroutine for leap year as you have mentioned ..
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Dec 18, 2008 6:17 am    Post subject:
Reply with quote

Hi Rupesh,

The code is listed below. You will probably have to make minor changes to fit your situation.
Code:
           05  WS-BIT-BUCKET              PIC S9(04) COMP-3.
           05  WS-LEAP-YR-IND-4           PIC S9(04) COMP-3.
               88  DIVISIBLE-BY-4                    VALUE +0.
           05  WS-LEAP-YR-IND-100         PIC S9(04) COMP-3.
               88  DIVISIBLE-BY-100                  VALUE +0.
           05  WS-LEAP-YR-IND-400         PIC S9(04) COMP-3.
               88  DIVISIBLE-BY-400                  VALUE +0.
           05  WS-LEAP-YR-SW              PIC  X(01) VALUE 'N'.
               88  ITS-A-LEAP-YR                     VALUE 'Y'.

           05  WS-DATE-8.
               10  WD8-CCYY.
               20  WD8-CC                     PIC 9(02) VALUE 19.
               20  WD8-YY                     PIC 9(02).
               10  WD8-CCYY-NUM REDEFINES
                   WD8-CCYY                             PIC  9(04).
               10  WD8-MM                     PIC 9(02).
               10  WD8-DD                     PIC 9(02).
           05  FILLER      REDEFINES
               WS-DATE-8.
               10  FILLER                               PIC XX.
               10  WS-DATE-6.
               20  WD6-MM                     PIC 9(02).
               20  WD6-DD                     PIC 9(02).
               20  WD6-YY                     PIC 9(02).

               COPY EOMLIST.

      /*****************************************************************
       1000-CALC-LEAP-YR.
      ******************************************************************
      *    THIS ROUTINE WILL:
      *              *>  EXPAND YOUR DATE TO 8 POSITIONS.
      *              *>  DETERMINE IF IT IS A LEAP YEAR.
      *              *>  ADJUST THE EOMLIST TABLE TO REFLECT THE LEAP YEAR.
      ******************************************************************

           MOVE    YOUR DATE            TO  WS-DATE-6
           IF      WD6-YY                <  90
           ADD       +1                 TO  WD8-CC

           DIVIDE  WD8-CCYY-NUM         BY  +4
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-LEAP-YR-IND-4

           DIVIDE  WD8-CCYY-NUM         BY  +100
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-LEAP-YR-IND-100

           DIVIDE  WD8-CCYY-NUM         BY  +400
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-LEAP-YR-IND-400

           EVALUATE TRUE              ALSO  TRUE
           WHEN DIVISIBLE-BY-400      ALSO  ANY
           WHEN DIVISIBLE-BY-4        ALSO  NOT DIVISIBLE-BY-100
                SET ITS-A-LEAP-YR       TO  TRUE
           END-EVALUATE

           IF      ITS-A-LEAP-YR
           ADD          +1              TO  ET-NEXT-EOM(1)
                                            ET-EOM(2)
                                            ET-PREV-EOM(3)
           .
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Wed Dec 24, 2008 3:51 pm    Post subject: Reply to: How to convert date from one format to other in Co
Reply with quote

hi jack,

i ran this code with some modification and its wroking fine.

Regards,
Rupesh
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    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 XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts Convert CLIST to REXX cvnlynn CLIST & REXX 12 Tue Jun 27, 2017 2:06 am
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us