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
 

 

Comparing two dates in different formats

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

New User


Joined: 06 Dec 2005
Posts: 3

PostPosted: Fri Dec 23, 2005 9:31 am    Post subject: Comparing two dates in different formats
Reply with quote

Hi, I have this problem I'm new in COBOL programing.

I read a date from a file the date format is:
20050730

and next i read a date from another file and the date format is:
2005-07-30

How i can compared this because the scripts - I cant do that.

or How I can eliminate That scripts and compare without scrips in a COBOL program

thanks for help me
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 9:34 am    Post subject: Re: turn date
Reply with quote

Quote:
How i can compared this because the scripts - I cant do that.


After reading first date format from inpt file you can move it similar sturucture variable like second date format. Then Compare...

Regards,

Priyesh.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Fri Dec 23, 2005 11:19 am    Post subject: Pic clause
Reply with quote

Hi DiegoVanc,
U can move to a picture class which is defined like this

Code:
77 temp-1 pic 9999-99-99.


Hope got it..
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 11:40 am    Post subject: Re: turn date
Reply with quote

khamarutheen,

You can not define PIC Clause of a variable like this.... Can You ?

Regards,

Priyesh.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 12:14 pm    Post subject: Re: turn date
Reply with quote

Fields should be define like this.

Code:
77 VAR PIC 99999999 VALUE 20051223.
01 TEMP.                           
   05 T-YEAR PIC 9999.             
   05 FILLER PIC X VALUE '-'.     
   05 T-MONTH PIC 99.             
   05 FILLER PIC X VALUE '-'.     
   05 T-DATE  PIC 99.             


Procedure Division.

Code:
MOVE VAR(1:4) TO T-YEAR. 
MOVE VAR(5:2) TO T-MONTH.
MOVE VAR(7:2) TO T-DATE. 
DISPLAY 'FINAL' TEMP.


It'll do.

Regards,

Priyesh.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Fri Dec 23, 2005 12:19 pm    Post subject: Pic clause
Reply with quote

Hi priyesh.agrawal,
I m sorry by mistake i had given a wrong info.. my appology for that..

Generally v have the following editing symbols.

Quote:
', B 0 / '


So here is the example for that

Sending Pic Data Receiving Pic Result
Code:
PIC 9(8)           20050730    PIC 9999B99B99      2005B07B30
PIC 9(8)           20050730    PIC 9999,99,99        2005,07,30
PIC 9(8)           20050730    PIC 9999099099       2005007030
PIC 9(8)           20050730    PIC 9999/99/99        2005/07/30



am i right???????
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 12:33 pm    Post subject: Re: turn date
Reply with quote

Quote:
am i right???????


Yes you are. In former case it would not accept "-" like you mentioned because in PIC Clause it'll be treated as MINUS sign, which can be either leftmost or rightmost character in the string.

Regards,

Priyesh.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Dec 28, 2005 7:31 am    Post subject:
Reply with quote

hi Diego,

You can try something like this:
Code:

01 file1-dt       pic x(8). 

01 file2-dt.
    05 yyyy       pic xxxx.
    05 fil        pic x.
    05 mm         pic xx.
    05 fil        pic x.
    05 dd         pic xx.

01 fixed-dt.
    05 yyyy       pic xxxx.
    05 mm         pic xx.
    05 dd         pic xx.

move corr file2-dt to fixed-dt
if file1-dt = fixed-dt
   display 'eureka!!'
else
   display 'oh well, he was wrong'
end-if
Back to top
View user's profile Send private message
Ramya A

Active User


Joined: 26 Jul 2004
Posts: 104

PostPosted: Thu Dec 29, 2005 4:24 am    Post subject: Re: turn date
Reply with quote

Just wondering if this would work...

Code:
VAR1 PIC X(8) value '20050730'
VAR2 PIC X(10) value '2005-07-30'

***To compare***

If VAR1(1:4) = VAR2(1:4) and VAR1(5:2) = VAR2(6:2)
    AND VAR1(7:2) = VAR2(9:2)

Isn't this possible???
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Dec 29, 2005 7:22 am    Post subject:
Reply with quote

Hi Ramya,

Yeah, it'll work but a bit unwieldy.

Here's another approach. Wasn't sure it would work so I tested, and it does.
Code:

05  dt       pic x(010) value '2005-11-22'.
05  dt-re    pic 9999B99B99.
05  dt2      pic 9(008).

move dt-re to dt2
display '>' dt2 '<'
This will display:
Code:
 >20051122<
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 Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts Need help on comparing hexadecimal va... ashok_uddaraju DFSORT/ICETOOL 4 Thu Apr 28, 2016 2:08 am
No new posts Comparing two VB files phani_nittice SYNCSORT 8 Fri Jan 22, 2016 1:19 am
No new posts Comparing timestamp in Synscort l.nethaji SYNCSORT 13 Wed Jan 20, 2016 4:47 pm


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