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
 

 

Date manipulation using COBOL

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

New User


Joined: 21 Jan 2006
Posts: 19
Location: Mumbai

PostPosted: Fri Jul 18, 2008 2:25 pm    Post subject: Date manipulation using COBOL
Reply with quote

Hi,

suppose we have date format like this;

01 ws-date pic x(6).
05 WS-MM PIC x(2).
05 WS-DD PIC x(2).
05 WS-YY PIC x(2).


i want this date in this format,

dd/mm/yy

please tell me how can we do this.
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Jul 18, 2008 2:37 pm    Post subject:
Reply with quote

Hi,

Try some thing like -
Code:
05  DATE-YYMMDD-IN.                                 
    10  DATE-OUT-YY          PIC X(02) VALUE SPACES. 
    10  DATE-OUT-MM          PIC X(02) VALUE SPACES. 
    10  DATE-OUT-DD          PIC X(02) VALUE SPACES. 

05  DATE-YYMMDD-OUT.
    10 WS-RUN-DATE-MM     PIC XX          VALUE SPACES.
    10 FILLER             PIC X           VALUE '/'.   
    10 WS-RUN-DATE-DD     PIC XX          VALUE SPACES.
    10 FILLER             PIC X           VALUE '/'.   
    10 WS-RUN-DATE-YY     PIC XX          VALUE SPACES.

Now, move DATE-YYMMDD-IN to DATE-YYMMDD-OUT. You might use REDEFINES.

Please use some suitable subject title, what does "COBOL" conveys to the reader..forum-name..!!
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Fri Jul 18, 2008 2:50 pm    Post subject: Reply to: COBOL
Reply with quote

Hi Anuj
I think that your code won't work.
This will do what he wants:

01 ws-date pic x(6).
05 WS-MM PIC x(2).
05 WS-DD PIC x(2).
05 WS-YY PIC x(2).

01 ws-date-new pic x(6).
05 WS-DD PIC x(2).
05 FILLER PIC X(1) VALUE '/'.
05 WS-MM PIC x(2).
05 FILLER PIC X(1) VALUE '/'.
05 WS-YY PIC x(2).

MOVE CORRESPONDING ws-date TO ws-date-new.

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

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Fri Jul 18, 2008 2:53 pm    Post subject: Reply to: COBOL
Reply with quote

Rajeev,

Quote:
i want this date in this format,

dd/mm/yy


You can use STRING for your requirement.

The Below code was not tested

Code:
STRING
WS-DD  DELIMITED BY SIZE
           '/' DELIMITED BY SIZE       
           WS-MM DELIMITED BY SIZE
           '/' DELIMITED BY SIZE
           WS-YY DELIMITED BY SIZE
        INTO destination
    END-STRING
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Jul 18, 2008 2:58 pm    Post subject:
Reply with quote

Hi,

I've never used a PIC clause on '01' level..
Code:
01 ws-date pic x(6).


Further, this
Quote:
move DATE-YYMMDD-IN to DATE-YYMMDD-OUT.

from my post is not the part of "code", whatever way you want you can use for MOVing data from one varibale to another; CORRESPONDING or individual varible MOVE.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Fri Jul 18, 2008 3:00 pm    Post subject: Reply to: COBOL
Reply with quote

Antonio,

Quote:
01 ws-date-new pic x(6).


Check your post, you have used a PIC clause on a 01 level variable.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri Jul 18, 2008 3:20 pm    Post subject:
Reply with quote

rajeevdas03

DO NOT .......................

Post the same question twice
Use meaningless titles

You have been warned !!!
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Fri Jul 18, 2008 4:20 pm    Post subject: Re: Reply to: COBOL
Reply with quote

Quote:

Check your post, you have used a PIC clause on a 01 level variable.

Right
I just did a copy-paste, didn't even look at it and, when defining the new structure made the same mistake.
Sorry for that.
Here goes the correction:
Code:

01 ws-date.
  05 WS-MM PIC x(2).
  05 WS-DD PIC x(2).
  05 WS-YY PIC x(2).

01 ws-date-new.
  05 WS-DD PIC x(2).
  05 FILLER PIC X(1) VALUE '/'.
  05 WS-MM PIC x(2).
  05 FILLER PIC X(1) VALUE '/'.
  05 WS-YY PIC x(2).

MOVE CORRESPONDING ws-date TO ws-date-new.


I Think this time it is right.
Regards
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am


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