How to program in REXX programming language for mainframe computers? - ByteScout
  • Home
  • /
  • Blog
  • /
  • How to program in REXX programming language for mainframe computers?

How to program in REXX programming language for mainframe computers?

Rexx was developed by IBM in the late 1970s. Rexx or Restructured Extended Executor is a programming language that carries various characteristics such as functions, support for UNIX commands, file I/O operations, debugging, and crash security. This article describes the use of REXX for mainframe computers.

  1. How to run a REXX program in the mainframe?
  2. How to execute parsing in mainframe using REXX?
  3. How to REX Loop in the mainframe computers?
  4. Types of REXX Instructions in the Mainframe
  5. Running an Exec from a CLIST for the Mainframe

REXX Programming Tutorial

How to run a REXX program in the mainframe?

A function is a built-in or visible method that delivers a unique result string. In REXX, a subroutine is a function that can deliver a result and it is called with the CALL instruction. The following program is showing the use of IRRXUTIL package in the mainframe:

/* REXX */	
	/* Get user information and display what is available */
	theVar  = "rr"
	theProfile = 'NEWUSER'
	theClass = 'USER'
	irrRC = IRRXUTIL('EXTRACT',theClass,theProfile,theVar,"",'FALSE')
	
	say "Class:   " rr.CLASS
	say "Profile: " rr.PROFILE
	say "Here are" rr.0 "segments"
	do s = 5 to rr.0
	seg = rr.s
	say "Segment information:" seg
	   do k = 1 to rr.seg.0
	      stem = rr.seg.k
	       do i = 5 to rr.seg.stem.0
	          say seg ":" rr.seg.k ":" rr.seg.stem.i
	       end
	   end
	end
	exit

IRRXUTIL is a utility that can be used to convert the result of a R_admin service to get a request to a set of REXX stem variables. The stem variables are created to the given profile data in one of the methods like: by field name where the field name is recognized by the caller.Rexx programming in the mainframe does not ask users to explicitly declare variables.

For instance, the variable is specified as the integer-value 10. Therefore, say the number would present the value 10 on the Mainframe output Screen. If the variable text is specified the string ‘We are learning Rexx Programming language’ then say text would present ‘We are learning Rexx Programming language’ on the output screen.

How to execute parsing in mainframe using REXX?

One of the most important characteristics of Rexx is its capacity to parse text values. The following program is displaying the use of parse in the mainframe.

Syntax

PARSE {UPPER|LOWER|caseless} source {src}

Example:

/* My Main program */ 
parse value 'I love Rexx Programs' with word1 word2 word3 word4 
say "'"word1"'" 
say "'"word2"'" 
say "'"word3"'" 
say "'"word4"'"

The above program will give the following output in the phases:

‘I’
‘love’
‘Rexx’
‘Programs’

How to REX Loop in the mainframe computers?

A REXX loop enables users to fulfill a statement or various statements numerous times. The following example is the common practice of a loop statement in the mainframe computers. In the mainframe, the do loop is applied to fulfill a number of statements for a specific number of times. It can be achieved by using a parameter and a condition.

Syntax

do index = start [limit] [increment] [for count] 
condition #1 
Condition #2 
end 

Example

/* My First program */ 
do a = 0 to 7 by 2 
   say "hello world" 
end

Types of REXX Instructions in the Mainframe

There are five types of REXX instructions. These are

  • Keyword
  • Assignment
  • Label
  • Null, and
  • Command

The following case is an ISPF/PDF Edit panel that displays an exec with different kinds of instructions. A summary of each kind of instruction issue after the case. In most of the reports, users will notice an edit line number.

 

EDIT —- USERID.REXX.EXEC ===> SCROLL ===> HALF ****** ************************ MAIN INFORMATION

************************************ 000001 /**************************

REXX ****************************/ 000002 /*

000005 Prog1:

000006

000007 SAY ‘How are you?’

000008 PULL userreply

000011 IF userreply = ‘ ‘ THEN

000012 SAY “O.K.”

000013 ELSE

000014 DO

000015 SAY “I’m fine:”

000016

000017 END

000018

000019 EXIT

****** *********************** END **********************************

Running an Exec from a CLIST for the Mainframe

A CLIST can request an exec with the EXEC command. It can request it explicitly or implicitly. If it requests it implicitly then the exec is in the PDS designated to SYSEXEC or SYSPROC. If it requests a CLIST implicitly then the CLIST is in a PDS allocated to SYSPROC.

When an exec requests a CLIST, the CLIST can give a number to the exec by using the EXIT CODE() argument with the output number inserted in brackets after CODE. The exec accepts the number in the REXX specific variable called RC.

 

   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next