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: 147
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: 147
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: 1679
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: 8036
Location: East Dubuque, Illinois, USA

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: 7315

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: 147
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 LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm
No new posts How to pick only YYMMDD from DATE1P (... atulbaviskar SYNCSORT 7 Wed Mar 22, 2017 11:39 am
No new posts Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm


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