Here’s one of the free format BIFs I can never remember as far as syntax is concerned. Maybe if I keep it here I will be able to find it again :). I copied some of this from http://www.bmeyers.net/faqs/frequently-asked-questions/41-free-format-alternatives-to-time (the Q&A part).
Q. In fixed format RPG IV, I used the TIME operation code to get the current date and time; but TIME is not supported by free format. You mentioned that the %DATE, %TIME, and %TIMESTAMP functions can replace TIME, but I’m not sure how to use them for this purpose.
In my programs, I create a data structure like this:
D DS D Dtime 14 0 D Wdate 8 0 Overlay(Dtime) D Wtime 6 0 Overlay(Dtime:*Next)
I’ve been using TIME to assign a value to Dtime, then I use Wtime and Wdate to assign values to work fields. How can I do this in free format?
A. If you do not specify a value for the %DATE, %TIME, and %TIMESTAMP functions they will return the current date, time, or timestamp. Then, it’s a simple matter to convert that value to a number in your data structure. Here’s one way to do it:
D DS D Dtime 14 0 D Wdate 8 0 Overlay(Dtime) D Wtime 6 0 Overlay(Dtime:*Next) // V5R3: Wtime = %Dec(%Time():*ISO); Wdate = %Dec(%Date():*ISO); // V5R2: Wtime = %Dec(%Char(%Time():*ISO0):6:0); <= This is like TIME into a 6,0 numeric field Wdate = %Dec(%Char(%Date():*ISO0):8:0);
Or, if you make a small change to the data structure:
D DS D Dtime 20 0 D Wdate 8 0 Overlay(Dtime) D Wtime 6 0 Overlay(Dtime:*Next) // V5R3: Dtime = %Dec(%Timestamp()); // V5R2: Dtime = %Dec(%Char(%Timestamp():*ISO0):20:0);
Thanks to bmeyers.net
Here what I just did with it.
AORDERTIME = %dec(%char(%time():*ISO0):6:0); // 0 means no separator
- RPGIV: Cycle or not? In-line code or subroutines? Is anybody still asking this?(myibmi.wordpress.com)
Copyright 2012 WallyDay.com