TechTalk: OPNQRYF Mapped Fields

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

From: Tim Johnston To: All

Attention all OPNQRYF gurus:

I have an order entry file which has an item number (LPROD), quantity ordered (LQORD) and selling price (LNET). I want to summarize the information into a file that has month-to-date information. I decided to try to use OPNQRYF and the mapped fields. The summary file looks like:

LPROD (15) MTD (11 2)

What I want to do is multiply the quantity ordered times the selling price, and summarize on that result. The CL compiles when I select the query for the month-to-date and tell it to summarize:

 MAPFLD(('MTD %SUM+ ("LQORD * LNET")')) 

But when I run the program, I get an error message "Operand for %SUM Function not valid."

Can I summarize a mapped field which has a calculation in it or am I going to have to find a way around it?

From: Ted Holt To: Tim Johnston

I think you have quote problems. Try this. I'll assume your data is in file FILEX and the summary file you're using to format the data is called SUMFILE.

 OVRDBF FILE(SUMFILE) + TOFILE(FILEX) SHARE(*YES) OPNQRYF FILE((FILEX)) + FORMAT(SUMFILE) + QRYSLT(whatever) + KEYFLD((LPROD)) + MAPFLD((MTD '%SUM+ (LQORD * LNET)')) + GRPFLD(LPROD) CALL program CLOF FILEX DLTOVR SUMFILE 

This is off the top of my head, so there may be a parenthesis or something out of whack.

From: Tim Johnston To: Ted Holt

You were close. All I needed was double parentheses around the expression:

 MAPFLD((MTD '%SUM+ ((LQORD * LNET))')) 

Makes perfect sense now, doesn't it? OPNQRYF is great, but some of the syntax rules just don't jive!

From: Ted Holt To: Tim Johnston

It wouldn't be so bad if you could catch more of these errors with the syntax checker, but most OPNQRYF errors are run-time errors. But OPNQRYF wouldn't have nearly the power it has if everything were bound at compile-time, rather than at run-time.

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: