cancel
Showing results for 
Search instead for 
Did you mean: 

Print SAPSCRIPT in background

Former Member
0 Kudos

Hi Guys,

I have a function module that runs in the background which in turn calls a print program for a sapscript. Here is the code I have in the print program:

IF sy-batch = space.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

dialog = 'X'

form = 'ZTRAVELER'

language = 'E'

IMPORTING

RESULT = i_itcpp.

MOVE-CORRESPONDING i_itcpp TO itcpo.

ELSE.

MESSAGE i000 WITH 'Printing Traveller'.

itcpo-tdimmed = 'X'.

itcpo-tdnewid = 'X'.

itcpo-tddelete = ' '.

itcpo-tdcopies = '1'.

itcpo-tdlifetime = '1'.

itcpo-tdprogram = sy-repid.

itcpo-tddest = 'LOCL'.

itcpo-tdpreview = ' '.

itcpo-tdsenddate = sy-datum.

itcpo-tdsendtime = ' '.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

device = 'PRINTER'

dialog = ' '

form = 'ZTRAVELER'

language = sy-langu

OPTIONS = itcpo.

ENDIF.

My form appears in the spool but it doesn't print immediately unless I manually go to SP01 and choose Print. Does anyone here know how I can make my form print immediately? Thanks, points will be rewarded for useful suggestions!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

U can't use the device LOCL: it's assigned to the default printer of your pc, so it can't used in background, because it's a front-end process.

Use another SAP printer:

itcpo-tdimmed = 'X'.

itcpo-tdnewid = 'X'.

itcpo-tddelete = ' '.

itcpo-tdcopies = '1'.

itcpo-tdlifetime = '1'.

itcpo-tdprogram = sy-repid.

*itcpo-tddest = 'LOCL'.

<b>itcpo-tddest = <SAP PRINTER>.</b>

itcpo-tdpreview = ' '.

itcpo-tdsenddate = sy-datum.

itcpo-tdsendtime = ' '.

Max

Former Member
0 Kudos

Hi Max,

Going the right way here, but the program will be run by different people at different times. I can't hard code a printer name in here because of that. I want it to be generic enough so that no matter who uses it, their default printer will be used. Is there a way to do this?

Former Member
0 Kudos

Hi

Try to set * for device: it should mean "to use the default printer user":

itcpo-tdimmed = 'X'.

itcpo-tdnewid = 'X'.

itcpo-tddelete = ' '.

itcpo-tdcopies = '1'.

itcpo-tdlifetime = '1'.

itcpo-tdprogram = sy-repid.

<b>itcpo-tddest = '*'.</b>

itcpo-tdpreview = ' '.

itcpo-tdsenddate = sy-datum.

itcpo-tdsendtime = ' '.

So u make sure every user has setted a default printer (go to Systems->User profile->Own data: Defaults or trx SU3).

In this way the system'll print on the default printer, the problem will be if the user sets LOCL as default printer: in this case the system'll be able to print in background and u can't do nothing.

Another solution can be to insert a parameter in selection-screen to choose the printer for background mode:

<b>PARAMETERS: P_DEST LIKE ITCPP-TDDEST.</b>

TABLES: ITCPO.

ITCPO-TDIMMED = 'X'.

ITCPO-TDNEWID = 'X'.

ITCPO-TDDELETE = ' '.

ITCPO-TDCOPIES = '1'.

ITCPO-TDLIFETIME = '1'.

ITCPO-TDPROGRAM = SY-REPID.

*itcpo-tddest = 'LOCL'.

<b>ITCPO-TDDEST = P_DEST.</b>

ITCPO-TDPREVIEW = ' '.

ITCPO-TDSENDDATE = SY-DATUM.

ITCPO-TDSENDTIME = ' '.

Max

Former Member
0 Kudos

Hi Max,

Thanks, I think the best I can do is to set the parameter to '*' as you suggested. That way if the default printer is anything other than 'LOCL' it'll print immediately, if not the user will just have to go to SP01 and manually print it. Thanks for the help. I'm awarding all points to you!

Answers (0)