Many years ago I wrote a simple COBOL program which would print a calendar showing all the dates within a particular year so I could quickly identify on which day of the week each date fell. The printed output looked like the following:-
I later decided to try and code it in Uniface just to see how easy (or difficult) it was. Due to the fact that Uniface contains some very nifty date functions it was surprisingly simple. My COBOL version was more complicated as I had to create my own set of date manipulation routines.
The structure of the CALENDAR form is as follows:-
After a YEAR number has been entered the code which fills the structure with data looks something like this:
entry BUILD_CALENDAR params numeric pi_Year : IN endparams variables date lv_Date numeric lv_Year, lv_Month, lv_Day numeric lv_DayOfWeek endvariables call CREATE_MONTHS ; insert name of each month lv_Date = $date("01/01/%%pi_Year") ; get first day of the year lv_Year = year.dummy setocc "month",1 ; start at month 1 setocc "week",1 ; start at week 1 while (lv_Year = pi_Year) lv_Day = lv_Date[D] ; extract day lv_DayOfWeek = lv_Date[A] ; extract day-of-week week_no.week = lv_Date[W] ; extract week number ; set day number into day-of-week for current week selectcase lv_DayOfWeek case 1 monday.week = lv_Day case 2 tuesday.week = lv_Day case 3 wednesday.week = lv_Day case 4 thursday.week = lv_Day case 5 friday.week = lv_Day case 6 saturday.week = lv_Day case 7 sunday.week = lv_Day endselectcase ; after day 7 increment to following week if (lv_DayOfWeek = 7) creocc "week",-1 lv_Date = lv_Date + 1d ; increment date by 1 day lv_Month = lv_Date[M] ; extract month ; check for change of month if (lv_Month != $curocc(month)) setocc "month",lv_Month ; next month setocc "week",1 ; start at week 1 lv_Year = lv_Date[Y] ; extract year endif endwhile end ; BUILD_CALENDAR
The actual code which I use can be downloaded from here.
Tony Marston
1st June 2002
mailto:tony@tonymarston.net
mailto:TonyMarston@hotmail.com
http://www.tonymarston.net