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

Comparing two dates in different formats


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 1448
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 9:34 am
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: 677
Location: NJ

PostPosted: Fri Dec 23, 2005 11:19 am
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: 1448
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 11:40 am
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: 1448
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 12:14 pm
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: 677
Location: NJ

PostPosted: Fri Dec 23, 2005 12:19 pm
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: 1448
Location: Chicago, IL

PostPosted: Fri Dec 23, 2005 12:33 pm
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Amount of days between two dates PL/I & Assembler 8
No new posts Comparing Header and Trailer. DFSORT/ICETOOL 7
No new posts Training on numeric fields data formats SYNCSORT 12
No new posts Dates compare on specific dates using... DFSORT/ICETOOL 2
No new posts Comparing Signed Packed decimal and p... SYNCSORT 2
Search our Forums:

Back to Top