MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » September 2012

Re: program to read pf in reverse order using cl/400 program



fixed

Using the number of records in the file and the position to keyword is not
a good solution. As everyone should know, the highest relative record
number might not match the total number of records because of deleted
records. You would need to add the number of deleted records to the number
of current records (this may have been mentioned and maybe I missed it so
sorry if that's true).

Open Query File will not work either... because if you specify *ASCEND or
*DESCEND you must specify the field names that it will be ordered by. You
cannot specify *FILE or *NONE as Key Field when using *ASCEND or *DESCEND.
You get this error message when you do...
CPD0072 List item value for parameter KEYFLD required.
Cause . . . . . : A required list item was not specified.
Recovery . . . : Specify the missing list item.

If you must read the file in reverse order in a CL program. I suggest you
go with the SQL insert into the QTEMP table. ORDER BY RRN(tablename) DESC

Or maybe create a RPGLE service program to read the file for you.

In the service program, you would create a procedure to position to end of
file.

CLEAR MYDS;
SETLL *END FILE;
RETURN;

Create another procedure to read previous and load the data into a global
DS for the RPGLE service program.
CLEAR MYDS;
READP FILE MYDS;
RETURN %EOF();

Create more procedures that will return the variables from MYDS that were
read into the DS.

1. Return MYDS.Field1;
2. Return MYDS.Field2;
3. Return MYDS.FIeld3;

Then in your CLLE program you could...

CALLPRC PRC(POSITIONTOENDOFFILE)
CALLPRC PRC(READPREVIOUSRECORD) RTNVAL(&EOF)
DOWHILE (&EOF = '0')
CALLPRC PRC(GETFIELD1VALUE) RTNVAL(&FIELD1)
CALLPRC PRC(GETFIELD2VALUE) RTNVAL(&FIELD2)
CALLPRC PRC(GETFIELD3VALUE) RTNVAL(&FIELD3)
CALLPRC PRC(READPREVIOUSRECORD) RTNVAL(&EOF)
ENDDO

When you compile the CLLE you must compile as a module, then use the CRTPGM
command to bound the CLLE module with the RPGLE service program.

On Mon, Sep 10, 2012 at 4:33 PM, Scott Klement
<midrange-l@xxxxxxxxxxxxxxxx>wrote:

Please post the file that you'd like to see in reverse order.

On 9/10/2012 1:06 PM, Rishi Seth wrote:
could you please send the code for the logic you have explained?

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.







Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot 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 here. If you have questions about this, please contact