REPORT ZEXAMPLE.

TYPE-POOLS: SLIS,

SP01R.

DATA: SPOOL_OWNER LIKE SY-UNAME,

PRN LIKE TSP03-PADEST VALUE 'LOCL',

SPOOL_NUMBER LIKE TSP01-RQIDENT.

DATA: BEGIN OF IRQTAB OCCURS 0.

INCLUDE STRUCTURE RSPORQ.

DATA: END OF IRQTAB.

DATA: LTAB TYPE SP01R_TVIEW WITH HEADER LINE,

RS_SELFIELD TYPE SLIS_SELFIELD.

SPOOL_OWNER = SY-UNAME.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

RQOWNER = SPOOL_OWNER

RQDEST = PRN

TABLES

SPOOLREQUESTS = IRQTAB.

WRITE:/ 'PRINTING SPOOLS OF', SPOOL_OWNER, 'ON PRINTER', PRN, 'NOW.'.

LOOP AT IRQTAB.

SPOOL_NUMBER = IRQTAB-RQIDENT.

CALL FUNCTION 'RSPO_OUTPUT_SPOOL_REQUEST'

EXPORTING

DEVICE = PRN

SPOOL_REQUEST_ID = SPOOL_NUMBER

EXCEPTIONS

OTHERS = 1.

SKIP.

IF SY-SUBRC EQ 0.

WRITE: IRQTAB-RQIDENT, 'PRINTED ON', PRN.

EXIT. "ONLY PRINT ONE IN THIS EXAMPLE

ELSE.

WRITE: IRQTAB-RQIDENT, 'NOT PRINTED ON', PRN.

ENDIF.

ENDLOOP.

* PRINT THE LAST ONE, WITH NO PRINT DIALOG BOX

MOVE-CORRESPONDING IRQTAB TO LTAB.

APPEND LTAB.

CALL FUNCTION 'RSPO_RPRINT_SPOOLREQ'

EXPORTING

TEND = SPOOL_NUMBER

POPUP = ' '

TABLES

REQ_VIEW = LTAB

CHANGING

RS_SELFIELD = RS_SELFIELD

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC EQ 0.

WRITE:/ LTAB-RQIDENT, 'PRINTED ON DEFAULT PRINTER'.

ELSE.

WRITE:/ LTAB-RQIDENT, 'NOT PRINTED'.

ENDIF.

* DOWNLOAD A SPOOLJOB TO A FILE

CALL FUNCTION 'RSPO_DOWNLOAD_SPOOLJOB'

EXPORTING

ID = LTAB-RQIDENT

FNAME = 'C:\TEMP\SPOOLFILE.TXT'.

WRITE:/ LTAB-RQIDENT, 'DOWNLOADED TO C:\TEMP\SPOOLFILE.TXT'.