How do I read a File to end active jobs within my CLP?

205 pts.
Tags:
AS/400 jobs
AS/400 Library
CLP
Job Control Language
WRKACTJOB
First I would like to say thanks to Tom for always helping.

Info: I performed a wrkactjob job(joblog*) and created a spool file based on the results, then I copied that to a pf file call myfile (all within a CLP). I would like to end the jobs that show up in myfile, but im a little lost again. I know what I would like my last command to be  ENDJOB JOB(&NBR/&USER/&JOB) but its the getting to that point that i can not wrap my head around. How do I retrieve the information I need from myfile. by rcvf? or some other means. I would like to keep all this within one cl. below is a draft of this spool file. As you can see there is more data then what im looking for. All I need is the job number, user and job.

 

 Browse : MYLIB/MYFILE(MYFILE)                                                                                                        Record :    1   of   17 by  18  Column : 1    132 by 131                                               Control :                                                                                                                                                                                                                                                              ....+....1....+....2....+....3....+....4....+....5....+........              ************Beginning of data**************                                                                             5722SS1 V5R4M0 060210                  Work with Active Jobs                                    Reset . . . . . . . . . . . . . . . :   *NO                                                                                     Subsystems  . . . . . . . . . . :   QALLWRK                                                                                 CPU Percent Limit . . . . .  . :   *NONE                                                                                   Response Time Limit . . . . :   *NONE                                                                                   Sequence  . . . . . . . . . . .. :   *SBS                                                                                    Job name  . . . . . . . . . .  . :   JOBLOG*                                                                                            Subsystem/Job  User   Number   User   Type Pool....     JOBLOG01     USER1  000001   USER1  BCH    2 .....    JOBLOG02     USER2  000002   USER2  BCH    2 .....     JOBLOG03     USER3  000003   USER3  BCH    2 .....    JOBLOG04     USER4  000004   USER4  BCH    2 .....    JOBLOG05     USER5  000005   USER5  bCH    2 .....    JOBLOG06     USER6  000006   USER6  BCH    2 .....      * * * * *  E N D  O F  L I S T I N G  * * * * *                                                                 ************End of Data********************                                                                           

                                                              



Software/Hardware used:
as400

Answer Wiki

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

Subsystem/Job User Number User Type Pool….
JOBLOG01 USER1 000001 USER1 BCH 2 …..
JOBLOG02 USER2 000002 USER2 BCH 2 …..
JOBLOG03 USER3 000003 USER3 BCH 2 …..
JOBLOG04 USER4 000004 USER4 BCH 2 …..
JOBLOG05 USER5 000005 USER5 bCH 2 …..
JOBLOG06 USER6 000006 USER6 BCH 2 …..
* * * * * E N D O F L I S T I N G * * * * *

