简体   繁体   中英

Selection of records in RPGLE program

So there is this RPGLE program that updates/writes records in a PF (say FILE1). The RPGLE program is quite old and huge and it is advisable to not make any changes to this.

Now what I need to do is to make the Program process only certain records in the file. To be more precise, process only those records which are present in another file as well.

For example, consider that the Program updates a file by the name STUDENTS which contains all student records. Imagine that there is another file ASIAN_STUDENTS.

So, the requirement would be to process only those student records which are present in the ASIAN_STUDENTS file as well.

The SQL equivalent (just to give an idea) of this would be:

SELECT * FROM STUDENTS WHERE STUDENT_ID IN (SELECT STUDENT_ID FROM ASIAN_STUDENTS);

How do I do this without having to modify the program? Any suggestions?

Can FILE1 be overridden in some way to show only the matching records prior to execution of the program?

I am hoping that there is some technique using OPNQRYF to achieve this. Kindly advise.

Please see below a code snippet of what I am trying to achieve:

 PGM                                                                   
                 OPNQRYF    FILE((MFGRP00) (MFRSP00)) OPTION(*INP) +      
                              FORMAT(MFGRP00 MFGRP00A) +                  
                              JFLD((MFRSP00/RSMORD MFGRP00/GRMORD *EQ) +  
                              (MFRSP00/RSASST MFGRP00/GRASST *EQ) +       
                              (MFRSP00/RSMRWK MFGRP00/GRMRWK *EQ)) +      
                              OPNSCOPE(*JOB)                              
                 OVRDBF     FILE(MFGRP00) TOFILE(MFGRP00) +               
                              OVRSCOPE(*JOB) SHARE(*YES)                  

      CALL MF125R00                                                       
    ENDPGM 

In the above snippet, MFGRP00 is the file processed by program MF125R00.

There are some errors at the moment related to the processing of MFGRP00 which I am trying to resolve at the moment.

Further to the answer, I had mentioned below, I have learned the hard way that the opnqryf to join the files works fine if we were to simply read the data. But to update the data as well as in the file being opened, this approach would not work as opnqryf does not allow updating a file if joined with another one. So, the only way out would be to modify the RPGLE program to process only those records which meet the selection criteria. (The one thing which I was trying to avoid the whole while). In case somebody knows some sort of technique to achieve this. ie do something like update a join logical file, please do mention here.

Update: Just an update, I have managed to modify the program which processes the records. The program is basically a subfile which presents records to users for modification. So what I had to do was to include an additional condition check just before the write to the subfile happened.

But as the paging up and down is being handled by the program in this case, this is not as clean as it should be.

I found this example in IBM RedBook if you want to use OPNQRYF

OVRDBF FILE(ITEM_JOIN3) TOFILE(ITEM_FACT) +
 OVRSCOPE(*JOB) SHARE(*YES)

OPNQRYF FILE((ITEM_FACT) (CUST_DIM) (TIME_DIM)) +
 FORMAT(ITEM_JOIN3)
 QRYSLT('TIME_DIM/YEAR *EQ 1997') +
 JFLD((ITEM_FACT/CUSTKEY CUST_DIM/CUSTKEY) +
 (ITEM_FACT/SHIPDATE TIME_DIM/DATEKEY)) +
 GRPFLD(CUST_DIM/CUSTOMER) +
 MAPFLD((TOTITEMS '%SUM(QUANTITY)') +
 (TOTREV '%SUM(REVENUE)') +
 (TRANSCOUNT '%COUNT')) +
 OPNSCOPE(*JOB)

CALL PGM(PROC_ROWS)
CLOF OPNID(ITEM_FACT)
DLTOVR FILE(ITEM_JOIN3) LVL(*JOB) 

I think the best way, if you can't modify the program is create a CL, call an RPGLE program that create a filtered file in QTEMP like the main file you read, and then call you program. Remember SQL is more performing than OPNQRYF.

I have arrived at an answer finally.

PGM

             OVRDBF     FILE(MFGRP00) SHARE(*YES) SEQONLY(*NO)       

             OPNQRYF    FILE((MFGRP00) (MFRSP00)) FORMAT(MFGRP00) +  
                          KEYFLD(*FILE) JFLD((MFGRP00/GRMORD +       
                          MFRSP00/RSMORD *EQ) (MFGRP00/GRASST +      
                          MFRSP00/RSASST *EQ) (MFGRP00/GRMRWK +      
                          MFRSP00/RSMRWK *EQ)) JDFTVAL(*NO)          

  CALL MF125R00                                                      
  CLOF MFGRP00            

This seems to be doing exactly what I need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM