On 11/2/13 9:02 AM, Paul Raulerson wrote:
I was updating some COBOL programs and realized that I was still
using old COBOL time and date formats -meaning PIC 9(8) and PIC9(6).

Just for the heck of it, I decided to put some date and timestamp
files in a record and see how difficult they are to use. Turns out,
they are a little more difficult to use in COBOL than in RPG. (grin)

Does anyone have some samples or a reply basic tutorial on using
Dates and TimeStamps in COBOL? What is the best way to use them? In
particular, when some of these records are updated, there are date
fields in the record itself, and a LAST_CHG_TS field.

I have gotten spoiled with RPG, especially the duration SUBDUR
opcode. I am sure I have done this before in ILE COBOL, but honestly,
I have forgotten how.

Anyone willing to share examples of or a basic tutorial for ILE COBOL
using date and timestamp fields?

First issue I recall in my first attempt to use a COPY DDS-ALL-FORMATS OF DATES_FILE was a need to prevent the loss of the database file DATE fields [when compiling CBLLE source], to unnamed FILLER fields IIRC, by compiling with the more desirable conversion options:
CVTOPT(*DATETIME *DATE *TIME *TIMESTAMP)

IIRC those are automatically the defaults for SQLCBLLE sources; i.e. the pre-compiler CRTSQLCBLI [or CRTSQLCBLI] invokes the CRTBNDCBL [or CRTCBLMOD] with those elements specified for the Conversion Options (CVTOPT) parameter.

The following archived message might be helpful as a /basic tutorial/ showing use of current-date, formatting, date components, and Durations:

http://archive.midrange.com/cobol400-l/200001/msg00037.html
Subject: New date handling functions in ILE/COBOL
From: Finucci Domenico <finucci@xxxxxxxxxxxx>
Date: Thu, 27 Jan 2000 15:13:15 +0100


And FWiW:

Additionally some general details about ILE CBL datetime:

IBM i 7.1 Information Center -> Programming -> Programming languages -> COBOL -> ILE COBOL Programmer's Guide -> ILE COBOL Programming Considerations -> Working with Data Items
http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/rzase/sc092540274.htm#wwddt
_i Working with Date-Time Data Types i_
"Items of COBOL class date-time, include date, time, and timestamp items. These items are declared with the FORMAT clause of a data description entry. For example:

01 group-item.
05 date1 FORMAT DATE "%m/%d/@Y".
05 date2 FORMAT DATE.
05 time1 FORMAT TIME SIZE 8 LOCALE german-locale.
05 time2 FORMAT TIME "%H:%M:%S".
05 time3 FORMAT TIME.
05 timestamp1 FORMAT TIMESTAMP.

For items of class date-time the FORMAT clause is used in place of a PICTURE clause. In the example above, after the keyword FORMAT one of the words DATE, TIME, or TIMESTAMP appears. These words identify the category of the date-time item.

Note:
The words DATE and TIME are reserved words; whereas, the word TIMESTAMP is a context-sensitive word.

After the reserved word or context-sensitive word that dictates the category of the date-time item a format literal may appear. A format literal is a non-numeric literal that describes the format of a date or time item.

In the case of data item date1 the %m stands for months, %d for days, and the @Y for year (including a 2-digit century). The % and @ character begin a specifier. ...
..."

Review also, in the expanded /Contents/ of "Intrinsic Functions" at the doc-link below, each doc snippet found when searching the page for each of:
DATE, DAY, DURATION, or YY

IBM i 7.1 Information Center -> Programming -> Programming languages -> COBOL -> ILE COBOL Language Reference -> Procedure Division
http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/rzasb/sc092539888.htm#intfunc
_i Intrinsic Functions i_
"Data processing problems often require the use of values that are not directly accessible in the data storage associated with the object program, but instead must be derived through performing operations on other data. An intrinsic function is a function that performs a mathematical, character, or logical operation, and thereby allows you to make reference to a data item whose value is derived automatically during the execution of the object program.

The functions can be grouped into six categories, based on the type of service performed: mathematical, statistical, date/time, financial, character-handling, and general.

You can reference a function by specifying its name, along with any required arguments, in a Procedure Division statement.

Functions are elementary data items, and return alphanumeric, DBCS, numeric, integer, boolean, or date-time values. Functions cannot serve as receiving operands.
..."


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2021 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.