Sidebar

An Easier Way to Find OS/400 Job Numbers in Multi-tiered Applications

Visual Basic
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

One persistent problem of developing multi-tiered applications with the AS/400 is the need to get AS/400 job log information. One client/server Web development trick-of-the-trade is interfacing with your iSeries-AS/400 over ODBC, OLE DB, or JDBC. All client jobs run in the QSERVER subsystem as a QZDASOINIT prestart job under the user profile QUSER. Even if a Java program is running on the AS/400 using JDBC, the program will cause a QZDASOINIT job to appear in the QSERVER subsystem to satisfy any SQL requests. As a result, the QSERVER subsystem is getting more crowded as more programs begin to use it for data manipulation and to call stored procedures.

Figure 1 shows you what a typical QSERVER subsystem look like, displaying lots of QZDASOINIT jobs serving Web, Java, and Visual Basic (VB) programs.

To find the user profile that is actually connected to the AS/400, you must first use option 5 against a QZDASOINIT job, then use option 10 to look at the job log. This seems to be the only way to identify which user profile actually logged on to the AS/400, barring working with known object locks or writing a special exit program. It is further complicated by the fact that most Web-based programs use only a single user profile to connect to the AS/400. So, you could potentially have hundreds of QZDASOINIT jobs that are all using the same OS/400 user profile. This situation makes it hard to pinpoint the exact job that you want to work with or debug.

In the past, I’ve shown you an OS/400 job number search technique that involves creating a CL program on the AS/400 to execute the Retrieve Job Attributes (RTVJOBA) command and returning the job number to the caller. To perform this technique, you have to create a stored procedure definition on the AS/400 to wrap the command and describe its output. Finally, you have to invoke the stored procedure from your client application to retrieve the job number under which that client application is currently executing. This is a nice way to locate a specific job number, but sometimes it isn’t practical; particularly if
you’re a consultant who doesn’t have the authority to create a procedure, or if you just
don’t want to invest the time required to declare and run the procedure on your AS/400. In this article, I will show you how IBM finds the job number of its current Operations Navigator (OpsNav) connection and give you another way to find the current connections job number.

A Little Background

I recently discovered this information while performing ODBC traces against the OpsNav Run SQL Scripts (RSS) component. RSS has some neat features, and, since I wanted to include a few of these features in my SQLThing product, I decided to trace how they


worked. [Editor’s Note: For more information on other RSS tricks, see “I Want to Be Like Mike,” Midrange Computing (Web Edition), February 2001 at www.midrangecomputing.com/mc/monthdisplay.cfm?md=200102.]

RSS connects to the AS/400 via the Client Access ODBC driver. By setting up the ODBC control panel application to trace calls to the ODBC driver, you will receive a complete log of the RSS ODBC calls while your application is connected to the AS/400. This log is useful for observing the wizard’s hidden functions as it can reveal how IBM programmers think about implementing new features in a client/server scenario.

Digging through the heaping mounds of ODBC trace information, I found the following gem: When RSS wants to know your job number, it uses the output of the OS/400 Display Job Log (DSPJOBLOG) command by formatting a call to the QCMDEXC API function. This function allows you to call any AS/400 command via the stored procedure mechanism available in SQL. However, since you are using the API, you do not have to pre-declare the stored procedure before you call it. QCMDEXC allows any AS/400 command to be called from an SQL connection. Here is the syntax of the command:

QSYS.QCMDEXC( , )

The first argument to QCMDEXC is a command string that you want to execute. The second argument is a decimal 10,5 number that represents the length of the string that you are passing to the QCMDEXC API.

So, when RSS wants to know its QZDASOINIT job number, it first calls the DSPJOBLOG command using the QCMDEXC API and redirects the output of the command to a file in QTEMP. Here is the syntax of the call to the QCMDEXC API that will write the job log to an output file:

CALL QSYS.QCMDEXC(‘QSYS/DSPJOBLOG OUTPUT(*OUTFILE) OUTFILE(QTEMP/QAUGDBJOBN)
OUTMBR(*FIRST *REPLACE)’,0000000081.00000)

