I was playing around with last week while we were talking about it also. My version with a few fields that I had checked at the beginning of the year as part of some cleanup added, as well as trapping and returning any errors on the api.
https://code.midrange.com/30da2d4c66.html
On Fri, 2020-01-17 at 20:43 -0500, Bruce Vining wrote:
I've added just a little error checking to the sample program.  Where the
original from yesterday had:
  errCde.hdr.QUSBPrv = 0;
  RtvReuse( rcvVar      :%size(rcvVar)       :qualRtnFN
           :'FILD0100'  :(fileIn + libIn)    :' *FIRST'
           :'0'         :'*LCL'              :'*INT'
           :errCde);
  ptrPFAtrs = ptrRcvVar + baseFD.QDBPFOf;
  if %bitand(pFAtrs.QDBBits33 :x'80') = x'80';
    reuseSts = 'YES';
  else;
    reuseSts = 'NO';
  endif;
  *inlr = *on;
  return;
The new code is:
  errCde.hdr.QUSBPrv = 0;
  monitor;
    RtvReuse( rcvVar      :%size(rcvVar)       :qualRtnFN
             :'FILD0100'  :(fileIn + libIn)    :' *FIRST'
             :'0'         :'*LCL'              :'*INT'
             :errCde);
    if %bitand(%subst(baseFD.QDBBits27 :1 :1) :x'20') = x'00';
      ptrPFAtrs = ptrRcvVar + baseFD.QDBPFOf;
      if %bitand(pFAtrs.QDBBits33 :x'80') = x'80';
        reuseSts = 'YES';
      else;
        reuseSts = 'NO';
      endif;
    else;
      reuseSts = 'N/A';
    endif;
  on-error;
    reuseStsInd = -1;
  endmon;
  *inlr = *on;
  return;
Basically I added a monitor block around the API call and related
processing.  If a hard error is encountered (most likely with the API call)
then NULL will be returned by the function ('-' if using STRSQL) and a
message can be found in the joblog identifying the problem.  For instance
select reuse_deleted_records('QPRINT', 'QGPL') from  sysibm/sysdummy1
will return NULL and CPF3C23 (Object QPRINT is not a file of the correct
type) will be in the joblog.  Likewise a file not found will result in
messages such as CPF5715.
Within the monitor block, when processing the API output, I also added a
check to make sure the file being processed is a physical file/table.  If
not, then 'N/A' is returned by the function.  So if you select from
systables and do NOT filter on table_type (I would recommend still
filtering on the select to avoid unnecessary calls to the function) then
other file types (a view or logical file for instance), if encountered,
will be returned as 'N/A' as in (using STRSQL):
Select system_table_name, system_table_schema,
       Reuse_Deleted_Records(system_table_name,system_Table_schema)
From systables
where system_table_schema = 'VINING'
SYSTEM_TABLE_NAME  SYSTEM_TABLE_SCHEMA  Function
   DATES               VINING           YES
   HEX                 VINING           NO
   MYFILE              VINING           NO
   MYFILELF            VINING           N/A
   QCLSRC              VINING           NO
   QPNLSRC             VINING           NO
   QRPGLESRC           VINING           NO
   QSQDSRC             VINING           NO
   QSQLSRC             VINING           NO
   TEST                VINING           YES
   UCS2                VINING           YES
   VIEW1               VINING           N/A
While in the program I also noticed that I had neglected to remove the
declare for variable theFile.  That line can be removed.
There are plenty of other additions that could be made to the function, but
these two changes will detect/avoid some of the more obvious problems.
[
https://www.medtronsoftware.com/img/MedtronMinilogo.bmp]  Kevin  Bucknum
                   Senior Programmer Analyst
                   MEDDATA / MEDTRON
                   120 Innwood Drive
                   Covington LA 70433
                   Local: 985-893-2550
                   Toll Free: 877-893-2550
                 
https://www.medtronsoftware.com
CONFIDENTIALITY NOTICE
This document and any accompanying this email transmission contain confidential information, belonging to the sender that is legally privileged.  This information is intended only for the use of the individual or entity named above.  The authorized recipient of this information is prohibited from disclosing this information to any other party and is required to destroy the information after its stated need has been fulfilled.  If you are not the intended recipient, or the employee of agent responsible to deliver it to the intended recipient, you are hereby notified that any disclosure, copying, distribution or action taken in reliance on the contents of these documents is STRICTLY PROHIBITED.  If you have received this email in error, please notify the sender immediately to arrange for return or destruction of these documents.
As an Amazon Associate we earn from qualifying purchases.