The following example, Figure 79, shows how to retrieve a four-digit year using the ILE bindable API, Get Current Local Time(CEELOCT). This API retrieves the current local time in three formats. The third format is the Gregorian date, the first four characters of which are the year.
The next section, Using Intrinsic Functions or the ACCEPT Statement to Retrieve Current Century, discusses how you can also use several of the intrinsic functions, and the ACCEPT statement to do the same thing.
Figure 79. Example of Retrieving Current Century.
IDENTIFICATION DIVISION. PROGRAM-ID. DATE1. * Example program to get the 4 digit year in ILE COBOL for ISERIES ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-ISERIES OBJECT-COMPUTER. IBM-ISERIES DATA DIVISION. WORKING-STORAGE SECTION. 01 date-vars. 05 lilian pic 9(9) usage binary. 05 lilian-time-stamp usage comp-2. 05 gregorian-date. 10 greg-year pic x(4). 10 greg-month pic x(2). 10 greg-day pic x(2). 10 greg-time pic x(9). 10 filler pic x(6). PROCEDURE DIVISION. TEST-PARA. call procedure "CEELOCT" using lilian lilian-time-stamp gregorian-date. display "date is " gregorian-date. display "year " greg-year. display "month " greg-month. STOP RUN. |
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.