|
|||||||
|
|
![]() |
|
|
|
|
||
|
Free-Format RPG and Date Conversions Hey, Ted: I find that the biggest problem with no support for MOVE in free-format RPG is the loss of the ability to easily change one date format to another. The %DATE built-in function lets you convert a numeric or character field to a date data type, but where's the other half to let you convert the date data type to a numeric or character field? --Rich Good question, Rich. Here are two fixed-format calculations to illustrate your dilemma. D DateField s d datfmt(*iso) D USADate s 8s 0 C *USA move USADate DateField C *USA move DateField USADate The first converts a numeric field called USADate to DateField, which is of the Date data type. The second converts in the opposite direction. As you say, converting a numeric or character field to a date field is no problem in free-format RPG because of the %DATE function. DateField = %date(USADate:*USA); To convert a date field to character or numeric is another matter. The following works with V5R2. USADate = %uns(%char(DateField:*USA0)); The %char function converts DateField to character format. The %uns (unsigned) function converts the character field to a number. However, the %uns function won't take a character argument in V5R1, so I asked IBM. They suggested using C's atoll function (which has nothing to do with ring-shaped islands that surround lagoons). The atoll function converts an alpha string data to a long long integer. (Long long variables can have an integer value of between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.)
H bnddir('QC2LE')
D charToNum pr 20i 0 extproc('atoll')
D string * value options(*string)
USADate = charToNum(%char(DateField:*USA0));
So the bottom line is that there's nothing in free-format RPG that's as simple and easy to use as the MOVE op code. Let's hope for something better in V5R3. --Ted
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |