[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 dollars
   internal or external function that will format a number in currency format
   give it 1234.5 it will return $1,234.50

   example of use:
   dollar_format_number = dollars(123.45)

   there is 1 optional parameter or argument (preceded by a comma)
   optional argument:
   argument # 2 - size of output field, in characters
                  if this is too small, it's ignored
   dollar_format_number = dollars(123.45, 10)
  for REXX information, Sample Code, books see

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


  may be distributed provided this entire comment is included

*/
dollars: /* procedure do not use procedure if this is external */

decimal  = "."
spacer   = ","
currency = "$"

out = ""
ctr = 0

if arg() < 1 then signal no_input

if datatype(arg(1)) <> "NUM"  then signal not_a_num

number   = arg(1)
size     = arg(2)

if datatype(size) = "NUM" | size = "" then nop
else signal bad_length

if number < 0 then number = number * -1

parse var number whole (decimal) fraction
whole = whole + 0

if length(whole) > 9 then signal too_big

do i = length(whole) to 1 by -1
   call join substr(whole,i,1)
end i

if pos(spacer,out) = 1 then out = substr(out,2)

if length(fraction)   > 2       then call round_fraction
if length(fraction)   = 1       then fraction = fraction"0"
if datatype(fraction) <> "NUM"  & fraction <> ""
   then signal not_a_num

if fraction = "" then out = currency""out""decimal"00"
else out = currency""out""decimal""fraction

if out <> "" & ,
   length(out) < size then out = copies(" ",size - length(out))out

return out

join:
arg in
ctr = ctr + 1
if ctr = 3 then do
   ctr = 0
   in = spacer""in
   end
out = in""out
return

no_input:
say "must supply at least one input parm, a valid number"
return ""

not_a_num:
say "must supply at least one input parm, a valid number"
return arg(1)

too_big:
say "max length of input number is 9"
return arg(1)

bad_length:
say "length parameter, " arg(2) "must be numeric"
return arg(1)
/*** 
    may be freely distributed
    provided that this notice is attached.
    See  
    http://theamericanprogrammer.com/programming/index.shtml
    I am an independant consultant and trainer.
    
***/
round_fraction:
numeric digits 2
fraction = fraction + 0
numeric digits 9
fraction = fraction + 0
fraction = left(fraction,2)
return
say fraction

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 |