You are on page 1of 9

Tutorial: Comparison of CLIST language and REXX

http://theamericanprogrammer.com/programming/rexx.clist.shtml
This will help you to convert CLIST to REXX. Literals. CLIST has no way of designating a literal and no consistent way of indicating that something is a variable. REXX, by contrast, has an excellent way of showing a literal: quotation marks or apostrophes. Variables are easily spotted in REXX's simply formed instructions. Variables. The ampersand (&) is used capriciously in CLISTs along with variables. Sometimes you use it; sometimes you don't. REXX makes it easy for you to show the difference between literals and variables, but forgives most lapses you might make. String manipulation. In order to manipulate strings of characters, you sometimes have to nest the &STR and &SUBSTR functions, which leads to very obscure coding. REXX is the queen of string manipulation. Its PARSE instruction and a multitude of functions make it easy to do anything you want with character data. Mathematics. CLIST does not take mathematics very seriously and should be used only for the simplest of calculations. CLIST may be adequate for calculating JCL SPACE requirements but for little else. REXX can do enough arithmetic to please almost anyone. Those who really like trigonometric functions and fractional exponents will probably forgive REXX for not having them when they see that REXX can do arithmetic to any precision. Control structures. CLIST now has adequate control structures, but one still finds many confusing programs that date back to the time when CLIST's control structures were poor. I feel sorrow and pity for the archaeologists in the twenty-third century who will spend innumerable days and nights poring over ancient CLISTs trying to fathom their meaning. Control structures and REXX grew up together. REXX fulfills every programmer's dreams about control structures. Rat's nest programs are possible in REXX, but REXX's designer took steps to penalize anyone who would abuse structured programming concepts. Clarity. CLIST programs often tax the poor programmer's analytical capabilities as he or she tries to understand how CLIST attempts to interpret data strings as expressions and then tries valiantly to prevent it from doing so. CLIST language is the incarnation of obscurity. REXX does not think data is to be analyzed. It contents itself with analyzing verbs, variables, literals, functions, and labels, but not, thank you, REXX, data! Usefulness. The CLIST language is like nothing else in the entire spectrum of programming languages. REXX is becoming a kind of Esperanto, or universal language, in the programming world. It looks a lot like BASIC, PLI (especially) and C (a little. Nothing else really looks like C!). I have used REXX in IBM's VM/CMS programming system, in OS/2, and in PC-DOS, and have found that it is the same in each environment. REXX is your key to other IBM programming environments. Here in tabular form are the major differences between CLIST and REXX:

CLIST Old Bad for data strings Lots of &&&&& Obscure at times Good control structures structures Bad for math Few useful functions Unique Prompts for positional parms positional parms

REXX New Good string handling English-like Clear Excellent control Good for math Many good functions Common No prompting for

Execution Differences CLISTs are generally contained in libraries (PDSs) whose names end in ".CLIST." (.CLIST not required, but recommended) TSO is informed of the library by means of the TSO command ALLOCATE, which specifies the name of the library and the DDNAME (data definition name, abbreviated DDN) SYSPROC.

The ALLOCATE command is done like this: ALLOC DDN(SYSPROC) SHR REUSE DSN(MYPROGS.CLIST) An ALTLIB command may also be done: ALTLIB ACTIVATE APPL(CLIST) DA(MYPROGS.CLIST)

REXX programs are generally contained in libraries (PDSs) whose names end in ".EXEC." (.EXEC not required, but recommended) TSO is informed of the library by means of the TSO command ALLOCATE, which specifies the name of the library and the DDNAME (data definition name, abbreviated DDN) SYSEXEC. The ALLOCATE command is done like this:

ALLOC DDN(SYSEXEC) SHR REUSE DSN(MYPROGS.EXEC) An ALTLIB command may also be done: ALTLIB ACTIVATE APPL(EXEC) DA(MYPROGS.EXEC)
REXX programs may be in the same libraries as CLISTs. If you do that, please start your REXX program with the comment shown just below. An explanation of when you need the comment and when you don't, is beyond the scope of this short paper

/*REXX */ ARG USERID "SEND 'HELLO' USER("USERID")"

Corresponding Features in CLIST and REXX

Conversion of one language to another requires a knowledge of both languages and how they function. CLISTs and REXX share many features. Both have good control structures such as DO WHILE. These can usually be converted without any problem. However, CLIST GOTOs cannot always be converted to REXX SIGNALs, because the latter destroy any loop or control structure they are in. You may have to rewrite the logic of CLIST GOTOs. Changing the value of a loop variable in REXX affects the outcome of the loop. An example of this is DO I = 1 to 10 and changing the value of I within the loop. CLIST does not function the same way. REXX has nothing even near GLOBAL variables. You can use ISPF Variable Services to produce the same results. CLIST examines a program statement and processes it repeatedly until all "&" variables are resolved. REXX examines a statement once only, unless you use the INTERPRET instruction. CLIST statements containing variables within variables may severely tax your conversion abilities. The CLIST PROC statement works differently from REXX ARG. There is no one-to-one correspondence. You will have to execute REXX differently without reliance on keyword parameters. REXX has no WRITENR which displays a message and leaves the cursor at the end of the line. You might consider using ISPF panels, although this is considerably more involved.

