Im aktuellen Artikel wird gezeigt, wie IBM i Services vom Typ TABLE FUNCTION mit Db2 Web Query verarbeitet werden können. Die Beispiele und deren Erläuterung betreffen das Thema Jobs und ihre Stati. Die Auswahl kann variabel und dynamisch erfolgen.
IBM i Services vom Typ TABLE FUNCTION
Alle Formen von IBM i SQL-Services können mit Db2 Web Query verarbeitet werden. Dies sind im einzelnen: Tabellen (TABLE), Tabellen-Funktionen (TABLE FUNCTION), Ansichten (VIEW), Skalar-Funktionen (SCALAR FUNCTION) und Gespeicherte Prozeduren (STORED PROCEDURE). Im aktuellen Artikel wird ein Service vom Typ TABLE FUNCTION verwendet.
Mit dem IBM i Service QSYS2.Services_Info vom Objekttyp VIEW erhält man eine Liste aller verfügbaren IBM i Services. Die folgende SQL-Anweisung liefert alle Services vom Typ TABLE FUNCTION:
— Liste aller Services als TABLE FUNCTION
Select *
From Qsys2.Services_Info
Where Sql_Object_Type = ‘TABLE FUNCTION’
Order By Service_Name;
— Wieviele Services als TABLE FUNCTION gibt es?
Select count(*)
From Qsys2.Services_Info
Where Sql_Object_Type = ‘TABLE FUNCTION’; — 59
In meinen Beispielen verwende ich den Service QSYS2.ACTIVE_JOB_INFO.
Die Spalte SAMPLE enthält für jeden Service ein SQL-Beispiel.
Select Service_Category, Service_Schema_Name, Service_Name, Sql_Object_Type, Example
From Qsys2.Services_Info
Where Sql_Object_Type = ‘TABLE FUNCTION’ And Service_Name = ‘ACTIVE_JOB_INFO‘;
Beim Service QSYS2.ACTIVE_JOB_INFO ist das:
— Description: Find the top 10 consumers of CPU in the QUSRWRK and QSYSWRK subsystems
Select Cpu_Time, A.*
From Table (
Qsys2.Active_Job_Info(Subsystem_List_Filter => ‘QUSRWRK,QSYSWRK’)
) A
Order By Cpu_Time Desc
Limit 10;
Hieraus ist ersichtlich, wie ein Service vom Typ TABLE FUNCTION syntaktisch verwendet wird.
Weitere Infos zu QSYS2.ACTIVE_JOB_INFO finden Sie unter: https://www.ibm.com/docs/en/i/7.3?topic=services-active-job-info-table-function
Tipps: Beim Arbeiten mit ACS und Run SQL Scripts haben Sie folgende Unterstützung:
Die zu lösende Aufgabe
Wie kann man alle aktiven Jobs ermitteln, die einen bestimmten Status haben? Insbesondere geht es um Jobs, die den Status ‘MSGW‘ (Message Waiting) haben und deshalb auf eine Antwort durch den Administrator warten.
Zur Lösung der Aufgabe gibt es verschiedene Ansätze und Möglichkeiten. Neben der manuellen Variante mit WRKACTJOB kann dies mit SQL und auch als CL-Programm mit ‘Embedded SQL‘ erfolgen. Die vierte Variante ist dann die Lösung mit Web Query. Schauen wir uns die einzelnen Varianten an.
Lösung-1 – Manuell mit WRKACTJOB
Mit dem CL-Befehl WRKACTJOB werden standardmäßig alle aktiven Jobs angezeigt. Unter anderem ist eine Selektion nach Subsystem möglich. Es besteht aber keine Möglichkeit, über einen Parameter Jobs mit dem Status ‘MSGW‘ herauszufiltern. Dazu sind manuelle Eingriffe erforderlich.
Mit der Funktionstaste F20 können Sie die Sortierfolge in ‘*STS‘ ändern. Und danach mit F7 die Zeichenfolge ‘MSGW‘ in der Spalte ‘*STS‘ suchen.
Lösung-2 – Mt SQL
Wie oben bereits erwähnt, enthält die Db2 einen Service QSYS2.ACTIVE_JOB_INFO. Mit den folgenden SQL-Beispielen erhalten Sie Informationen zu dem Service:
— welche Stati gibt es? –> Auswahlliste Db2 Web Query
Select distinct Job_Status
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
)
order by Job_Status;
— wieviele Stati gibt es?
Select count(distinct Job_Status)
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
); — 12
— alle Jobs anzeigen
Select *
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
)
— Jobs mit Status EVTW
Select *
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
)
Where Job_Status = ‘EVTW’;
Die folgende SQL-Anweisung liefert die gewünschte Lösung:
— Jobs mit Status MSGW
Select *
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
)
Where Job_Status = ‘MSGW’;
Lösung-3 – Mit CL-Programm
Die zuvor ermittelte SQL-Anweisung kann auch in einem CL-Programm mit dem CL-Befehl RUNSQL eingesetzt werden. Hier ist die Programm-Quelle:
/* CL-Programm JOBSMSGW */
pgm
RUNSQL SQL(‘drop table qtemp.jobsmsgw if exists’) +
COMMIT(*NONE)
RUNSQL SQL(‘CREATE TABLE qtemp.jobsmsgw AS (SELECT +
Job_Status, Job_Name, Subsystem +
FROM Table +
(Qsys2.Active_Job_Info(Detailed_Info => +
”ALL”)) +
Where Job_Status = +
”MSGW”) –
WITH DATA’) COMMIT(*NONE) NAMING(*SQL)
RUNQRY QRYFILE((QTEMP/JOBSMSGW))
endpgm
Mit dem Einsatz einer Variablen für die Spalte Job_Status kann das Programm auch für die Abfrage von anderen Stati verwendet und damit auch flexibler verwendet werden.
Lösung-4 – Mit Db2 Web Query
Und hier folgt nun die Lösung mit Db2 Web Query. Dazu verwende ich die SQL-Anweisung mit der Tabellenfunktion QSYS2.ACTIVE_JOB_INFO:
— alle Jobs anzeigen
Select *
From Table (
Qsys2.Active_Job_Info(Detailed_Info => ‘ALL’)
)
;
Für die Verarbeitung mit Db2 Web Query wird ein Synonym benötigt. Dazu setze ich das Feature EZ-Report ein. Dieses finden Sie im Ordner IBM Db2 Web Query Developer Utilities.
Für die Erstellung des Synonyms und eines Reports fülle ich die benötigten Angaben wie folgt aus:
In das Feld SQL Statement kopiere ich einfach die obige Select-Anweisung und führe den Erstellungsprozess aus. Danach erscheint die folgende Erfolgsmeldung:
Mit EZ-Report wird sowohl ein Synonym, als auch ein Report mit dem angegebenen Namen erstellt.
Diesen Report verwende ich nun als Grundlage und führe folgende Änderungen und Erweiterungen durch:
- Nur die wichtigsten Spalten werden angezeigt
- Drei dynamische Parameter werden definiert: Status, Subsystem, Job_User_Identity
- Die Überschrift wird geändert in:
Aktive Jobs mit Status <ACTIVEJOBINFO.ActiveJobInfo.JOB_STATUS - Weitere Anpassungen können selbstverständlich durchgeführt werden
Die beiden anderen Filter für SUBSYSTEM und JOB_IDENTITY wurden auf die gleiche Weier erstellt. Damit wird nun bei der Ausführung eine Auswahlliste für die drei Parameter erzeugt.
Hinweis: Bei der dynamischen Version der Auswahlliste für Status werden nur die Stati
angezeigt, die auch aktuell vorhanden sind. Falls kein aktiver Job mit dem Status ‘MSGW‘
existiert, wird dieser Status in der Auswahlliste nicht angezeigt. Anstatt die Auswahlliste
dynamisch erstellen zu lassen (= Select DISTINCT Status..), können Sie die Werte für den
Parameter manuell eintragen, also auch mit Status=‘MSGW‘. Der Nachteil dabei könnte allerdings sein, dass dann Jobs mit einem neuen Status, der noch nicht in der Liste eingetragen ist,
nicht angezeigt werden.
Zum Schluss habe ich noch einen neuen Report erstellt, bei dem die Spalte Job_Status konstant mit ‘MSGW‘ verglichen wird. Damit erhalte ich – ohne Auswahl eines Parameters – sofort eine Liste aller Jobs, die auf eine Antwort warten.
Vorschau: Im nächsten Artikel geht es um IBM i Services vom Objekttyp VIEW.
Bis dahin wünsche ich Ihnen weiterhin viel Spaß beim Vermehren Ihrer Fertigkeiten.
Der Autor Theo Bär schreibt regelmäßig für den TechKnowLetter.
- seit über 30 Jahren im IBM-Midrangebereich tätig, selbstständiger Berater und IBM Business Partner
- Dipl.Wirtschafts-Ingenieur, 5 Jahre als Systemingenieur bei IBM, Dozent und Trainer
- Autor ITP-Fachbücher “DB2 Web Query” (Dezember 2008 und 2012)
- Co-Autor IBM Redbook “RPG Update” (2005)
- Co-Autor IBM Redbook “DB2 Web Query 2.1” (2012)
Sie erreichen ihn unter:
EDV-Beratung Theo Bär
Ringmauerweg 1
69250 Schönau
Tel.: (+49) 6228 912 630
E-Mail: [info@edv-baer.com]
Sechs Ausgaben des TechKnowLetters erhalten Sie hier für 88 Euro.