Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search 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 -> Mainframe COBOL
Author Message
rajeevdas03
Warnings : 1

New User


Joined: 21 Jan 2006
Posts: 9
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
References
Anuj D.

Global Moderator


Joined: 22 Apr 2006
Posts: 2154
Location: Phoenix, AZ

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: 36
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: 1129
Location: Mumbai - 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 D.

Global Moderator


Joined: 22 Apr 2006
Posts: 2154
Location: Phoenix, AZ

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: 1129
Location: Mumbai - 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: 3505
Location: Brussels once more ...

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: 36
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1