TechTalk: Use %WLDCRD to match the end of a field.

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

The Open Query File (OPNQRYF) command's wild card (%WLDCRD) function is great for selecting records based on the contents of character fields, but sometimes you have to go to extra lengths to make it do what you want. For example, suppose you have an inventory file with item numbers of one to six characters. If you want to select all items that start with 1T, you can use the following OPNQRYF command:

 OPNQRYF FILE((ITEMPF)) + QRYSLT('ITEM = %WLDCRD("1T*")') 

If you want the items that have 1T anywhere in the item number, you would change the QRYSLT parameter to this:

 QRYSLT('ITEM = %WLDCRD("*1T*")') 

or

 QRYSLT('ITEM *CT "1T"') 

What if you want the items whose item numbers end in 1T? You might think this would do it:

 QRYSLT('ITEM = %WLDCRD("*1T")') 

This will work if all item numbers use the full six bytes. But if there are shorter item numbers, such as 4X1T, this query selection expression won't work. To retrieve shorter item numbers is a little messy but not difficult. The trick is to add some blanks to both parts of the expression. The minimum number of blanks is the length of the field minus the number of matching characters in the wild card. In this case, the minimum number of blanks is four, because the item number is six characters long and 1T is two characters long. The safe way to figure out how many characters to add is to just use the length of the field. There is one additional requirement. You have to add an extra "match-all" character (usually an asterisk) to the end of the wild card. The query select parameter looks like this:

 QRYSLT('ITEM *CAT " " = + %WLDCRD("*1T *")') 

This expression will select items such as 1T, 4X1T, and 53351T. To see how it works, consider the case in which ITEM has the value 4X1T. The left side of the expression is 4X1T followed by eight trailing blanks. The characters 4X match the first asterisk in the wild card. The characters 1T and the following six blanks match exactly. The remaining two blanks match the last * in the wild card.

- Ted Holt

TED HOLT

Ted Holt is IT manager of Manufacturing Systems Development for Day-Brite Capri Omega, a manufacturer of lighting fixtures in Tupelo, Mississippi. He has worked in the information processing industry since 1981 and is the author or co-author of seven books. 


MC Press books written by Ted Holt available now on the MC Press Bookstore.

Complete CL: Fifth Edition Complete CL: Fifth Edition
Become a CL guru and fully leverage the abilities of your system.
List Price $79.95

Now On Sale

Complete CL: Sixth Edition Complete CL: Sixth Edition
Now fully updated! Get the master guide to Control Language programming.
List Price $79.95

Now On Sale

IBM i5/iSeries Primer IBM i5/iSeries Primer
Check out the ultimate resource and “must-have” guide for every professional working with the i5/iSeries.
List Price $99.95

Now On Sale

Qshell for iSeries Qshell for iSeries
Check out this Unix-style shell and utilities command interface for OS/400.
List Price $79.95

Now On Sale

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: