29
Fri, Nov
0 New Articles

The Retrieve User Space Tools

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Among the most powerful OS/400 application program interfaces (APIs) are those that produce lists (e.g., a list of fields, members, objects, or jobs). These APIs perform functions similar to OS/400 commands which provide "outfile" processing. The main difference is that list APIs create entries in a user space instead of writing records to a database file. This makes the API method far more efficient than an equivalent CL command. (For a discussion of user space concepts, see the "What is a User Space?" sidebar on page 120 of MC's October 1993 issue or consult the System Programmers Interface Reference.)

Retrieving entries from a user space is usually done from within a high-level language such as RPG or COBOL. This works well when you want to use the information to display a subfile or produce a report. But what if you need to execute a CL command against each entry? In this case, it makes more sense to retrieve the entries directly from within a CL program. Two QUSRTOOL commands are specifically designed for that purpose: the Retrieve User Space Initialization (RTVUSRSPCI) and Retrieve User Space Entry (RTVUSRSPCE) commands.

Overview

The RTVUSRSPCI and RTVUSRSPCE commands are designed for execution from within a CL program. This CL program would typically perform the following tasks:

o Create a user space.

o Call one of the list APIs to load the user space.

o Execute the RTVUSRSPCI command to retrieve the user space initialization information.

o Execute the RTVUSRSPCE command in a loop to retrieve each entry in the user space.

The RTVUSRSPCI command retrieves the initialization information from a user space. This information contains the number of entries in the list, the starting position of the first entry, and the length of each entry. Your CL program uses the number of entries in the list to determine how many times to execute the RTVUSRSPCE command.

The RTVUSRSPCE command retrieves one entry from a user space. This command uses the starting position and entry length retrieved from the RTVUSRSPCI command. The RTVUSRSPCE command returns the user space entry to a variable in your CL program. Each execution of the RTVUSRSPCE command automatically updates the starting position value to point to the next entry in the list.

The RTVUSRSPCI Command

Required Parameters

USRSPC

Specify the qualified name of the user space whose initialization values are to be retrieved. The possible values are:

*LIBL: The library list is used to locate the user space.

*CURLIB: The user space is located in the current library.

library-name: Specify the name of the library that contains the user space.

user-space: Specify the name of the user space.

Optional Parameters

STRPOS

Specify the name of the CL variable to contain the starting position of the first entry in the list in the user space specified in USRSPC. STRPOS must be defined as a *CHAR field with a length of four bytes. The value returned is the binary equivalent of the starting position. This value may be specified in the STRPOS parameter of the RTVUSRSPCE command.

NBRENT

Specify the name of the CL variable to contain the number of entries in the list in the user space specified in USRSPC. NBRENT must be defined as a *DEC field with a length of nine bytes and zero decimal positions.

ENTLEN

Specify the name of the CL variable to contain the length of each entry in the list in the user space specified in USRSPC. ENTLEN must be defined as a *CHAR field, four bytes in length. The value returned is the binary equivalent of the entry length. This value may be specified in the ENTLEN parameter of the RTVUSRSPCE command.

Source Members

INFO: RTVUSRSPCI (QATTINFO) CDO: TAASPCB (QATTCMD) CPP: TAASPCBR (QATTRPG) The RTVUSRSPCE Command

Required Parameters

USRSPC

Specify the qualified name of the user space whose entries are to be retrieved. The possible values are:

*LIBL: The library list is used to locate the user space.

*CURLIB: The user space is located in the current library.

library-name: Specify the name of the library that contains the user space.

user-space: Specify the name of the user space.

Optional Parameters

ENTLEN

Specify the length of the user space entry to be retrieved. ENTLEN must be defined as a *CHAR field, four bytes in length, and must contain the binary value of the entry length. You can retrieve the formatted entry length value from the parameter returned by the RTVUSRSPCI command.

STRPOS

Specify the starting position within the user space. The entry is retrieved for the length specified in ENTLEN starting at this position. STRPOS must be defined as a *CHAR field, four bytes in length, and must contain the binary value of the entry length. You can retrieve the formatted start position value from the parameter returned by the RTVUSRSPCI command.

The STRPOS value is incremented for each execution of the RTVUSRSPCE command. This allows you to execute the RTV-USRSPCE command within a CL program loop, retrieving list entries in order.

RTNVAR

Specify the name of the CL program variable to contain the retrieved user space entry. RTNVAR must be defined as a *CHAR field with a length of 1000 bytes. The entry retrieved from the user space is left-adjusted into this field.

SETLR

Specify whether the processing program should set the LR indicator on or off. Because the processing program for the RTVUSRSPCE command is an RPG program, the user can control when the program is deactivated by setting this parameter.

*OFF: The RPG processing program is not deactivated upon return. This is the recommended setting when the command is executed more than a few times in succession. Leaving the program activated results in faster execution of the RTVUSRSPCE command, since the processing program does not have to be initialized each time it is called.

*ON: The RPG processing program is to set on the LR indicator and return. The user space is not accessed. This deactivates the program. You would normally specify *ON after the last execution of the RTVUSRSPCE command. If this value is specified and the RPG program has not been activated, the RPG H1 indicator is set on.

Source Members

INFO: RTVUSRSPCE (QATTINFO) CDO: TAASPCC (QATTCMD) CPP: TAASPCCR (QATTRPG)

Example

To demonstrate the use of the RTVUSRSPCI and RTVUSRSPCE commands, look at the CL program in 1. This program's task is to create a spool file using the Display Job Description (DSPJOBD) command for every job description in library QGPL.

To demonstrate the use of the RTVUSRSPCI and RTVUSRSPCE commands, look at the CL program in Figure 1. This program's task is to create a spool file using the Display Job Description (DSPJOBD) command for every job description in library QGPL.

This program performs the following tasks:

o Calls the Create User Space (QUSCRTUS) API to create user space TMPSPC in library QTEMP.

o Calls the List Object (QUSLOBJ) API to load the user space with information about every job description in library QGPL.

o Executes the RTVUSRSPCI command to retrieve the starting position of the list, the length of each entry in the list, and the number of entries in the list.

o Drops into a loop where it increments a counter and then compares the counter to the number of entries in the list. When the counter exceeds the number of entries in the list, the program branches to a label outside of the loop.

o Passes the entry length and starting position to the RTVUSRSPCE command to retrieve an entry from the list into a CL variable.

o Extracts the job description name from the CL variable, &RTNVAR.

o Executes the DSPJOBD command against the job description to create a spool file.

o Completes the loop by branching up to a label to retrieve the next entry in the list.

o When the loop terminates, executes the RTVUSRSPCE command, if necessary, to deactivate the RPG processing program.

Robin Klima is a senior technical editor of Midrange Computing.

These tools are documented in Midrange Computing's QUSRTOOL Command Reference. The manual contains explanations and syntax diagrams for more than 300 useful tools.


The Retrieve User Space Tools

Figure 1 Display Job Descriptions in QGPL

 /*===============================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/XRK004CL) SRCFILE(XXX/QCLSRC) */ /* */ /*===============================================================*/ XRK004CL: PGM DCL VAR(&ENTLEN) TYPE(*CHAR) LEN(4) DCL VAR(&NBRENT) TYPE(*DEC) LEN(9 0) DCL VAR(&JOBD) TYPE(*CHAR) LEN(10) DCL VAR(&STRPOS) TYPE(*CHAR) LEN(4) DCL VAR(&RTNVAR) TYPE(*CHAR) LEN(1000) DCL VAR(&COUNT) TYPE(*DEC) LEN(9 0) /* Create user space in QTEMP */ CALL PGM(QUSCRTUS) PARM('TMPSPC QTEMP' + 'USRSPC' X'00000020' ' ' '*ALL' + 'Temporary user space' '*YES' X'00000000') /* List job descriptions in QGPL */ CALL PGM(QUSLOBJ) PARM('TMPSPC QTEMP' + 'OBJL0100' '*ALL QGPL' '*JOBD') /* Retrieve initialization values */ RTVUSRSPCI USRSPC(QTEMP/TMPSPC) STRPOS(&STRPOS) + NBRENT(&NBRENT) ENTLEN(&ENTLEN) /* Increment counter */ LOOP: CHGVAR VAR(&COUNT) VALUE(&COUNT + 1) /* Compare counter to number of entries */ IF COND(&COUNT *GT &NBRENT) THEN(GOTO + CMDLBL(DONE)) /* Retrieve an entry */ RTVUSRSPCE USRSPC(QTEMP/TMPSPC) ENTLEN(&ENTLEN) + STRPOS(&STRPOS) RTNVAR(&RTNVAR) /* Extract job description from return variable */ CHGVAR VAR(&JOBD) VALUE(%SST(&RTNVAR 1 10)) /* Display the job description */ DSPJOBD JOBD(QGPL/&JOBD) OUTPUT(*PRINT) /* Go get next entry */ GOTO CMDLBL(LOOP) /* Set on LR if necessary */ DONE: IF COND(&NBRENT *GT 0) THEN(RTVUSRSPCE + USRSPC(QTEMP/TMPSPC) SETLR(*ON)) ENDPGM 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: