The subject of handling dates is vast enough to consume a multi-day seminar or a reference book. Although I'll be adding some information to this area it not intended to be an exhaustive reference on dates. The purpose of this page is to give BRIEF answers to questions that still linger in your mind after reading the text and hearing the class lecture.
Method 1 (DAY)
You previously had the following line in the procedure division of your program:
ACCEPT DATE-P FROM DAY
DATE-P in this case represents a 5 byte field in your report heading. DAY returned the Julian date from the system and placed it in this DATE-P field. The Julian date is in the form YYDDD where YY is the year and DDD is the days number out of 365. Thus you saw something like 99275 in your report heading line. 99001 would be January 1, 1999, etc.
Method 2 (DATE)
In method 1 as in this method you will use the accept verb. The syntax is as follows:
ACCEPT IDENTIFIER FROM RESERVED WORD
The identifier specifies where the information will be placed. The reserved word (of which their are many) in this case will be DATE. See your text for more reserved words that can be used with accept to return the date in different forms. DATE returns the date in the form YYMMDD. The line in the procedure division would be as follows:
ACCEPT IDENTIFIER FROM DATE
We haven't decided on an identifier yet. We want the date to be in the form MM/DD/YY. This presents two problems. First, the system doesn't return the date in that order. The system returns the year, the month and the day and we want the month, the day and the year. Secondly, we want to add slash marks to improve readability in our heading. How do we solve this problem?
Instead of accepting the DAY to the DATE-P field which is already in the heading, we will accept the DATE into an intermediate field with the year month and day as elementary items, and then move those elementary items into elementary items separated by slash marks in the report heading. Consider the following area we will create in working storage:
**********THIS IS MY DATE STORAGE AREA*******
05 RUN-YEAR PIC 99.
Notice I added a comment to separate and document this area. This is NOT your report heading. This is a separate section of code you drop into a convenient area of working storage. You may want to put it after your flags for instance. I called the group name WS-DATE but you can choose anything that you feel is descriptive and helps self-document the code. With that group name chose we would have a final ACCEPT statement as follows:
ACCEPT WS-DATE FROM DATE
Now when the above line of code runs in your procedure division you will have the year in RUN-YEAR, the month in RUN-MONTH, and the day in RUN-DAY. We still haven't shifted the date elements or inserted the slash marks. We will do this by the arrangement of elementary items in the heading line. Next we modify the heading to include NOT DATE-P but several new elementary items. We have added MM-OUT, DD-OUT, and YY-OUT as well as slashes between them
We finally add three more lines after the ACCEPT so the final code in the procedure division dealing with the date is as follows:
ACCEPT WS-DATE FROM DATE
Our trick was really to accept the date into 3 elementary items instead of one large 6 byte field. Then we were free to move the elements into their respective fields in the report heading line. We simply added a slash character in between the date elements in the output by using a value of "/" instead of spaces.
I have only presented one of many variations you can use to accomplish the task of putting MM/DD/YY in your heading line. Feel free to experiment with other methods. You can also use a subprogram to handle your date and thus move most of the date code out of the main program. This is a preferred method using code similar to ldate.cbl listed under lecture notes on this website.
All pictures and material Copyright © 1998 - 2004, A+ copyright Comptia, CCNA copyright Cisco Systems. This page is optimized for Internet Explorer 6.0 at 800 x 600 resolution For problems or questions regarding this web contact [Webmaster]. Last updated: April 20, 2004.