Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 13 -- April 21, 2004

Make a CL Program or Module Retrieve Its Name


Hey, Ted:

As if I didn't have enough to do, I wasted an hour on a wild goose chase. A user contacted me when a program cancelled. The message she received told her that program XYZ had ended abnormally. It took me a while to determine that program ABC had cancelled instead. It turned out that ABC was a clone of XYZ and still included the following, misleading CL command.

SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Program +
              XYZ ended abnormally') MSGTYPE(*ESCAPE)     

I would like to make CL programs determine their own names, so that I can make sure each program reports the correct name in error messages, even when cloned. I have not found a CL command or an API to make a program retrieve its own name. Is this possible?

--Chuck


Yes. The trick is to make a program send a message to itself and retrieve the program name from the message about the sender. The following code works in OPM CL programs, ILE CL programs, and ILE CL modules.

dcl   &MsgKey        *char      4                               
dcl   &PgmName       *char     10                               
dcl   &Sender        *char     80                               
                                                                
sndpgmmsg msg(' ') topgmq(*same) msgtype(*info) keyvar(&msgkey) 
rcvmsg    pgmq(*same) msgtype(*info) sender(&sender) rmv(*yes)     
chgvar    &PgmName   %sst(&Sender 56 10)                        

In the case of CL modules, you should know that this routine returns the name of the program in which this module is bound, not the name of the module. In ILE modules, try the following code to retrieve both program name and module name.

dcl   &MsgKey        *char      4                             
dcl   &PgmName       *char     10                             
dcl   &ModName       *char     10                             
dcl   &Sender        *char    720                             
                                                              
sndpgmmsg msg(' ') topgmq(*same) msgtype(*info) keyvar(&msgkey
rcvmsg    pgmq(*same) msgtype(*info) rmv(*yes) +              
             sender(&sender) senderfmt(*long)                 
chgvar    &PgmName   %sst(&Sender 42 10)                      
chgvar    &ModName   %sst(&Sender 54 10)                      

--Ted

Sponsored By
COMMON

COMMON Spring 2004 IT Education Conference & Expo
San Antonio, Texas
May 2-6, 2004

Conference activities will take place in the Marriott River Walk and the Henry B. Gonzalez Convention Center.

Click here for online registration and hotel reservations.

The conference includes a special focus on Linux Education.

Browse the Online Session Guide for the conference.

View an online video on COMMON conferences and other member benefits.

Download a PDF of the Conference Invitation and the Conference Preview brochure. (Right-click on these links and select "Save Target as" to download.)

First time attending a COMMON conference? You need the First-Timers' Kit --information that will "show you the ropes."

COMMON is the best value in IT education, so don't miss out!
Click and visit www.common.org for details!


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Joel Cochran, Wayne 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
Damon Technologies
COMMON
iTera
Guild Companies


BACK ISSUES

TABLE OF
CONTENTS
Smooth the Java Journey with Struts

Programming with Assertions

Make a CL Program or Module Retrieve Its Name

Admin Alert: When Management Central Server Won't Start

OS/400 Alert: Microsoft Extends the Life of JVM



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