You cannot do this in background.
One option that you can try is send the output to spool in the submit program and then get the data from the spool. This would work fine in background.
Check this sample code.
data: jobname type tbtcjob-jobname value 'JOBNAME'.
data: jobcount type tbtcjob-jobcount,
host type msxxlist-host.
data: starttimeimmediate type btch0000-char1 value 'X',
print_parameters TYPE pri_params.
DATA: seltab type table of rsparams,
seltab_wa like line of seltab,
ld_pernr type pernr-pernr.
seltab_wa-selname = 'SO_PERNR'.
seltab_wa-sign = 'I'.
seltab_wa-option = 'EQ'.
seltab_wa-low = ld_pernr.
append seltab_wa to seltab.
* Job open
call function 'JOB_OPEN'
EXPORTING
delanfrep = ' '
jobgroup = ' '
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit
IMPORTING
jobcount = jobcount
EXCEPTIONS
cant_create_job = 01
invalid_job_data = 02
jobname_missing = 03.
*Setup print parameters
*Only values used in example are to tell it not to print immediately
*and not display a print dialog box)
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
* ARCHIVE_ID = C_CHAR_UNKNOWN
* ARCHIVE_INFO = C_CHAR_UNKNOWN
* ARCHIVE_MODE = C_CHAR_UNKNOWN
* ARCHIVE_TEXT = C_CHAR_UNKNOWN
* AR_OBJECT = C_CHAR_UNKNOWN
* ARCHIVE_REPORT = C_CHAR_UNKNOWN
* AUTHORITY = C_CHAR_UNKNOWN
* COPIES = C_NUM3_UNKNOWN
* COVER_PAGE = C_CHAR_UNKNOWN
* DATA_SET = C_CHAR_UNKNOWN
* DEPARTMENT = C_CHAR_UNKNOWN
* DESTINATION = C_CHAR_UNKNOWN
* EXPIRATION = C_NUM1_UNKNOWN
IMMEDIATELY = ' ' " leave blank so is not sent to print
* IN_ARCHIVE_PARAMETERS = ' '
* IN_PARAMETERS = ' '
* LAYOUT = C_CHAR_UNKNOWN
* LINE_COUNT = C_INT_UNKNOWN
* LINE_SIZE = C_INT_UNKNOWN
* LIST_NAME = C_CHAR_UNKNOWN
* LIST_TEXT = C_CHAR_UNKNOWN
* MODE = ' '
* NEW_LIST_ID = C_CHAR_UNKNOWN
* PROTECT_LIST = C_CHAR_UNKNOWN
NO_DIALOG = 'X'
* RECEIVER = C_CHAR_UNKNOWN
* RELEASE = C_CHAR_UNKNOWN
* REPORT = C_CHAR_UNKNOWN
* SAP_COVER_PAGE = C_CHAR_UNKNOWN
* HOST_COVER_PAGE = C_CHAR_UNKNOWN
* PRIORITY = C_NUM1_UNKNOWN
* SAP_OBJECT = C_CHAR_UNKNOWN
* TYPE = C_CHAR_UNKNOWN
* USER = SY-UNAME
* USE_OLD_LAYOUT = ' '
* UC_DISPLAY_MODE = C_CHAR_UNKNOWN
* DRAFT = C_CHAR_UNKNOWN
* ABAP_LIST = ' '
* USE_ARCHIVENAME_DEF = ' '
* DEFAULT_SPOOL_SIZE = C_CHAR_UNKNOWN
* WITH_STRUCTURE = C_CHAR_UNKNOWN
* SUPPRESS_SHADING = C_CHAR_UNKNOWN
* PO_FAX_STORE = ' '
* NO_FRAMES = C_CHAR_UNKNOWN
IMPORTING
* OUT_ARCHIVE_PARAMETERS =
OUT_PARAMETERS = print_parameters
* VALID =
* VALID_FOR_SPOOL_CREATION =
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4.
*Execute abap program ZTESTREP in background job storing any output to spool
submit ZTESTREP to sap-spool and return
with selection-table seltab
user 'ADMIN' "user name with correct/additional authorisation
SPOOL PARAMETERS print_parameters
WITHOUT SPOOL DYNPRO
via job jobname
number jobcount.
* Close job
call function 'JOB_CLOSE'
EXPORTING
jobcount = jobcount
jobname = jobname
strtimmed = starttimeimmediate
EXCEPTIONS
cant_start_immediate = 01
invalid_startdate = 02
jobname_missing = 03
job_close_failed = 04
job_nosteps = 05
job_notex = 06
lock_failed = 07
others = 99.
Source :
SUBMIT ABAP Report in SAP