Newsletters   Subscriptions  Forums  Store   Career  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 5, Number 31 -- August 10, 2005

Editing Numbers in CL


by Cletus the Codeslinger


Think about some of the PC-based software you use. You've never seen the source code. You don't know what interesting and esoteric techniques the programmer(s) used. All you know is what you see, which is how the program performs. You're happy when it works effectively and annoyed (or worse) when it doesn't. In other words, you're an end user.

Now think about the end users that use your code. They have no emotional attachments to your clever use of subfiles. They couldn't care less that you used that obfuscated API that no one else in your shop could figure out. They're not impressed that you didn't use any GOTO's or indicators. They just want your program to make their lives easier.

It is my conviction that the best ways to improve people's lives are often simple ones. Sometimes programs are hard to use, not because the techniques to make the software easy to use were difficult to implement, but because the programmer didn't try to make the software easier to use. Call it a lack of engineering, probably caused by an urgency to begin writing code.

Consider the occasional need to edit numbers in CL programs. Suppose a CL program is to send a message to a user indicating the number of new orders that were entered into the database during a batch run. You might use some code like this:

DCL VAR(&CUSTORDERS) TYPE(*DEC) LEN(10 0) 
DCL VAR(&ALPHANUM) TYPE(*CHAR) LEN(10) 
                                                          
RTVMBRD FILE(ORDERS) NBRCURRCD(&CUSTORDERS) 
CHGVAR VAR(&ALPHANUM) VALUE(&CUSTORDERS) 
                                                          
SNDMSG MSG(&ALPHANUM *BCAT 'orders were added to + 
             the database.') TOUSR(Somebody) 

The user would get a message like this:

0000000420 orders were added to the database.

The message is accurate, but the leading zeros make it less readable than it could be. I have known users to misread a zero that has an embedded dot, thinking it was an eight, and vice versa. How can we give the user a cleaner message, a message less likely to be misinterpreted?

CL has no editing capabilities, but IBM has written three APIs to edit numbers. They yield the same results you get from edit codes and edit words in RPG and DDS. They have lots of parameters, but they are not hard to use and you can read about them at the links given below.


The following solution applies the 1 (one) edit code to the number of orders that were added to the database.

DCL        VAR(&CUSTORDERS) TYPE(*DEC) LEN(10 0)        
DCL        VAR(&ALPHANUM) TYPE(*CHAR) LEN(13)           
                                                        
DCL        VAR(&EDTMASK) TYPE(*CHAR) LEN(256)           
DCL        VAR(&EDTMASKLEN) TYPE(*CHAR) LEN(4)          
DCL        VAR(&RCVVARLEN) TYPE(*CHAR) LEN(4)           
DCL        VAR(&ZROBAL) TYPE(*CHAR) LEN(1)              
DCL        VAR(&EDTCODE) TYPE(*CHAR) LEN(1) VALUE('1')  
DCL        VAR(&CURRENCY) TYPE(*CHAR) LEN(1)            
DCL        VAR(&SRCVARPCSN) TYPE(*CHAR) LEN(4)          
DCL        VAR(&SRCVARDEC) TYPE(*CHAR) LEN(4)           
DCL        VAR(&ERRORDATA) TYPE(*CHAR) LEN(16) +        
             VALUE(X'0000000000000000')                 
                                                        
RTVMBRD    FILE(ORDERS) NBRCURRCD(&CUSTORDERS)          
                                                        
CHGVAR     VAR(%BIN(&SRCVARPCSN)) VALUE(10)             
CHGVAR     VAR(%BIN(&SRCVARDEC)) VALUE(0)               
CALL       PGM(QECCVTEC) PARM(&EDTMASK &EDTMASKLEN +    
             &RCVVARLEN &ZROBAL &EDTCODE &CURRENCY +
             &SRCVARPCSN &SRCVARDEC &ERRORDATA)        
CALL       PGM(QECEDT) PARM(&ALPHANUM &RCVVARLEN +     
             &CUSTORDERS *PACKED &SRCVARPCSN &EDTMASK +
             &EDTMASKLEN &ZROBAL &ERRORDATA)
SNDMSG     MSG(&ALPHANUM *BCAT 'orders were added to +   
             the database.') TOUSR(Somebody)

QECCVTEC creates an editing mask for a field of a certain size that is to be edited with a certain edit code. This task need be done only once for a variable. QECEDT applies the edit mask to the numeric variable. This task could be done repeatedly, within a loop, for instance, as necessary. The message now looks like this:

             420 orders were added to the database.

There are a few blanks on the front of the message, but I do think this is an improvement.

But maybe you don't have time to plow through a lot of API parameters. That's understandable. Let's consider an even simpler solution. The following section of CL source code uses a simple loop to remove leading zeros.

             DCL VAR(&CUSTORDERS) TYPE(*DEC) LEN(10 0) 
             DCL VAR(&ALPHANUM) TYPE(*CHAR) LEN(10) 
             RTVMBRD    FILE(ORDERS) NBRCURRCD(&CUSTORDERS)              
             CHGVAR     VAR(&ALPHANUM) VALUE(&CUSTORDERS)                

 /* remove the leading zeros from &alphanum */                         
 TESTZERO:   IF         COND(%SST(&ALPHANUM 1 1) *EQ '0' *AND +          
                          %SST(&ALPHANUM 2 1) *NE ' ') THEN(DO)          
               CHGVAR     VAR(&ALPHANUM) VALUE(%SST(&ALPHANUM 2 9))  
               GOTO       CMDLBL(TESTZERO)                           
             ENDDO
             SNDMSG     MSG(&ALPHANUM *BCAT 'orders were added to +   
                           the database.') TOUSR(Somebody)

The message looks like this:

420 orders were added to the database.

A simple loop made a big difference in a message someone will look at every day, especially if that someone tends to confuse zeros and eights.

API Information:

QECCVTEC

QECCVTEW

QECEDT

Sponsored By
ADVANCED SYSTEMS CONCEPTS

SEQUEL can be used for virtually ALL data access functions on the iSeries.

A Windows-based user interface makes it easy to design queries and reports.

SEQUEL offers executive dashboards, drill-down data analysis and run-time prompts to deliver important iSeries data to managers and other non-technical users.

E-mail and FTP delivery let you deliver information to remote users and servers.

www.asc-iseries.com


Technical Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.


THIS ISSUE
SPONSORED BY:

T.L. Ashford
Advanced Systems Concepts
Bug Busters Software Engineering


Four Hundred Guru

BACK ISSUES

TABLE OF
CONTENTS
Embedding SQL in RPG IV--Episode I

Editing Numbers in CL

Five Ways to Access IFS Data from a Windows PC without FTP


The Four Hundred
IBM Keeps CGIDEV2 Alive, Considers Open Source

The i5 Shows Linear Scalability on SAP Benchmark

IBM Brings New Workplace Portal to iSeries and zSeries

As I See It: Frame and Reframe

Four Hundred Stuff
Biometrics and SSO Treat Password Disease at Prescription Solutions

Infor Taking an 'Assembler' Approach to ERP Acquisitions

RJS Software Unveils Java-Based Forms Package

Tango/04 Provides a VISUAL Clue into Server Performance

Four Hundred Monitor


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc. (formerly Midrange Server), 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement