+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Reading multiple records by key

  1. #1
    Guest.Visitor Guest

    Default Reading multiple records by key

    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==

  2. #2
    Guest.Visitor Guest

    Default Reading multiple records by key

    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.

  3. #3
    Guest.Visitor Guest

    Default Reading multiple records by key

    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.

  4. #4

    Default Reading multiple records by key

    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

  5. #5
    Guest.Visitor Guest

    Default Reading multiple records by key

    ...you probably should consider a join logical file to select the information you need... 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==

  6. #6
    Guest.Visitor Guest

    Default Reading multiple records by key

    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

  7. #7

    Default Reading multiple records by key

    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

  8. #8
    Guest.Visitor Guest

    Default Reading multiple records by key

    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

  9. #9
    B.Myrick Guest

    Default Reading multiple records by key

    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

  10. #10
    Guest.Visitor Guest

    Default Reading multiple records by key

    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

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 10-01-2007, 06:47 PM
  2. read only reading 1st five records
    By Guest.Visitor in forum General
    Replies: 6
    Last Post: 06-11-2006, 10:37 PM
  3. Reading IFS Directory
    By Guest.Visitor in forum IBM i (OS/400, i5/OS)
    Replies: 0
    Last Post: 08-08-2002, 05:43 AM
  4. Reading a record in 'C'
    By Guest.Visitor in forum Programming
    Replies: 1
    Last Post: 10-05-1999, 02:03 AM
  5. Reading from the IFS
    By Guest.Visitor in forum Programming
    Replies: 0
    Last Post: 01-01-1995, 02:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts