Change the date display format.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Maulik
Registered Member
Posts: 16
Joined: Thu Dec 12, 2013 8:28 pm

Change the date display format.

Post by Maulik »

Hi,

In a file I have a date in the format (ccyymmdd) and I need to create another file using this which in the format YYYYMon. Where "mon" is three letter representation of Month in words.

For example: if Input file has: 20130820the output should be 2013AUG. How do I do it? Please help.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Change the date display format.

Post by zprogrammer »

Move the DATE to a structure like below

Code: Select all

01 WS-DATE.
     05 WS-YEAR                      PIC X(04).
     05 WS-MON                       PIC X(02).
     05 WS-DAY                       PIC X(02).

01 WS-DATE2.
     05 WS-YEAR2                     PIC X(04).
     05 WS-MON2                      PIC X(03).


You could use EVALUATE to acheive the following

Code: Select all

EVALUATE WS-MON
                 WHEN "01"      
                           MOVE WS-YEAR TO WS-YEAR2
                           MOVE 'JAN'        TO WS-MON2
                 WHEN "02"      
                           MOVE WS-YEAR TO WS-YEAR2
                           MOVE 'FEB'        TO WS-MON2
                  ..
                 WHEN "12"      
                           MOVE WS-YEAR TO WS-YEAR2
                           MOVE 'DEC'        TO WS-MON2
                 WHEN OTHER      
                           PERFORM ERROR
END-EVALUATE
zprogrammer
Maulik
Registered Member
Posts: 16
Joined: Thu Dec 12, 2013 8:28 pm

Re: Change the date display format.

Post by Maulik »

Thanks Pandora-Box, this helps and I get the code written that way. I'm testing it and let you how I progress.
Maulik
Registered Member
Posts: 16
Joined: Thu Dec 12, 2013 8:28 pm

Re: Change the date display format.

Post by Maulik »

Hi Enrico,

Thanks for the pointer - this is a new project for the team and no one was aware of such a routine. Though now we came to know about a in house date-routine and I think I've two solution for this problem now... :)

This is a great help. Thanks for your time.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”