• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Editing Numbers in CL

    August 10, 2005 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tango/04 Provides a VISUAL Clue into Server Performance Profound Logic Whips Up ‘Dream Architecture’ for RPG Programmers

    2 thoughts on “Editing Numbers in CL”

    • Richard Bryant says:
      February 15, 2017 at 3:13 pm

      thank you, cl option easy and gets it done.

      Reply
    • Max says:
      July 18, 2018 at 7:16 am

      Your simple solution saved me a lot of time today.
      Much appreciated!

      Reply

    Leave a Reply Cancel reply

Volume 5, Number 31 -- August 10, 2005
THIS ISSUE
SPONSORED BY:

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

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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Positive News From The Kyndryl Mainframe Modernization Report
  • NAViGATE, inPower 2025 On Tap for September 2025
  • Guru: WCA4i And Granite – Because You’ve Got Bigger Things To Build
  • As I See It: Digital Coup
  • IBM i PTF Guide, Volume 27, Number 37
  • AI Is Coming for ERP. How Will IBM i Respond?
  • The Power And Storage Price Wiggling Continues – Again
  • LaserVault Adds Multi-Path Support To ViTL
  • As I See It: Spacing Out
  • IBM i PTF Guide, Volume 27, Numbers 34, 35, And 36

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle