23
Mon, Dec
1 New Articles

TechTip: Struggling with Those DB2 Web Query Functions?

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

Help is available! Learn about the handy Function Assist feature available in the DB2 Web Query Developer Workbench tool.

 

DB2 Web Query is loaded with built-in functions to help you transform your raw DB2 for i data into something more meaningful and useful for use in your reports, graphs, dashboards, and compound documents. Some of these functions have multiple parameters and a limited number of acceptable values, so unless you have been working with the product for some time, it may not be obvious how to implement the correct format, syntax, and values to make them work. Wouldn't it be nice if there was an interface complete with help text and examples to guide you through the process of defining these functions?

 

Well, hot diggity, there actually is! If you have the DB2 Web Query Developer Workbench tool installed on your PC, help is right at your fingertips in the Synonym Editor tool! The Synonym Editor has many nice help-related features, perhaps the most useful of which is a little gem called Function Assist.

 

To use Function Assist, open DB2 Web Query Developer Workbench, find your synonym and open it in the Synonym Editor. An example is shown below.

 

042211CobbFig1

Figure 1: Open the Synonym Editor. (Click images to enlarge.)

 

In order to use DB2 Web Query built-in functions, you must create either a Define or Computed field in your synonym. These are virtual columns that are not actual fields in your database file but can be based on a field from the file (or even another virtual column). While they are similar, there is a difference between a Define and a Computed column: the expression in a define column is executed for every row in the result set returned by the DB2 Web Query report, while a computed column's expression is executed for only each row from the grouped/aggregated result set after the aggregation has been performed. For more information on this, see Tyler Even's TechTip: "Exploit DB2 Web Query's Defined and Computed Fields."

 

For this article, we are going to create a Define column that uses the DATEADD function to calculate the date two weeks before the value of the ORDERDATE field in our database. To do this, click on the Add Define smart icon. As shown in the example below, it looks like a lowercase "f" with a thick blue underscore.

 

042211CobbFig2

Figure 2: Click on the Add Define icon.

 

In the name text box, type the name of your new define field (call it TwoWeeksBeforeOrder), and click on the Functions tab:

 

042211CobbFig3

Figure 3: Enter your define field and click on Functions.

 

You can either try to locate the desired function by expanding the function categories (provided you know which category it falls under) or—an easier way—use the Find icon as shown below.

 

042211CobbFig4

Figure 4: Locate the desired function with the Find icon.

 

Simply type the name of the function (or even the first few letters of it) and click Find Next. If a match is found, that function will be highlighted in the expanded category it is under. This is shown in Figure 5 below.

 

042211CobbFig5 

Figure 5: Your match is highlighted.

 

If you want help on the selected function, select it and click Help from the right-mouse-click context menu. As example is shown below.

 

042211CobbFig6

Figure 6: Right-mouse-click for help.

 

As you can see in Figure 7, this action opens up a new window titled Function References with information about the specific function you selected.

 

042211CobbFig7

Figure 7: Get information about the function you selected.

 

From here, a wealth of information is available about that function, including details about the syntax, valid parameter values, useful tips, and some examples to help guide you. Other functions can be researched by utilizing the Search and Index features in the left pane of this window. You can even build and save a list of Favorite searches!

 

Once you close the Function References window, you will return to the Define Calculator window. Simply double-click on the function to present it in the Function Assist window.

 

Function Assist is an extremely useful interface that will help you decide what values to specify for each of the function's parameters. If the parameter value is limited to a set of values, a drop-down list interface is presented for that parameter. In our example, the first parameter for DATEADD is the date field that you want to increment. If you click on the drop-down list twisty icon as shown in Figure 8, it will display all of the date columns from the synonym. Simply select the one that you want.

 

042211CobbFig8

Figure 8: Function Assist will help you choose values for the function's parameters.

 

The next parameter for DATEADD is the 'component_code'. Again, click on the drop-down twisty to see the valid parameter values. In the bottom pane, more information is displayed about the parameter.

 

042211CobbFig9

Figure 9: A drop-down list shows valid parameter values.

 

In our example, we want to add 14 days (two weeks) to ORDERDATE, so select 'D' for day units.

 

Finally, specify the number of days you want to increment ORDERDATE by. In our example, we specified 14, as shown below.

 

042211CobbFig10

Figure 10: Choose the number of days to increment by.

 

If you wanted to see some examples that use the function, simply click on the Example button, as shown in Figure 11.

 

042211CobbFig11

Figure 11: See examples that use the function.

 

The Example dialog is displayed. This gives you one or two examples, often with some other useful information specific to this function.

 

042211CobbFig12v2

Figure 12: Here's your example, along with other helpful information.

 

Click OK to close this window and return to the Function Assist Window. Once you are satisfied with the parameter values, click OK to return to the Define Calculator window.

 

042211CobbFig13

Figure 13: Return to the Define Calculator menu.

 

As you can see, all of the values specified from Function Assist are plugged into the Define Calculator.

 

You can bring up the Function Assist window directly from the Define Calculator field as well. This is often more efficient than going through the above Search process (particularly if you already know the name of the function you want to use). Simply type the function in the Expression pane (be sure to include both the left and right parenthesis after the function name) and click on the Function Assist button as shown in the example below using the SUBSTR function.

 

042211CobbFig14

Figure 14: Bring up Function Assist from the Define Calculator window.

 

The (hopefully) now-familiar Function Assist dialog window is displayed for the SUBSTR function:

 

042211CobbFig15

Figure 15: Your Function Assist window shows the chosen function.

 

Unfortunately, not all of the Function Assist and help features described above are available in the report development tools (such as Report Assistant and InfoAssist). However, you can use the Developer Workbench Synonym Editor and the techniques described to help you formulate the correct function syntax and values. Once you have them, simply copy/paste the expression into the Define Fields in Report Assistant and InfoAssist. Easy, pleasy, lemon-squeezy! If you currently do not have DB2 Web Query Developer Workbench installed, you can install a free 70-day trial version and take it for a test drive  The trial version can be downloaded here:

http://www.ibm.com/services/forms/preLogin.do?lang=en_US&source=swg-idwq

 

Hopefully, this tip has shown you the wide variety of helpful options that are available to lend you a hand while adding DB2 Web Query functions to your synonyms and reports. If you have other questions on the product or are looking for other tips and techniques, visit IBM's online forum, where you can post your questions to the experts. Just use the Forum link on the IBM DB2 Web Query developerWorks Web site.

 

Once registered, you can post your questions! You can even subscribe to the forum and get email alerts whenever there is a response to your question. Or if you just can't get enough DB2 Web Query information, you can subscribe to all the threads!

as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1, V7, V6R1

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • 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.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • 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: