View previous topic :: View next topic
|
Author |
Message |
DiegoVanc
New User
Joined: 06 Dec 2005 Posts: 3
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
khamarutheen,
You can not define PIC Clause of a variable like this.... Can You ?
Regards,
Priyesh. |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
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.
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
Ramya A
Active User
Joined: 26 Jul 2004 Posts: 104
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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:
|
|
Back to top |
|
|
|