Microsoft KB Archive/36810

Three Ways to Format and Display System Date in COBOL 3.0

PSS ID Number: Q36810 Article last modified on 04-20-1993

3.00 | 3.00 MS-DOS | OS/2

Summary: Formatting of the system date can be handled in three ways by COBOL Version 3.0: 1. Move CURRENT-DATE to an eight-character field. 2. Break down system date and move the pieces out to reordered fields that are deliminated by fields containing a literal (i.e. ‘/’). 3. Redefine the date field accepted from the system as Alphanumeric, reorder it as needed and move it to an alphanumeric edited field.

More Information: The Cobol Version 3.0 special registers are listed on Page 2-15 of the “Microsoft COBOL Compiler Version 3.0: Language Reference Manual.” The CURRENT-DATE special register is an eight-character field formatted as follows: MM/DD/YY To use the CURRENT-DATE, move CURRENT-DATE to an eight-character field. Because CURRENT-DATE is a special register, it is not defined by the program. The ACCEPT ws-program-defined-date FROM DATE receives the date as a six digit numeric field in yymmdd format. The stroke character (i.e., ‘/’) is an alphanumeric editing character, not a numeric editing character. In the output to the code example below it is shown that if you move the numeric date field to the numeric edited field 99/99/99, the stroke characters are written over. To use the stroke character you have to either break down the date into subfields with a subfield deliminating them filled with the stroke value, or redefine the numeric field as alphanumeric then move the redefined field to an alphanumeric edited field with a PIC XX/XX/XX. The following is a code example: Here is the contents of the OUTPUT.DAT text file created by the program further below: from system pic 99/99/99 current-date broken down character edited 881005 100588 10/05/88 10/05/88 88/10/05 The COBOL Version 3.0 program is as follows:

$set vsc2 $set osvs Identification division. Environment division. Special-names. console is CRT. Input-output section. File-control. SELECT output-file assign to EXTERNAL DISK organization is LINE SEQUENTIAL ACCESS MODE IS sequential. Data Division. File section. FD output-file value of file-id is &quot;output.dat&quot; data record is output-rec. 01 output-rec              pic x(72). working-storage section. 01 dl-output-rec. 05 filler       pic x(3) value spaces. 05 dl-date-from-system      pic 9(6). 05 filler       pic x(8) value spaces. 05 dl-mm-dd-yy-ed          pic 99/99/99. 05 filler       pic x(4)  value spaces. 05 dl-current-date         pic x(8). 05 filler       pic x(4) value spaces. 05 dl-date-broken-down. 10 dl-mm-broken-down     pic 99. 10 filler     pic x value '/'. 10 dl-dd-broken-down     pic 99. 10 filler     pic x value '/'. 10 dl-yy-broken-down     pic 99. 05 filler       pic x(4) value spaces. 05 dl-char-date         pic xx/xx/xx. 01 hd-heading-line. 05 filler       pic x(12)   value 'from system'. 05 filler       pic x(15) value 'pic 99/99/99'. 05 filler       pic x(13) value 'current-date'. 05 filler       pic x(12) value &quot;broken down&quot;. 05 filler       pic x(15) value 'charater edited'. 01 ws-yy-mm-dd-sys. 05 ws-yy-sys    pic 9(2). 05 ws-mm-sys    pic 9(2). 05 ws-dd-sys    pic 9(2). 01 ws-char-date  redefines ws-yy-mm-dd-sys pic x(8). 01 ws-mm-dd-sys. 05 ws-mm        pic 99. 05 ws-dd        pic 99. 05 ws-yy        pic 99. 01 ws-mm-dd-yy-ed    pic 99/99/99. 78 clear-screen value x&quot;e4&quot;. Screen section. 01 screen-date line 10 column 30 using ws-mm-dd-sys pic 99/99/99. procedure division. Main-line. open output output-file. accept ws-yy-mm-dd-sys from DATE. move ws-yy-mm-dd-sys to dl-date-from-system. move current-date to dl-current-date. move ws-dd-sys to dl-dd-broken-down ws-dd. move ws-mm-sys to dl-mm-broken-down ws-mm. move ws-yy-sys to dl-yy-broken-down ws-yy. move ws-mm-dd-sys to dl-mm-dd-yy-ed. move ws-char-date to dl-char-date. write output-rec from hd-heading-line. write output-rec from dl-output-rec. close output-file. stop run. Additional reference words: 3.00 Copyright Microsoft Corporation 1993.