Newsletters Subscriptions Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 36 -- May 28, 2003

Returning Qshell Data to OS/400


Hey, Ted:

I have been trying to find a way to return a variable from within a Qshell script back to an OS/400 environment variable in a CL program, with no luck. Making a variable available to a Qshell session is no problem: I use Create Environment Variable (CRTENVVAR), and the value in that variable is now visible in my Qshell script. But when exiting the Qshell script, all external variables return to their original value. Of course, this is what you would expect under normal scoping rules. Is there a way to declare the environment variable in my CL as global?

--Steven


No. It is typical in Unix for a called routine not to be able to modify the arguments (parameters) that are passed to it. It reminds me of OCL procedures on the S/34 and S/36. We could pass arguments to a procedure, but the called procedure couldn't modify them in the caller.

I suggest you stuff the values of variables into permanent objects, such as IFS files, database files, or data areas. There are plenty of ways to place data in IFS and database files from Qshell. Be sure to reference database files in IFS format.

/qsys.lib/mylib.lib/myfile.file/mymbr.mbr

To place data in a data area, you can use Qshell's system utility to execute CL commands. The following code creates a data area called NAME in library MYLIB and loads the value of Qshell variable name into it.

system "CRTDTAARA DTAARA(MYLIB/NAME) TYPE(*CHAR) LEN(48)"

system "CHGDTAARA MYLIB/NAME VALUE('$name')"

If you are at OS/400 V5R2, you can use Qshell's datarea utility. This utility is mentioned, but not explained, in IBM's Qshell manual.

The following command writes the value of the name variable to data area NAME in library MYLIB.

datarea -w /qsys.lib/mylib.lib/name.dtaara  "$name"

The value is placed in the data area beginning in position 1, and the remainder of the data area is cleared.

To write to part of a data area, use the -s option, specifying the beginning and ending positions to be modified, separated by a hyphen (-). The following Qshell command places the value of the name variable in positions 7 through 44 of data area NAME in library MYLIB.

datarea -w    -s 7-44   /qsys.lib/mylib.lib/name.dtaara  "$name"

--Ted


Sponsored By
WORKSRIGHT SOFTWARE

600 Billion

That's how much a recent independent study estimated U.S. businesses spend on dirty data. How much of that 600 billion is spent by your company? Cleanse your dirty ZIP Codes and mailing addresses with our software and save big bucks.

WorksRight Software, Inc.
Phone: 601-856-8337
E-mail: software@worksright.com
Web site: www.worksright.com


THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
WorksRight Software


BACK ISSUES

TABLE OF
CONTENTS

How Dynamic Is OPNQRYF?

Returning Qshell Data to OS/400

Reader Feedback and Insights: DDS Column Headings


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Shannon O'Donnell

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.