Is it possible to find the job name using job number alone in AS/400?

70 pts.
Tags:
AS/400
AS/400 jobs
AS/400 search
Hi All,

I need to find out the job name using the job number alone in AS400, is this possible? if yes, How?[o:p][/o:p]

ASKED: June 23, 2010  7:01 AM
UPDATED: July 6, 2010  6:03 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

The <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusljob.htm”>List Job (QUSLJOB) API</a> will list jobs for a specific job number in a user space. An simple example of calling the API:<pre>
CALL PGM( QSYS/QUSLJOB ) PARM(‘LSTAJOBNBRMYLIB ‘
‘JOBL0100′
‘*ALL *ALL 321654′
‘*ACTIVE ‘)</pre>
That will place the list into a user space named MYLIB/LSTAJOBNBR. (The user space must be created first.) The format of the list entries will be JOBL0100 which is only the basic information for each list entry. The example qualified job name is 321654/*ALL/*ALL (most likely only a single job will be listed.) And the example asks <b>only</b> for *ACTIVE jobs.

Naturally, those values would probably be in variables rather than literals.

Comparison against the API documentation should illuminate how to request other kinds of lists. Instead of ‘*ACTIVE ‘, you might want to specify ‘*ALL ‘ in order to list all jobs with that job number, regardless of status. That is, you might not know if your particular job number is active or if it’s finished and has output on an *OUTQ.

For a specific job number, you would normally get zero or one list entry. It’s possible to get more than one if your job numbers have wrapped.

Of course, this API isn’t much use without the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/quscrtus.htm”>Create User Space (QUSCRTUS)</a>, <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusrtvus.htm”>Retrieve User Space (QUSRTVUS)</a> (or better, <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusptrus.htm”>Retrieve Pointer to User Space (QUSPTRUS)</a>) and <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusdltus.htm”>Delete User Space (QUSDLTUS)</a> APIs. When learning about user spaces, you probably should also become familiar with the DMPOBJ command because you’re likely to do a lot of byte counting the first couple times.

Also, you’ll need to check the QALWUSRDMN system value to verify that you can create a user space in the library of your choice. That includes QTEMP.

Tom

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • vssagar
    I got to do some trail and error method on this.. Thanks Tom.
    70 pointsBadges:
    report
  • TomLiotta
    The user space APIs can used in OPM CL (except the Retrieve Pointer to User Space (QUSPTRUS) API) and even REXX, so they're not too difficult to work with. The first time can be confusing in a couple details. But once those are understood, the APIs can be used over and over again with many other APIs and for your own uses. They're used almost the same every time, so you almost just copy your code for the next usage. A new thread about user spaces would be good for the site. Tom
    125,585 pointsBadges:
    report
  • Rudedog
    you can do DspLog (Display Log) for the timeframe in question, to a printer file. then just use F16 (shift + F4) after typing the job number in the search line, when looking at the printer file with option 5. -sarge
    950 pointsBadges:
    report
  • TomLiotta
    you can do DspLog (Display Log) for the timeframe in question, to a printer file. ...{F16 to search...} This is a useful tip for basic interactive searches. It assumes that the timeframe of the job activity fits within the current QHST* range. Also, it assumes that the search is being done by general interactive means rather than by some automated application or operations procedure. (Technically, it also assumes that spooled file size limits won't be an issue; but that's not a major obstacle for most sites.) Tom
    125,585 pointsBadges:
    report
  • vssagar
    As I am new to RPG and working with a new client, I was not able to try API. Sarge - Thanks for a very useful tip, I was able to find most of jobs very easily. Tom - I would like to know more about API, can you provide additional study material. Thank you both -Sagar
    70 pointsBadges:
    report
  • TomLiotta
    I would like to know more about API, can you provide additional study material. To learn about most APIs, I use CL. Once I know what to expect an API to do, I can use it in RPG (or COBOL or C or whatever) much more easily. Here's a basic CLP that accepts a job number and sends a message for every job that it finds matching that number:
    pgm    ( +
             &pChkNbr      +
           )
    
    
       dcl   &pChkNbr       *char       6
    
    
       dcl   &usrspc        *char      10  VALUE( '#$FNDJBNBR' )
       dcl   &usrspclib     *char      10  VALUE( 'QTEMP     ' )
    
       dcl   &qusrspc       *char      20
    
       dcl   &us_hdr        *char     150   /* Space header      */
       dcl   &us_lste       *char      56   /* List entry        */
    
       dcl   &job           *char      10
       dcl   &jobusr        *char      10
       dcl   &jobnbr        *char       6
    
    
    /* Number of list entries: Listed jobs...                           */
    
       dcl   &NbrLstE       *dec      (7)
    
       dcl   &offsetlst     *int
       dcl   &szLstE        *int
    
    
    /*  The qualified search job name...                                */
       dcl   &SchJob        *char     26
    
    
       chgvar    &qusrspc        ( &usrspc *cat &usrspclib )
    
    /*  Create a usrspc to hold the job list data...                    */
    
       call  QUSCRTUS         ( +
                                &qusrspc                +
                                'TMPLST    '            +
                                x'00001000'             +
                                X'00'                   +
                                '*ALL      '            +
                                'Temp list by job nbr   ' +
                                '*YES      '            +
                                x'0000000000000000'     +
                              )
    
    /*                                                                  */
    /*  Populate the usrspc with appropriate job list data...           */
    /*                                                                  */
    
       chgvar    &SchJob         ( +
                                   '*ALL      ' *cat         +
                                   '*ALL      ' *cat         +
                                   &pChkNbr                  +
                                 )
    
       call  QUSLJOB          ( +
                                &qusrspc                +
                                'JOBL0100'              +
                                &SchJob                 +
                                '*ALL      '            +
                                x'0000000000000000'     +
                                '*'                     +
                                x'00000000'             +
                                x'00000000'             +
                              )
    
    
    /*  Retrieve the header data...                                     */
    
       call  QUSRTVUS         ( +
                                &qusrspc                +
                                x'00000001'             +
                                x'00000096'             +
                                &us_hdr                 +
                              )
    
       chgvar    &NbrLstE        %bin( &us_hdr    133 4 )
    
    
       if ( &NbrLstE *eq 0 )  do
          sndpgmmsg  msgid( CPF9898 ) msgf( QCPFMSG ) +
                       msgdta( 'No jobs found' )
          goto  Clean_up
       enddo
    
       chgvar    &offsetlst    ( %bin( &us_hdr    125 4 ) + 1 )
       chgvar    &szLstE         %bin( &us_hdr    137 4 )
    
    /*                                                                  */
    /*  Retrieve each list entry and increment offset...                */
    /*    Count down number of list entries...                          */
    /*                                                                  */
    
       dowhile  ( &NbrLstE *gt 0 )
    
          call  QUSRTVUS      ( +
                                &qusrspc                +
                                &offsetlst              +
                                &szLstE                 +
                                &us_lste                +
                              )
    
          chgvar &job            %sst( &us_lste    1 10 )
          chgvar &jobusr         %sst( &us_lste   11 10 )
          chgvar &jobnbr         %sst( &us_lste   21  6 )
    
          sndpgmmsg  msgid( CPF9898 ) msgf( QCPFMSG ) +
                       msgdta( +
                               'Job'            *bcat +
                               &jobnbr          *cat  +
                               '/'              *cat  +
                               &jobusr          *tcat +
                               '/'              *cat  +
                               &job             *bcat +
                               'found'                +
                             )
    
          chgvar &offsetlst          ( &offsetlst + &szLstE )
          chgvar &NbrLstE            ( &NbrLstE - 1 )
    
       enddo
    
    
    Clean_up:
    
       dltusrspc   &usrspclib/&usrspc
    
       return
    
    endpgm
    Note that the parm value will be numeric characters, so it must be enclosed in quotes if you call the program from a command line or submit to batch. It sends a message, but you would probably do something else with the values. It only reports the job name -- it doesn't report the status nor anything else. If there are multiple jobs with the same number (very unlikely but possible), a message should be returned for each one. (The history log would probably only know about the latest one if it found any at all.) Finally, it uses the simpler but less efficient QUSRTVUS API rather than the QUSPTRUS API. That's because I only have V5R3 at home (and because this coding is easy to adapt to all earlier releases). Compile the program in batch and note the job number of the compile job. If you call the program using that number, the message should report the full job name of the compile. If you can understand how the program works, try re-writing it in RPG or try writing it in V5R4 ILE CL and use the QUSPTRUS API. If problems appear, post a new question specific to your programming and the problem. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following