****************************************
      * Program name: uts.cbl
      * This is an example of a web base
      * program that collects time sheet
      * information. 
      *
      * Copyright 2000 Deskware, Inc.
      ****************************************                                                             
      * Define a text file to store the TimeSheet information.
       FD `timesht.txt` RECORD IS 110 BYTES.
      * TimeSheet Record Layout
       1 timesheet_record.
           5 rec_employee_name           PIC X(20).
           5 rec_year                    PIC X(04).
           5 rec_month                   PIC 9(02).
           5 rec_day                     PIC 9(02).
           5 rec_hours                   PIC 9(02).
           5 rec_desc                    PIC X(80).
      * Program Variables
       1 month                           PIC X(12) VALUE `January`.
       1 month_val                       PIC 9(02) VALUE 01.
       1 year                            PIC 9(04) VALUE 2000.
       1 day_var                         PIC 9(02).
       1 employee_name                   PIC X(20) VALUE `Matt`.
      * CGI Variables
       1 update-data.
          5 update_flag                  PIC X     VALUE `N`.
          5 update_hours                 PIC 9(02).
          5 update_desc                  PIC X(80).
          5 update_record_key            PIC 9(05).
      * Weekly Totals
       1 weekly_totals occurs 6 times.
         5 weekly_total pic ZZ9.
       1 grand_total   pic Z,ZZ9.
      * Define an array to hold an employees hours/descriptions for a month
       1 hours_with_descriptions OCCURS 43 TIMES.
          5 hours                     PIC 9(02)    VALUE 0.
          5 description               PIC X(80).
          5 record_key                PIC 9(05)    VALUE 0.
      * Calendar
       1 calendar.
          5 calendar_line1            PIC X(30).
          5 calendar_line2            PIC X(30).
          5 calendar_line3            PIC X(30).
          5 calendar_line4            PIC X(30).
          5 calendar_line5            PIC X(30).
          5 calendar_line6            PIC X(30).
          5 calendar_line7            PIC X(30).
          5 calendar_line8            PIC X(30).
      * Numeric formated calendar
       1 numeric_calendar.
          5 month_year_header            PIC X(30).
          5 days_of_week_header          PIC X(30).
          5 weeks_of_the_month occurs 6 times.
             10 days_of_the_week occurs 7 times.
                20 day pic 9(02).
                20 filler pic x.
      *
       1 misc_variables.
         5 x                             PIC ZZZ9.
         5 y                             PIC 9999.
         5 i                             PIC 99.
         5 temp_str                      PIC x(80).
         5 content_length                PIC 9999  VALUE 0.
         5 eof                           PIC X     VALUE `N`.
         5 counter                       PIC 9(05).
        
       MAIN.
           PERFORM GET_INPUT_FROM_WEB_PAGE.
           PERFORM DISPLAY_DOCUMENT_HEADER.

           IF update_flag = `Y` AND update_record_key > 0 THEN
              PERFORM UPDATE_TIMESHEET_RECORD
           END-IF.

           IF update_flag = `Y` AND update_record_key = 0 THEN
              PERFORM APPEND_TIMESHEET_RECORD
           END-IF.

           PERFORM LOAD_TIMESHEET.
           PERFORM BUILD_CALENDAR.
           PERFORM DISPLAY_CALENDAR.
           PERFORM DISPLAY_TIMESHEET.

           COMPUTE grand_total = weekly_total(1) +
                                 weekly_total(2) +
                                 weekly_total(3) +
                                 weekly_total(4) +
                                 weekly_total(5) +
                                 weekly_total(6).

            DISPLAY `Grand Total: ` & grand_total & ` hours

`. DISPLAY ``. STOP RUN. LOAD_TIMESHEET. OPEN `timesht.txt` FOR READING. MOVE `N` TO eof. MOVE 0 TO counter. READ `timesht.txt` INTO timesheet_record AT END MOVE `Y` TO eof. PERFORM READ_TIMESHEET_RECORD UNTIL eof = `Y`. CLOSE `timesht.txt`. READ_TIMESHEET_RECORD. ADD 1 TO counter. IF rec_employee_name = employee_name AND rec_month = month_val AND rec_year = year THEN MOVE rec_hours TO hours(rec_day) MOVE rec_desc TO description(rec_day) MOVE counter TO record_key(rec_day) END-IF. READ `timesht.txt` INTO timesheet_record AT END MOVE `Y` TO eof. UPDATE_TIMESHEET_RECORD. OPEN `timesht.txt` FOR UPDATING. POSITION `timesht.txt` AT RECORD update_record_key. MOVE employee_name TO rec_employee_name. MOVE month_val TO rec_month. MOVE year TO rec_year. MOVE day_var TO rec_day. MOVE update_hours TO rec_hours. MOVE update_desc TO rec_desc. WRITE timesheet_record TO `timesht.txt`. CLOSE `timesht.txt`. APPEND_TIMESHEET_RECORD. OPEN `timesht.txt` FOR APPENDING. MOVE employee_name TO rec_employee_name. MOVE month_val TO rec_month. MOVE year TO rec_year. MOVE day_var TO rec_day. MOVE update_hours TO rec_hours. MOVE update_desc TO rec_desc. WRITE timesheet_record TO `timesht.txt`. CLOSE `timesht.txt`. GET_INPUT_FROM_WEB_PAGE. GETENV USING `CONTENT_LENGTH` content_length. IF content_length IS GREATER THAN 0 THEN ACCEPT DATA FROM WEBPAGE IF month(1:8) = `January` MOVE 01 TO month_val ELSIF month(1:8) = `February` MOVE 02 TO month_val ELSIF month(1:5) = `March` MOVE 03 TO month_val ELSIF month(1:5) = `April` MOVE 04 TO month_val ELSIF month(1:3) = `May` MOVE 05 TO month_val ELSIF month(1:4) = `June` MOVE 06 TO month_val ELSIF month(1:4) = `July` MOVE 07 TO month_val ELSIF month(1:6) = `August` MOVE 08 TO month_val ELSIF month(1:9) = `September` MOVE 09 TO month_val ELSIF month(1:7) = `October` MOVE 10 TO month_val ELSIF month(1:9) = `Novemeber` MOVE 11 TO month_val ELSIF month(1:8) = `December` MOVE 12 TO month_val END-IF END-IF. DISPLAY_DOCUMENT_HEADER. DISPLAY `Content-type: text/html`. DISPLAY ``. DISPLAY ``. DISPLAY `
`. DISPLAY `Time Sheet Application
`. DISPLAY `
`. DISPLAY `
`. DISPLAY `

`. DISPLAY `
`. DISPLAY `Employee Name: `. DISPLAY ` `. DISPLAY `Month: `. DISPLAY ` `. DISPLAY `Year: `. DISPLAY ` `. DISPLAY ``. DISPLAY `
`. DISPLAY `

`. DISPLAY `
`. BUILD_CALENDAR. GETCALENDAR USING year month_val calendar. MOVE calendar_line3 TO days_of_the_week(1). MOVE calendar_line4 TO days_of_the_week(2). MOVE calendar_line5 TO days_of_the_week(3). MOVE calendar_line6 TO days_of_the_week(4). MOVE calendar_line7 TO days_of_the_week(5). MOVE calendar_line8 TO days_of_the_week(6). DISPLAY_CALENDAR. DISPLAY `
`. DISPLAY ``. DISPLAY ``. DISPLAY `
` & calendar_line1 & `
`. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. DISPLAY ``. PERFORM VARYING x from 1 by 1 until x > 6 DISPLAY `` PERFORM VARYING y from 1 by 1 until y > 7 DISPLAY `` END-PERFORM DISPLAY `` END-PERFORM. DISPLAY `
SMTuWThFS
` & day(x,y) & `
`. DISPLAY `
`. DISPLAY `
`. DISPLAY_TIMESHEET. PERFORM VARYING x from 1 by 1 until x > 6 MOVE 0 to weekly_total(x) DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` PERFORM VARYING y from 1 by 1 until y > 7 DISPLAY `` DISPLAY `` DISPLAY `` IF day(x,y) > ` 0` THEN DISPLAY `` DISPLAY `` DISPLAY `` ADD hours(day(x,y)) TO weekly_total(x) END-IF DISPLAY `` END-PERFORM DISPLAY `
Week ` & x & ` - ` & calendar_line1 DISPLAY `
Day of WeekDateHoursDescription
` IF y = 1 DISPLAY `Sunday` ELSIF y = 2 DISPLAY `Monday` ELSIF y = 3 DISPLAY `Tuesday` ELSIF y = 4 DISPLAY `Wednesday` ELSIF y = 5 DISPLAY `Thrusday` ELSIF y = 6 DISPLAY `Friday` ELSE DISPLAY `Saturday` END-IF DISPLAY `` & day(x,y) & `` DISPLAY `
` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY `` DISPLAY ` ` & `
` & `` & `` & ` ` & `
` DISPLAY `Total: ` & weekly_total(x) & ` hours

` END-PERFORM.