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
 

 

Two digit Date format

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

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri May 06, 2016 6:51 pm    Post subject: Two digit Date format
Reply with quote

Hi,

Is there any function in cobol to do the following,

Input date : 1/1/2001
output date I need is: 01/01/2001

Currently my code is something like this and I am unable to achieve what I am expecting,

Code:
01 WS-EFF-DATE1.                                           
    05 WS-EFF-MM1             PIC X(02)  VALUE SPACES.     
    05 FILLER                 PIC X(01)  VALUE '/'.       
    05 WS-EFF-DD1             PIC X(02)  VALUE SPACES.     
    05 FILLER                 PIC X(01)  VALUE '/'.       
    05 WS-EFF-YYYY1           PIC X(04)  VALUE SPACES.     



Request your help on this.
Back to top
View user's profile Send private message

abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri May 06, 2016 6:53 pm    Post subject: Query on date format
Reply with quote

subject changed.
Back to top
View user's profile Send private message
boyti ko

New User


Joined: 03 Nov 2014
Posts: 78
Location: Malaysia

PostPosted: Fri May 06, 2016 7:13 pm    Post subject:
Reply with quote

try to search for PIC Z.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Fri May 06, 2016 7:35 pm    Post subject:
Reply with quote

make a use of intrinsic functions,
look for
Code:
VALUE SPACES
vs
Code:
VALUE ZEROES
, look how redefine can be leveraged , look CEECBLDY too.
Quote:
try to search for PIC Z.

how would this add leading 0?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Fri May 06, 2016 8:18 pm    Post subject:
Reply with quote

COBOL does not have anything directly to do what you want, but the code isn't very complicated:
Code:
 77  WS-FIELD1                   PIC X(10) VALUE '1/1/2001'. 
 77  WS-HOLD-VALUE               PIC X(02).                   
 77  WS-HOLD-FIELD               PIC X(10).                   
 77  WS-CHARS                    PIC 9(02).                   
 01  WS-EFF-DATE1.                                           
     05  WS-EFF-MM1              PIC 9(02).                   
     05  FILLER                  PIC X(01)  VALUE '/'.       
     05  WS-EFF-DD1              PIC 9(02).                   
     05  FILLER                  PIC X(01)  VALUE '/'.       
     05  WS-EFF-YYYY1            PIC X(04).                   

...
     INSPECT WS-FIELD1                                           
         TALLYING WS-CHARS FOR CHARACTERS BEFORE INITIAL '/'.     
     IF  WS-CHARS > 0                                             
         MOVE WS-FIELD1 (1 : WS-CHARS)                           
           TO  WS-HOLD-VALUE                                     
         COMPUTE WS-EFF-MM1 = FUNCTION NUMVAL (WS-HOLD-VALUE)     
         MOVE WS-FIELD1 (WS-CHARS + 2 : )                         
           TO  WS-HOLD-FIELD                                     
     END-IF.                                                     
     MOVE ZERO                    TO  WS-CHARS.                   
     INSPECT WS-HOLD-FIELD                                       
         TALLYING WS-CHARS FOR CHARACTERS BEFORE INITIAL '/'.     
     IF  WS-CHARS > 0                                             
         MOVE WS-HOLD-FIELD (1 : WS-CHARS)                       
           TO  WS-HOLD-VALUE                                     
         COMPUTE WS-EFF-DD1 = FUNCTION NUMVAL (WS-HOLD-VALUE)     
         MOVE WS-HOLD-FIELD (WS-CHARS + 2 : )                     
           TO  WS-EFF-YYYY1                                       
     END-IF.                                                     
     DISPLAY WS-FIELD1 ' ' WS-EFF-DATE1.                         
produces output ot
Code:
1/1/2001   01/01/2001 
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7226

PostPosted: Sat May 07, 2016 2:11 pm    Post subject: Reply to: Two digit Date format
Reply with quote

If your data are reliable, it is even simpler:

Code:
       01  SOURCE-FIELD PIC X(30) VALUE "1/1/2016".
       01  RESULT-FIELD.
           05  RF-DD PIC 99.
           05  FILLER PIC X VALUE "/".
           05  RF-MM PIC 99.
           05  FILLER PIC X VALUE "/".
           05  RF-YYYY PIC XXXX.
       ...       
           UNSTRING SOURCE-FIELD DELIMITED BY "/"
               INTO RF-DD RF-MM RF-YYYY


I normally define date-fields as PIC X. Here I have 99 for the DD and MM as I want the leading-zero-fill which is automatically associated with a MOVE to a numeric field (the UNSTRING ends up using the same rules as MOVE).

Note that the YYYY is PIC X because I don't want the properties of a numeric for a MOVE. I want left-justified and right-truncation.

If desperate for some odd reason to use 9s for the YYYY, include an additional value (SPACE) on the DELIMITED BY.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon May 09, 2016 10:18 am    Post subject:
Reply with quote

Thanks Bill and Robert for your kind help.
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 TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm


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