Please enable JavaScript to view this site.
You can use the IBM supplied API QUSRSPLA to retrieve the attributes of a spool file. If you specify *LAST [-1] as the Spool File number it will return the actual number.
Here is some sample RPGLE code to retrieve the spool file number:
*
* Receiver variable for spool file attributes - SPLA0200
D RcvVar DS 3745
D JobName 49 58
D UserName 59 68
D JobNbr 69 74
D FileName 75 84
D FileNbr 85 88B 0
D FormTyp 89 98
D UserData 99 108
D HoldFile 129 138
D TotPages 149 152B 0
D Copies 173 176B 0
D OutQName 191 200
D OutQLib 201 210
D DateCreate 211 217
D TimeCreate 218 223
D DevFileNam 224 233
D DevFileLib 234 243
*
* API Error Code Parameter data structure
D APIErr DS
D ErByProv 1 4B 0 INZ(116)
D ErByAvail 5 8B 0
D ErExId 9 15
D ErExData 17 116
*
* Parameters for QUSRSPLA API
D DS
D RsRLen 1 4B 0 INZ(3745)
D RsFmtN 5 12 INZ('SPLA0200')
D RsQJob 13 38
D RsJbNm 13 22
D RsUsNm 23 32
D RsJbNo 33 38
D RsInJb 39 54
D RsInSp 55 70
D RsSpNm 71 80
D RsSpNo 81 84B 0
*
* Setup paramters for QUSRSPLA AI...
C MoveL XXUserNam RsUsNm *User name
C MoveL XXJobNam RsQJob *Qualjobname
C MoveL XXJobNbr RsJbNo *Qualjobnumber
C MoveL XXSpoolNam RsSpNm *SPLF name
C Clear RsInJb *Internal JobNo
C Clear RsInSp *Internal SPLF
*
* Spooled number... For *LAST use -1
C Z-Sub 1 RsSpNo *SPLF number
*
* Call QUSRSPLA API...
C Call 'QUSRSPLA' 99 *99 - error
C Parm RcvVar *Receiver Var
C Parm RsRLen *RCVVAR length
C Parm RsFmtN *Format name
C Parm RsQJob *Qual job name
C Parm RsInJb *Internal Job
C Parm RsInSp *Internal SPLF
C Parm RsSpNm *SPLF name
C Parm RsSpNo *SPLF number
C Parm APIErr *Error code
* Error... Add error handling as required
C ErByAvail IfGt 0
C Else
* Good...
C Z-Add FileNbr DaSNum *SPLF No retrn
C EndIf