CALL is the syntax that lets the SQL transport know that you are about to call a stored procedure on the AS/400. QSYS.QCMDEXC is the name of the stored procedure (in this case, an API function) that you are about to call. The first argument to the stored procedure is the command string representing the DSPJOBLOG command. Note that the call to DSPJOBLOG causes the output of the command to be written to a file named QAUGDBJOBN in the QTEMP library. The DSPJOBLOG command also instructs the AS/400 to put the output in the first member and to replace any member or file records that already exist. The final argument to the API-stored procedure is the length of the first argument command string. In this case, the string passed in the first argument is 81 bytes in length, so the number 81 must be passed to the second argument of the QCMDEXC API as a decimal (10,5) number. Note that QCMDEXC must have the length passed as a decimal 10,5 number, and that value must match exactly the length of the passed string or the API call will fail.

Once control returns to RSS, a file exists in QTEMP that has the existing job’s joblog contents as its first member. To retrieve the job number, RSS issues the following SQL statement to read the QMHJOB field (message data field) where the QMHMID field (message ID field) is equal to ‘CPIAD02’.

SELECT QMHJOB FROM QTEMP.QAUGDBJOBN WHERE QMHMID = ‘CPIAD02’


Whenever a QZDASOINIT job connects to the AS/400, one of the first actions of the job is to send the message CPIAD02 to the job log. This message indicates which user profile is being served by the job. The data returned to RSS by the SQL statement looks like this:

QZDASOINITQUSER 467925

The first 10 characters are the job name, the second 10 characters are the user profile, and the last 6 characters are the job number. By executing the following variant of the SQL statement IBM uses, you can get the data returned as three separate fields instead of having to substring the value of the job number in your client application:

SELECT SUBSTRING(QMHJOB,1,10) AS JOBNAME,
SUBSTRING(QMHJOB,11,10) AS USERNAME,
SUBSTRING(QMHJOB,21,6) AS JOBNUM
FROM QTEMP.QAUGDBJOBN WHERE QMHMID = ‘CPIAD02’;

This little trick is a unique way to find an elusive job number and avoid having to create a special stored procedure on the AS/400. Since the technique relies on the use of the QCMDEXC API function and the ability to call AS/400 commands as stored procedures (even if they are not declared as such), it will work from OLE DB, ODBC, or JDBC. Figure 2 shows a VB snippet that will use ADO to perform the same actions as RSS and print the job number in a Windows message box. Figure 3 shows a simple Java program that will run on your AS/400 and return its QZDASOINIT job number. This Java program should also run on a client PC, as it is 100% Pure Java and does not use any proprietary AS/400 features other than the call to the QCMDEXC API.

Caveats, Anyone?

The only caveat is that you must ensure that you have the Translate coded character set (CCSID) 65535 option enabled if you are using ODBC as your transport. This can be set via the ODBC Control panel applet (under the Translation tab), or set dynamically via the connection properties if you are using an OLE DB provider. The QMHJOB field is data type LONG VARBINARY, and it is stored in CCSID 65535 as it holds job message data which can be binary or character information. If you do not have the translate option enabled, the data will be returned to a PC client in EBCDIC characters instead of ASCII, and you would have to translate the data to ASCII yourself.

This is a neat way to retrieve a job number, the only drawback being that it writes information to a file in QTEMP. Should your job be in debug more or have a large job log, the execution of the DSPJOBLOG command could take some time, so you might want to use the stored procedure method to retrieve the number as it is more efficient.

References and Related Materials

“AS/400 Stored Procedures to the Rescue!” Howard F. Arner, Jr., Midrange Computing (Web Edition), August 2000, www.midrangecomputing.com/mc/article. cfm?titleid=b1462&md=20008

“iSeries and AS/400 SQL at Work,” Howard F. Arner, Jr., MC Press

“I Want to Be Like Mike,” Howard F. Arner, Jr., Midrange Computing (Web Edition), February 2001, www.midrangecomputing. com/mc/monthdisplay.cfm?md=200102

“Optimizing the Optimizer,” Howard F. Arner, Jr., Midrange Computing, July 1999


“Pesky Stored Procedure Pitfalls,” Howard F. Arner, Jr., Midrange Network Expert (Web Edition), November/December 2000, www.midrangecomputing.com/ ane/article.cfm?id=1034&md=20005

“Stored Procedures 101,” Howard F. Arner, Jr., Midrange Computing (Web Edition), October 2000, www.midrangecomputing. com/mc/article.cfm?titleid=b1556&md=200010

Figure 1: This is what a typical QSERVER subsystem looks like, with lots of QZDASOINIT jobs serving Web, Java, and Visual Basic programs.


An_Easier_Way_to_Find_OS-_400_Job_Numbers_in...04-00.jpg 444x351

