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

Two digit Date format


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Fri May 06, 2016 6:51 pm
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: 184
Location: Coimbatore

PostPosted: Fri May 06, 2016 6:53 pm
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
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Fri May 06, 2016 7:35 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri May 06, 2016 8:18 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat May 07, 2016 2:11 pm
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: 184
Location: Coimbatore

PostPosted: Mon May 09, 2016 10:18 am
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 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 Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
Search our Forums:

Back to Top