/** * \brief Vector Example 2 * * This example shows how to add more complex data to a vector. * *

* * Every object from the passed library or QGPL will be listed. * The object name and type are displayed. * * \author Mihael Schmidt * \date 30.01.2009 * * \param Library name */ HDFTACTGRP(*NO) HACTGRP(*CALLER) *------------------------------------------------------------------------- * PEP *------------------------------------------------------------------------- D main PR extpgm('VECTOR02') D library 10A const options(*nopass) D main PI D library 10A const options(*nopass) *------------------------------------------------------------------------- * Prototypes *------------------------------------------------------------------------- /copy VECTOR_H /copy API_ERR_H /copy USRSPC_H /copy QUSLOBJ_H * D local_listObjects... D PR D vector * const D library 10A const * D local_createUserspace... D PR * D usName 10A D usLib 10A D usPtr S * *------------------------------------------------------------------------- * Data structures *------------------------------------------------------------------------- D tmpl_object DS qualified based(nullPointer) D name 10A D library 10A D type 10A D extAttr 10A D desc 50A D userDefAttr 10A *------------------------------------------------------------------------- * Variables *------------------------------------------------------------------------- D lib S 10A inz('QGPL') D vector S * D tmp S 50A D i S 10I 0 D ptr S * D entry DS likeds(tmpl_object) based(ptr) /free if (%parms() = 1); // library has been passed lib = library; endif; vector = vector_create(); // add spooled files of the current user to the vector // in form of local_listObjects(vector : lib); // display number of entries dsply %trimr('Number of entries: ' + %char(vector_getSize(vector))); if (vector_getSize(vector) = 0); dsply 'No objects in this library.'; elseif (vector_getSize(vector) <= 100); for i = 0 to vector_getSize(vector) - 1; ptr = vector_get(vector : i); dsply %trimr(%trimr(entry.name) + ' (' + %trimr(entry.type) + ')'); endfor; else; dsply 'There are more than 100 entries in this library.'; dsply 'Choose a smaller library.'; endif; // free all allocated memory of the vector vector_dispose(vector); *inlr = *on; return; /end-free /** * \brief List objects * * The objects of the passed library are retrieved and put into the * passed vector. The format of the entry is as follows: * * * * \param Pointer to the vector * \param Library name */ P local_listObjects... P B D PI D vector * const D library 10A const * D usName S 10A inz('VECTOR02') D usLib S 10A inz('QTEMP') D usPtr S * D usHeader DS likeds(userspace_gen) based(usPtr) D i S 10I 0 * D ptr S * D object DS qualified based(ptr) D name 10A D library 10A D type 10A D infoStatus 1A D extAttr 10A D desc 50A D userDefAttr 10A D reserved 7A * D entry DS likeds(tmpl_object) /free // create userspace usPtr = local_createUserspace(usName : usLib); if (usPtr = *null); return; endif; // list my spooled files listObjects( usName + usLib : 'OBJL0100' : '*ALL ' + library : '*ALL' : apiErrDs ); if (apiErrCode = *blank); for i = 0 to usHeader.nmbrEntries - 1; ptr = usPtr + usHeader.offsetList + (i * usHeader.entrySize); // fill data structure for vector entry entry.name = object.name; entry.library = object.library; entry.type = object.type; entry.extAttr = object.extAttr; entry.desc = object.desc; entry.userDefAttr = object.userDefAttr; vector_add(vector : %addr(entry) : %size(entry)); endfor; endif; // remove userspace (if it was created) if (usPtr <> *null); deleteUserspace(usName + usLib : apiErrDs); endif; /end-free P E /** * \brief Create userspace * * Creates a userspace with the passed object name and library and * returns a pointer to that userspace. Any existing userspace with * the passed name will be replaced. * * \param User space name * \param User space library * * \return Pointer to the created user space or *null if no user space * could be created. */ P local_createUserspace... P B D PI * D usName 10A D usLib 10A D usPtr S * /free createUserSpace(usName + usLib : *blank : 4096 : X'00' : '*ALL' : 'Vector Example UserSpace' : '*YES' : apiErrDs ); if (apiErrCode <> *blank); return *null; endif; // change user space attributes to autoextend userspace_attr.size = 1; // 1=attribute will be changed userspace_attr.key = 3; // 3=extensibility attribute userspace_attr.dataLength = 1; userspace_attr.data = '1'; // user space is extensible changeUserspaceAttr(usLib : usName + usLib : userspace_attr : apiErrDs); if (apiErrCode <> *blank); return *null; endif; retrieveUserspacePtr(usName + usLib : usPtr : apiErrDs); if (apiErrCode <> *blank); return *null; else; return usPtr; endif; /end-free P E