search results

Devel(UP) Your Skills

Wednesday, October 27, 2021

SQL to find any interactive jobs

 SQL to find any interactive jobs

Quick SQL query (SQL400) to find any interactive jobs that are waiting for a reply to an inquiry message:

SELECT
    X1.JOB_NAME, X1.AUTHORIZATION_NAME, X3.program_name, X3.program_library_name
    FROM (select job_name, authorization_name from TABLE(QSYS2.ACTIVE_JOB_INFO(
           SUBSYSTEM_LIST_FILTER => 'QINTER')) x0 where x0.job_status = 'DSPW')
    AS X1,
   LATERAL
   (select * from table(qsys2.stack_info(x1.job_name)) x2
where x2.entry_type = 'OPM' order by ordinal_position desc limit 1 )
   AS x3
where (x3.program_name = 'QDMACCIN') and (x3.program_library_name = 'QSYS')

Reading Source Members in SQL400


Reading Source Members in SQL400

READSRC (Read Source File Member) is an SQL Table Function that accepts the source file library, file name, and member name input parameters and returns the Source Sequence number, Statement Changed Date, and the Source Statement Line itself. 

Suppose you want to view the contents of the last source member added to the QRPGLESRC source file. Using READSRC() you would specify the following

select * from table( sqltools.readsrc( 'yourlib', 'qrpglesrc', '*last'))

notes: yourlib (library name). you can use *last, *first, member name.

We have alternate traditional way to access source member by OVRDBF or CREATE ALIAS. But this new way helps user to access the source from anywhere like 5250, RDi, iNavigator etc.

Tuesday, October 26, 2021

Copy Data from Remote to Local #IBMi

 

Copy Data from Remote to Local #IBMi

how to copy data from a remote system to the local system using Db2 SQL.

The key is to use the 3-level naming support available in Db2 for i for about 10 years. Basically you can code something like the following to get to a remote location's database files:

SELECT * FROM CHICAGO.QIWS.QCUSTCDT;

Run this from SQL iQuery, the Command Entry screen, or from IBM ACS and it will pull in the records from the QCUSTCDT file on the remote server named CHICAGO.

To make this all work you need to have the remote location identified on your system. The WRKRDBDIRE command is used to setup these remote entries. Basically you give it a name, the IP address, and a couple of settings. For example, to setup the CHICAGO remote location, you might code the following:

ADDRDBDIRE RDB(CHICAGO) RMTLOCNAME('8.8.8.8' *IP) RMTAUTMTH(*USRID)

I used the *USRID option for remote authentication, but the default value may be best for your shop--basically this controls what is sent to the remote for the Authentication step (e.g., the equivalent of Sign On). When mixing IBM i release levels, as I always have to accommodate, then *USRID works best in my situation, but your situation would be different.

To pull in data from a remote file we combined the 3-level names with an INSERT statement. Consider the following INSERT statement that copies data from the remote CHICAGO location to the local system.

INSERT INTO MYDATA.CUSTOMERS
SELECT * from CHICAGO.MYDATA.CUSTOMERS WHERE BALDUE > 10000;

In this example, the customers located on the Chicago server are copied to the CUSTOMERS file on the local system when the remote record's BALDUE is over $10,000.

What about Functions? For example, one of our SQL iQuery customers has Power systems installed in nearly a dozen locations--all of which are on different land masses (i.e., islands). So the ability to drive there and check out the system isn't a frequent occurrence. I put together a little script that uses the #SQLTools DISK_LIST UDTF (you can use IBM's SYSDISKSTAT on V7R3 and later) to pull in the current status of the Disk drivers on those remote systems. The so called Protection Status column containing anything except 'ACTIVE' (e.g., DEGREDATED) is what we are looking for. IBM added PROTECTION_STATUS in a late TR on V7R3/R4 but not to R2 so if your disks are degraded SYSDISKSTAT won't help you know this.

When using a UDTF, you can't qualify it to 3-level name; that is chicago.sqltools.disk_list() will return a syntax error. But there is a work around!

You move the 3-level name to a dummy WHERE clause and the SQL processor realizes what you're doing and allows it. For example:

SELECT * FROM table( SQLTOOLS.DISK_LIST() ) d
WHERE EXISTS (SELECT * FROM CHICAGO.sysibm.sysdummy1);

This runs perfectly as expected!

Of course I realize if you're on V7R3 or later, then in the context of Disk Protection Status, you can easily use the following, instead:

select unit_number, resource_name, percent_used,protection_status
from chicago.qsys2.sysdiskStat;

Remember that a single physical system can contain multiple partitions (e.g., Production of DevOps). Three-level naming can be used between those partitions just the same. This provides an easy way to update data on the development partition when savrstobj isn't configured or isn't right for the situation.

Country calling code