ISPF Services for REXX: Panel, Edit & Library Services
ISPF services provide REXX scripts with access to ISPF capabilities, enabling powerful automation and application development. REXX can use panel services to display interactive dialogs, edit services to work with datasets, and library services to manage ISPF libraries. Understanding ISPF services helps you create sophisticated REXX applications that integrate with ISPF. This tutorial covers panel services, edit services, library services, and how to use them in REXX scripts.
ISPF services extend REXX capabilities by providing access to ISPF functions. Panel services enable interactive user interfaces, edit services provide dataset operations, and library services manage ISPF library contents. Learning to use these services enables you to build powerful ISPF applications with REXX. This tutorial provides practical guidance for using ISPF services in REXX.
Understanding ISPF Services
ISPF services are functions that REXX can call to interact with ISPF.
What are ISPF Services?
ISPF services are:
Functions accessible from REXX
Provide ISPF capabilities to REXX scripts
Called using ADDRESS ISPEXEC
Return codes indicate success or failure
Enable REXX-ISPF integration
ADDRESS ISPEXEC
The ADDRESS ISPEXEC command:
Directs commands to ISPF
Required for ISPF service calls
Sets up ISPF environment
Enables service access
Example:
text
1
2
3
4
5
/*REXX*/
address ispexec
'DISPLAY PANEL(MYPANEL)'
if rc <> 0 then exit 8
exit 0
Panel Services
Panel services enable REXX to display and process ISPF panels.
DISPLAY PANEL
The DISPLAY PANEL service:
Displays an ISPF panel
Collects user input
Returns when user exits panel
Return code indicates how user exited
Example:
text
1
2
3
4
5
6
7
8
9
10
11
/*REXX*/
address ispexec
'DISPLAY PANEL(MYINPUT)'
if rc = 0 then do
say 'User entered:' zuser
end
else do
say 'User cancelled'
exit 8
end
exit 0
TBDISPL
The TBDISPL service:
Displays table display panels
Shows tabular data
Allows row selection
Returns selected row information
Panel Variables
Panel services use ISPF variables:
Z variables for system information
User-defined variables for input/output
Variables accessible in REXX
Set and retrieved through services
Edit Services
Edit services enable REXX to work with datasets.
EDIT DATASET
The EDIT DATASET service:
Opens dataset in ISPF editor
Allows programmatic edit operations
Returns when editor closes
Can specify member for PDS
Example:
text
1
2
3
4
5
6
7
8
9
10
11
12
/*REXX*/
parse arg dsn member
address ispexec
if member <> '' then
'EDIT DATASET('"'"dsn"("member")"'"')'
else
'EDIT DATASET('"'"dsn"'"')'
if rc <> 0 then do
say 'Error opening dataset'
exit 8
end
exit 0
Library services enable REXX to manage ISPF libraries.
LMINIT
The LMINIT service:
Initializes library access
Sets up library connection
Returns dataset ID
Required before other library operations
Example:
text
1
2
3
4
5
6
7
8
9
10
11
/*REXX*/
parse arg libname
address ispexec
'LMINIT DATASETID(id) DATASET('"'"libname"'"')'
if rc <> 0 then do
say 'Error initializing library'
exit 8
end
/* Use library */
'LMFREE DATASETID(id)'
exit 0
LMOPEN
The LMOPEN service:
Opens library for access
After LMINIT
Prepares library for operations
Required for member access
LMMLIST
The LMMLIST service:
Lists library members
Returns member information
Useful for member enumeration
Can filter members
LMCLOSE and LMFREE
Library cleanup services:
LMCLOSE closes library
LMFREE frees library resources
Should be called when done
Prevents resource leaks
Table Services
Table services enable REXX to work with ISPF tables.
TBOPEN
The TBOPEN service:
Opens ISPF table
Prepares table for access
Returns table handle
Required for table operations
TBADD
The TBADD service:
Adds row to table
Inserts data into table
Requires table to be open
Returns success status
TBSAVE
The TBSAVE service:
Saves table changes
Persists table data
Required to keep modifications
Returns success status
TBCLOSE
The TBCLOSE service:
Closes ISPF table
Releases table resources
Should be called when done
Prevents resource leaks
Variable Services
Variable services enable REXX to handle ISPF variables.
VGET
The VGET service:
Gets ISPF variable values
Retrieves variable to REXX
Can get single or multiple variables
Makes variables available in REXX
Example:
text
1
2
3
4
5
6
/*REXX*/
address ispexec
'VGET (ZUSER ZPREFIX)'
say 'User:' zuser
say 'Prefix:' zprefix
exit 0
Proper error handling is essential when using ISPF services.
Checking Return Codes
Always check return codes:
RC = 0 indicates success
RC > 0 indicates error or special condition
Check RC after each service call
Handle errors appropriately
Common Return Codes
Common return codes:
0: Success
4: Warning or user action (like cancel)
8: Error
12: Severe error
Error Handling Pattern
Standard error handling:
text
1
2
3
4
5
6
7
8
9
10
11
/*REXX*/
address ispexec
'DISPLAY PANEL(MYPANEL)'
if rc <> 0 then do
if rc = 4 then
say 'User cancelled'
else
say 'Error displaying panel, RC=' rc
exit rc
end
exit 0
Best Practices
Following best practices improves REXX-ISPF integration:
Use ADDRESS ISPEXEC: Always use ADDRESS ISPEXEC for ISPF services
Check Return Codes: Always check RC after service calls
Validate Input: Validate input before using services
Use Appropriate Services: Choose the right service for the task
Test Incrementally: Test services one at a time
Document Service Usage: Document which services are used
Explain Like I'm 5: ISPF Services for REXX
Think of ISPF services like special tools REXX can use:
ISPF Services are like special tools that REXX can borrow from ISPF. Just like you can borrow tools from a toolbox, REXX can use ISPF's tools (services) to do things like show screens, edit files, and manage libraries. It's like REXX asking ISPF "can I use your tools?" and ISPF saying "yes, here they are!"
Panel Services are like tools for showing pictures and asking questions. REXX uses these tools to display screens (panels) to users and get their answers. It's like REXX using ISPF's tool to show a form and collect information!
Edit Services are like tools for working with files. REXX uses these tools to open files for editing or viewing. It's like REXX using ISPF's tool to open a notebook and let you write in it or read it!
Library Services are like tools for managing collections of things. REXX uses these tools to work with libraries (collections of panels, messages, etc.). It's like REXX using ISPF's tool to organize and find things in a filing cabinet!
ADDRESS ISPEXEC is like telling REXX "when I say 'use this tool', I mean use ISPF's tool." It's like saying "hey REXX, when I ask for a tool, get it from ISPF's toolbox!"
So ISPF services are like special tools that REXX can borrow from ISPF to do things like show screens, edit files, and manage libraries!
Practice Exercises
Complete these exercises to reinforce your ISPF services skills:
Exercise 1: Use Panel Service
Practice panel: write REXX script that displays a panel, use DISPLAY PANEL, handle user input, check return codes, and learn panel services. Master panel services.
Exercise 2: Use Edit Service
Practice edit: write REXX script that opens dataset for editing, use EDIT DATASET, handle errors, verify operation, and learn edit services. Master edit services.
Exercise 3: Use Library Service
Practice library: write REXX script that accesses ISPF library, use LMINIT and LMOPEN, list members, free resources, and learn library services. Master library services.
Exercise 4: Use Variable Service
Practice variable: write REXX script that gets and sets ISPF variables, use VGET and VPUT, understand variable handling, and learn variable services. Master variable services.
Exercise 5: Complete Application
Practice complete: write REXX script using multiple ISPF services, create interactive application, handle errors properly, and learn service integration. Master ISPF services integration.