How to retrive only MSGW status in AS/400 through CL?

5 pts.
Tags:
AS/400
CL
MSGW
How can I retrive only a MSGW status in AS/400 through CL?

Answer Wiki

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

Discuss This Question: 21  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
    Thanks for coming to ITKE.
    Can you give us more information as the problem you are trying to solve? Some jobs that are @ MSGW are OK like that depending on what you are all doing on your iSeries.
    I'm guessing you may be trying to monitor QSYSOPR for messages. If so, the best way is to use APIs. You can search this site for examples of that.
    Please let us know if you have more questions that we can help you with.
    41,665 pointsBadges:
    report
  • WoodEngineer
    We are doing what I suspect you wish to do.  As Charlie Brown recommends, we use an API to retrieve QSYSOPR messages and look for MSGW status.  If found, an e-mail is sent to a couple of key people in IT.  

    There are indeed jobs which are in MSGW as a normal part of their processing, such as jobs which are waiting for data to arrive at a data queue.  You will need a technique to skip such exceptions.
    6,955 pointsBadges:
    report
  • JohnD2
    Are these API's something already on the 400 or are they something you purchase?
    15 pointsBadges:
    report
  • Splat
    APIs are part of the system - no additional purchase is required.
    8,610 pointsBadges:
    report
  • ToddN2000
    Are you looking for messages that need a reply from a message queue or any job running in a MSGW status? There have been some solutions mentioned already. What is the purpose of the request? There may be an easier solution to complete your task.
    25,175 pointsBadges:
    report
  • thaihi
    I have similar request. We need job running in a MSGW status from specific subsystem.
    50 pointsBadges:
    report
  • ToddN2000
    Thaihi, a MWGW status could be for a job that is running but has no error to respond to. It could be just waiting on data to enter a message queue in order to proceed. We have a lot of these "async" jobs running all day here. I think it may be more along the lines of monitoring for a CPF halt that requires a user response. Can you elaborate more on your specific issue?
    25,175 pointsBadges:
    report
  • thaihi
    Thanks ToddN200 for your quick response, We have application related subsystem and some of the jobs under this subsystem is going in MSGW status (Waiting for some message) , Until we monitor the subsystem manually every 5 mins we will not come to know about this. So I am in the process of creating CL program and schedule it to run every 5 minutes to send email with the job name, number and subsystem name for all the jobs in MSGW status. I have tried using QUSRJOBI API but the problem with this API is I have to pass qualified job name (job name , number and user) . Later I found QGYOLJOB API and I am stuck up in how to pass parameters for this . If you could let me know any API which shows The list of active jobs is grouped by subsystem, I will be able to achieve my requirement. Hope this claifies my specific issue
    50 pointsBadges:
    report
  • TheRealRaven
    Wouldn't it be better to just fix the problems that cause the MSGW status? It's actually pretty complex to get only the jobs that need a message reply while ignoring jobs that are waiting on a message queue.
    6,975 pointsBadges:
    report
  • azohawk

    We had a problem similar to this, just an occasional MSGW status but it might sit for hours holding up everything (most of our jobqs are single threaded) until someone called. Had problems with an occasional overnight job not running for the same reason.  I found some RPG code (on another website), that seems to use several APIs. Made a few changes so it would email me at my work email during work hours and send a text alert to my cell during off hours. Wrapped it in a CL program that looks at the current time and adds  xx minutes (again based on work hours or not) and resubmits itself to run again. We run this in a seperate jobq otherwise another job with a MSGW status could keep it from running, which defeats the purpose. 

    But we did this for the unexpected MSGW when users submit jobs that they don't have authority to, wrong parms etc. (inherited programs and sourceless vendor programs). The surprising thing to me was getting notifications on printer issues (typically, change form). If you are getting the same programs getting MSGW status on a regular basis, I would look to fix the problem: have some internal code that performs the needed checks and deals with them appropriately.

    I agree with what others have said, if you have jobs that are in MSGW status becuase they are a queue waiting for something to be submitted, this may not be a viable solution or may take some careful review. 

    1,325 pointsBadges:
    report
  • ToddN2000
    Found some old code we had. Basically down and dirty, we dumped the QSYSOPR mesage queue and looked for CFP messages needing a reply. If one was found it would e-mail the spool file to a selected e-mail address for review. They would then log in remotely and answer as needed.

    /* Description:                                                     */
    /*  This program overrides print file and calls program to E-MAIL   */
    /*  commission statements.                                          */
    /*                                                                  */
    /********************************************************************/
    /*                                                                  */
    /*   M O D I F I C A T I O N   L I S T                              */
    /*                                                                  */
    /*   Modified by     Date     Description                           */
    /*                                                                  */
    /********************************************************************/
                 PGM                                                
                                                                    
                 DCL        VAR(&ERR) TYPE(*CHAR) LEN(11)           
                 DCL        VAR(&CPF) TYPE(*CHAR) LEN(11)           
                 DCL        VAR(&INFO)  TYPE(*CHAR) LEN(99)         
                 DCL        VAR(&SUBJ)  TYPE(*CHAR) LEN(36)         
                                                                    
                 DCL        VAR(&SPOOL)  TYPE(*CHAR) LEN(6)         
                 DCL        VAR(&JOBNR)  TYPE(*CHAR) LEN(6)         
                 DCL        VAR(&HALTS_05) TYPE(*CHAR) LEN(132)     
                 DCL        VAR(&USRNM)  TYPE(*CHAR) LEN(10)        
                 DCL        VAR(&JOBNM)  TYPE(*CHAR) LEN(10)        
                 DCL        VAR(&FILE)  TYPE(*CHAR) LEN(10)         
                 DCL        VAR(&EMAIL)  TYPE(*CHAR) LEN(50)        
                 DCL        VAR(&NOEMAIL)  TYPE(*CHAR) LEN(50)      
                                                                    
                 DCLF       FILE(HALTS_05)                          
                                                                    
                 DSPMSG     MSGQ(QSYSOPR) OUTPUT(*PRINT)            
                 CPYSPLF    FILE(QPDSPMSG) TOFILE(QTEMP/HALTS_05)  
                                                                            
                 RTVJOBA    JOB(&JOBNM) USER(&USRNM) NBR(&JOBNR)            
                 CHGVAR     VAR(&SPOOL) VALUE('000004')                     
                                                                            
    TAG05:       RCVF                                                       
                                                                            
                 MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(TAG10))         
                 CHGVAR     VAR(&ERR) VALUE(%SST(&HALTS_05 10 11))          
                 CHGVAR     VAR(&CPF) VALUE(%SST(&HALTS_05 27 3))           
                                                                            
    /*     IF ERROR CONDITION IS FOUND SEND REPORT AND END JOB          */  
                                                                            
                 IF         COND(&ERR *EQ '99  INQUIRY' *AND &CPF *EQ +     
                              'CPF') THEN(DO)                               
                                                                            
                 CHGVAR     VAR(&EMAIL) VALUE('EMA=MY_HOME@YAHOO.COM')   
                 CHGVAR     VAR(&SUBJ) VALUE('EMS=Halts on CORP')           
                 CHGVAR     VAR(&INFO) +                                    
                            VALUE(&EMAIL || &SUBJ || 'EDM=HALTSFND')        
                                                                            
                 SNDTCPSPLF RMTSYS(*INTNETADR) +                        
                              PRTQ(&EMAIL) +                            
                              FILE(QSYSPRT) JOB(&JOBNR/&USRNM/&JOBNM) + 
                              SPLNBR(&SPOOL) DESTTYP(*AS400) +          
                              TRANSFORM(*NO) INTNETADR('10.1.8.11')     
                                                                        
                 MONMSG     MSGID(CPA0701) EXEC(GOTO CMDLBL(TAG10))     
                                                                        
                 GOTO       CMDLBL(TAG10)                               
                                                                        
                              ENDDO                                     
                                                                        
                 GOTO       CMDLBL(TAG05)                               
                                                                        
    TAG10:       CPYSPLF    FILE(QPDSPMSG) TOFILE(QTEMP/HALTS_05)      
                 ENDPGM
    25,175 pointsBadges:
    report
  • thaihi
    Thanks Todd for your code ..
    Hi Azohawk, Can you please share your code as well.. Thanks
    50 pointsBadges:
    report
  • azohawk

    The RPG Code  (watch for indication of local mods)

    // The orignial code was posted on CODE400.com by "jamief" on 7/18/2008
    //-----Compiling instructions-------------
    // Compile with CRTRPGMOD, then create as a program as follows
    // Create Program (CRTPGM)
    // Program . . . . . . . . . . . . > MSGWPGM           Name
    // Library . . . . . . . . . . . *CURLIB Name, *CURLIB
    // Module . . . . . . . . . . . . . > MSGWPGM        Name, generic*, *PGM, *ALL
    // Library . . . . . . . . . . . >   MyLib           Name, *LIBL, *CURLIB...
    // + for more values > SYSVALR
    // Text 'description' . . . . . . . > 'list active jobs in MSGW status'

    H option(*nodebugio: *srcstmt) debug(*yes)
     
    * CrtUsrSpc: Create User Space for OS/400 API's
    //Fntfyhist O E DISK
    *
    d QUSCRTUS pr extpgm('QUSCRTUS')
    d UsrSpc 20A const
    d ExtAttr 10A const
    d InitialSize 10I 0 const
    d InitialVal 1A const
    d PublicAuth 10A const
    d Text 50A const
    d Replace 10A const
    d ErrorCode 32766A options(*nopass: *varsize)
    *
    * --- Prototype for API Retrive User Space
    *
    d QUSRTVUS pr extpgm( 'QUSRTVUS' )
    d QRtvUserSpace...
    d 20
    d QRtvStartingPosition...
    d 8b 0
    d QRtvLengthOfData...
    d 8b 0
    d QRtvReceiverVariable...
    d 32048
    d QRtvError...
    d 256
    * --- Prototype for API Retrive List Job
    *
    d QUSLJOB pr extpgm( 'QUSLJOB' )
    d QJobUserSpace...
    d 20
    d QJobFormatName...
    d 8
    d QJobJobName...
    d 26
    d QFldStatus...
    d 10
    d QFldError...
    d 256
    d QJobType...
    d 1
    d QNbrFldRtn...
    d 8b 0
    d QKeyFldRtn...
    d 8b 0 dim( 100 )
    *
    d qcmdexc pr extpgm( 'QCMDEXC' )
    d os400_cmd 2000A options( *varsize ) const
    d cmdlength 15P 5 const
    *
    * Defined variables
    *
    d emailaddress s 24 inz('myemail@mycompany.com')  //our mod
    d phoneaddress s 24 inz('MyPhone@myprovider.com')  //out mod
    d notifyaddress s 24
    d size s 10I 0
    d UsrSpcName s 20 inz( 'DSPJOB QTEMP ' )
    d DayOfWeek s 4a
    d TimeOfDay s 6a
    d datetimestampa s 26a
    d datetimestampz s z inz(*sys)
    d addmin s 3 0
    d sbdate s 6a
    d sbtime s 6a
    *
    ******************************************************************
    dQUSA0100 DS
    d QUsrSpcOffset...
    d 1 4B 0
    d QUsrSpcEntries...
    d 9 12B 0
    d QUsrSpcEntrieSize...
    d 13 16B 0
    dLJOBINPUT ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d Status...
    d 27 36
    d UserSpace...
    d 37 46
    d UserSpaceLibrary...
    d 47 56
    d Format...
    d 57 64
    d JobType...
    d 65 65
    d Reserved01...
    d 66 68
    d Reserved02...
    d 69 72B 0
    *
    dLJOB100 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    *
    dLJOB200 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    d JobInfoStatus...
    d 57 57
    d Reserved02...
    d 58 60
    d NumberOfFieldsReturned...
    d 61 64B 0
    d ReturnedData...
    d 65 1064
    *
    dLJOB200KEY ds qualified
    d KeyNumber01...
    d 1 4B 0
    d NumberOfKeys...
    d 5 8B 0
    *
    dLJOBKEYINFO ds qualified
    d LengthOfInformation...
    d 1 4b 0
    d KeyField...
    d 5 8b 0
    d TypeOfData...
    d 9 9
    d Reserved01...
    d 10 12
    d LengthOfData...
    d 13 16B 0
    d KeyData...
    d 17 1016
    *
    * APIErrDef Standard API error handling structure. *
     *
    dQUSEC DS
    d ErrorBytesProvided...
    d 1 4B 0
    d ErrorBytesAvailble...
    d 5 8b 0
    d ErrorExceptionId...
    d 9 15
    d ErrorReserved...
    d 16 16
     *
    dAPIError DS
    d APIErrorProvied...
    dLIKE( ErrorBytesProvided )
    dINZ( %LEN( APIError ) )
    d APIErrorAvailble...
    dLIKE( ErrorBytesAvailble )
    d APIErrorMessageID...
    dLIKE( ErrorExceptionId )
    d APIErrorReserved...
    dLIKE( ErrorReserved )
    d APIErrorInformation...
    d 240A
     *-----------------------------------------------------------------
     * program status dataarea
     *-----------------------------------------------------------------
    d PgmSts SDS
    d P1User 254 263
    d @job 244 253
    d W1Program *PROC
     *--------------------------------------------------------------*
     * work fields *
     *--------------------------------------------------------------*
    d Variables ds
    d Q 1 inz( '''' )
    d Count 15 0 inz( 0 )
    d KeyCount 15 0 inz( 0 )
    d EndPos 15 0 inz( 0 )
    d JobbStatus 4 inz( ' ' )
    d Subsystem 20 inz( ' ' )
    d ReturnCode 1 inz( ' ' )
    d FormatName 8 inz( ' ' )
    d QualifedJobName...
    d 26 inz( ' ' )
    d JobStatus 10 inz( ' ' )
    d JobType 1 inz( ' ' )
    d NbrOfFldRtn 8B 0 inz( 0 )
    d KeyFldRtn 8B 0 inz( 0 ) dim( 100 )
    d StartingPosition...
    d 8B 0 inz( 0 )
    d LengthOfData...
    d 8B 0 inz( 0 )
    d KeyStartingPosition...
    d 8B 0 inz( 0 )
    d KeyLengthOfData...
    d 8B 0 inz( 0 )
    d ReceiverVariable...
    d 32048
    d OS400_Cmd 2000 inz( ' ' )
    d CmdLength 15P 5 inz( %size( OS400_Cmd ) )
    d True 1 inz( *on )
    d False 1 inz( *off )
    *
    /COPY QCPYSRC,SYSVALR_P
    // begin free format code
    // Create a user space
    //
    size = 10000;
    // Create a user space
    QUSCRTUS(UsrSpcName: 'USRSPC': size: x'00': '*ALL':
    'Temp User Space for QUSLJOB API': '*YES': APIError);

    DayOfWeek = rtvsysval( 'QDAYOFWEEK' );//begin our mod
    TimeOfDay = rtvsysval( 'QTIME' );
    exsr CheckStatusOfJob;
    if DayOfWeek = '*SUN' or  
     DayOfWeek = '*SAT' or
     TimeOfDay > '170000' or
     TimeOfDay < '060000';
     Addmin = 60;
    else;
     addmin = 15;
    endif;                     //end our mod

    datetimestampz = datetimestampz + %minutes(addmin);
    datetimestampa = %char(datetimestampz);
    %subst(sbdate:1:2) = %subst(datetimestampa:6:2);
    %subst(sbdate:3:2) = %subst(datetimestampa:9:2);
    %subst(sbdate:5:2) = %subst(datetimestampa:3:2);
    %subst(sbtime:1:2) = %subst(datetimestampa:12:2);
    %subst(sbtime:3:2) = %subst(datetimestampa:15:2);
    %subst(sbtime:5:2) = '00';
    //format the submit job for the next check and send.
    os400_cmd = ' SBMJOB CMD(Call lstactjobp) LOGCLPGM(*JOBD) ' +
    ' SCDDATE(' + SBDATE + ')' +
    ' SCDTIME(' + SbTIME + ')' +
    ' JOB(CHKMSGW) ' +
    ' JOBQ(QGPL/QBATCHN) ' +
    ' USER(QSYSOPR) ';
    qcmdexc ( os400_cmd : %size ( os400_cmd ) );
    *inlr = *on;
    // *************************************************************
    // check status of an job
    // -------------------------------------------------------------
    begsr CheckStatusOfJob;
    // run API to fill user space with information about all iSeries job
    FormatName = 'JOBL0200';
    QualifedJobName = '*ALL ' + '*ALL ' + '*ALL ';
    JobStatus = '*ACTIVE';
    JobType = '*';
    NbrOfFldRtn = 2;
    KeyFldRtn( 1 ) = 0101;
    KeyFldRtn( 2 ) = 1906;
    callp QUSLJOB( UsrSpcName : FormatName : QualifedJobName :
    JobStatus : APIError :
    JobType : NbrOfFldRtn : KeyFldRtn );

    // if error message from the retrieve job API then dump program
    if APIErrorMessageID <> ' ';
     dump;
     ReturnCode = True;
     leavesr;
    endif;
    // run API to get user space attribute
    StartingPosition = 125;
    LengthOfData = 16;
    callp QUSRTVUS( UsrSpcName : StartingPosition :
    LengthOfData : ReceiverVariable :
    APIError );
    QUSA0100 = ReceiverVariable;
     // if error message from the retrieve user space API then dump program
    if APIErrorMessageID <> ' ';
     dump;
     ReturnCode = True;
     leavesr;
    endif;

    // preperation to read from user space
    StartingPosition = QUsrSpcOffset + 1;
    LengthOfData = QUsrSpcEntrieSize;
    // read from user space

    for count = 1 to QUsrSpcEntries;
     callp QUSRTVUS( UsrSpcName : StartingPosition :
     LengthOfData : ReceiverVariable :
     APIError );
     LJOB200 = ReceiverVariable;

     if APIErrorMessageID <> ' ';
      dump;
      ReturnCode = True;
      leavesr;
     endif;

    // check status of job
     JobbStatus = ' ';
     Subsystem = ' ';
     LJobKeyInfo = LJob200.ReturnedData;
    // Job type
    // A The job is an autostart job.
    // B The job is a batch job.
    // I The job is an interactive job.
    // M The job is a subsystem monitor job.
    // R The job is a spooled reader job.
    // S The job is a system job.
    // W The job is a spooled writer job.
    // X The job is the SCPF system job
    // Job subtype
    // D The job is a batch immediate job.
    // E The job started with a procedure start request.
    // F The job is an AS/400 Advanced 36 machine server job.
    // J The job is a prestart job.
    // P The job is a print driver job.
    // T The job is a System/36 multiple requester terminal (MRT) job.
    // U The job is an alternate spool user.
     KeyStartingPosition = 1;
     KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
     for keycount = 1 to LJob200.NumberOfFieldsReturned;
      LJobKeyInfo = %subst( LJob200.ReturnedData :
      KeyStartingPosition :
      KeyLengthOfData );
      KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
      LJobKeyInfo = %subst( LJob200.ReturnedData :
      KeyStartingPosition :
      KeyLengthOfData );
      Endpos = LJobKeyInfo.LengthOfData;
      if LJobKeyInfo.KeyField = 0101;
       JobbStatus = %subst( LJobKeyInfo.KeyData : 1 : Endpos );
      elseif LJobKeyInfo.KeyField = 1906;
       Subsystem = %subst( LJobKeyInfo.KeyData : 1 : Endpos );
      endif;
       KeyStartingPosition = KeyStartingPosition + KeyLengthOfData;
      endfor;

     // if job in message wait then email message to address in
     // variable email address
     if Jobbstatus = 'MSGW'; //begin our mod
      if DayOfWeek = '*SUN' or
       DayOfWeek = '*SAT' or
       TimeOfDay > '170000' or
       TimeOfDay < '060000';
       notifyaddress = phoneaddress; //off hours
      Else;
       notifyaddress = emailaddress; //work hours
      ENDIF;   //end our mod

      os400_cmd = 'snddst type(*lmsg) ' +
      'tointnet((' + Q + %trim(notifyAddress) +
      Q + ')) dstd(' + Q +
      'Job in MSGW status! ' +
      %trim(@job) + ' ' + %char(%time()) +
      Q + ') longmsg(' + Q +
      'Job in Message wait: ' +
      %trim(ljob200.jobname) + ' ' +
      %trim(ljob200.username) + ' ' +
      %trim(ljob200.jobnumber) + ' sent at ' +
      %char(%time()) +
      Q +')' + ' USRID(*CURRENT ) ' ;

    // prepare to write to history
    //njobnam = %trim(ljob200.jobname;
    //njobusr = %trim(ljob200.username;
    //njobnum = %trim(ljob200.jobnumber;
    //nnotdat = %date();
    //nnottim = %time();
    //nnotsnd = notifyaddress;
    //write ntfyhstr;

      qcmdexc ( os400_cmd : %size ( os400_cmd ) );
     endif;
     StartingPosition = StartingPosition + LengthOfData;
    endfor;
    endsr;


     

    1,325 pointsBadges:
    report
  • azohawk

    RPG Code part 1  (watch for local mod indications)

    // The orignial code was posted on CODE400.com by "jamief" on 7/18/2008
    //-----Compiling instructions-------------
    // Compile with CRTRPGMOD, then create as a program as follows
    // Create Program (CRTPGM)
    // Program . . . . . . . . . . . . > MSGWPGM           Name
    // Library . . . . . . . . . . . *CURLIB Name, *CURLIB
    // Module . . . . . . . . . . . . . > MSGWPGM        Name, generic*, *PGM, *ALL
    // Library . . . . . . . . . . . >   MyLib           Name, *LIBL, *CURLIB...
    // + for more values > SYSVALR
    // Text 'description' . . . . . . . > 'list active jobs in MSGW status'

    H option(*nodebugio: *srcstmt) debug(*yes)
     
    * CrtUsrSpc: Create User Space for OS/400 API's
    //Fntfyhist O E DISK
    *
    d QUSCRTUS pr extpgm('QUSCRTUS')
    d UsrSpc 20A const
    d ExtAttr 10A const
    d InitialSize 10I 0 const
    d InitialVal 1A const
    d PublicAuth 10A const
    d Text 50A const
    d Replace 10A const
    d ErrorCode 32766A options(*nopass: *varsize)
    *
    * --- Prototype for API Retrive User Space
    *
    d QUSRTVUS pr extpgm( 'QUSRTVUS' )
    d QRtvUserSpace...
    d 20
    d QRtvStartingPosition...
    d 8b 0
    d QRtvLengthOfData...
    d 8b 0
    d QRtvReceiverVariable...
    d 32048
    d QRtvError...
    d 256
    * --- Prototype for API Retrive List Job
    *
    d QUSLJOB pr extpgm( 'QUSLJOB' )
    d QJobUserSpace...
    d 20
    d QJobFormatName...
    d 8
    d QJobJobName...
    d 26
    d QFldStatus...
    d 10
    d QFldError...
    d 256
    d QJobType...
    d 1
    d QNbrFldRtn...
    d 8b 0
    d QKeyFldRtn...
    d 8b 0 dim( 100 )
    *
    d qcmdexc pr extpgm( 'QCMDEXC' )
    d os400_cmd 2000A options( *varsize ) const
    d cmdlength 15P 5 const
    *
    * Defined variables
    *
    d emailaddress s 24 inz('myemail@mycompany.com')  //our mod
    d phoneaddress s 24 inz('MyPhone@myprovider.com')  //out mod
    d notifyaddress s 24
    d size s 10I 0
    d UsrSpcName s 20 inz( 'DSPJOB QTEMP ' )
    d DayOfWeek s 4a
    d TimeOfDay s 6a
    d datetimestampa s 26a
    d datetimestampz s z inz(*sys)
    d addmin s 3 0
    d sbdate s 6a
    d sbtime s 6a
    *
    ******************************************************************
    dQUSA0100 DS
    d QUsrSpcOffset...
    d 1 4B 0
    d QUsrSpcEntries...
    d 9 12B 0
    d QUsrSpcEntrieSize...
    d 13 16B 0
    dLJOBINPUT ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d Status...
    d 27 36
    d UserSpace...
    d 37 46
    d UserSpaceLibrary...
    d 47 56
    d Format...
    d 57 64
    d JobType...
    d 65 65
    d Reserved01...
    d 66 68
    d Reserved02...
    d 69 72B 0
    *
    dLJOB100 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    *
    dLJOB200 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    d JobInfoStatus...
    d 57 57
    d Reserved02...
    d 58 60
    d NumberOfFieldsReturned...
    d 61 64B 0
    d ReturnedData...
    d 65 1064
    *
    dLJOB200KEY ds qualified
    d KeyNumber01...
    d 1 4B 0
    d NumberOfKeys...
    d 5 8B 0
    *
    dLJOBKEYINFO ds qualified
    d LengthOfInformation...
    d 1 4b 0
    d KeyField...
    d 5 8b 0
    d TypeOfData...
    d 9 9
    d Reserved01...
    d 10 12
    d LengthOfData...
    d 13 16B 0
    d KeyData...
    d 17 1016
    *
    * APIErrDef Standard API error handling structure. *
     *
    dQUSEC DS
    d ErrorBytesProvided...
    d 1 4B 0
    d ErrorBytesAvailble...
    d 5 8b 0
    d ErrorExceptionId...
    d 9 15
    d ErrorReserved...
    d 16 16
     *
    dAPIError DS
    d APIErrorProvied...
    dLIKE( ErrorBytesProvided )
    dINZ( %LEN( APIError ) )
    d APIErrorAvailble...
    dLIKE( ErrorBytesAvailble )
    d APIErrorMessageID...
    dLIKE( ErrorExceptionId )
    d APIErrorReserved...
    dLIKE( ErrorReserved )
    d APIErrorInformation...
    d 240A
     *-----------------------------------------------------------------
     * program status dataarea
     *-----------------------------------------------------------------
    d PgmSts SDS
    d P1User 254 263
    d @job 244 253
    d W1Program *PROC
     *--------------------------------------------------------------*
     * work fields *
     *--------------------------------------------------------------*
    d Variables ds
    d Q 1 inz( '''' )
    d Count 15 0 inz( 0 )
    d KeyCount 15 0 inz( 0 )
    d EndPos 15 0 inz( 0 )
    d JobbStatus 4 inz( ' ' )
    d Subsystem 20 inz( ' ' )
    d ReturnCode 1 inz( ' ' )
    d FormatName 8 inz( ' ' )
    d QualifedJobName...
    d 26 inz( ' ' )
    d JobStatus 10 inz( ' ' )
    d JobType 1 inz( ' ' )
    d NbrOfFldRtn 8B 0 inz( 0 )
    d KeyFldRtn 8B 0 inz( 0 ) dim( 100 )
    d StartingPosition...
    d 8B 0 inz( 0 )
    d LengthOfData...
    d 8B 0 inz( 0 )
    d KeyStartingPosition...
    d 8B 0 inz( 0 )
    d KeyLengthOfData...
    d 8B 0 inz( 0 )
    d ReceiverVariable...
    d 32048
    d OS400_Cmd 2000 inz( ' ' )
    d CmdLength 15P 5 inz( %size( OS400_Cmd ) )
    d True 1 inz( *on )
    d False 1 inz( *off )
    *
    /COPY QCPYSRC,SYSVALR_P

    1,325 pointsBadges:
    report
  • azohawk
    I will have to post in parts- watch for indications of local modifications
    1,325 pointsBadges:
    report
  • azohawk

    //-----Compiling instructions-------------
    // Compile with CRTRPGMOD, then create as a program as follows
    // Create Program (CRTPGM)
    // Program . . . . . . . . . . . . > MSGWPGM           Name
    // Library . . . . . . . . . . . *CURLIB Name, *CURLIB
    // Module . . . . . . . . . . . . . > MSGWPGM        Name, generic*, *PGM, *ALL
    // Library . . . . . . . . . . . >   MyLib           Name, *LIBL, *CURLIB...
    // + for more values > SYSVALR
    // Text 'description' . . . . . . . > 'list active jobs in MSGW status'

    H option(*nodebugio: *srcstmt) debug(*yes)
     
    * CrtUsrSpc: Create User Space for OS/400 API's
    //Fntfyhist O E DISK
    *
    d QUSCRTUS pr extpgm('QUSCRTUS')
    d UsrSpc 20A const
    d ExtAttr 10A const
    d InitialSize 10I 0 const
    d InitialVal 1A const
    d PublicAuth 10A const
    d Text 50A const
    d Replace 10A const
    d ErrorCode 32766A options(*nopass: *varsize)
    *
    * --- Prototype for API Retrive User Space
    *
    d QUSRTVUS pr extpgm( 'QUSRTVUS' )
    d QRtvUserSpace...
    d 20
    d QRtvStartingPosition...
    d 8b 0
    d QRtvLengthOfData...
    d 8b 0
    d QRtvReceiverVariable...
    d 32048
    d QRtvError...
    d 256
    * --- Prototype for API Retrive List Job
    *
    d QUSLJOB pr extpgm( 'QUSLJOB' )
    d QJobUserSpace...
    d 20
    d QJobFormatName...
    d 8
    d QJobJobName...
    d 26
    d QFldStatus...
    d 10
    d QFldError...
    d 256
    d QJobType...
    d 1
    d QNbrFldRtn...
    d 8b 0
    d QKeyFldRtn...
    d 8b 0 dim( 100 )
    *
    d qcmdexc pr extpgm( 'QCMDEXC' )
    d os400_cmd 2000A options( *varsize ) const
    d cmdlength 15P 5 const
    *
    * Defined variables
    *
    d emailaddress s 24 inz('myemail@mycompany.com')  //our mod
    d phoneaddress s 24 inz('MyPhone@myprovider.com')  //out mod
    d notifyaddress s 24
    d size s 10I 0
    d UsrSpcName s 20 inz( 'DSPJOB QTEMP ' )
    d DayOfWeek s 4a
    d TimeOfDay s 6a
    d datetimestampa s 26a
    d datetimestampz s z inz(*sys)
    d addmin s 3 0
    d sbdate s 6a
    d sbtime s 6a
    *
    ******************************************************************
    dQUSA0100 DS
    d QUsrSpcOffset...
    d 1 4B 0
    d QUsrSpcEntries...
    d 9 12B 0
    d QUsrSpcEntrieSize...
    d 13 16B 0
    dLJOBINPUT ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d Status...
    d 27 36
    d UserSpace...
    d 37 46
    d UserSpaceLibrary...
    d 47 56
    d Format...
    d 57 64
    d JobType...
    d 65 65
    d Reserved01...
    d 66 68
    d Reserved02...
    d 69 72B 0
    *

    1,325 pointsBadges:
    report
  • azohawk
    // The orignial code was posted on CODE400.com by "jamief" on 7/18/2008
    //-----Compiling instructions------------- 
    // Compile with CRTRPGMOD, then create as a program as follows
    // Create Program (CRTPGM)
    // Program . . . . . . . . . . . . > MSGWPGM           Name
    // Library . . . . . . . . . . . *CURLIB Name, *CURLIB
    // Module . . . . . . . . . . . . . > MSGWPGM        Name, generic*, *PGM, *ALL
    // Library . . . . . . . . . . . >   MyLib           Name, *LIBL, *CURLIB...
    // + for more values > SYSVALR
    // Text 'description' . . . . . . . > 'list active jobs in MSGW status'
    
    H option(*nodebugio: *srcstmt) debug(*yes)
     
    * CrtUsrSpc: Create User Space for OS/400 API's
    //Fntfyhist O E DISK
    *
    d QUSCRTUS pr extpgm('QUSCRTUS')
    d UsrSpc 20A const
    d ExtAttr 10A const
    d InitialSize 10I 0 const
    d InitialVal 1A const
    d PublicAuth 10A const
    d Text 50A const
    d Replace 10A const
    d ErrorCode 32766A options(*nopass: *varsize)
    *
    * --- Prototype for API Retrive User Space
    *
    d QUSRTVUS pr extpgm( 'QUSRTVUS' )
    d QRtvUserSpace...
    d 20
    d QRtvStartingPosition...
    d 8b 0
    d QRtvLengthOfData...
    d 8b 0
    d QRtvReceiverVariable...
    d 32048
    d QRtvError...
    d 256
    * --- Prototype for API Retrive List Job
    *
    d QUSLJOB pr extpgm( 'QUSLJOB' )
    d QJobUserSpace...
    d 20
    d QJobFormatName...
    d 8
    d QJobJobName...
    d 26
    d QFldStatus...
    d 10
    d QFldError...
    d 256
    d QJobType...
    d 1
    d QNbrFldRtn...
    d 8b 0
    d QKeyFldRtn...
    d 8b 0 dim( 100 )
    *
    d qcmdexc pr extpgm( 'QCMDEXC' )
    d os400_cmd 2000A options( *varsize ) const
    d cmdlength 15P 5 const
    *
    * Defined variables
    *
    d emailaddress s 24 inz('myemail@mycompany.com')  //our mod
    d phoneaddress s 24 inz('MyPhone@myprovider.com')  //out mod
    d notifyaddress s 24
    d size s 10I 0
    d UsrSpcName s 20 inz( 'DSPJOB QTEMP ' )
    d DayOfWeek s 4a
    d TimeOfDay s 6a
    d datetimestampa s 26a
    d datetimestampz s z inz(*sys)
    d addmin s 3 0
    d sbdate s 6a
    d sbtime s 6a
    *
    ******************************************************************
    dQUSA0100 DS
    d QUsrSpcOffset...
    d 1 4B 0
    d QUsrSpcEntries...
    d 9 12B 0
    d QUsrSpcEntrieSize...
    d 13 16B 0
    dLJOBINPUT ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d Status...
    d 27 36
    d UserSpace...
    d 37 46
    d UserSpaceLibrary...
    d 47 56
    d Format...
    d 57 64
    d JobType...
    d 65 65
    d Reserved01...
    d 66 68
    d Reserved02...
    d 69 72B 0
    *
    dLJOB100 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    *
    dLJOB200 ds qualified
    d JobName...
    d 1 10
    d UserName...
    d 11 20
    d JobNumber...
    d 21 26
    d InternalJobId...
    d 27 42
    d Status...
    d 43 52
    d JobType...
    d 53 53
    d JobSubType...
    d 54 54
    d Reserved01...
    d 55 56
    d JobInfoStatus...
    d 57 57
    d Reserved02...
    d 58 60
    d NumberOfFieldsReturned...
    d 61 64B 0
    d ReturnedData...
    d 65 1064
    *
    dLJOB200KEY ds qualified
    d KeyNumber01...
    d 1 4B 0
    d NumberOfKeys...
    d 5 8B 0
    *
    dLJOBKEYINFO ds qualified
    d LengthOfInformation...
    d 1 4b 0
    d KeyField...
    d 5 8b 0
    d TypeOfData...
    d 9 9
    d Reserved01...
    d 10 12
    d LengthOfData...
    d 13 16B 0
    d KeyData...
    d 17 1016
    *
    * APIErrDef Standard API error handling structure. *
     *
    dQUSEC DS
    d ErrorBytesProvided...
    d 1 4B 0
    d ErrorBytesAvailble...
    d 5 8b 0
    d ErrorExceptionId...
    d 9 15
    d ErrorReserved...
    d 16 16
     *
    dAPIError DS
    d APIErrorProvied...
    dLIKE( ErrorBytesProvided )
    dINZ( %LEN( APIError ) )
    d APIErrorAvailble...
    dLIKE( ErrorBytesAvailble )
    d APIErrorMessageID...
    dLIKE( ErrorExceptionId )
    d APIErrorReserved...
    dLIKE( ErrorReserved )
    d APIErrorInformation...
    d 240A
     *-----------------------------------------------------------------
     * program status dataarea
     *-----------------------------------------------------------------
    d PgmSts SDS
    d P1User 254 263
    d @job 244 253
    d W1Program *PROC
     *--------------------------------------------------------------*
     * work fields *
     *--------------------------------------------------------------*
    d Variables ds
    d Q 1 inz( '''' )
    d Count 15 0 inz( 0 )
    d KeyCount 15 0 inz( 0 )
    d EndPos 15 0 inz( 0 )
    d JobbStatus 4 inz( ' ' )
    d Subsystem 20 inz( ' ' )
    d ReturnCode 1 inz( ' ' )
    d FormatName 8 inz( ' ' )
    d QualifedJobName...
    d 26 inz( ' ' )
    d JobStatus 10 inz( ' ' )
    d JobType 1 inz( ' ' )
    d NbrOfFldRtn 8B 0 inz( 0 )
    d KeyFldRtn 8B 0 inz( 0 ) dim( 100 )
    d StartingPosition...
    d 8B 0 inz( 0 )
    d LengthOfData...
    d 8B 0 inz( 0 )
    d KeyStartingPosition...
    d 8B 0 inz( 0 )
    d KeyLengthOfData...
    d 8B 0 inz( 0 )
    d ReceiverVariable...
    d 32048
    d OS400_Cmd 2000 inz( ' ' )
    d CmdLength 15P 5 inz( %size( OS400_Cmd ) )
    d True 1 inz( *on )
    d False 1 inz( *off )
    *
    /COPY QCPYSRC,SYSVALR_P
    // begin free format code 
    // Create a user space
    //
    size = 10000;
    // Create a user space
    QUSCRTUS(UsrSpcName: 'USRSPC': size: x'00': '*ALL':
    'Temp User Space for QUSLJOB API': '*YES': APIError);
    
    DayOfWeek = rtvsysval( 'QDAYOFWEEK' );//begin our mod
    TimeOfDay = rtvsysval( 'QTIME' );
    exsr CheckStatusOfJob;
    if DayOfWeek = '*SUN' or   
     DayOfWeek = '*SAT' or
     TimeOfDay > '170000' or
     TimeOfDay < '060000';
     Addmin = 60;
    else;
     addmin = 15;
    endif;                     //end our mod
    
    datetimestampz = datetimestampz + %minutes(addmin);
    datetimestampa = %char(datetimestampz);
    %subst(sbdate:1:2) = %subst(datetimestampa:6:2);
    %subst(sbdate:3:2) = %subst(datetimestampa:9:2);
    %subst(sbdate:5:2) = %subst(datetimestampa:3:2);
    %subst(sbtime:1:2) = %subst(datetimestampa:12:2);
    %subst(sbtime:3:2) = %subst(datetimestampa:15:2);
    %subst(sbtime:5:2) = '00';
    //format the submit job for the next check and send.
    os400_cmd = ' SBMJOB CMD(Call lstactjobp) LOGCLPGM(*JOBD) ' +
    ' SCDDATE(' + SBDATE + ')' +
    ' SCDTIME(' + SbTIME + ')' +
    ' JOB(CHKMSGW) ' +
    ' JOBQ(QGPL/QBATCHN) ' +
    ' USER(QSYSOPR) ';
    qcmdexc ( os400_cmd : %size ( os400_cmd ) );
    *inlr = *on;
    // *************************************************************
    // check status of an job
    // -------------------------------------------------------------
    begsr CheckStatusOfJob;
    // run API to fill user space with information about all iSeries job
    FormatName = 'JOBL0200';
    QualifedJobName = '*ALL ' + '*ALL ' + '*ALL ';
    JobStatus = '*ACTIVE';
    JobType = '*';
    NbrOfFldRtn = 2;
    KeyFldRtn( 1 ) = 0101;
    KeyFldRtn( 2 ) = 1906;
    callp QUSLJOB( UsrSpcName : FormatName : QualifedJobName :
    JobStatus : APIError :
    JobType : NbrOfFldRtn : KeyFldRtn );
    
    // if error message from the retrieve job API then dump program
    if APIErrorMessageID <> ' ';
     dump;
     ReturnCode = True;
     leavesr;
    endif;
    // run API to get user space attribute
    StartingPosition = 125;
    LengthOfData = 16;
    callp QUSRTVUS( UsrSpcName : StartingPosition :
    LengthOfData : ReceiverVariable :
    APIError );
    QUSA0100 = ReceiverVariable;
     // if error message from the retrieve user space API then dump program
    if APIErrorMessageID <> ' ';
     dump;
     ReturnCode = True;
     leavesr;
    endif;
    
    // preperation to read from user space
    StartingPosition = QUsrSpcOffset + 1;
    LengthOfData = QUsrSpcEntrieSize;
    // read from user space
    
    for count = 1 to QUsrSpcEntries;
     callp QUSRTVUS( UsrSpcName : StartingPosition :
     LengthOfData : ReceiverVariable :
     APIError );
     LJOB200 = ReceiverVariable;
    
     if APIErrorMessageID <> ' ';
      dump;
      ReturnCode = True;
      leavesr;
     endif;
    
    // check status of job
     JobbStatus = ' ';
     Subsystem = ' ';
     LJobKeyInfo = LJob200.ReturnedData;
    // Job type
    // A The job is an autostart job.
    // B The job is a batch job.
    // I The job is an interactive job.
    // M The job is a subsystem monitor job.
    // R The job is a spooled reader job.
    // S The job is a system job.
    // W The job is a spooled writer job.
    // X The job is the SCPF system job
    // Job subtype
    // D The job is a batch immediate job.
    // E The job started with a procedure start request.
    // F The job is an AS/400 Advanced 36 machine server job.
    // J The job is a prestart job.
    // P The job is a print driver job. 
    // T The job is a System/36 multiple requester terminal (MRT) job.
    // U The job is an alternate spool user.
     KeyStartingPosition = 1;
     KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
     for keycount = 1 to LJob200.NumberOfFieldsReturned;
      LJobKeyInfo = %subst( LJob200.ReturnedData :
      KeyStartingPosition :
      KeyLengthOfData );
      KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
      LJobKeyInfo = %subst( LJob200.ReturnedData :
      KeyStartingPosition :
      KeyLengthOfData );
      Endpos = LJobKeyInfo.LengthOfData;
      if LJobKeyInfo.KeyField = 0101;
       JobbStatus = %subst( LJobKeyInfo.KeyData : 1 : Endpos );
      elseif LJobKeyInfo.KeyField = 1906;
       Subsystem = %subst( LJobKeyInfo.KeyData : 1 : Endpos );
      endif;
       KeyStartingPosition = KeyStartingPosition + KeyLengthOfData;
      endfor;
    
     // if job in message wait then email message to address in
     // variable email address
     if Jobbstatus = 'MSGW'; //begin our mod
      if DayOfWeek = '*SUN' or
       DayOfWeek = '*SAT' or
       TimeOfDay > '170000' or
       TimeOfDay < '060000';
       notifyaddress = phoneaddress; //off hours
      Else;
       notifyaddress = emailaddress; //work hours
      ENDIF;   //end our mod
    
      os400_cmd = 'snddst type(*lmsg) ' +
      'tointnet((' + Q + %trim(notifyAddress) +
      Q + ')) dstd(' + Q +
      'Job in MSGW status! ' +
      %trim(@job) + ' ' + %char(%time()) +
      Q + ') longmsg(' + Q +
      'Job in Message wait: ' +
      %trim(ljob200.jobname) + ' ' +
      %trim(ljob200.username) + ' ' +
      %trim(ljob200.jobnumber) + ' sent at ' +
      %char(%time()) +
      Q +')' + ' USRID(*CURRENT ) ' ;
    
    // prepare to write to history
    //njobnam = %trim(ljob200.jobname;
    //njobusr = %trim(ljob200.username;
    //njobnum = %trim(ljob200.jobnumber;
    //nnotdat = %date();
    //nnottim = %time();
    //nnotsnd = notifyaddress;
    //write ntfyhstr;
    
      qcmdexc ( os400_cmd : %size ( os400_cmd ) );
     endif;
     StartingPosition = StartingPosition + LengthOfData;
    endfor;
    endsr;
    
    
    
    1,325 pointsBadges:
    report
  • thaihi
    Thanks azohawk for your help..
    50 pointsBadges:
    report
  • thaihi
    Hi ToddN2000 & Azohawk, Can you guys help me here to understand whats going wrong. I have created a CL program to create user space and get the active jobs from API QUSLJOB stored in User space. But the CL program is running fine and no errors in the log but user space is not created

    PGM        PARM(&USRSPC)                                 
    DCL        VAR(&USRSPCNAME) TYPE(*CHAR) LEN(20)          
    DCL        VAR(&USRSPC) TYPE(*CHAR) LEN(10)              
    DCL        VAR(&USRSPCNAM) TYPE(*CHAR) LEN(10)           
    DCL        VAR(&USRSPCLIB) TYPE(*CHAR) LEN(10)           
    DCL        VAR(&USRSPCERR) TYPE(*CHAR) LEN(8)            
    CHGVAR     VAR(&USRSPCNAM) VALUE(&USRSPC)                
    CHGVAR     VAR(&USRSPCLIB) VALUE(<My Library>)               
    CHGVAR     VAR(%SST(&USRSPCNAME 1 10)) VALUE(&USRSPCNAM) 
    CHGVAR     VAR(%SST(&USRSPCNAME 11 10)) VALUE(&USRSPCLIB)
    CALL       PGM(QUSCRTUS) PARM(&USRSPCNAME ' ' '10000' +  
                 X'00' '*ALL ' 'Temp User Space for +        
                 QUSLJOB API' '*YES' &USRSPCERR)             
    ENDPGM

    - This is part of my CL program, I have put it in debugger and its not giving any error and I have put this in separate CL program and ran it , its still not giving any error but User Space is not created. Can you please help me on this ? Thanks
    50 pointsBadges:
    report
  • TheRealRaven
    When I run it, an error is returned. I can't tell what the error is, though, because the &USRSPCERR error structure isn't properly initialized (or is way too small).

    Actually, I can see problems with the CALL command. Some of the PARM() values are incorrect. But you should fix the error structure to see how the errors are returned.

    First thing to do is run it in debug again. Stop after the CALL command and look at the value in &USRSPCERR.

    Then change the DCL to be:

    DCL        VAR(&USRSPCERR) TYPE(*CHAR) LEN(8)  value( x'0000000000000000' )
    Run the program again after recompiling.


    6,975 pointsBadges:
    report
  • TheRealRaven
    Also, if you would have searched this site instead of asking your question, you would have found program code much sooner.
    6,975 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:

Share this item with your network:

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