Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
SQL iQuery Documentation - UDF and UDTF
has no ratings.
Published: 20 Jun 2019
Revised: 12 Sep 2019 - 403 days ago
Last viewed on: 19 Oct 2020 (1288 views) 
  1. SQL iQuery - RUNiQRY CL Command
  2. CSV() - Read and Parse Comma Separated Values File
  3. CSV_VAL() Extract CSV Column Value
  4. CSV_XXXX() Extract CSV Column Value as xxxx
  5. CSV_COUNT - Retrieve Field Count
  6. ObjExist - Check Object Exits
  7. DTAARA - Data Area
  8. encode_URL Encode URL for the Web
  9. encode_TAG Encode HTML TAG Content
  10. FLDLIST - List the Fields of a Table
  11. FROMHEX - Fold 2-hex Chars into 1 Char
  12. GET CPUCNT, CURLIB, ENV, SRLNBR, SYSNAME
  13. MD5_HASH - UDF - Return MD5 Hash
  14. ifsStat - Get IFS File Attributes
  15. ifsExists - Check if IFS File Exists
  16. ifsFile - Query Contents of IFS Text File
  17. ifsDIR - List IFS Directory Entires
  18. DEPFILE - List Dependent Database Relations
  19. JOB - Get Job Name Component
  20. Job_ATTR - Job Attributes
  21. JOB_DATE Retrieve the Job Date
  22. JOBLOG - Write Message to Joblog
  23. Library List UDF and Procedures
  24. MBRLIST - Member List
  25. MCHINFO Machine Type and Model Number and OS version
  26. OSVER and OSVRM Get IBM i Version/Release
  27. PrintPDF - Print a PDF to a PDF Compatible Printer
  28. CPYTOPDF - Copy SPOOLED File to PDF file
  29. OBJ_LIST List Object in a Library
  30. LIB_LIST List Descriptions of Libraries on the Library List
  31. OBJ_EXPORTS List Exported Items from an Object
  32. OBJ_STRUCT Retrieve Objects Components
  33. RTVCMDD Retrieve Command Definition
  34. RTVJOBA - Retrieve Job Attributes
  35. RTVJOBD - Retrieve Job Description
  36. RTVLASTSPLF - Retrieve ID of Last SPOOLED File for this Job
  37. RTVxxx - Retrieve Various Objects Description Table Functions
  38. WATCHLIST - List Current Watches
  39. Polymorphic Qualified Name Syntax

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

iQuery.objExists - UDF Published by: Bob Cozzi on 20 Jun 2019 view comments

Check Object Exists

[ NOTE: CHKOBJ() has been deprecated. The OBJEXISTS() UDF is preferred over CHKOBJ(). We shall continue to ship CHKOBJ() and evetually it will become a wrapper for OBJEXISTS(). ]

The iQuery.objExists() UDF checks to see if the object exists. If it exists, the UDF returns 1, otherwise it returns 0.

Note: This function uses our polymorphic qualified name syntax.

Parameters

iQuery.objExists( 'library-name', 'object-name', 'object-type' = *FILE, quietMode = 1);

iQuery.objExists( 'object-name', 'object-type' = *FILE, quietMode = 1);

The library-name is the name of the library that contains the object-name specified on the second parameter. This parameter may be a library name, or a special value including *LIBL and *CURLIB. Long SQL names are supported.

The object-name is the name of the object to be checked for existence. SQL long names are supported. In form 2, the object name may be a fully qualified object name (e.g., qgpl/qrpglesrc) or just the object name (unqualified).

The object-type is the IBM i system object type, such as *FILE, *PGM, *LIB, *DTAARA, etc. with or without the leading asterisk. If unspecified, the default is *FILE.

The quoteMode controls whether to generate an Object Not Found message in the joblog. The original SQL iQuery CHKOBJ() UDF defaulted to 0, which meant users who processed long lists of object were seeing lots of "Object Not Found" messages in their joblog. The default for OBJEXISTS() is to run in quite mode and not log the not found message. To log the Not Found message, specify 0 for this parameter, to avoid logging the Not Found message, specify 1 for this parameter, this is the default. 

Return Value

The return value is 1 if the object exists, otherwise 0 is returned.

Examples

Check if the file ORDERSUM in lirary SALESLIB exists. 
dcl-s exists int(10);
exec sql values iQuery.objExists('SALESLIB', 'ORDERSUM') into :EXISTS;
if (exists = 1); // Does the file exist?
exec SQL drop table saleslib.ordersum;
endif;
Using qualified syntax to check if the data area ORDERSEQ exists.
dcl-s exists int(10);
dcl-s nextOrder varchar(7);
exec sql values iQuery.objExists('SALESLIB/ORDERSEQ','*dtaara') into :EXISTS;
if (exists = 1); // Does the data area exist?
exec SQL select value INTO :nextOrder
FROM table(iQuery.dtaara('SALESLIB/ORDERSEQ')) da;
endif;

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS