fhg
Volume 8, Number 23 -- June 11, 2008

Seeking Advice on REXX

Published: June 11, 2008

Hey Bruce:

I want to call from CL program a REXX program, where the REXX program returns a calculate of date (yymmdd). Do you have an example you could send me?

Thanks in advance,

--Larry


Larry,

REXX can't directly return a value to CL the way other languages do. You'd have to have your REXX procedure write the data to a file or use the REXX External Data Queue.

To use a file you'd have to first override STDOUT to a file of your choice, then use "SAY" to write the data. In your REXX procedure you could do this:

'OVRDBF FILE(STDOUT) TOFILE(yourlib/yourfile) OVRSCOPE(*JOB)'
SAY value
'DLTOVR FILE(STDOUT) LVL(*JOB)'

Notice that I put the OVRDBF and DLTOVR in quotes. That way REXX treats them as CL commands. The "value" is whatever value you want returned. The layout of the file can be anything you want as REXX treats all files as flat (it doesn't understand "externally described").

To use the REXX External Data Queue you'll need to push the data to the queue in your REXX procedure, then do an API call in your CL to retrieve the data:

In REXX:

PUSH value

In CL, the length of &DATA and value of &LENGTH can be whatever you need (they just need to match):

DCL        VAR(&DATA) +
TYPE(*CHAR) +
LEN(50)   <=========
DCL        VAR(&LENGTH) +       |
TYPE(*INT) +       | The LEN and VALUE must match
LEN(4) +           |
VALUE(50) <=========
DCL        VAR(&RETURNCODE) +
TYPE(*INT) +
LEN(2)

CALL       PGM(QREXQ) +
PARM('P' &DATA &LENGTH 0 &RETURNCODE)

For more information you can check out my article, REXX Can Talk to Other Languages, which describes it in more detail.

--Bruce


Hi Bruce,

I just read your article, but I don't understand the different when using STRREXPRC, QREXX, or QREXQ. Could you tell me what is the correct form or option that I must to use (1, 2 or 3)

If I write the CL:

 PGM                                                    
 DCLF       FILE(SOPTEC400/DEP_QHST)    
 DCL        VAR(&FH) TYPE(*CHAR) LEN(6)                          
 DCL        VAR(&LEN) TYPE(*INT) LEN(6)
 DCL        VAR(&RETC) TYPE(*INT) LEN(2)                                   
 CHGCURLIB  CURLIB(SOPTEC400)                           
 MONMSG CPF0000                                         
 CLRPFM     FILE(*LIBL/DEP_QHST)                        
 DSPOBJD    OBJ(QSYS/QHST*) OBJTYPE(*FILE) +            
    OUTPUT(*OUTFILE) OUTFILE(*LIBL/DEP_QHST)  
PROCCESS: RCVF                                             
 MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(FIN))       
 CHGVAR     VAR(&FEC) VALUE(%SST(&ODOBTX 2 6))          
1-> STRREXPRC  SRCMBR(FECHA) SRCFILE(SOPTEC400/QREXSRC) PARM(&FH)  
2-> CALL       PGM(QREXX) PARM(FECHA     QREXSRC   SOPTEC400 &FH)
3-> CALL       PGM(QREXQ) PARM('P' &FH &LEN 0 &RETC)

In REXX:

parse value date('O') with aņo '/' mes '/' dia
d=dia-7; if length(d)<2 then d=0||d
FH=aņo||mes||d
return


Larry,

I'm guessing that the field FH is the value that you wish to return. With that in mind, here is what you need in your REXX. Before your "return" add the following line:

push FH   <=== This places the value in field FH
                into the External Data Queue

In your CL you should have the following:

DCL        VAR(&FH) TYPE(*CHAR) LEN(6)
DCL        VAR(&LEN) TYPE(*INT) LEN(4) VALUE(6)
DCL        VAR(&RETC) TYPE(*INT) LEN(2)

STRREXPRC  SRCMBR(FECHA) SRCFILE(SOPTEC400/QREXSRC)   <=== 

This executes your REXX:

CALL       PGM(QREXQ) PARM('P' &FH &LEN 0 &RETC)      <===

This retrieves the value that was "pushed" to the External Data Queue.

Notice that I removed the PARM from the STRREXPRC statement. PARMs can only be passed into REXX, not returned. If I understand your REXX procedure properly you are not passing a value in, simply calculating a date value and returning it. Also, I corrected your definition of field &LEN. It needs to be TYPE(*INT) LEN(4) with a VALUE indicating the length of the data being returned (which should match the LEN of field &FH). It is the VALUE that must match the LEN of &FH. This VALUE is passed to QREXQ and tells the program how much data to return.

One more thing, program QREXX is just another way to execute a REXX procedure (like STRREXPRC command does). So, you could replace your STRREXPRC command with a call to QREXX, but since you're using CL, there is no good reason to do that. If you were calling your REXX from RPG or COBOL, then it might make more sense.

Let me know if you have more questions.

--Bruce


Hi Bruce,

It's me again. Your advice worked. I prefer to work in REXX because I have worked 18 years with mainframe (VM and VSE), and my company just changed machines from zSeries for iSeries three years ago. But my co-workers do not know REXX, only CL. Is there some trick for doing the following in CL?

REXX:

l.1='LINEATM';l.2='LINEHSM';l.3='LINELOCAL';l.4='LINEVISA';l.5='LINEMC'
do k=1 to 5
   "VFYCFG CFGOBJ("l.k") CFGTYPE(*LIN) STATUS(*ON)"
end
exit

--Larry


Larry:

