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
 

 

Date Comparison in COBOL

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

New User


Joined: 12 Apr 2007
Posts: 21
Location: Coimbatore

PostPosted: Mon Dec 24, 2007 10:28 pm    Post subject: Date Comparison in COBOL
Reply with quote

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
View user's profile Send private message

stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Dec 25, 2007 8:18 am    Post subject:
Reply with quote

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
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 147
Location: Columbia, MO

PostPosted: Wed Dec 26, 2007 9:49 pm    Post subject: Reply to: Date Comparison in COBOL
Reply with quote

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
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Wed Dec 26, 2007 11:56 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mohitsaini
Warnings : 1

New User


Joined: 15 May 2006
Posts: 90

PostPosted: Fri Jan 11, 2008 4:45 pm    Post subject:
Reply with quote

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
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am


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