Newsletters Subscriptions Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 31 -- May 7, 2003

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


Sponsored By
INFINIUM USERNET

Infinium UserNet is the user-run organization for professionals who support, manage and rely on Infinium software applications.

Attend the 2003 Infinium UserNet Conference & Expo from June 18-20 in Oak Brook, IL. Technical education, in-depth seminars, user experiences, new product showcase and networking opportunities abound. Register by May 16 for advance discounts.

For the latest information and registration, visit
www.infiniumusernet.org


THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
Infinium UserNet


BACK ISSUES

TABLE OF
CONTENTS

Random Decisions in Java

Free-Format RPG and Date Conversions

Reader Feedback and Insights: Tips We Can All Relate To


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Shannon O'Donnell

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.