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

265 lines
12 KiB
HTML

<?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="Examples: Define receiver variables" />
<meta name="abstract" content="When defining receiver variables, the most common error is to create them too small for the amount of data that they are to receive. Both of these example programs are coded in RPG and, when run, list all active jobs on the system." />
<meta name="description" content="When defining receiver variables, the most common error is to create them too small for the amount of data that they are to receive. Both of these example programs are coded in RPG and, when run, list all active jobs on the system." />
<meta name="DC.Relation" scheme="URI" content="pgmerr.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="pgmerr_receive" />
<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>Examples: Define receiver variables</title>
</head>
<body id="pgmerr_receive"><a name="pgmerr_receive"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Examples: Define receiver variables</h1>
<div><p>When defining receiver variables, the most common error is to create
them too small for the amount of data that they are to receive. Both of these
example programs are coded in RPG and, when run, list all active jobs on the
system.</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>
</div>
<div class="section" id="pgmerr_receive__receive_incorrect"><a name="pgmerr_receive__receive_incorrect"><!-- --></a><h4 class="sectiontitle">Example of incorrect coding: Defining
receiver variables</h4><p>The following example program may fail because
the receiver variable has been defined as 50 bytes, as shown at <a href="#pgmerr_receive__SPTRK7A">(1)</a>,
but 60 bytes are being requested to be passed back from the API, as shown
at <a href="#pgmerr_receive__SPTRK8A">(2)</a> in the incorrect program
and at <a href="#pgmerr_receive__SPTRK8B">(3)</a> in the correct program.
The correct coding is shown at <a href="#pgmerr_receive__SPTRK9B">(4)</a>.</p>
<p>When
this happens, other variables are overwritten with unintended data. This causes
the other variables to be incorrect. For example, the first 10 characters
of QUSBN may be written over with these extra characters. On the call to the
next API, the error code parameter may appear to contain meaningless characters
that would cause the next call to an API to fail.</p>
<pre> *****************************************************************
*
*Program Name: PGM1
*
*Program Language: RPG
*
*Description: This sample program illustrates the incorrect
* way of defining receiver variables.
*
*Header Files Included: QUSEC - Error Code Parameter
* QUSLJOB - List Job API
* QUSGEN - User Space Format for Generic Header
*
*APIs Used: QUSCRTUS - Create User Space
* QUSLJOB - List Job
* QUSRTVUS - Retrieve User Space
* QUSDLTUS - Delete User Space
*****************************************************************
* THIS PROGRAM WILL CREATE THE NECESSARY SPACE AND THEN CALL
* THE QUSLJOB API TO GET A LIST OF ALL ACTIVE JOBS ON THE SYSTEM.
* BRING IN THE GENERIC USER SPACE HEADER FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSGEN
*
* BRING IN THE ERROR STRUCTURE FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSEC
*
** JOBL0100 FORMAT RETURNED FROM QUSLJOB API
I/COPY QSYSINC/QRPGSRC,QUSLJOB
*
** JOB NAME STRUCTURE FOR CALLING QUSLJOB
IJOBNAM DS
I I '*ALL ' 1 10 JOB
I I '*ALL ' 11 20 USER
I I '*ALL' 21 26 JOBNUM
ISPCNAM DS
I I 'SPCNAME ' 1 10 SPC
I I 'QTEMP ' 11 20 LIB
** OTHER ASSORTED VARIABLES
I DS
I I 2000 B 1 40SIZ
I B 5 80START
I B 9 120LENDTA
I I X'00' 13 13 INTVAL
*
* SET UP TO ACCEPT EXCEPTIONS
C Z-ADD*ZEROS QUSBNB
*
* CREATE THE SPACE TO HOLD THE DATA
C CALL 'QUSCRTUS'
C PARM SPCNAM
C PARM 'EXT_ATTR'EXTATR 10
C PARM SIZ
C PARM INTVAL
C PARM '*ALL 'PUBAUT 10
C PARM 'TEXT DSC'TXTDSC 50
C PARM '*YES 'REPLAC 10
C PARM QUSBN
*
* CALL THE API TO LIST THE ACTIVE JOBS
C CALL 'QUSLJOB'
C PARM SPCNAM
C PARM 'JOBL0100'FORMAT 8
C PARM JOBNAM
C PARM '*ACTIVE 'STAT 10
C PARM QUSBN
*
* RETRIEVE THE OFFSET OF THE FIRST LIST ENTRY FROM THE SPACE
C Z-ADD1 START
C Z-ADD140 LENDTA
C CALL 'QUSRTVUS'
C PARM SPCNAM
C PARM START
C PARM LENDTA
C PARM QUSBP
C PARM QUSBN
*
* RETRIEVE THE LIST ENTRIES
C QUSBPQ ADD 1 START
*
C Z-ADD60 LENDTA <span class="uicontrol" id="pgmerr_receive__SPTRK8A"><a name="pgmerr_receive__SPTRK8A"><!-- --></a>(2)</span>
*
C Z-ADD1 X 90
C X DOWLEQUSBPS
C CALL 'QUSRTVUS'
C PARM SPCNAM
C PARM START
C PARM LENDTA
C PARM RECVR 50 <span class="uicontrol" id="pgmerr_receive__SPTRK7A"><a name="pgmerr_receive__SPTRK7A"><!-- --></a>(1)</span>
C PARM QUSBN
*
C MOVEL RECVR QUSDD
*
C ADD QUSBPT START
C ADD 1 X
C END
* DELETE THE SPACE THAT HELD THE DATA
C CALL 'QUSDLTUS'
C PARM SPCNAM
C PARM QUSBN
*
C SETON LR</pre>
</div>
<div class="section" id="pgmerr_receive__receive_correct"><a name="pgmerr_receive__receive_correct"><!-- --></a><h4 class="sectiontitle">Example: Defining receiver variables
of correct coding</h4><p>The following example program defines a larger
receiver variable: 60 bytes. This is shown at position <a href="#pgmerr_receive__SPTRK9B">(4)</a>.
This increase in the receiver variable allows up to 60 bytes of data to be
received.</p>
<pre> *****************************************************************
*
*Program Name: PGM2
*
*Program Language: RPG
*
*Description: This sample program illustrates the correct
* way of defining receiver variables.
*
*Header Files Included: QUSEC - Error Code Parameter
* QUSLJOB - List Job API
* QUSGEN - User Space Format for Generic Header
*
*APIs Used: QUSCRTUS - Create User Space
* QUSLJOB - List Job
* QUSRTVUS - Retrieve User Space
* QUSDLTUS - Delete User Space
*****************************************************************
*
* BRING IN THE ERROR STRUCTURE FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSEC
* BRING IN THE GENERIC USER SPACE HEADER FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSGEN
*
** JOBL0100 FORMAT RETURNED FROM QUSLJOB API
I/COPY QSYSINC/QRPGSRC,QUSLJOB
*
** JOB NAME STRUCTURE FOR CALLING QUSLJOB
IJOBNAM DS
I I '*ALL ' 1 10 JOB
I I '*ALL ' 11 20 USER
I I '*ALL' 21 26 JOBNUM
ISPCNAM DS
I I 'SPCNAME ' 1 10 SPC
I I 'QTEMP ' 11 20 LIB
** OTHER ASSORTED VARIABLES
I DS
I I 2000 B 1 40SIZ
I B 5 80START
I B 9 120LENDTA
I I X'00' 13 13 INTVAL
*
* SET UP TO ACCEPT EXCEPTIONS
C Z-ADD*ZEROS QUSBNB
*
* CREATE THE SPACE TO HOLD THE DATA
C CALL 'QUSCRTUS'
C PARM SPCNAM
C PARM 'EXT_ATTR'EXTATR 10
C PARM SIZ
C PARM INTVAL
C PARM '*ALL 'PUBAUT 10
C PARM 'TEXT DSC'TXTDSC 50
C PARM '*YES 'REPLAC 10
C PARM QUSBN
*
* CALL THE API TO LIST THE ACTIVE JOBS
C CALL 'QUSLJOB'
C PARM SPCNAM
C PARM 'JOBL0100'FORMAT 8
C PARM JOBNAM
C PARM '*ACTIVE 'STAT 10
C PARM QUSBN
*
* RETRIEVE THE OFFSET OF THE FIRST LIST ENTRY FROM THE SPACE
C Z-ADD1 START
C Z-ADD140 LENDTA
C CALL 'QUSRTVUS'
C PARM SPCNAM
C PARM START
C PARM LENDTA
C PARM QUSBP
C PARM QUSBN
*
* RETRIEVE LIST ENTRIES
C QUSBPQ ADD 1 START
*
C Z-ADD60 LENDTA <span class="uicontrol" id="pgmerr_receive__SPTRK8B"><a name="pgmerr_receive__SPTRK8B"><!-- --></a>(3)</span>
*
C Z-ADD1 X 90
C X DOWLEQUSBPS
C CALL 'QUSRTVUS'
C PARM SPCNAM
C PARM START
C PARM LENDTA
C PARM RECVR 60 <span class="uicontrol" id="pgmerr_receive__SPTRK9B"><a name="pgmerr_receive__SPTRK9B"><!-- --></a>(4)</span>
C PARM QUSBN
*
C MOVELRECVR QUSDD
C ADD QUSBPT START
C ADD 1 X
C END
* DELETE THE SPACE THAT HELD THE DATA
C CALL 'QUSDLTUS'
C PARM SPCNAM
C PARM QUSBN
*
C SETON LR
*</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="pgmerr.htm" title="Provides information about common programming errors, as well as examples of correct and incorrect coding.">Common API programming errors</a></div>
</div>
</div>
</body>
</html>