TechTalk: Taking OPNQRYF to the %MAX

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The Open Query File (OPNQRYF) command allows you to summarize groups of records by specifying one or more fields in the GRPFLD parameter. Using this technique, you can create one query record for each group of records. Normally, you can only include fields other than the ones you're grouping by in the query record if they are summarized with the %SUM function. However, by using the %MAX function on fields that are not going to be grouped or summarized (e.g., description and date fields), you can include all of the fields in the original record format and actually summarize a database file using its own format.

This method provides a number of benefits:

? Eliminates the usual requirement to create an additional record format.

? Eliminates the need to override to another file.

? Allows the HLL program to view the same file and format.

? Makes the fields not grouped or summed available.

? Provides an alternative to Format Data (FMTDTA) summarizing.

3 and 4 provide an example of this technique. 3 shows the description of the SALESPF file. 4 shows a CL program that uses OPNQRYF to summarize the Sales amount (SALAMT) by the Product number (PRDNO). Note that you must qualify all mapped field names with the file name. That way, you avoid the OPNQRYF error of referencing a field to itself, which in this case is exactly what is being done. Also, be sure that any fields you summarize (in this case SALAMT) are large enough to contain the total value for a group.

Figures 3 and 4 provide an example of this technique. Figure 3 shows the description of the SALESPF file. Figure 4 shows a CL program that uses OPNQRYF to summarize the Sales amount (SALAMT) by the Product number (PRDNO). Note that you must qualify all mapped field names with the file name. That way, you avoid the OPNQRYF error of referencing a field to itself, which in this case is exactly what is being done. Also, be sure that any fields you summarize (in this case SALAMT) are large enough to contain the total value for a group.

? Tom Conover


TechTalk: Taking OPNQRYF to the %MAX

Figure 3: Sales File SALESPF

 A R SALESR TEXT('Sales Record') A PRDNO 12A TEXT('Product Number') A PRDDSC 50A TEXT('Description') A SALAMT 7P 2 TEXT('Sales Amount') A INVYR 4S 0 TEXT('Invoice Year') A INVMM 2S 0 TEXT('Invoice Month') A INVDD 2S 0 TEXT('Invoice Day') 
TechTalk: Taking OPNQRYF to the %MAX

Figure 4: OPNQRYF Summarizing Technique

 PGM OVRDBF FILE(SALESPF) SHARE(*YES) OPNQRYF FILE((SALESPF)) KEYFLD((PRDNO)) + GRPFLD(PRDNO) + MAPFLD((PRDDSC '%MAX(SALESPF/PRDDSC)') + (SALAMT '%SUM(SALESPF/SALAMT)') + (INVYR '%MAX(SALESPF/INVYR)') + (INVMM '%MAX(SALESPF/INVMM)') + (INVDD '%MAX(SALESPF/INVDD)')) CALL PGM(HLLPGM) CLOF OPNID(SALESPF) DLTOVR FILE(SALESPF) ENDPGM 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: