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

How to convert date from one format to other in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2358
Location: Israel

PostPosted: Mon Dec 15, 2008 5:30 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Dec 15, 2008 11:30 pm
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
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: 8700
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 16, 2008 1:59 am
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

Moderator Emeritus


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

PostPosted: Tue Dec 16, 2008 4:24 am
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
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

Moderator Emeritus


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

PostPosted: Tue Dec 16, 2008 7:42 am
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Date format correction using dfsort DFSORT/ICETOOL 3
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Sorting Date Field DFSORT/ICETOOL 4
Search our Forums:

Back to Top