[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Using REXX OUTTRAP
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Bubble Sort

Execute a TSO command, and capture and use the output in your REXX program

This illustrates the use of the REXX OUTTRAP function.
/* REXX FIXLENG
   EXTERNAL FUNCTION FOR ALL PLATFORMS
   GIVE IT A NUMBER AND DESIRED LENGTH
   RETURNS A FIXED LENGTH NUMBER
   WITH LEADING ZEROS.
   IF YOU GIVE IT A NUMBER ALREADY TOO BIG,
   THE NUMBER IS RETURNED UNCHANGED.
   EXECUTE BY SAY FIXLENG(5,9)
   OR X = FIXLENG(5,9)
   WHERE 5 IS THE NUMBER AND 9 IS THE DESIRED LENGTH.
TO TEST: (IN ANOTHER PROGRAM!)
I = 10
DO 10
  I = I * 5
  SAY I
  SAY FIXLENG(I,9)
END
EXIT

  for REXX information, Sample Code, books see

              http://theamericanprogrammer.com/programming/index.shtml


  may be distributed PROVIDED this entire comment is included
  
*/

ARG NUMBER, DESIRED

CALL VALIDATE
ACTUAL = LENGTH(NUMBER)
NEEDED = DESIRED - ACTUAL
IF ACTUAL > DESIRED THEN RETURN NUMBER
FINAL = COPIES(0,NEEDED)NUMBER

RETURN FINAL

VALIDATE:
PARSE SOURCE . HOW_CALLED .
IF HOW_CALLED = "COMMAND"
   THEN DO
     SAY "THIS IS AN EXTERNAL FUNCTION "
     SAY "IT MAY NOT BE EXECUTED AS A COMMAND"
     SAY "EXECUTE LIKE THIS:"
     SAY "IN ANOTHER PROGRAM, "
     SAY "SAY FIXLENG(6,7)"
     SAY "OR X = FIXLENG(6,7)"
     SAY "WHERE 6 IS THE NUMBER TO BE ACTED ON"
     SAY "AND 7 IS THE DESIRED LENGTH"
     SAY "THIS RETURNS THE ORIGINAL NUMBER WITH THE DESIRED LENGTH"
     SAY "WITH LEADING ZEROS"
     EXIT
     END
IF DATATYPE(DESIRED) <> "NUM"
   THEN DO
     SAY "REQUIRED INPUT IS TWO NUMBERS SEPARATED BY A COMMA"
     SAY "FIRST NUMBER IS ACTUAL NUMBER TO BE ACTED ON"
     SAY "SECOND NUMBER IS THE DESIRED LENGTH"
     SAY "RETURNS A NUMBER OF THE DESIRED LENGTH"
     SAY "UNLESS THE ORIGINAL NUMBER IS TOO BIG"
     SAY "IN WHICH CASE THE ORIGINAL NUMBER IS RETURNED UNCHANGED"
     EXIT
     END
RETURN


Learn how to use all the features of REXX: REXX Programming Book for TSO (published 2012)

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |