Home > AS/400 Tips > iSeries administrator tips > New, undocumented Query function can boost your productivity
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

New, undocumented Query function can boost your productivity


Ron Turull
01.31.2005
Rating: -3.60- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



Ron Turull

If the use of Query for iSeries is a part of your daily iSeries chores, then a new function introduced in V5R3 could spell big gains. However, the documentation for the function did not make it into the Query for iSeries Use manual. The new function is Length, and it returns the length of its argument.

The details of Length
The Length function is similar, if not identical, to the Length function in SQL. The function has one parameter, which can be a field name or an expression; the function then returns the length of that field or expression.

The parameter can be of any valid type, character or numeric. Date, time and graphic types are also supported.

In most cases, the result (i.e., the Length's return value) is the buffer length of the field (or the expression if it were in a buffer). Specifically, the possible return values are as follows:

  • Small integer: 2.
  • Large integer: 4.
  • Big integer: 8.
  • Single-precision float: 4.
  • Double-precision float: 8.
  • Packed decimal numbers with a precision of (i.e., total number of digits) p: the integral (i.e., whole number) part of (p/2)+1.
  • Zoned decimal numbers with precision p: p.
  • Fixed-length strings: the length of the string including blanks.
  • Variable-length strings: the length of the actual string (trailing blanks not included).
  • Time: 3.
  • Date: 4.
  • Timestamp: 10.
  • Row ID: 26.

More Information

If the field or expression passed as the parameter supports null values, then the result of the Length function will support null values. Moreover, if the argument is null, then the result will be null.

How can you use the new Length function
Many situations can call for the new Length function. I run into them frequently, especially when doing data transfers to other systems. Electronic data interchange (EDI) systems are a good example. Many EDI systems require that a length attribute precede each field of data. The Length function makes this a simple chore if you prepare data using Query for iSeries.

When using the Length function with packed decimal data, you must take care to avoid mistakes interpreting the results. For example, a 15.2 packed decimal field will have a length of 8 (int(15/2) + 1). A 14.5 packed decimal field also has a length of 8.

When doing data exchanges, packed decimal data is usually not acceptable because most platforms don't support it, so you will be converting it to other data types. For example, floating decimal point data is often acceptable. Sometimes you may just want to convert packed decimal data to character string data. For example, a 9.2 packed decimal field named Amount could be converted to character using the following Query function:

Digits(Amount)

And you could calculate the length of that resulting character string using the new Length function:

Length(Digits(Amount))

-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Oracle on iSeries
IBM steps up iSeries, pSeries overlap
Securing query definitions
Get the system to recognize a date separator
Run multiple SQL statements
Updating the 'VALUE' column using DB2/400
Populate a Lotus Notes database with iSeries data
Inserting data into a table
Is the SQL Path being used?
CHAR fields vs. VARCHAR
Expert advice on DB2

Business-to-business (EDI, UCCnet)
LANSA launches Data Sync Direct 2.5
SMBs meet DoD needs with RFID compliance
2004 Products of the Year: Top business-to-business solutions
Survivor EDI - Accommodating Relentless Change is Key to Keeping EDI Relevant
Vendor - IT Briefing Dynamic web enablement using RPG
Meeting that UCCnet Data Synchronization Mandate: Look Before you Leap!
Document Imaging
Does Your WebSphere Team Get Along? It Can with Enterprise Application Management
Vendor IT Briefing EDI- Has the need outpaced the translators?
UCCnet: One version of the Truth
Business-to-business (EDI, UCCnet) Research

Documentation
Print private authorities (PRTPVTAUT) command for user objects in a library with *public exclude
iSeries i5/OS: Top 10 Q&As
iSeries i5/OS: Top 10 Q&As
New option within the WRKSYSACT command
See the users with *change or *all authority
If at first you don't succeed, read the documentation
Copy a spoolfile (report) into the IFS as a .txt file
Limit command line access
Upgrade from V5R1 to V5R3 and license validation
Set up journals

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
UCCnet  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts