ibm-information-center/dist/eclipse/plugins/i5OS.ic.apiref_5.4.0.1/listRPG.htm

541 lines
27 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example in RPG: List Object API" />
<meta name="abstract" content="This example program prints a report that shows all objects that adopt owner authority." />
<meta name="description" content="This example program prints a report that shows all objects that adopt owner authority." />
<meta name="DC.Relation" scheme="URI" content="listOverview.htm" />
<meta name="DC.Relation" scheme="URI" content="listGeneral.htm" />
<meta name="DC.Relation" scheme="URI" content="listUserWOPointer.htm" />
<meta name="DC.Relation" scheme="URI" content="pgmerr_liste.htm" />
<meta name="DC.Relation" scheme="URI" content="listCOBOL.htm" />
<meta name="DC.Relation" scheme="URI" content="listILEC.htm" />
<meta name="DC.Relation" scheme="URI" content="listILERPG.htm" />
<meta name="DC.Relation" scheme="URI" content="listILEC.htm" />
<meta name="DC.Relation" scheme="URI" content="listILERPG.htm" />
<meta name="DC.Relation" scheme="URI" content="listCOBOL.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="listRPG" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example in RPG: List Object API</title>
</head>
<body id="listRPG"><a name="listRPG"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example in RPG: List Object API</h1>
<div><p>This example program prints a report that shows all objects that
adopt owner authority.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
legal information.</div>
<pre>F*
F*****************************************************************
F*****************************************************************
F*****************************************************************
F*****************************************************************
F*
F*Program Name: List objects which adopt owner authority
F*
F*Language: OPM RPG
F*
F*Description: This program prints a report showing all objects
F* that adopt owner authority. The two parameters
F* passed to the program are the profile to be
F* checked and the type of objects to be listed.
F* The parameter values are the same as those
F* accepted by the QSYLOBJP API.
F*
F*APIs Used: QSYLOBJP - List Objects that Adopt Owner Authority
F* QUSCRTUS - Create User Space
F* QUSROBJD - Retrieve Object Description /
F* QUSRTVUS - Retrieve From User Space /
F*
F*****************************************************************
F*****************************************************************
F*
FQSYSPRT O F 132 OF PRINTER
F***************************************************************
I/COPY QSYSINC/QRPGSRC,QSYLOBJP
I/COPY QSYSINC/QRPGSRC,QUSROBJD
I/COPY QSYSINC/QRPGSRC,QUSGEN
C*****************************************************************
I* Error Code Structure
I*
I* This shows how the user can define the variable length portion
I* of error code for the exception data.
I*
I*/COPY QSYSINC/QRPGSRC,QUSEC
I*** START HEADER FILE SPECIFICATIONS ****************************
I*
I*Header File Name: QRPGSRC/QUSEC
I*
I*Descriptive Name: Error Code Parameter.
I*
I*5763-SS1 (C) Copyright IBM Corp. 1994,1994
I*All rights reserved.
I*US Government Users Restricted Rights -
I*Use, duplication or disclosure restricted
I*by GSA ADP Schedule Contract with IBM Corp.
I*
I*Licensed Materials-Property of IBM
I*
I*
I*Description: Include header file for the error code parameter.
I*
I*Header Files Included: None.
I*
I*Macros List: None.
I*
I*Structure List: Qus_EC_t
I* Qus_ERRC0200_t
I*
I*Function Prototype List: None.
I*
I*Change Activity:
I*
I*CFD List:
I*
I*FLAG REASON LEVEL DATE PGMR CHANGE DESCRIPTION
I*---- ------------ ----- ------ --------- ----------------------
I*$A0= D2862000 3D10 931201 DPOHLSON: New Include
I*$B1= D9179400 3D60 940904 GEORGE : Add Qus_ERRC0200_t
I* structure.
I*
I*End CFD List.
I*
I*Additional notes about the Change Activity
I*End Change Activity.
I*** END HEADER FILE SPECIFICATIONS ******************************
I*****************************************************************
I*Record structure for Error Code Parameter
I**** ***
I*NOTE: The following type definition only defines the fixed
I* portion of the format. Varying length field Exception
I* Data will not be defined here.
I*****************************************************************
IQUSBN DS
I* Qus EC
I B 1 40QUSBNB
I* Bytes Provided
I B 5 80QUSBNC
I* Bytes Available
I 9 15 QUSBND
I* Exception Id
I 16 16 QUSBNF
I* Reserved
I* Following statement was uncommented and 17 was changed to 100
I 17 100 QUSBNG
I*
I* Varying length
IQUSKY DS
I* Qus ERRC0200
I B 1 40QUSKYB
I* Key
I B 5 80QUSKYC
I* Bytes Provided
I B 9 120QUSKYD
I* Bytes Available
I 13 19 QUSKYF
I* Exception Id
I 20 20 QUSKYG
I* Reserved
I B 21 240QUSKYH
I* CCSID
I B 25 280QUSKYJ
I* Offset Exc Data
I B 29 320QUSKYK
I* Length Exc Data
I* 33 33 QUSKYL
I* Reserved2
I*
I* 34 34 QUSKYM
I*
I*
I* Global Variables
I*
I DS
I 1 10 APINAM
I 11 30 CONHDL
I I 'QSYSLOBJP ' 31 40 EXTATR
I 41 41 LSTSTS
I I 'OBJP0200' 42 49 MBRLST
I I 'OBJD0100' 68 75 RJOBDF
I I '*ALL ' 76 85 SPCAUT
I I '*USER ' 86 95 SPCDMN
I I X'00' 96 96 SPCINT
I I 'ADOPTS QTEMP ' 97 116 SPCNAM
I I '*YES ' 117 126 SPCREP
I 127 176 SPCTXT
I I '*USRSPC ' 177 186 SPCTYP
I I 8 B 197 2000RCVLEN
I B 201 2040SIZENT
I I 1 B 205 2080SPCSIZ
I B 209 2120I
I B 213 2160NUMENT
I B 217 2200OFFSET
I B 221 2240STRPOS
IRCVVAR DS 2000
C*
C* Beginning of Mainline
C*
C* Two parameters are being passed into this program.
C*
C *ENTRY PLIST
C PARM USRPRF 10
C PARM OBJTYP 10
C*
C*****************************************************************
C EXSR INIT
C EXSR PROCES
C EXSR DONE
C*
C* End of MAINLINE
C*
C*
C*****************************************************************
C* Function: getlst
C*
C* Description: This function calls QSYLOBJP to build a list.
C*
C*****************************************************************
C*
C GETLST BEGSR
C MOVEL'OBJP0200'MBRLST
C*****************************************************************
C* Call QSYLOBJP API to generate a list. The continuation handle
C* is set by the caller of this function.
C*****************************************************************
C CALL 'QSYLOBJP'
C PARM SPCNAM User space/lib
C PARM MBRLST Member list
C PARM USRPRF User profile
C PARM OBJTYP Object type sc
C PARM CONHDL Continuation ha <span class="uicontrol" id="listRPG__Numthree"><a name="listRPG__Numthree"><!-- --></a>(3)</span>
C PARM QUSBN Error Code
C*****************************************************************
C* Check for errors on QSYLOBJP.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QSYLOBJP'APINAM
C EXSR APIERR
C ENDIF
C ENDSR
C*****************************************************************
C* Function: INIT
C*
C* Description: This function does all the necessary
C* initialization for this program and the
C* rest is done in the I specs.
C*****************************************************************
C INIT BEGSR
C*****************************************************************
C Z-ADD100 QUSBNB
C*****************************************************************
C* Call QUSROBJD to see if the user space was previously created
C* in QTEMP. If it was, simply reuse it.
C*****************************************************************
C CALL 'QUSROBJD'
C PARM RCVVAR Receiver Var
C PARM RCVLEN Rec Var Length
C PARM RJOBDF Format
C PARM SPCNAM Qual User Space
C PARM SPCTYP User object typ
C PARM QUSBN Error Code
C*
C QUSBNC IFGT 0
C*****************************************************************
C* If a CPF9801 error was received, then the user space was not
C* found.
C*****************************************************************
C QUSBND IFEQ 'CPF9801'
C*****************************************************************
C* Create a user space for the list generated by QSYLOBJP.
C*****************************************************************
C CALL 'QUSCRTUS'
C PARM SPCNAM Qual User Space
C PARM EXTATR Extended Attrib
C PARM SPCSIZ Size user space
C PARM SPCINT Space Initializ
C PARM SPCAUT Public Authorit
C PARM SPCTXT User space text
C PARM SPCREP Replace existin
C PARM QUSBN Error Code
C PARM SPCDMN Domain of us
C*****************************************************************
C* Check for errors on QUSCRTUS.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QUSCRTUS'APINAM
C EXSR APIERR
C ENDIF
C*****************************************************************
C* An error occurred accessing the user space.
C*****************************************************************
C ELSE
C MOVEL'QUSROBJD'APINAM
C EXSR APIERR
C ENDIF CPF9801 ELSE
C ENDIF BYTAVL &gt; 0
C*****************************************************************
C* Set QSYLOBJP (via GETLST) to start a new list.
C*****************************************************************
C MOVE *BLANKS CONHDL
C EXSR GETLST
C*****************************************************************
C* Let's retrieve the generic header information from the user
C* space since OPM RPG does not have pointer support.
C*****************************************************************
C Z-ADD1 STRPOS
C Z-ADD192 RCVLEN Format 100
C CALL 'QUSRTVUS'
C PARM SPCNAM Qual User Space
C PARM STRPOS Start Position
C PARM RCVLEN Length of Data
C PARM QUSBP Receiver Var.
C PARM QUSBN Error Code
C*****************************************************************
C* Check for errors on QUSRTVUS.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QUSRTVUS'APINAM
C EXSR APIERR
C ENDIF
C 1 ADD QUSBPQ STRPOS Offset to List <span class="uicontrol" id="listRPG__Numfive"><a name="listRPG__Numfive"><!-- --></a>(5)</span>
C ENDSR
C*****************************************************************
C* Function: proc2
C*
C* Description: This function processes each entry returned by
C* QSYLOBJP.
C*
C*****************************************************************
C PROC2 BEGSR
C CALL 'QUSRTVUS'
C PARM SPCNAM Qual User Space
C PARM STRPOS Start Position
C PARM SIZENT Length of Data
C PARM QSYB6 Receiver Var.
C PARM QUSBN Error Code
C*****************************************************************
C* Check for errors on QUSRTVUS.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QUSRTVUS'APINAM
C EXSR APIERR
C ENDIF
C EXCPTPRTENT
C*****************************************************************
C* After each entry, increment to the next entry.
C*****************************************************************
C STRPOS ADD SIZENT STRPOS <span class="uicontrol" id="listRPG__Numseven"><a name="listRPG__Numseven"><!-- --></a>(7)</span>
C ENDSR
C*****************************************************************
C* Function: proc1
C*
C* Description: This function processes each entry returned by
C* QSYLOBJP.
C*
C*****************************************************************
C PROC1 BEGSR
C*****************************************************************
C* If valid information was returned. <span class="uicontrol" id="listRPG__Numone"><a name="listRPG__Numone"><!-- --></a>(1)</span>
C*****************************************************************
C Z-ADDQUSBPS NUMENT
C QUSBPJ IFEQ 'P'
C QUSBPJ OREQ 'C'
C NUMENT IFGT 0
C*****************************************************************
C* Get the size of each entry to use later. <span class="uicontrol" id="listRPG__Numfour"><a name="listRPG__Numfour"><!-- --></a>(4)</span>
C*****************************************************************
C Z-ADDQUSBPT SIZENT
C*****************************************************************
C* Increment to the first list entry.
C*****************************************************************
C 1 ADD QUSBPQ OFFSET
C*****************************************************************
C* Process all of the entries.
C*****************************************************************
C 1 DO NUMENT I <span class="uicontrol" id="listRPG__Numsix"><a name="listRPG__Numsix"><!-- --></a>(6)</span>
C EXSR PROC2
C ENDDO
C*****************************************************************
C* If all entries in this user space have been processed, check
C* if more entries exist than can fit in one user space.
C****************************************************************
C QUSBPJ IFEQ 'P'
C*****************************************************************
C* Address the input parameter header.
C*****************************************************************
C 1 ADD QUSBPL STRPOS
C Z-ADD68 RCVLEN Format 100
C CALL 'QUSRTVUS'
C PARM SPCNAM Qual User Space
C PARM STRPOS Start Position
C PARM RCVLEN Length of Data
C PARM QUSBP Receiver Var.
C PARM QUSBN Error Code
C*****************************************************************
C* Check for errors on QUSRTVUS.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QUSRTVUS'APINAM
C EXSR APIERR
C ENDIF
C*****************************************************************
C* If the continuation handle in the input parameter header
C* is blank, then set the list status to complete.
C*****************************************************************
C QSYCRJ IFEQ *BLANKS
C MOVE 'C' LSTSTS
C ELSE
C***************************************************************
C* Else, call QSYLOBJP reusing the user space to get more
C* list entries.
C****************************************************************
C MOVELQSYCRJ CONHDL <span class="uicontrol" id="listRPG__Numtwo"><a name="listRPG__Numtwo"><!-- --></a>(2)</span>
C EXSR GETLST
C Z-ADD1 STRPOS
C Z-ADD192 RCVLEN Format 100
C CALL 'QUSRTVUS'
C PARM SPCNAM Qual User Space
C PARM STRPOS Start Position
C PARM RCVLEN Length of Data
C PARM QUSBP Receiver Var.
C PARM QUSBN Error Code
C*****************************************************************
C* Check for errors on QUSRTVUS.
C*****************************************************************
C QUSBNC IFGT 0
C MOVEL'QUSRTVUS'APINAM
C EXSR APIERR
C ENDIF
C MOVE QUSBPJ LSTSTS
C ENDIF HDL = BLANKS
C ENDIF INFOSTS = 0
C ELSE
C*****************************************************************
C*If there exists an unexpected status, log an error (not shown)
C*and exit.
C*****************************************************************
C EXSR DONE done();
C ENDIF #ENT &gt; 0
C ENDIF USRSPC=P/C
C ENDSR
C*****************************************************************
C* Function: proces
C*
C* Description: Processes entries until they are complete.
C*
C*****************************************************************
C PROCES BEGSR
C MOVELQUSBPJ LSTSTS
C LSTSTS DOUEQ'C'
C LSTSTS OREQ 'I'
C EXSR PROC1 proces1();
C ENDDO
C ENDSR
C*****************************************************************
C* Function: done
C*
C* Description: Exits the program.
C*
C*****************************************************************
C DONE BEGSR
C EXCPTENDLST
C SETON LR
C ENDSR
C*****************************************************************
C* Function: apierr
C*
C* Description: This function prints the API name, and exception
C* identifier of an error that occurred.
C*****************************************************************
C APIERR BEGSR
C APINAM DSPLY
C QUSBND DSPLY
C EXSR DONE
C ENDSR
O*****************************************************************
O* Function: PRTENT
O*
O* Description: This function prints the information returned in
O* user space.
O*****************************************************************
OQSYSPRT E 106 PRTENT
O 'Object: '
O QSYB6C
O 'Library: '
O QSYB6D
O 'Type: '
O QSYB6F
O 'Text: '
O QSYB6J
O*****************************************************************
O* Function: ENDLST
O*
O* Description: This function prints the end of listing print
O* line and returns to the caller.
O*****************************************************************
OQSYSPRT E 106 ENDLST
O '*** End of List'</pre>
<p>The value in the information status field is shown at <a href="#listRPG__Numone">(1)</a>. The continuation handle in the header section
to return the remaining information to the user space is shown at <a href="#listRPG__Numtwo">(2)</a>.
The user then passes this value back to the API as an input parameter so that
the API can locate the remaining information and place it in the user space,
as shown at <a href="#listRPG__Numthree">(3)</a>.</p>
</div>
<div class="section"><h4 class="sectiontitle">Processing a list</h4><p>This is the preferred method for
processing lists. To correctly process through a list, do the following:</p>
<ol><li>Use the offset to list data section field <a href="#listRPG__Numfive">(5)</a></li>
<li>Look at the number of list entries field in the list <a href="#listRPG__Numsix">(6)</a></li>
<li>For processing lists with fixed-length entries, add the size of each entry
field to get to the start of the next entry <a href="#listRPG__Numseven">(7)</a></li>
<li>For variable-length entries, you add the length of the entry (or displacement
in some cases) to the next entry.</li>
</ol>
<p>IBM<sup>®</sup> may
add fields to the bottom of formats in future releases. If this occurs and
your code uses the size of each entry for a previous release, your list would
not process at the start of each entry.</p>
<p>The example program defines
the size of each entry at <a href="#listRPG__Numfour">(4)</a>. For another
example that shows the correct and incorrect way, see Defining list entry
format lengths.</p>
<p>See the following for the same example in different
languages:</p>
<ul><li><a href="listCOBOL.htm">COBOL and ILE COBOL</a></li>
<li><a href="listILEC.htm">ILE C</a></li>
<li><a href="listILERPG.htm">ILE RPG</a></li>
</ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="listOverview.htm" title="List APIs return a list unique to a given API. The section discusses the characteristics of a list API and provides information that you should be aware of when you use list APIs.">List APIs overview</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="listUserWOPointer.htm" title="When programming in a language that does not support pointers, you can use the Change user space (QUSCHGUS) and Retrieve user space (QUSRTVUS) APIs to manipulate data. However, you must first understand how to use positions and lengths with these APIs.">Manipulate a user space without pointers</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="listGeneral.htm" title="Describes some of the more important fields that comprise the general data structure.">List Object API general data structure</a></div>
<div><a href="pgmerr_liste.htm" title="The example programs in this topic show how to code flexibility into your program as it works its way through the formats used by an API.">Define list entry format lengths</a></div>
<div><a href="listCOBOL.htm" title="The example program prints a report that shows all objects that adopt owner authority.">Example in ILE COBOL: List Object API</a></div>
<div><a href="listILEC.htm" title="The example program prints a report that shows all objects that adopt owner authority.">Example in ILE C: List Object API</a></div>
<div><a href="listILERPG.htm" title="The example program prints a report that shows all objects that adopt owner authority.">Example in ILE RPG: List Object API</a></div>
</div>
</div>
</body>
</html>