CLIST Features AND IF &A = 1 AND &B ATTN ATTN DO ... END CLOSFILE Concatenation by juxtaposition juxtaposition All spaces remain. become 1 space WRITE HI NICE DAY! DAY! -> HI NICE DAY! Concatenation with operator with operator SET &NAME = WILL FRED CONTROL LIST CONTROL NOMSG CONTROL PROMPT CONTROL SYMLIST CONLIST DATA commands in quotes LISTCAT LISTDS ENDDATA &DATATYPE IF &DATATYPE(&NUM1) = NUM DATATYPE(NUM1) = "NUM" DO WHILE

REXX Equivalents & IF A = 1 & B = 2 HALT trap SIGNAL ON HALT

= 2

EXECIO with FINIS option Concatenation by > 1 spaces SAY HI NICE

-> HI NICE DAY! Concatenation NAME = "WILL" "FRED" TRACE C CALL MSG "OFF" CALL PROMPT "ON" TRACE I Environment "LISTCAT" "LISTDS"

DATATYPE function IF

DO WHILE

Error trap traps ERROR DO ... END &EVAL EXIT CODE(number EXIT CODE(10) EXIT QUIT File IO GETFILE

ERROR, SYNTAX SIGNAL ON ERROR SIGNAL ON SYNTAX

No equivalent EXIT number EXIT 10 No equivalent EXECIO EXECIO 1 DISKR INFILE No equivalent

INFILE

GLOBAL variables GLOBAL &V1 &V2 &V3 IF ... AND IF ... OR IF (null GOTO GOTO ENDPROG &LASTCC and &MAXCC set after all instructions environment commands &LENGTH &LENGTH(ABCD) LISTDSI dsn "dsn" Literal has no delimiter, ', or no delimiter or uses &STR() WRITE HELLO &MAXCC set after all instructions environment commands

IF ... & IF ... IF ... NOP SIGNAL label SIGNAL ENDPROG RC set after

LENGTH function LENGTH("ABCD") CALL LISTDSI

Literal uses " or SAY "HELLO"

RC set after

NGLOBAL NGLOBAL VAR1 &NRSTR OPENFILE PROC keyword parameters with default PROC 0 TRACE(NO) PROC keyword parameters without default PROC 0 TRACE PROC prompts for positionals prompt PROC 1 VAR1 ARG VAR1 PROC statement PROC 1 VAR1 PUTFILE READ &var READ &NAME EXECIO

No equivalent

No equivalent

No equivalent

No equivalent

ARG does not

ARG (approximate) ARG VAR1 EXECIO DISKW PULL (approximate)

PULL NAME

READ (goes into &SYSDVAL) RETURN (approximate) SELECT subroutine label SUBR: PROC 1 VAR1 subroutine END subroutine SYSREF (approximate) SYSREF VAR1 &SUBSTR

No equivalent RETURN

SELECT subroutine label: SUBR: ARG VAR1 subroutine RETURN subroutine EXPOSE EXPOSE VAR1 SUBSTR function

WRITE &SUBSTR(1:3,ABC) SUBSTR("ABC",1,3) &STR equivalent. delimiters &SYSASIS

SAY

No exact Consider literal

No exact equivalent. Consider PARSE [UPPER] CALL CALL SUBROUT PARSE UPPER SYSVAR(SYSCPU)

SYSCALL SYSCALL SUBROUT &SYSCAPS &SYSCPU function &SYSDATE, &SYSTIME WRITE &SYSDATE &SYSDLM &SYSDSN &SYSDVAL &SYSENV function &SYSFLUSH &SYSHSM function &SYSICMD

DATE function SAY DATE() No equivalent SYSDSN function No equivalent SYSVAR(SYSENV)

No equivalent SYSVAR(SYSHSM)

No equivalent (but see PARSE SOURCE) INDEX function SYSVAR(SYSISPF) function No equivalent

&SYSINDEX &SYSISPF &SYSLC

&SYSJDATE &SYSLTERM &SYSLRACF &SYSNEST &SYSNSUB &SYSOUTLINE SET &LINE = &&SYSOUTLINE&ctr (in loop varying I) &SYSOUTTRAP OUTTRAP function SET &SYSOUTTRAP = 200 "LINE.", 200 SET &SYSOUTTRAP = 0 "OFF" &SYSPCMD &SYSPREF &SYSPROC WRITE THE PROC = WRITE &SYSPROC SYSVAR(SYSPROC) &SYSRACF &SYSSCAN &SYSSCMD &SYSSDATE &SYSSRV function &SYSSTIME

DATE("J") function SYSVAR(SYSLTERM) function SYSVAR(SYSLRACF) function SYSVAR(SYSNEST) function No equivalent OUTTRAP function LINE = LINE.I

CALL OUTTRAP

CALL OUTTRAP

No equivalent SYSVAR(SYSPREF) function SYSVAR(SYSPROC) function SAY "THE PROC = " SAY

SYSVAR(SYSRACF) function No equivalent No equivalent DATE("S") function SYSVAR(SYSSRV)

TIME() function

&SYSTIME &SYSTSOE &SYSUID WRITE YOU ARE &SYSUID USERID() &SYSWTERM function TERMIN Variable starts with & no special way WRITE &NAME WRITE WRITE PLEASE ENTER NAME WRITENR equivalent + - continuation WRITE PLEASE ENTER + ENTER", NAME

TIME() function SYSVAR(SYSTSOE) function USERID() function SAY "YOU ARE "

LINESIZE function or SYSVAR(SYSWTERM)

No equivalent Variable starts SAY NAME SAY SAY "PLEASE ENTER NAME" No exact

continuation with "," SAY "PLEASE "NAME"