There is a way to do this in CL, but it is a bit more cumbersome than the REXX option. Also, it depends on what version of the OS you're at.

CL doesn't support arrays, but you can do something like it. If you're at V5R4 you can use pointers in CL, otherwise you'd need to use %SST.

In V5R4:

PGM

DCL	VAR(&LINES) TYPE(*CHAR) LEN(50) VALUE('LINEATM   LINEHSM   
LINELOCAL LINEVISA  LINEMC    ')   <== Each value is 10 long, 
                                        total 50 chars.
DCL	VAR(&LINEPTR) TYPE(*PTR) ADDRESS(&LINES)
DCL	VAR(&CURLINE) TYPE(*CHAR) STG(*BASED) LEN(10) BASPTR)&LINEPTR)

DCL	VAR(&I) TYPE(*UINT)

DOFOR	VAR(&I) FROM(1) TO(5)

CHGVAR	VAR(&LINEPTR) VALUE(&LINEPTR + ((&I - 1) * 10))

VRYCFG	CFGOBJ(&CURLINE) CFGTYPE(*LIN) STATUS(*ON)

ENDDO

ENDPGM

Before V5R4:

PGM

DCL	VAR(&LINES) TYPE(*CHAR) LEN(50) VALUE('LINEATM   LINEHSM   
LINELOCAL LINEVISA  LINEMC    ')   <== Each value is 10 long, 
                                        total 50 chars.
DCL	VAR(&LINEPOS) TYPE(*DEC) LEN(3 0) VALUE(0)
DCL	VAR(&CURLINE) TYPE(*CHAR) STG(*BASED) LEN(10) BASPTR)&LINEPTR)

DCL	VAR(&I) TYPE(*UINT)

DOFOR	VAR(&I) FROM(1) TO(5)

CHGVAR	VAR(&LINEPOS) VALUE(((&I - 1) * 10) + 1)
CHGVAR	VAR(&CURLINE) VALUE(%SST(&LINES &LINEPOS 10))

VRYCFG	CFGOBJ(&CURLINE) CFGTYPE(*LIN) STATUS(*ON)

ENDDO

ENDPGM

If you're at a release before DOFOR came out, you'll have to modify your logic to increment &I from 1 to 5, otherwise the second example stays the same. (I'll leave that to your co-workers.)

I haven't tested the above code, but it should be pretty close.

--Bruce


RELATED STORY

REXX Can Talk to Other Languages



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
GROUP8 SECURITY

The most effective way to improve security is by making the right business decisions
--not just the right technical decisions.
At the heart is the security equation: security=ƒ(cost, risk). Simply put, security is as much about business decisions (cost) as it is about mitigating risk. Technology alone cannot solve all of your problems.

If you're ready to take a new approach to security, learn more about Group8 and how our approach is designed to put you in control. We'll be your partner throughout the process and beyond, always there to make sure your security is the right fit for you.

Learn more. Call 775.852.8887 today.


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
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.

Sponsored Links

COMMON:  Join us at the Focus 2008 workshop conference, October 5 - 8, in San Francisco, California
Profound Logic Software:  Web-enable in less than a day with Genie
Vision Solutions:  System i Management Tips Blog - Free i5/OS Tips Each Week!


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
The Power Systems M15 and M25 Versus Their Predecessors

Forget About Platforms, Let's Talk About Jobs

Zend Taps System i-PHP Guru, Pushes the i Platform

As I See It: Citizen CEO

Imtech Buys Reseller Real Solutions for U.K. Expansion

The Linux Beacon
How's Red Hat Enterprise Linux 5 Doing?

AMD Finishes Off Quad Cores with Budapest Opterons

Forget About Platforms, Let's Talk About Jobs

As I See It: Citizen CEO

Looks Like Unisys Is Reselling Sun's X4600 Opteron Boxes

Four Hundred Stuff
Bank's Approach to Biometric Authentication a 'Valid' One

Programmer Conveniences Added to BCD's WebSmart ILE

ASNA Brings RPG to .NET Migration Software to Latest Windows IDE

Safestone Re-emerges with New Corporate Identity, i OS Security Tools

NetManage and HiT Software Partner for Structured Data

Big Iron
The Back and Forth of the PSI-IBM Lawsuit

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
June 7, 2008: Volume 10, Number 23

May 31, 2008: Volume 10, Number 22

May 24, 2008: Volume 10, Number 21

May 17, 2008: Volume 10, Number 20

May 10, 2008: Volume 10, Number 19

May 3, 2008: Volume 10, Number 18

The Windows Observer
Microsoft Kicks Off TechEd 2008 with Gates and Previews

Dynamics AX 2009 ERP Suite Comes to Market

U.S. Drags Down Server Sales in Q1, But Weak Dollar Helps

Servers, Storage, Laptops and Weak Dollars Buoy Dell in Q1

Server Branding 101: Big Name, Big Game?

The Unix Guardian
AMD Finishes Off Quad Cores with Budapest Opterons

U.S. Drags Down Server Sales in Q1, But Weak Dollar Helps

Looks Like Unisys Is Reselling Sun's X4600 Opteron Boxes

Themis Partners with Sun to Make Sparc T2 Blade Server

Server Branding 101: Big Name, Big Game?

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Help/Systems
Group8 Security
COMMON


Printer Friendly Version


TABLE OF CONTENTS
Keeping 5250 Alive

Seeking Advice on REXX

Admin Alert: All About the System i Attention Light

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Capture Sort File and Copy to Database File

SNMP Traps on i5OS

Java Messages

Copying recs from a subfile to a file and keeping highlights

Imbedded SQL

CPYFRMSTMF problem





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

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

Privacy Statement