View Full Version : Reading multiple records by key
01-01-1995, 02:00 AM
I would like to post this question and start some discussion on everyone's view of the best way to accomplish the following: I have file A that is a "header" file (contains invoice header). I have file B that is a "detail" file (contains invoice line items). The key on file B is Invoice Number and Sequence Number When I read a record from file A, I then need to get all the detail records. This is the way I typically do it: I define a key list for file B as INVCNBR and SEQNBR. Then I set the INVCNBR and set the SEQNBR to *LOVAL. Then I perform a SETLL followed by a READ. Then I start a loop while the indicator from the READ is *OFF. Inside the loop I then check to see if the INVCNBR has gone out of key sequence, in which case I can drop out of the loop. If not, I process the record, perform a read and loop to the top. What are thoughts of doing a READE instead, or can you define a key list on just partial fields in the file's key list? (In this case, I mean defining a key list on just INVCNBR and performing a READE in my loop so I don't have to keep checking to see if the INVCNBR is different than the header file's INVCNBR field.) Any thoughts everyone? ==Scott==
05-09-2000, 01:36 PM
I think doing a SETLL and a READE would be the easist and you don't even need to create a KLIST, just use the invoice number field from the header file. When the key is no longer equal your DO loop should kick you out to the next C spec following your ENDDO.
05-09-2000, 03:08 PM
If you cannot use RPG record matching, you probably should consider a join logical file to select the information you need. This gets the finagling into DB2 and out of the RPG thing, which is always a good thing.
05-09-2000, 05:38 PM
Scott Cargill wrote: can you define a key list on just partial fields in the file's key list? Yes! Define another key list with only partial fields. Dave
05-09-2000, 06:32 PM
<font color=blue>...you probably should consider a join logical file to select the information you need...</font> Good idea! I never thought of a logical file. I'll try that! Thanks everyone for all the good responses. I also like the idea of being able to define a key list on just some of the file's key fields. I notice the compiler didn't mind, but was worried that something would go wrong later on... Thanks again... ==Scott==
05-10-2000, 03:10 AM
Hello David, I too could not find an appropriate API. The only way that comes to my mind at the moment to retrieve this information is the cumbersome procedure to do a DSPJOB JOB(999999/YYYYYYYYYY/XXXXXXXXXX) OUTPUT(*PRINT) OPTION(*JOBLOG) (where 999999 is your jobnumber, YYYYYYYYYY your user and XXXXXXXXXX your jobname). Then copy the resulting SPLF to a PF etc. etc. etc. The desired information starts in row 6, column 58. But you can not be sure that this will still be true tomorow ... Not a very straightforward way as I have to admit. Best Regards Bernd
05-10-2000, 03:18 AM
Hi David, You should be able to retrieve the initial request using the QMHRTVRQ (Retrieve Request Message) API. Please let me know if you need an RPG/IV example. Best regards, Carsten Flensburg
05-10-2000, 06:22 AM
You could also add a Validity Checking Program to the SBMJOB command with the CHGCMD command. The command string is passed to the program specified on the VLDCKR parameter. HTH
05-10-2000, 07:54 AM
Scott, I refrain from using join logicals because of the key overhead. I know it's not much, but I try to avoid it when possible. I prefer: c inv# setll invdetail c readc invdetail c dow not %eof(invdetail) c put your favourite process here c readc invdetail c enddo Using the DOW only performs the logic if the criteria is met, whereas the DOU will perform at least once (even if the keys don't match). This is a simple built in function of RPG and does not require any system overhead in key reference when records are added to one of the joined files. Hope this helps, Bret Myrick
05-10-2000, 08:01 AM
Carsten, Unfortunately The Retrieve Request Message (QMHRTVRQ) API retrieves request messages from the current job's job message queue. Alan, The validity checking program is probably too intrusive. As the requirement is to install the software on systems we dont own. We have a component of our solution that presents a single console image for a hetorgenous networked environment. Ideally we want to be able to display the CMD set by the SBMJOB for all AS/400 jobs. Thanks David
05-10-2000, 12:54 PM
Bret, <font color=blue> c readc invdetail </font> READC?
05-10-2000, 08:12 PM
Whoops! Been a long week of desinging new subfile programs with multiple windows, message files and updates. That should have been: c reade invdetail Sorry for the snafu, :(
05-12-2000, 06:51 AM
Hello David, Look at MC 99/03. Download the code http://www.midrangecomputing.com/ftp/prog/99/990303.txt it ,ay be help
05-12-2000, 08:59 AM
David, If I understand you correctly, you would like to store the request/command to be executed in the submitted job. If so, I developed a small system that used a routing entry program in the subsystem. The routing program would retrieve the request message from the message queue, and write it to a data file including the job details, time started etc, When the routing step ended the file would be updated showing duration, etc. These is also an exit point for jobs (QIBM_QWT_JOBNOTIFY NTFY0100) that you might want to look into. HTH Paul.
05-14-2000, 09:49 PM
<font color blue>These is also an exit point for jobs (QIBM_QWT_JOBNOTIFY NTFY0100) that you might want to look into. </font Paul Thanks for the suggestion the exit point doesnt contain sufficient information. The article from Midrange Computing (posted by Vadim) looks interesting and I'll investigate further. David</font>
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.