GETSPLF and PUTSPLF – read and write spools to physical files including all Advanced Function Printing Data Stream (AFPDS)

  • Home
  • /
  • Blog
  • /
  • GETSPLF and PUTSPLF – read and write spools to physical files including all Advanced Function Printing Data Stream (AFPDS)

August 4, 2017

GETSPLF and PUTSPLF – read and write spools to physical files including all Advanced Function Printing Data Stream (AFPDS)

By NickLitten

August 4, 2017

snippet, API, getsplf, putsplf, splf

Wow- that has got to be the longest url yet 😉

If you want to write a program to save and restore SPLF information from any output queue on your IBM i System, then you have come to the right place!

QSPGETF AND QSPPUTF APIs AND COMMANDS

IBM Knowledgebase item 8011926 describes two APIs that are undocumented in the IBM i manuals. The two APIs, Get Spooled File (QSPGETF) and Put Spooled File (QSPPUTF), copy spool files to and restore them from physical files, respectively.

The advantage of QSPGETF and QSPPUTF over the well-documented Copy Spooled File command (CPYSPLF) is that the APIs are able to copy Advanced Function Printing Data Stream (AFPDS) and Intelligent Printer Data Stream (IPDS) spool files, whereas CPYSPLF cannot.

You can call the QSPGETF and QSPPUTF APIs directly, or you can call them using command wrappers over the APIs.

Calling the APIs Directly

The QSPGETF API call below saves spool file QPRINT to database file SPOOLDB in USER1LIB library, member MBR1, where the spool file number is 1 and the spool file job is 010160/user1/dsp03:

CALL PGM(QSYS/QSPGETF) PARM('QPRINT ' 'SPOOLDB USER1LIB ' 'DSP03 USER1 010160' X'0001' 'MBR1 ')

The QSPPUTF API call below creates a spool file in USER1 output queue in QGPL library from the MBR1 member in the SPOOLDB database file:

CALL PGM(QSYS/QSPPUTF) PARM('SPOOLDB USER1LIB ' 'USER1 QGPL ' 'MBR1 ')

Calling the APIs from command wrappers

The two calls below correspond to the examples above, but these examples use the command calls instead of calls directly to the APIs:

GETSPLF FILE(QPRINT) TOFILE(USER1LIB/SPOOLDB) JOB(010160/USER1/DSP03) SPLNBR(1) TOMBR(MBR1)

PUTSPLF FROMFILE(USER1LIB/SPOOLDB) OUTQ(QGPL/USER1) FROMMBR(MBR1)

Although the QSPGETF and QSPPUTF APIs are included in every OS/400 release since V3R2, the commands are not included. Luckily the source code for command GETSPLF, command interface to QSYS/QSPGETF looks like this:

To compile the command, on the OS/400 command line type the following:

RPG Code Snippet GETSPLF and PUTSPLFCRTCMD CMD(lib_name/GETSPLF) PGM(QSYS/QSPGETF) SRCFILE(lib_name/file_name) SRCMBR(*CMD)

