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

215 lines
9.3 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="Example in ILE COBOL: Retrieving a file description to a user space" />
<meta name="abstract" content="This program retrieves a file definition template to a user space." />
<meta name="description" content="This program retrieves a file definition template to a user space." />
<meta name="DC.Relation" scheme="URI" content="ExTaskRetfile.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="exretilecobol" />
<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 ILE COBOL: Retrieving a file description to a user space</title>
</head>
<body id="exretilecobol"><a name="exretilecobol"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example in ILE COBOL: Retrieving a file description to a user space</h1>
<div><p>This program retrieves a file definition template to a user space.</p>
<div class="section"><p>Refer to <a href="exretilec.htm">Example in ILE C: Retrieving a file description to a user space</a> for
the original example. The following program also works with OPM COBOL.</p>
<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> IDENTIFICATION DIVISION.
***************************************************************
***************************************************************
*
* Program: RTVFD
*
* Language: COBOL
*
* Description: This program retrieves a file definition
* template to a user space.
*
* APIs Used: QDBRTVFD - Retrieve File Description
* QUSCRTUS - Create User Space
* QUSCUSAT - Change User Space Attributes
* QUSPTRUS - Retrieve a pointer to a User Space
*
***************************************************************
***************************************************************
PROGRAM-ID. RTVFD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-AS400.
OBJECT-COMPUTER. IBM-AS400.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
* Error Code parameter include. As this sample program
* uses COPY to include the error code structure, only the first
* 16 bytes of the error code structure are available. If the
* application program needs to access the variable length
* exception data for the error, the developer should physically
* copy the QSYSINC include and modify the copied include to
* define additional storage for the exception data.
*
COPY QUSEC OF QSYSINC-QLBLSRC.
*
* Misc. elements
*
01 MISC.
05 EXIT-POINT-NAME PIC X(20) VALUE "EXAMPLE_EXIT_POINT".
05 EXIT-PGM-NBR PIC S9(09) VALUE -1 BINARY.
05 EXIT-PARAMETERS PIC X(10).
05 FILE-USED PIC X(20).
05 LIBRARY-NAME PIC X(10).
05 SPACE-SIZE PIC S9(09) BINARY.
05 SPACE-INIT PIC X(01) VALUE "X'00'".
05 SPACE-POINTER POINTER.
05 FORMAT-NAME-1 PIC X(08).
05 OVERRIDES PIC X(01) VALUE "0".
05 SYSTEM PIC X(10) VALUE "*LCL".
05 FORMAT-1 PIC X(10) VALUE "*INT".
05 EXT-ATTR PIC X(10).
05 SPACE-AUT PIC X(10) VALUE "*CHANGE".
05 SPACE-TEXT PIC X(50) VALUE "QDBRTVFD".
05 SPACE-REPLACE PIC X(10) VALUE "*YES".
05 SPACE-DOMAIN PIC X(10) VALUE "*USER".
05 API-NAME PIC X(10).
01 CHG-US-ATTR.
05 NBR-OF-ATTR PIC S9(09) VALUE 1 BINARY.
05 ATTR-KEY PIC S9(09) VALUE 3 BINARY.
05 DATA-SIZE PIC S9(09) VALUE 1 BINARY.
05 ATTR-DATA PIC X(01) VALUE "1".
*
LINKAGE SECTION.
01 SPACE-NAME PIC X(20).
01 FILE-NAME PIC X(20).
01 FORMAT-NAME-PARM PIC X(10).
*
* Retrieve File Description API include.
*
COPY QDBRTVFD OF QSYSINC-QLBLSRC.
*
* Beginning of mainline
*
PROCEDURE DIVISION USING SPACE-NAME, FILE-NAME,
FORMAT-NAME-PARM.
MAIN-LINE.
*
PERFORM INITIALIZE-SPACE.
PERFORM PROCESS-SPACE.
PERFORM PROGRAM-DONE.
*
* Start of subroutines
*
*****************************************************************
PROCESS-SPACE.
*
* The template returned from QDBRTVFD is now addressable by way
* of SPACE-POINTER; as an example the program will now display
* the access method for the file:
*
DISPLAY QDBFPACT OF QDB-QDBFH.
*
*****************************************************************
*
INITIALIZE-SPACE.
*
* One time initialization code for this program
*
* Set Error Code structure to not use exceptions
*
MOVE 16 TO BYTES-PROVIDED OF QUS-EC.
*
* Create a User Space for QDBRTVFD
*
MOVE 1024 TO SPACE-SIZE.
CALL "QUSCRTUS" USING SPACE-NAME, EXT-ATTR, SPACE-SIZE,
SPACE-INIT, SPACE-AUT, SPACE-TEXT,
SPACE-REPLACE, QUS-EC, SPACE-DOMAIN.
*
* Check for errors on QUSCRTUS
*
IF BYTES-AVAILABLE OF QUS-EC &gt; 0
MOVE "QUSCRTUS" TO API-NAME,
PERFORM API-ERROR-FOUND.
*
* Change the User Space so that it is extendable
*
CALL "QUSCUSAT" USING LIBRARY-NAME, SPACE-NAME,
CHG-US-ATTR, QUS-EC.
*
* Check for errors on QUSCUSAT
*
IF BYTES-AVAILABLE OF QUS-EC &gt; 0
MOVE "QUSCUSAT" TO API-NAME,
PERFORM API-ERROR-FOUND.
*
* Get a resolved pointer to the User Space
*
CALL "QUSPTRUS" USING SPACE-NAME, SPACE-POINTER, QUS-EC.
*
* Check for errors on QUSPTRUS
*
IF BYTES-AVAILABLE OF QUS-EC &gt; 0
MOVE "QUSPTRAT" TO API-NAME,
PERFORM API-ERROR-FOUND.
*
* If no errors, then call QDBRTVFD passing the address of the
* User Space as the receiver variable. To accomplish this,
* assign the address of QDB-QDBFH to SPACE-POINTER and then
* pass QDB-QDBFH.
*
SET ADDRESS OF QDB-QDBFH TO SPACE-POINTER.
*
MOVE 16776704 TO SPACE-SIZE.
MOVE "FILD0100" TO FORMAT-NAME-1.
*
CALL "QDBRTVFD" USING QDB-QDBFH, SPACE-SIZE, FILE-USED,
FORMAT-NAME-1, FILE-NAME,
FORMAT-NAME-PARM, OVERRIDES,
SYSTEM OF MISC, FORMAT-1, QUS-EC.
*
* Check for errors on QDBRTVFD
*
IF BYTES-AVAILABLE OF QUS-EC &gt; 0
MOVE "QDBRTVFD" TO API-NAME,
PERFORM API-ERROR-FOUND.
*****************************************************************
API-ERROR-FOUND.
*
* Log any error encountered, and exit the program
*
DISPLAY API-NAME.
DISPLAY EXCEPTION-ID OF QUS-EC.
PERFORM PROGRAM-DONE.
*****************************************************************
PROGRAM-DONE.
*
* Exit the program
*
STOP RUN.</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="ExTaskRetfile.htm" title="These programming examples show an application that uses a user space as a receiver variable by retrieving a file description to a user space. This approach is possible only if you use an HLL that is able to work with pointers.">Examples: Retrieving a file description to a user space</a></div>
</div>
</div>
</body>
</html>