rexx入门教程
转载请注明FROM:hi.baidu/kokwind/
Author: Aven.guo
Update: 13 AUG 2008
Mail:
前言:
REXX是一个很强大的脚本语言,支持目前所有平台,包括移 动设备,当然Mainframe上也不例外,它几乎没有语言的限制,想怎么写就怎么写,阅读之前大家可以参照这篇文章来具体了解下REXX《快速学习REXX》,当然,在昨天初学的时候我也是借助这篇文章来入门的,现在通过下面我写的sample程序来帮助你入门和深入了解一下吧。
功能说明:
从命令行或JCL传递数据集的名字和要检索的字符串,此程序会再指定数据集中检索所有MEMBER的内容,如果有匹配的字符,则打印出MEMBER的名字。
使用方法:
1. TSO COMMANDè EXEC 'DATA SET NAME (REXXNAME)' 'PDSNAME STRING'
2. JCL
-------------------------------------------------------------------------------------
//JOBCARD
// SET PDS=PDS_NAME
// SET ST=STRING
//REXXJCL EXEC PGM=IKJEFT01,
// PARM='%REXXNAME &PDS &ST'
//SYSTSPRT DD SYSOUT=*
//SYSEXEC DD DISP=SHR,DSN=STJI.MJA.SRC.VE025
//SYSTSIN DD DUMMY
//*
--------------------------------------------------------------------------------------
参数说明:
1. ARG来捕捉命令行或JCL传递过来的参数,
2. SAY用来向终端打印出引号中的内容
3. SYSDSN是REXX的关键字,用来验证输入的数据集是否存在于当前的系统中
4. LISTDS是TSO命令,用来显示数据集的属性。对于VSAM和非VSAM 类型的数据集,该命令显示内 容有所不同。对非VSAM 类型的数据集,该命令可显示数据集所在的磁盘卷号、
记录长度、
记录块大小、记录格式、组织形式以及安全方面的属性等等信息。后跟MEMBERS参数会列出此数据集下所有MEMBER的名字
5. OUTTRAP捕捉LISTDS列出的信息,并放到TRAP.数组里。
6. STRIP用来去掉字符串两边的空格
7. ALLOC是TSO命令,用来为运行程序动态分配所需的VSAM,NON-VSAM数据集,也可以动态分配HFS文件。
ALLOC DATASET(‘USER01.INPUT.DATA’) FILE(FILE01) OLD
此例用来定位一个以存在的数据集
ALLOC DATASET(‘USER01.MY.DATA’) DDNAME(SYSLIB) SHR
可分配一个已存在但未编目的数据集。
8. EXECIO是REXX功能,提供从硬盘上读写文件的操作,把上面ALLOC的XXIN里面的内容读到IN.数组中
9. FREE释放掉XXIN的ALLOCATION
10. POS从文件的第一行匹配是否有指定的字符串。
-------------------------------------------------------Program area-------------------------------------------------------
/* REXX */
/* FUCTION: SEARCH A VARIABLE USING GIVEN NAME.
DESIGN: AVEN GUO
UPDATE: AUG 2008
DESCRIPTION: THE PROGRAM WILL SEARCH A GIVEN STRING IN A DATASET
WHICH PICKING UP ARGUMENTS FROM COMMAND LINE AND
VARIABLE NAMES.
SYNTAX: %SEARC 'PDS STRING' */
/* THE ARG INSTRUCTION TELLS REXX TO ACCESS THE COMMAND LINE ARGUMENTS,
AND PDS_NAME AND STRING ARE THE VARIABLES WHERE YOU PLACE THE
ARGUMENTS. */
ARG PDS_NAME STRING
/* HERE IS A CHECK,IF NO HAVE PDS_NAME AND STRING THEN SAY ERROR MSG
THE SAY INSTRUCTION WRITES OUTPUT TO THE SCREEN */
IF PDS_NAME = ' '
THEN DO
SAY 'ERROR. NO ARGUMENT ENTERED.'
SAY ''
EXIT 8
END
IF STRING = ' '
THEN DO
SAY 'ERROR. NO STRING ENTERED.'
SAY ''
EXIT 8
END
/* HERE IS A HELPFUL KEYWORD('SYSDSN') TO VERIFY THAT THE INPUT PDS
PROVIDED IS A VALID DATA SET NAME.IF THE RESULE OF THE SYSDSN TEST
IN NOT EQUAL TO OK,THIS PDS NOT EXISTING,THEN A DO LOOP IS EXECUTED.
*/
IF SYSDSN("'"PDS_NAME"'") <> 'OK'
THEN DO
SAY 'ERROR..' PDS_NAME SYSDSN("'"PDS_NAME"'")
SAY ''
EXIT 8
END
/* OUTTRAP IS A FUCTION OF REXX WHICH IS THE STEM WHERE YOU CAN PLACE
ALL TRAP RECORDS.AND THEN EXCUTE THE LISTDS AS A TSO COMMAND:
THE FIRST PARAMETER TO LISTDS IS THE NAME OF DATA SET TO PROCESS AND
THE SECOND PARAMETER IS THE LITERAL MEMBERS TO TELL LISTDS TO LIST
ALL MEMBERS. */
CALL OUTTRAP "TRAP."
"LISTDS '"||PDS_NAME||"' MEMBERS"
IF RC <> 0 THEN DO
SAY "ERROR: DATA SET DOES NOT EXIST"
EXIT 12
END
CALL OUTTRAP "OFF"
/* OUTTRAP PLACES THE NUMBER OF RECORDS CAPTURED INTO THE .0 STEM VALUE
STEM TRAP.1 WOULD BE THE FIRST REAL RECORD,TRAP.2 THE NEXT,AND SO
FORTH.DO LOOP THAT USES THE VARIABLE 'I',SETTING IT TO 1 TO START
UNTIL IT IS THE SAME AS THE VALUE IN TRAP.0.LOOKS FOR THE STRING
"--MEMBERS--" IN POSITION 1 OF THE TRAPPED RECORD,IF MATCHED THEN
LEAVED THIS LOOP */
字符串截取第几行DO I = 1 TO TRAP.0
IF TRAP.I = "--MEMBERS--" THEN LEAVE
END
/* THE VARIABLE 'I' IS INCREMENTED BECAUSE IT WAS LAST SET WITH THE
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论