View previous topic :: View next topic
|
Author |
Message |
GiridharanN
New User
Joined: 12 Apr 2007 Posts: 21 Location: Coimbatore
|
|
|
|
I have 2 date fields Date1 and Date2. They are both in MYY format i.e., a single byte month and 2 byte year. The month values are '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' '-' '&' i.e., Month is alphanumeric and Oct, Nov and Dec are assigned with '0' '-' and '&' respectively.
I have to execute a paragraph if date1>date2.
The only logic that comes to my mind is regenerating 2 byte month from single byte month and assign century to year field. But this requires lot of variables in addition to the input file variables. Also lot of IF is used.
Can you help me in optimising the comparison? |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Whoever designed your input used poor data design.
Using one character for a month indicator is horrible when you have a known set of 12 and they gave a later month a sequence number lower than an earlier month. Only 2 bytes for a year because you can't tell when a century changes from say 2000 to 2100. If you aren't given the century then the best you are doing is guessing. If you have been guarenteed (not your own assumption) that the input years will always fall in the same century.
Code: |
01 ws-input-date1
05 ws-date1-m pic x.
88 Dec1 value '&'.
88 Nov1 value '-'.
88 the rest of the months
05 ws-date1-yy pic 9(2).
01 ws-input-date2
05 ws-date2-m
88 Dec2 value '&'.
88 Nov2 value '-'.
88 the rest of the months
05 ws-date2-yy pic 9(2).
if (ws-date1-yy > ws-date2-yy)
perform needed-paragraph
Else
if (ws-date1-yy = ws-date2-yy) AND (ws-date1-m NOT = ws-date2-m)
if (Dec2 or Nov2 or Oct2) OR (Dec1 or Nov1 or Oct1)
if dec1
perform needed-paragraph
else
*
*
*here is where the messy part is, but I am too tired to write it for you now
*if you are any good, you should be able to come up with some date logic
* here yourself. it is not very easy because of poor data design and you
*don't want to reformat the date to something resonable that you can do
*numeric operations on. But then again it shouldn't be terribly difficult.
*
*
end-if
else
if (ws-date1-m > ws-date2-m)
perform needed-paragraph
end-if
end-if
end-if
end if
|
|
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
I work on a very archaic system where the dates are stored in MMDDYY on all flat and VSAM files, but have full DB2 dates on the tables.
So every program we have that uses any kind of date comparison has to use some sort of date conversion.
We have chosen to use date windowing as a stop-gap measure while the system is slowly converted (one file at a time) to using the CCYY-MM-DD format.
For date comparisons, we convert the dates to CCYYMMDD format. This involves code like this:
Code: |
01 WS-COMPARE-DATE-1.
03 WS-COMP-1-CC PIC 9(02).
03 WS-COMP-1-YY PIC 9(02).
03 WS-COMP-1-MM PIC 9(02).
03 WS-COMP-2-DD PIC 9(02).
01 WS-COMPARE-DATE-2.
03 WS-COMP-2-CC PIC 9(02).
03 WS-COMP-2-YY PIC 9(02).
03 WS-COMP-2-MM PIC 9(02).
03 WS-COMP-2-DD PIC 9(02).
(in the copybook, the DB2 date is broken down by each portion of the date)
MOVE FILE-SHORT-MM TO WS-COMP-1-MM
MOVE FILE-SHORT-DD TO WS-COMP-1-DD
MOVE FILE-SHORT-YY TO WS-COMP-1-YY
IF FILE-SHORT-YY > 50
MOVE 19 TO WS-COMP-1-CC
ELSE
MOVE 20 TO WS-COMP-1-CC
END-IF
(do a similar move for the other date to WS-COMPARE-DATE-2 fields)
IF WS-COMPARE-DATE-1 < WS-COMPARE-DATE-2
do something
ELSE
do something else
END-IF
|
Pathetic, but it works. Thank God we are a government agency and can get away with lousy performance. |
|
Back to top |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
You can also use the date functions.
01 ws-date-area.
05 ws-compare-date-1 pic 9(08) value zeroes.
05 ws-compare-date-2 pic 9(08) value zeroes.
ws-input-date-1 and ws-input-date-2 are your YYMMDD input dates.
they account for the correct century or you can adjust the DATE WINDOW
to allow for years less than 50 years prior or 50 years greater then the
current year.
compute ws-compare-date-1 = FUNCTION DATE-TO-YYYYMMDD
(ws-input-date-1)
compute ws-compare-date-2 = FUNCTION DATE-TO-YYYYMMDD
(ws-input-date-2)
IF ws-compare-date-2 > ws-compare-date-1 |
|
Back to top |
|
|
mohitsaini Warnings : 1 New User
Joined: 15 May 2006 Posts: 92
|
|
|
|
If the date is in DDMMYY format .... then can it be converted to DDMMYYYY format ??
my question is like ... if I get the date 011020 ... would it be converted to 01101920 OR 01102020 ????
Any kind of help in this regard would be really appreciated. |
|
Back to top |
|
|
|