Discuss This Question: 4  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
  • CharlieBrowne
    Yes, you use RCFV You would use %SST to identify with records are the records you need to process. For instance pos 2 = blank and pos 70 = period. YOU NEED to be careful what you are cancelling. The WRKACTJOB is giving you job information from all subsystems. I'm guesing you only want selected jobs, like TYPE = INT ot something. Or selected USRPRF.
    41,380 pointsBadges:
    report
  • Nickhutcheson
    One trick that works well is to : run your command whatever it is to an outfile, run a query to an outfile selecting the records and fields you are concerned with. Then read that file (RCVF) in a CLP inside a loop, process (end job, delete user profile- just kidding, whatever), until EOF (CPF0864). To add to CharlieBrowne's post, WRKACTJOB SBS(QINTER, QPGMR, QBATCH). Do it like eating an apple, one bite at a time. Nick
    165 pointsBadges:
    report
  • TomLiotta
    Assuming that you want to end all *ACTIVE jobs that have job names beginning with JOBLOG*, this is a little easier than the previous one:
    pgm
    
    /* Identify a PARTIAL job-name to work over...                      */
       dcl   &SCHNAME     *char   10     value( 'JOBLOG*' )
    
       dcl   &SchJob      *char   26
    
    /* Identify a *USRSPC name...                                       */
       dcl   &usrspc      *char   10     value( 'LSTACTJOBS' )
       dcl   &usrspclib   *char   10     value( 'QTEMP' )
    
       dcl   &qusrspc     *char   20
    
    /* General fields from *usrspc header...                            */
       dcl   &offslst     *int
       dcl   &nbrlste     *int
       dcl   &sizlste     *int
    
    /* Various work fields...                                           */
    
       dcl   &jobname     *char   10
       dcl   &jobusr      *char   10
       dcl   &jobnbr      *char    6
    
       dcl   &qjob        *char   26
    
    /* Various receiver variables...                                    */
       dcl   &us_hdr      *char  150
       dcl   &JOBL0100F   *char   56
    
    
    /*---------------------------------------------------------------------------*/
    /* Global MONMSG...                                                          */
    /*---------------------------------------------------------------------------*/
    
       monmsg    ( cpf0000 mch0000 ) exec( goto Std_Err )
    
    
    /*                                                                           */
    /* Create *usrspc for the SBS info APIs...                                   */
    /*                                                                           */
    
       chgvar          &qusrspc               ( &usrspc *cat &usrspclib )
    
       call  QUSCRTUS         ( +
                                &qusrspc                +
                                'ACTJOB    '            +
                                x'00004000'             +
                                X'00'                   +
                                '*ALL      '            +
                      'List active jobs                                  ' +
                                '*YES      '            +
                                x'0000000000000000'     +
                              )
    
    
    /* Set the qualified search-job name -- list 'em all...                      */
    
       chgvar          &SchJob                ( &SCHNAME *cat '*ALL      *ALL  ' )
    
    
    /*                                                                           */
    /* List the active jobs into our *usrspc...                                  */
    /*                                                                           */
    
       call  QUSLJOB          ( +
                                &qusrspc                +
                                'JOBL0100'              +
                                &SchJob                 +
                                '*ACTIVE   '            +
                                x'0000000000000000'     +
                                '*'                     +
                                x'00000000'             +
                                x'00000000'             +
                              )
    
    
    /* Retrieve the *usrspc header...                                            */
    
       call  QUSRTVUS         ( +
                                &qusrspc                +
                                x'00000001'             +
                                x'00000096'             +
                                &us_hdr                 +
                              )
    
    /*                                                           */
    /* Get the offset to the list within the space, the number   */
    /*   of list entries and size of each entry from the header. */
    /*                                                           */
       chgvar          &offslst           %bin( &us_hdr    125 4 )
       chgvar          &nbrlste           %bin( &us_hdr    133 4 )
       chgvar          &sizlste           %bin( &us_hdr    137 4 )
    
    
    /* If no entries, then get out of here...                    */
    
       if  ( &nbrlste *eq 0 )     do
          sndpgmmsg  msgid( CPF9897 ) msgf( QCPFMSG ) +
                       msgdta( 'No active jobs found.' ) +
                       topgmq( *EXT ) +
                       msgtype( *COMP )
          goto   End_Run
       enddo
    
    
    /* Set the offset to the list within the space...            */
    
       chgvar          &offslst               ( &offslst + 1 )
    
    
    
        dowhile  ( &nbrlste *gt 0 )
    
    /*    Retrieve one listed job entry from the list...                         */
    
          call  QUSRTVUS      ( +
                                &qusrspc                +
                                &offslst                +
                                &sizlste                +
                                &JOBL0100F              +
                              )
    
    
    /* Get the qualified job name from the list entry...                         */
    
          chgvar       &qjob              %sst( &JOBL0100F  1 26 )
    
    
          chgvar       &jobname           %sst( &qjob  1 10 )
          chgvar       &jobusr            %sst( &qjob 11 10 )
          chgvar       &jobnbr            %sst( &qjob 21  6 )
    
          endjob      job( &jobnbr/&jobusr/&jobname )
    
    
    /* Bump our offset up by the size of a list entry...                         */
    
          chgvar       &offslst               ( &offslst + &sizlste )
    
    /* Decrement our loop counter and loop back if more...                       */
    
          chgvar       &nbrlste               ( &nbrlste - 1 )
    
       enddo
    
    
    End_Run:
    
       dltusrspc   &usrspclib/&usrspc  /* Cleanup */
    
       return
    
    
     Std_Err:
    
       /* Move any *DIAG messages up the stack...        */
    
       Qsys/call       QSYS/QMHMOVPM       ( +
                                             '    '          +
                                             '*DIAG     '    +
                                             x'00000001'     +
                                             '*         '    +
                                             x'00000001'     +
                                             x'00000000'     +
                                           )
       Qsys/monmsg     ( CPF0000 MCH0000 )
    
       /* Resend any *ESCAPE messages up the stack...     */
    
       Qsys/call       QSYS/QMHRSNEM       ( +
                                             '    '          +
                                             x'00000000'     +
                                           )
       Qsys/monmsg     ( CPF0000 MCH0000 )
    
       return
    
    
    endpgm
    Compare the code to note the differences. Also compare to note how they essentially the same program, with just some differences in details. Once you have one API-based solution, it's easy to clone it for a new solution. In the new version, the SearchName has become the generic name -- "JOBLOG*". When the generic name is concatenated with *ALL users and *ALL job numbers, it becomes "all fully qualified jobs that begin with 'JOBLOG'". If that's all we need for selection criteria, then all we have to do is list them into a temporary space and end every job that was listed. We don't even need to check any of the job attributes. We already know it's an *ACTIVE job, it has a name that begins with JOBLOG* and we don't care what subsystem it's running in nor what any other attribute is. But, as for your actual question, you'll put your spooled file into a physical file and code something like this:
    dountil  ( &eofJobs )
       rcvf
       monmsg  ( cpf0864 )  exec( do )
          chgvar   &eofJobs  '1'
          iterate
       enddo
    
       if ( [valid_line] *and [valid_job] )  do
          endjob ...
       enddo
    
    enddo
    I don't know how you will create the condition to test for a "valid_line". You'll probably do something like CharlieBrowne suggested and simply check different positions in the line to see if your program recognizes the line as a header line or a detail line or just blank. And I suppose for the "valid_job" condition you'll just check the job name columns to see if they have a name that you want to handle. If the conditions are met, then substring the name, user and nbr from the line and end that job. In order to compile the program, you will need to have the database file already created. The compiler will need the file description in order to supply the RCVF command with the correct attributes. You probably only want the database file to exist in QTEMP when your program runs, but you can add an OVRDBF command to redirect to your QTEMP file at run-time. Tom
    125,585 pointsBadges:
    report
  • lotofbad
    [...] How do I read a file to end active jobs within my CLP? [...]
    0 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