Newsletters   Subscriptions  Forums  Store   Career  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 5, Number 45 -- December 7, 2005

Find the Length of a Character String in CL, Take Two


Hey, Ted:


Just yesterday, I was trying to determine the length of the value of a CL variable, so your tip today using the MSGDTA trick was helpful. I was thinking that IBM had added %TRIM and %LEN to the list of CL built-in functions (BIFs) that exist in recent releases, but I guess I was imagining this. Why hasn't IBM done this, with all the other great enhancements to CL recently? Is there a way to add your own BIFs to CL by creating your own commands?

--Flagler


I have long advocated the creation of commands to extend the CL language, but I find that many programmers have never created a command. So, yes, I think you have a good idea by suggesting the use of commands, even though the commands you create are not true built-in functions.

One reader, Steve, sent in a command he uses to determine the length of character values up to 2000 bytes long. Here's the command definition source code.




/* Command: RTVVARLEN                     */
/* CPP: RTVVARLENC                        */
/* Retrieve the length of a CL variable   */
/* without trailing blanks                */
 CMD     PROMPT('Return the length of a CL var')
 PARM    KWD(STRING) TYPE(*CHAR) LEN(2000) MIN(1) +
           EXPR(*YES) VARY(*YES) CHOICE('String +
           variable') PROMPT('String variable to check')
 PARM    KWD(LEN) TYPE(*DEC) LEN(4) RTNVAL(*YES) +
           MIN(1) PROMPT('Return variable (4,0)')

Steve didn't tell me what he calls his command, so I used the name RTVVARLEN (Retrieve Variable Length). Here's the command to create the command.

CRTCMD CMD(xxx/RTVVARLEN)
       PGM(*LIBL/RTVVARLENC)
       SRCFILE(xxx/QCMDSRC)
       ALLOW(*BPGM *IPGM *BREXX *IREXX)

The command-processing program is short and simple.

/* Retrieve the length of a CL variable */
/* with trailing blanks removed */
PGM        PARM(&STRING &LEN)
DCL        VAR(&STRING) TYPE(*CHAR) LEN(2000)
DCL        VAR(&LEN) TYPE(*DEC) LEN(4 0)
CHGVAR     VAR(&LEN) VALUE(%BIN(&STRING 1 2))

I called the program RTVVARLENC and implemented it as an ILE program compiled to run in the calling program's activation group.

CRTBNDCL PGM(xxx/RTVVARLENC)
         SRCFILE(xxx/QCLSRC)
         SRCMBR(RTVVARLENC)
         DFTACTGRP(*NO)
         ACTGRP(*CALLER)

Last, here's the program I used to test Steve's command. I called it RTVVARLENT.

PGM        PARM(&P1)
DCL        VAR(&P1) TYPE(*CHAR) LEN(32)
DCL        VAR(&LEN) TYPE(*DEC) LEN(4)
RTVVARLEN  STRING(&P1) LEN(&LEN)
DMPCLPGM

I found it returned the correct length of anything I passed to it in the first parameter.

I can't answer the first question, but I am encouraged by the enhancements IBM made to the CL compiler in V5R3 and am hopeful that we will see more and better things in future releases.

--Ted


RELATED STORY

Find the Length of a Character String in CL

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:

Advanced Systems Concepts
WorksRight Software
iTera


Four Hundred Guru

BACK ISSUES

TABLE OF
CONTENTS
Find the Length of a Character String in CL, Take Two

Installing WebSphere Application Server 6.0

Admin Alert: Backing Up i5/OS Partitions to Disk


The Four Hundred
iSeries Application Innovation Program Exceeds IBM's Expectations

Server Sales Skyrocket in Q3--But Can It Last?

Major IT Firms Join to Standardize SOA

As I See It: RAM, ROM, and Rama Rama Ding Dong

Four Hundred Stuff
NetManage Cuts Complexity and Cost of iSeries Product

ACOM To Launch No-Frills Content Management System

Capgemini Finds Tango/04 a Cure for Systems Management Woes

ProData Goes 'On Demand' with DBU

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