How would you find this record? RPGLE program

roosterup
roosterup used Ask the Experts™
on
I'm looking for some sample code on how to find the desired record from my DB.

The program will be passed a department code and needs to return the last check# recorded for that dept.  I need the record with the latest date, and then the highest check number.  The DDS for my file:


pfile:

A          R AHREC  
A            AHCHK#         7  0       COLHDG('CLAIM CHECK NUMBER')
A            AHCKDT         8  0       COLHDG('CHECK' 'DATE')      
A            AHDEPT         3  0       COLHDG('DEPARTMENT' 'CODE')

logical file:
A          R AHREC                     PFILE(ACCPAYHS)
 *                                                    
A          K AHDEPT                                  
A          K AHCKDT                                  
A          K AHCHK#        

how would you do this?
                               
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Application Consultant
Commented:
Oke I don't hav an example at home fom an RPGLE program and I don't know all columns but here an example in RPG (in ILE its almost the same):

Copy this tou your source or any editor with a fixed-font to get a clear view on this example
------------------------------------------------------------

FACCPAYL IF  E           K        DISK
   
C           *ENTRY    PLIST
C                     PARM           AHDEPT

C           ACCKEY    KLIST
C                     KFLD           AHDEPT

C           ACCKEY    SETGTMYFILE
C                     READPFILEA                    10     <- Example 1

      Or

C           ACCKEY    SETGTMYFILE
C           ACCKEY    REDPEMYFILE                   20     <- Example 2


--------------------------------------------------------------
( I defined ACCPAYL as your logical)


In Example 1 the index is set after the last record with the same first key-element.
(if there is any it's set after the place where it normaly should be.

The READP will read the previous record (even if the key element is not the same)
Indicator 10 will turn on if begin of file is reached.
you don't want this.

In Example 2 the index is set after the last record (same as example 1)

The REAPE will read the previous record with the same key element.
If there isn't any, indicator 20 will set on like it is a begin of file situation

Theo KouwenhovenApplication Consultant

Commented:
Sorry MYFILE must be ACCPAYL....... ;(

Commented:
and your last line of code isn't REDPE but READPE ! just in case !
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Theo KouwenhovenApplication Consultant

Commented:
Yes Helixir, You are right if this war RPGLE,

But that is what I mentioned before this is an RPG example. And READPE are 6 positions, that i 1 t much to fit in the opperator column.

In RPG it's REDPE.

Regards,

Murphey

Commented:
your logical file is keyed by department, date, check number I suggest to create a different logical  with only the department and checknumber as the keys.
then you can do the setgt and the redpe operations properly.
Theo KouwenhovenApplication Consultant

Commented:
roosterup,

tolitski is right, that will say if you aresure the check-date is allways in sequence, if not use the key as you defined it that was a good start already (and it works great) as long as the dateformat will be YYYYMMDD.

regards,

Murph
Commented:
I may be missing something, but here is a comment:

Make sure your logical is ordered by department, date (in ascending order) then check number (in ascending order)
as I see by your example it is correct for my example below


You pass the department number into your code
Do the following:

factor1:                 opcode         filename

deptnumber          setgt            your logical file structured as above.

Then do this opcode

                              readpe

This will get you the last check on the last date for the department you are looking for.  I may be restating what the other experts have already suggested, but hopefully with this example and the other comments we can get you where you need to be.

HTH,

jjjjjjj
Theo KouwenhovenApplication Consultant

Commented:
Great thinking jjjjjjj,

or REDPE in non ILE, but that was the same I told in my first comment

Commented:
I'm playing the site police!!!

Roosterup,

I would like to suggest that you accept a comment as an answer so we can close this one down.

jjjjjjj   :)

Commented:
One more time.........

Unless another expert sees a flaw in my conclusion, and posts appropriately, I am going to recommend to the administrator to do the following with this question:

1. Review the comments
2. Enter a grade of "A" and either split the points between Murph and I (Murph, you can have the 35 and I'll take the 30) or give me all of the points as I feel my comment nailed the solution.

I'll give this one a day or two for responses before I contact the administrator.

jjjjjjj
Theo KouwenhovenApplication Consultant

Commented:
Wauw jjjjjjj,

You need this points really badly isn't it?????

Commented:
Murph,

Nope....Don't need 'em and if you want 'em all let me know.  I just like to keep our site as clean as possible, and see to it that points are awarded for effort put forth.  We both put forth the same effort, and maybe I restated stuff that you already said in RPGLE version.

I'll leave the final decision to you or the administrator, your shout.

Cheers,

jjjjjjj

Commented:
Murph,

Nope....Don't need 'em and if you want 'em all let me know.  I just like to keep our site as clean as possible, and see to it that points are awarded for effort put forth.  We both put forth the same effort, and maybe I restated stuff that you already said in RPGLE version.

I'll leave the final decision to you or the administrator, your shout.

Cheers,

jjjjjjj

Commented:
Murph,

Nope....Don't need 'em and if you want 'em all let me know.  I just like to keep our site as clean as possible, and see to it that points are awarded for effort put forth.  We both put forth the same effort, and maybe I restated stuff that you already said in RPGLE version.

I'll leave the final decision to you or the administrator, your shout.

Cheers,

jjjjjjj
Theo KouwenhovenApplication Consultant

Commented:
jjjjjjj

This question is less thatn a month old, let roosterup test the solutions we give him, and let him decide who earns the points, isn't that the standard procedure

Author

Commented:
I thought i already gave points on this one?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial