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

462 lines
22 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 C: List Object API" />
<meta name="abstract" content="The example program prints a report that shows all objects that adopt owner authority." />
<meta name="description" content="The 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="listRPG.htm" />
<meta name="DC.Relation" scheme="URI" content="listRPG.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="listILEC" />
<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 C: List Object API</title>
</head>
<body id="listILEC"><a name="listILEC"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example in ILE C: List Object API</h1>
<div><p>The 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>
<p>Refer to Example in RPG: List Object
API for the original example.</p>
<pre>/**********************************************************************/
/**********************************************************************/
/* */
/* Program: List objects that adopt owner authority */
/* */
/* Language: ILE C */
/* */
/* Description: This program prints a report showing all objects */
/* that adopt owner authority. The two parameters */
/* passed to the program are the profile to be */
/* checked and the type of objects to be listed. */
/* The parameter values are the same as those */
/* accepted by the QSYLOBJP API. */
/* */
/* APIs Used: QSYLOBJP - List Objects that Adopt Owner Authority */
/* QUSCRTUS - Create User Space */
/* QUSPTRUS - Retrieve Pointer to User Space */
/* QUSROBJD - Retrieve Object Description */
/* */
/**********************************************************************/
/**********************************************************************/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;qsylobjp.h&gt; /* QSYLOBJP API Header */
#include &lt;quscrtus.h&gt; /* QUSCRTUS API Header */
#include &lt;qusptrus.h&gt; /* QUSPTRUS API Header */
#include &lt;qusrobjd.h&gt; /* QUSROBJD API Header */
#include &lt;qusgen.h&gt; /* Format Structures for User Space */
#include &lt;qusec.h&gt; /* Error Code Parameter Include for the APIs */
#include &lt;qliept.h&gt; /* Entry Point Table Include */
/**********************************************************************/
/* Error Code Structure */
/* */
/* This shows how the user can define the variable length portion of */
/* error code for the exception data. */
/* */
/**********************************************************************/
typedef struct {
Qus_EC_t ec_fields;
char Exception_Data[100];
} error_code_t;
/**********************************************************************/
/* Global Variables */
/**********************************************************************/
char api_name[10];
char cont_hdl[20];
char ext_attr[10];
char list_status;
char mbr_list[8];
char obj_type[10];
char rcvvar[8];
char rjobd_fmt[8];
char space_auth[10];
char space_dmn[10];
char space_init;
char space_name[20];
char space_rep[10];
char space_text[50];
char space_type[10];
char usr_prf[10];
char *usrspc_ptr, *usrspc_base;
int rcvlen = 8;
int size_entry;
int space_size = 1;
error_code_t error_code;
FILE *record;
/**********************************************************************/
/* Function: done */
/* */
/* Description: This function prints the end of listing print line */
/* and returns to the caller. */
/**********************************************************************/
void done()
{
char command_string[32];
fwrite("*** End of List",1, 15, record);
fclose(record);
exit();
} /* done */
/**********************************************************************/
/* Function: apierr */
/* */
/* Description: This function prints the API name, and exception */
/* identifier of an error that occurred. */
/**********************************************************************/
void apierr()
{
printf("API: %.10s\n", api_name);
printf("Failed with exception: %.7s\n",
error_code.ec_fields.Exception_Id);
done();
} /* apierr */
/**********************************************************************/
/* Function: getlst */
/* */
/* Description: This function calls QSYLOBJP to build a list. */
/* */
/**********************************************************************/
void getlst()
{
memcpy(mbr_list, "OBJP0200", 8);
/********************************************************************/
/* Call QSYLOBJP API to generate a list. The continuation handle */
/* is set by the caller of this function. */
/********************************************************************/
QSYLOBJP(space_name, /* User space and library */
mbr_list, /* Member list */
usr_prf, /* User profile */
obj_type, /* Object type */
cont_hdl, /* Continuation handle <span class="uicontrol">(3)</span> */
&amp;error_code); /* Error code */
/********************************************************************/
/* Check for errors on QSYLOBJP. */
/********************************************************************/
if(error_code.ec_fields.Bytes_Available &gt; 0)
{
memcpy(api_name, "QSYLOBJP ", 10);
apierr();
}
} /* getlst */
/**********************************************************************/
/* Function: init */
/* */
/* Description: This function does all the necessary initialization */
/* for this program. */
/**********************************************************************/
void init()
{
memcpy(space_name, "ADOPTS QTEMP ", 20);
space_init = 0x00;
memcpy(mbr_list, "OBJP0200", 8);
memcpy(rjobd_fmt, "OBJD0100", 8);
memcpy(space_type, "*USRSPC ", 10);
memcpy(ext_attr, "QSYLOBJP ", 10);
memcpy(space_auth, "*ALL ", 10);
memcpy(space_rep, "*YES ", 10);
memcpy(space_dmn, "*USER ", 10);
/********************************************************************/
/* Open QPRINT file so that data can be written to it. If the file */
/* cannot be opened, print a message and exit. */
/********************************************************************/
if((record = fopen("QPRINT", "wb, lrecl=132, type=record")) == NULL)
{
printf("File could not be opened\n");
exit(1);
}
error_code.ec_fields.Bytes_Provided = sizeof(error_code_t);
/********************************************************************/
/* Call QUSROBJD to see if the user space was previously created in */
/* QTEMP. If it was, simply reuse it. */
/********************************************************************/
QUSROBJD(rcvvar, /* Receiver variable */
rcvlen, /* Receiver variable length */
rjobd_fmt, /* Format */
space_name, /* User space name and library */
space_type, /* User object type */
&amp;error_code); /* Error code */
if(error_code.ec_fields.Bytes_Available &gt; 0)
{
/******************************************************************/
/* If a CPF9801 error was received, then the user space was not */
/* found. */
/******************************************************************/
if(memcmp(error_code.ec_fields.Exception_Id, "CPF9801", 7) == 0)
{
/****************************************************************/
/* Create a user space for the list generated by QSYLOBJP. */
/****************************************************************/
QUSCRTUS(space_name, /* User space name and library */
ext_attr, /* Extended attribute */
space_size, /* Size of the user space */
&amp;space_init, /* Space initialization */
space_auth, /* Public authority to user space */
space_text, /* User space text */
space_rep, /* Replace existing user space? */
&amp;error_code, /* Error Code */
space_dmn); /* Domain of created user space */
/****************************************************************/
/* Check for errors on QUSCRTUS. */
/****************************************************************/
if(error_code.ec_fields.Bytes_Available &gt; 0)
{
memcpy(api_name, "QUSCRTUS ", 10);
apierr();
}
}
/******************************************************************/
/* An error occurred accessing the user space. */
/******************************************************************/
else
{
memcpy(api_name, "QUSRJOBD ", 10);
apierr();
}
}
/******************************************************************/
/* Set QSYLOBJP (via GETLST) to start a new list. */
/******************************************************************/
memset(cont_hdl, ' ', 20);
getlst();
/******************************************************************/
/* Get a resolved pointer to the user space for performance. */
/******************************************************************/
QUSPTRUS(space_name, /* User space name and library */
&amp;usrspc_ptr, /* User space pointer */
&amp;error_code); /* Error Code */
/******************************************************************/
/* Check for errors on QUSPTRUS. */
/******************************************************************/
if(error_code.ec_fields.Bytes_Available &gt; 0)
{
memcpy(api_name, "QUSPTRUS ", 10);
apierr();
}
usrspc_base = usrspc_ptr;
} /* init */
/**********************************************************************/
/* Function: proces2 */
/* */
/* Description: This function processes each entry returned by */
/* QSYLOBJP. */
/* */
/**********************************************************************/
void proces2()
{
char obj_type[112];
sprintf(obj_type, "Object: %.10s Library: %.10s Type: %.10s Text: %.50s\n",
((Qsy_OBJP0200_List_T *)usrspc_ptr)-&gt;Object.Name,
((Qsy_OBJP0200_List_T *)usrspc_ptr)-&gt;Object.Library,
((Qsy_OBJP0200_List_T *)usrspc_ptr)-&gt;Object_Type,
((Qsy_OBJP0200_List_T *)usrspc_ptr)-&gt;Object_Text);
fwrite(obj_type, 1, 112, record);
/********************************************************************/
/* After each entry, increment to the next entry. */
/********************************************************************/
usrspc_ptr += size_entry; <span class="uicontrol">(7)</span>
} /* proces2 */
/**********************************************************************/
/* Function: proces1 */
/* */
/* Description: This function processes each entry returned by */
/* QSYLOBJP. */
/* */
/**********************************************************************/
void proces1()
{
int i;
int num_entries;
int offset;
num_entries = ((Qus_Generic_Header_0100_t *)\
usrspc_ptr)-&gt;Number_List_Entries;
/********************************************************************/
/* If valid information was returned. <span class="uicontrol">(1)</span> */
/********************************************************************/
if((((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Information_Status == 'C') ||
(((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Information_Status == 'P'))
{
if(num_entries &gt; 0)
{
/****************************************************************/
/* Get the size of each entry to use later. <span class="uicontrol">(4)</span> */
/****************************************************************/
size_entry = ((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Size_Each_Entry;
/****************************************************************/
/* Increment to the first list entry. */
/****************************************************************/
offset = ((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Offset_List_Data; <span class="uicontrol">(5)</span>
usrspc_ptr += offset;
/****************************************************************/
/* Process all of the entries. */
/****************************************************************/
for(i=0; i&lt;num_entries; i++) <span class="uicontrol">(6)</span>
proces2();
/****************************************************************/
/* Reset the user space pointer to the beginning. */
/****************************************************************/
usrspc_ptr = usrspc_base;
/****************************************************************/
/* If all entries in this user space have been processed, check */
/* if more entries exist than can fit in one user space. */
/****************************************************************/
if(((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Information_Status == 'P')
{
/**************************************************************/
/* Address the input parameter header. */
/**************************************************************/
offset = ((Qus_Generic_Header_0100_t *)\
usrspc_ptr)-&gt;Offset_Input_Parameter;
usrspc_ptr += offset;
/**************************************************************/
/* If the continuation handle in the input parameter header */
/* is blank, then set the list status to complete.
/**************************************************************/
if(memcmp(((Qsy_OBJP_Input_T *)usrspc_ptr)-&gt;Continuation_Handle,
" ", 20) == 0)
{
list_status = 'C';
}
else
/**************************************************************/
/* Else, call QSYLOBJP reusing the user space to get more */
/* list entries. */
/**************************************************************/
{
memcpy(cont_hdl, ((Qsy_OBJP_Input_T *)\
usrspc_ptr)-&gt;Continuation_Handle, 20); <span class="uicontrol">(2)</span>
getlst();
list_status = ((Qus_Generic_Header_0100_t *)\
usrspc_ptr)-&gt;Information_Status;
}
}
}
else
/******************************************************************/
/* If there exists an unexpected status, log an error (not shown) */
/* and exit. */
/******************************************************************/
{
done();
}
}
} /* proces1 */
/**********************************************************************/
/* Function: proces */
/* */
/* Description: Processes entries until they are complete. */
/* */
/**********************************************************************/
void proces()
{
list_status = ((Qus_Generic_Header_0100_t *)usrspc_ptr)-&gt;Information_Status;
do
{
proces1();
} while (list_status != 'C');
} /* proces */
/**********************************************************************/
/* main */
/**********************************************************************/
main(int argc, char *argv[])
{
/********************************************************************/
/* Make sure we received the correct number of parameters. The argc */
/* parameter will contain the number of parameters that was passed */
/* to this program. This number also includes the program itself, */
/* so we need to evaluate argc-1. */
/********************************************************************/
if (((argc - 1) &lt; 2) || ((argc - 1 &gt; 2)))
/********************************************************************/
/* We did not receive all of the required parameters so exit the */
/* program. */
/********************************************************************/
{
exit(1);
}
else
/********************************************************************/
/* Copy parameters into local variables. */
/********************************************************************/
{
memcpy(usr_prf, argv[1], 10);
memcpy(obj_type, argv[2], 10);
}
init();
proces();
done();
} /* main */
</pre>
</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="relref"><strong>Related reference</strong><br />
<div><a href="listRPG.htm" title="This example program prints a report that shows all objects that adopt owner authority.">Example in RPG: List Object API</a></div>
</div>
</div>
</body>
</html>