'Assumes con1 is an active ADO connection object
'connected to your AS/400
dim cmd1 as new adodb.command
dim rs as new adodb.recordset
cmd1.activeconnection = con1
cmd1.commandtext = "CALL QSYS.QCMDEXC('QSYS/DSPJOBLOG " & _

"OUTPUT(*OUTFILE) OUTFILE(QTEMP/QAUGDBJOBN) " & _
"OUTMBR(*FIRST *REPLACE)',0000000081.00000)"
cmd1.execute
cmd1.commandtext = "SELECT SUBSTRING(QMHJOB,1,10) AS JOBNAME," & _

"SUBSTRING(QMHJOB,11,10) AS USERNAME," & _
"SUBSTRING(QMHJOB,21,6) AS JOBNUM " & _
"FROM QTEMP.QAUGDBJOBN WHERE QMHMID = 'CPIAD02'"
rs.open cmd1
msgbox "Your Job Number is: " & rs.fields("JOBNUM").value
rs.close
set cmd1=nothing
set rs=nothing

Figure 2: This snippet of Visual Basic will print the job number of the QZDASOINIT job VB is using to service SQL requests.

import java.sql.*;
import java.math.*;

class AS400SP {

Connection con = null;

long c = 0;

AS400SP () {

try {

Class.forName("com.ibm.as400.access.AS400JDBCDriver");

} catch( ClassNotFoundException e) {

System.out.println("JDBC Driver not found: " + e);

System.exit(0);

}

try {

con = DriverManager.getConnection ("jdbc:as400://10.10.10.1;extended

dynamic=true;","arner","arner");

long timer1=System.currentTimeMillis();

Statement stmt = con.createStatement();

stmt.executeUpdate("CALL QSYS.QCMDEXC('QSYS/DSPJOBLOG
OUTPUT(*OUTFILE) OUTFILE(QTEMP/QAUGDBJOBN) OUTMBR(*FIRST
*REPLACE)',0000000081.00000)");

System.out.println("Procedure Executed");

ResultSet rs = stmt.executeQuery ("SELECT SUBSTRING(QMHJOB,1,10) AS
JOBNAME,SUBSTRING(QMHJOB,11,10) AS USERNAME,SUBSTRING(QMHJOB,20,6)
AS JOBNUM FROM QTEMP.QAUGDBJOBN WHERE QMHMID = 'CPIAD02'");

rs.next();
System.out.println(rs.getString("JOBNAME")) ;
System.out.println(rs.getString("USERNAME")) ;
System.out.println(rs.getString("JOBNUM")) ;

System.out.println("End Test");
} catch (SQLException e) {

System.out.println("SQL error : " + e);

return;

}

}

public static void main (String[] pList) {

new AS400SP ();

System.exit(0);

}

}

Figure 3: This simple Java program will connect and then retrieve and display the QZDASOINIT job number.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

RESOURCE CENTER

  • WHITE PAPERS

  • WEBCAST

  • TRIAL SOFTWARE

  • White Paper: Node.js for Enterprise IBM i Modernization

    SB Profound WP 5539

    If your business is thinking about modernizing your legacy IBM i (also known as AS/400 or iSeries) applications, you will want to read this white paper first!

    Download this paper and learn how Node.js can ensure that you:
    - Modernize on-time and budget - no more lengthy, costly, disruptive app rewrites!
    - Retain your IBM i systems of record
    - Find and hire new development talent
    - Integrate new Node.js applications with your existing RPG, Java, .Net, and PHP apps
    - Extend your IBM i capabilties to include Watson API, Cloud, and Internet of Things


    Read Node.js for Enterprise IBM i Modernization Now!

     

  • Profound Logic Solution Guide

    SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation.
    Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects.
    The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the companyare not aligned with the current IT environment.

    Get your copy of this important guide today!

     

  • 2022 IBM i Marketplace Survey Results

    Fortra2022 marks the eighth edition of the IBM i Marketplace Survey Results. Each year, Fortra captures data on how businesses use the IBM i platform and the IT and cybersecurity initiatives it supports.

    Over the years, this survey has become a true industry benchmark, revealing to readers the trends that are shaping and driving the market and providing insight into what the future may bring for this technology.

  • Brunswick bowls a perfect 300 with LANSA!

    FortraBrunswick is the leader in bowling products, services, and industry expertise for the development and renovation of new and existing bowling centers and mixed-use recreation facilities across the entertainment industry. However, the lifeblood of Brunswick’s capital equipment business was running on a 15-year-old software application written in Visual Basic 6 (VB6) with a SQL Server back-end. The application was at the end of its life and needed to be replaced.
    With the help of Visual LANSA, they found an easy-to-use, long-term platform that enabled their team to collaborate, innovate, and integrate with existing systems and databases within a single platform.
    Read the case study to learn how they achieved success and increased the speed of development by 30% with Visual LANSA.

     

  • Progressive Web Apps: Create a Universal Experience Across All Devices

    LANSAProgressive Web Apps allow you to reach anyone, anywhere, and on any device with a single unified codebase. This means that your applications—regardless of browser, device, or platform—instantly become more reliable and consistent. They are the present and future of application development, and more and more businesses are catching on.
    Download this whitepaper and learn:

    • How PWAs support fast application development and streamline DevOps
    • How to give your business a competitive edge using PWAs
    • What makes progressive web apps so versatile, both online and offline

     

     

  • The Power of Coding in a Low-Code Solution

    LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed.
    Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks

     

     

  • Why Migrate When You Can Modernize?

    LANSABusiness users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
    In this white paper, you’ll learn how to think of these issues as opportunities rather than problems. We’ll explore motivations to migrate or modernize, their risks and considerations you should be aware of before embarking on a (migration or modernization) project.
    Lastly, we’ll discuss how modernizing IBM i applications with optimized business workflows, integration with other technologies and new mobile and web user interfaces will enable IT – and the business – to experience time-added value and much more.

     

  • UPDATED: Developer Kit: Making a Business Case for Modernization and Beyond

    Profound Logic Software, Inc.Having trouble getting management approval for modernization projects? The problem may be you're not speaking enough "business" to them.

    This Developer Kit provides you study-backed data and a ready-to-use business case template to help get your very next development project approved!

  • What to Do When Your AS/400 Talent Retires

    FortraIT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators is small.

    This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:

    • Why IBM i skills depletion is a top concern
    • How leading organizations are coping
    • Where automation will make the biggest impact

     

  • Node.js on IBM i Webinar Series Pt. 2: Setting Up Your Development Tools

    Profound Logic Software, Inc.Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. In Part 2, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Attend this webinar to learn:

    • Different tools to develop Node.js applications on IBM i
    • Debugging Node.js
    • The basics of Git and tools to help those new to it
    • Using NodeRun.com as a pre-built development environment

     

     

  • Expert Tips for IBM i Security: Beyond the Basics

    SB PowerTech WC GenericIn this session, IBM i security expert Robin Tatam provides a quick recap of IBM i security basics and guides you through some advanced cybersecurity techniques that can help you take data protection to the next level. Robin will cover:

    • Reducing the risk posed by special authorities
    • Establishing object-level security
    • Overseeing user actions and data access

    Don't miss this chance to take your knowledge of IBM i security beyond the basics.

     

     

  • 5 IBM i Security Quick Wins

    SB PowerTech WC GenericIn today’s threat landscape, upper management is laser-focused on cybersecurity. You need to make progress in securing your systems—and make it fast.
    There’s no shortage of actions you could take, but what tactics will actually deliver the results you need? And how can you find a security strategy that fits your budget and time constraints?
    Join top IBM i security expert Robin Tatam as he outlines the five fastest and most impactful changes you can make to strengthen IBM i security this year.
    Your system didn’t become unsecure overnight and you won’t be able to turn it around overnight either. But quick wins are possible with IBM i security, and Robin Tatam will show you how to achieve them.

  • Security Bulletin: Malware Infection Discovered on IBM i Server!

    SB PowerTech WC GenericMalicious programs can bring entire businesses to their knees—and IBM i shops are not immune. It’s critical to grasp the true impact malware can have on IBM i and the network that connects to it. Attend this webinar to gain a thorough understanding of the relationships between:

    • Viruses, native objects, and the integrated file system (IFS)
    • Power Systems and Windows-based viruses and malware
    • PC-based anti-virus scanning versus native IBM i scanning

    There are a number of ways you can minimize your exposure to viruses. IBM i security expert Sandi Moore explains the facts, including how to ensure you're fully protected and compliant with regulations such as PCI.

     

     

  • Encryption on IBM i Simplified

    SB PowerTech WC GenericDB2 Field Procedures (FieldProcs) were introduced in IBM i 7.1 and have greatly simplified encryption, often without requiring any application changes. Now you can quickly encrypt sensitive data on the IBM i including PII, PCI, PHI data in your physical files and tables.
    Watch this webinar to learn how you can quickly implement encryption on the IBM i. During the webinar, security expert Robin Tatam will show you how to:

    • Use Field Procedures to automate encryption and decryption
    • Restrict and mask field level access by user or group
    • Meet compliance requirements with effective key management and audit trails

     

  • Lessons Learned from IBM i Cyber Attacks

    SB PowerTech WC GenericDespite the many options IBM has provided to protect your systems and data, many organizations still struggle to apply appropriate security controls.
    In this webinar, you'll get insight into how the criminals accessed these systems, the fallout from these attacks, and how the incidents could have been avoided by following security best practices.

    • Learn which security gaps cyber criminals love most
    • Find out how other IBM i organizations have fallen victim
    • Get the details on policies and processes you can implement to protect your organization, even when staff works from home

    You will learn the steps you can take to avoid the mistakes made in these examples, as well as other inadequate and misconfigured settings that put businesses at risk.

     

     

  • The Power of Coding in a Low-Code Solution

    SB PowerTech WC GenericWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed.
    Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks

     

     

  • Node Webinar Series Pt. 1: The World of Node.js on IBM i

    SB Profound WC GenericHave you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.
    Part 1 will teach you what Node.js is, why it's a great option for IBM i shops, and how to take advantage of the ecosystem surrounding Node.
    In addition to background information, our Director of Product Development Scott Klement will demonstrate applications that take advantage of the Node Package Manager (npm).
    Watch Now.

  • The Biggest Mistakes in IBM i Security

    SB Profound WC Generic The Biggest Mistakes in IBM i Security
    Here’s the harsh reality: cybersecurity pros have to get their jobs right every single day, while an attacker only has to succeed once to do incredible damage.
    Whether that’s thousands of exposed records, millions of dollars in fines and legal fees, or diminished share value, it’s easy to judge organizations that fall victim. IBM i enjoys an enviable reputation for security, but no system is impervious to mistakes.
    Join this webinar to learn about the biggest errors made when securing a Power Systems server.
    This knowledge is critical for ensuring integrity of your application data and preventing you from becoming the next Equifax. It’s also essential for complying with all formal regulations, including SOX, PCI, GDPR, and HIPAA
    Watch Now.

  • Comply in 5! Well, actually UNDER 5 minutes!!

    SB CYBRA PPL 5382

    TRY the one package that solves all your document design and printing challenges on all your platforms.

    Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product.

    Request your trial now!

  • Backup and Recovery on IBM i: Your Strategy for the Unexpected

    FortraRobot automates the routine tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:
    - Simplified backup procedures
    - Easy data encryption
    - Save media management
    - Guided restoration
    - Seamless product integration
    Make sure your data survives when catastrophe hits. Try the Robot Backup and Recovery Solution FREE for 30 days.

  • Manage IBM i Messages by Exception with Robot

    SB HelpSystems SC 5413Managing messages on your IBM i can be more than a full-time job if you have to do it manually. How can you be sure you won’t miss important system events?
    Automate your message center with the Robot Message Management Solution. Key features include:
    - Automated message management
    - Tailored notifications and automatic escalation
    - System-wide control of your IBM i partitions
    - Two-way system notifications from your mobile device
    - Seamless product integration
    Try the Robot Message Management Solution FREE for 30 days.

  • Easiest Way to Save Money? Stop Printing IBM i Reports

    FortraRobot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing.
    Manage your reports with the Robot Report Management Solution. Key features include:

    - Automated report distribution
    - View online without delay
    - Browser interface to make notes
    - Custom retention capabilities
    - Seamless product integration
    Rerun another report? Never again. Try the Robot Report Management Solution FREE for 30 days.

  • Hassle-Free IBM i Operations around the Clock

    SB HelpSystems SC 5413For over 30 years, Robot has been a leader in systems management for IBM i.
    Manage your job schedule with the Robot Job Scheduling Solution. Key features include:
    - Automated batch, interactive, and cross-platform scheduling
    - Event-driven dependency processing
    - Centralized monitoring and reporting
    - Audit log and ready-to-use reports
    - Seamless product integration
    Scale your software, not your staff. Try the Robot Job Scheduling Solution FREE for 30 days.