The ACCEPT verb is used to get data from the keyboard, a peripheral device, or certain system variables.
When the first format is used, the ACCEPT inserts the data typed at the keyboard (or coming from the peripheral device), into the receiving data-item.
When the second format is used, the ACCEPT inserts the data obtained from one of the system variables, into the receiving data-item.
Using the ACCEPT to get the system date and time
The second format of the ACCEPT allows the programmer to access the system date and time (i.e.the date and time held in the computer's internal clock). The system variables provided are -
* Day of the year
* Day of the week
The declarations and comments below show the format required for data-items receiving each of the system variables.
01 CurrentDate PIC 9(6).
* CurrentDate is the date in YYMMDD format
01 DayOfYear PIC 9(5).
* DayOfYear is current day in YYDDD format
01 Day0fWeek PIC 9.
* DAY-OF-WEEK is a single digit where 1=Monday
01 CurrentTime PIC 9(8).
* CurrentTime is the time in HHMMSSss format where s = S/100
New formats for the ACCEPT
The problem with ACCEPT ..FROM DATE and ACCEPT..FROM DAY is that since they hold only the year in only two digits, they are subject to the millennium bug. To resolve this problem, these two formats of now take additional (optional) formatting instructions to allow the programmer to specify that the date is to be supplied with a 4 digit year.
The syntax for these new formatting instructions is:
ACCEPT DATE [YYYYMMDD]
ACCEPT DAY [YYYYDDD]
When the new formatting instructions are used, the receiving fields must be defined as;
01 Y2KDate PIC 9(8).
* Y2KDate is the date in YYYYMMDD format
01 Y2KDayOfYear PIC 9(7).
* Y2KDayOfYear is current day in YYYYDDD format
ACCEPT and DISPLAY example program
This example program uses the ACCEPT and DISPLAY to get a student record from the user and display some of its fields. It also demonstrates how the ACCEPT can be used to get the system date and time.
$ SET SOURCEFORMAT"FREE"
AUTHOR. Michael Coughlan.
* Uses the ACCEPT and DISPLAY verbs to accept a student record from the user and display some of the fields. Also shows how
* the ACCEPT may be used to get the system date and time. The YYYYMMDD in "ACCEPT CurrentDate FROM DATE YYYYMMDD."
* is a format command that ensures that the date contains a 4 digit year. If not used, the year supplied by the system
* will only contain two digits which may cause a problem in the year 2000.
02 StudentId PIC 9(7).
03 Surname PIC X(8).
03 Initials PIC XX.
02 CourseCode PIC X(4).
02 Gender PIC X.
02 CurrentYear PIC 9(4).
02 CurrentMonth PIC 99.
02 CurrentDay PIC 99.
02 FILLER PIC 9(4).
02 YearDay PIC 9(3).
* HHMMSSss s = S/100
02 CurrentHour PIC 99.
02 CurrentMinute PIC 99.
02 FILLER PIC 9(4).
DISPLAY "Enter student details using template below".
DISPLAY "Enter - ID,Surname,Initials,CourseCode,Gender"
ACCEPT CurrentDate FROM DATE YYYYMMDD.
ACCEPT DayOfYear FROM DAY YYYYDDD.
ACCEPT CurrentTime FROM TIME.
DISPLAY "Name is ", Initials SPACE Surname.
DISPLAY "Date is " CurrentDay SPACE CurrentMonth
DISPLAY "Today is day " YearDay " of the year".
DISPLAY "The time is " CurrentHour ":" CurrentMinute.
Results of running ACCEPT.CBL
Enter student details using template below
Enter - ID,Surname,Initials,CourseCode,Gender
Name is NS Power
Date is 01 03 1999
Today is day 060 of the year
The time is 14:41
Feasibility Study Structure - Feasibility study is created in order to minimize risk and to ascertain the viability of a project, a thorough study must first be undertaken. As soon as ...