GETSPLF: CMD PROMPT('Get Spooled File')

 PARM KWD(FILE) TYPE(*NAME) LEN(10) RTNVAL(*NO) RSTD(*NO) MIN(1) +
 MAX(1) FILE(*IN) FULL(*NO) EXPR(*YES) VARY(*NO) PASSATR(*NO) +
 PROMPT('Spooled file')

 PARM KWD(TOFILE) TYPE(Q1) RTNVAL(*NO) MIN(1) MAX(1) FILE(*OUT) +
 PROMPT('To data base file')

 PARM KWD(JOB) TYPE(Q2) RTNVAL(*NO) DFT(*) SNGVAL(*) MIN(0) MAX(1) +
 FILE(*NO) PROMPT('Job name')

 PARM KWD(SPLNBR) TYPE(*INT2) RTNVAL(*NO) RSTD(*NO) DFT(*ONLY) +
 RANGE(1 9999) SPCVAL((*ONLY 0) (*LAST -1)) MIN(0) MAX(1) +
 EXPR(*YES) VARY(*NO) PASSATR(*NO) PROMPT('Spooled file number')

 PARM KWD(TOMBR) TYPE(*NAME) LEN(10) RTNVAL(*NO) RSTD(*NO) +
 DFT(*FIRST) SPCVAL(*FIRST) MIN(0) MAX(1) FILE(*NO) FULL(*NO) +
 EXPR(*YES) VARY(*NO) PASSATR(*NO) PROMPT('To member')

 Q1: QUAL TYPE(*NAME) LEN(10) RSTD(*NO) MIN(1) FULL(*NO) VARY(*NO) +
 EXPR(*YES) PASSATR(*NO)

 QUAL TYPE(*NAME) LEN(10) RSTD(*NO) DFT(*LIBL) MIN(0) FULL(*NO) +
 SPCVAL((*LIBL) (*CURLIB *CURLIB)) VARY(*NO) EXPR(*YES)+
 PASSATR(*NO) PROMPT('Library')

 Q2: QUAL TYPE(*NAME) LEN(10) RSTD(*NO) MIN(1) FULL(*NO) +
 VARY(*NO) EXPR(*YES) PASSATR(*NO)

 QUAL TYPE(*NAME) LEN(10) RSTD(*NO) MIN(0) FULL(*NO) VARY(*NO) +
 EXPR(*YES) PASSATR(*NO) PROMPT('User')

 QUAL TYPE(*CHAR) LEN(6) RSTD(*NO) RANGE(000000 999999) MIN(0) +
 FULL(*YES) EXPR(*YES) PASSATR(*NO) PROMPT('Number')

The source code for command PUTSPLF, command interface to QSYS/QSPPUTF looks like this:

To compile the command, on the OS/400 command line type the following:

CRTCMD CMD(lib_name/PUTSPLF) PGM(QSYS/QSPPUTF) + SRCFILE(lib_name/file_name) SRCMBR(*CMD)

/*********************************************************************/

/* COMMAND FROM IBM - CALLS API QSPPUTF */
 /* THIS COMMAND WILL COPY AN AFPDS OR IPDS DISK FILE BACK TO A */
 /* SPOOL FILE. THE SPOOL FILE WILL BE QPRINT. */
 /* OF THE CONTROL CHARACTERS IN THE SPOOL FILE. */
 /* THIS COMMAND WILL RESTORE THE SPOOL FILE FROM A 4083 CHARACTER */
 /* FILE. USE THE GETSPLF COMMAND TO STORE TO A DISK FILE. */
 /*********************************************************************/
 PUTSPLF: CMD PROMPT('Put Back To Spooled File')

PARM KWD(TOFILE) TYPE(Q1) RTNVAL(*NO) MIN(1) +
 MAX(1) FILE(*OUT) PROMPT('From data base file')

PARM KWD(OUTQ) TYPE(Q2) PROMPT('Spooled Output +
 Queue Name:')

 PARM KWD(FRMMBR) TYPE(*NAME) LEN(10) RTNVAL(*NO) +
 RSTD(*NO) DFT(*FIRST) SPCVAL((*FIRST)) +
 MIN(0) MAX(1) FILE(*NO) FULL(*NO) +
 EXPR(*YES) VARY(*NO) PASSATR(*NO) +
 PROMPT('From member')

Q1: QUAL TYPE(*NAME) LEN(10) RSTD(*NO) MIN(1) +
 FULL(*NO) EXPR(*YES) VARY(*NO) PASSATR(*NO)

QUAL TYPE(*NAME) LEN(10) RSTD(*NO) DFT(*LIBL) +
 SPCVAL((*LIBL) (*CURLIB *CURLIB)) MIN(0) +
 FULL(*NO) EXPR(*YES) VARY(*NO) +
 PASSATR(*NO) PROMPT('Library')

Q2: QUAL TYPE(*NAME) LEN(10) DFT(*PRTFILE) +
 SPCVAL((*PRTFILE)) EXPR(*YES)

 QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
 SPCVAL((*LIBL)) EXPR(*YES) +
 PROMPT('Library Name:')
  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

    >