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

Date manipulation using COBOL


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

Superior Member


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

PostPosted: Fri Jul 18, 2008 2:37 pm
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
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: 1287
Location: Chennai, India

PostPosted: Fri Jul 18, 2008 2:53 pm
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

Superior Member


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

PostPosted: Fri Jul 18, 2008 2:58 pm
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: 1287
Location: Chennai, India

PostPosted: Fri Jul 18, 2008 3:00 pm
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: 8797
Location: Welsh Wales

PostPosted: Fri Jul 18, 2008 3:20 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top