Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Background Submit to Spool, convert spool to PDF send via email

Former Member
0 Kudos

I am calling an ABAP in the background. this abap makes use of a custom table as the main driver ie on each change of vendor within this custom table I want to create a spool and email the spool - the spool is suppossed to be created via a submit RMCB0300 with screen selection to to sap-spool and return. I then want the program to take the spool convert it to PDF and email.

Problems I am encountering:

1. writing to the spool via background ABAP as follows

submit RMCB0300 with selection-table rspar

to sap-spool

spool parameters %_print

archive parameters %_archive

without spool dynpro and return.

Doesn't appear to be creating the spool - rspar is populated.

2. Best way to retrieve the correct spool number.

3. how to successfully convert PDF output after CONVERT_ABAPSPOOLJOB_2_PDF for email attachment - if this returns IT_PDF_OUTPUT.

is this the best way to do it:

Loop at IT_PDF_OUTPUT

Translate IT_PDF_OUTPUT using ' ~'.

concatenate gd_buffer it_pdf_output into gd_buffer

endloop.

translate gd_buffer using '~ '

Do it_mess_att = gd_buffer.

append it_mess_att.

shift gd_buffer left by 255 places

if gd_buffer is initial

exit.

endif.

enddo.

Thanks

Mark

Edited by: Matt on Apr 2, 2009 11:03 AM - amended title with formatting problems.

8 REPLIES 8

Former Member
0 Kudos

Please find the code for converting SPool to pdf and sending mail

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = LV_MI_RQIDENT

NO_DIALOG = 'X'

DST_DEVICE = LV_PRINT_PARMS-PDEST

IMPORTING

PDF_BYTECOUNT = LV_BYTECOUNT

PDF_SPOOLID = LV_RQIDENT

TABLES

PDF = LT_MTAB_PDF

EXCEPTIONS

ERR_NO_ABAP_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DESTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 9

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11

OTHERS = 12.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT LT_MTAB_PDF INTO LWA_MTAB_PDF.

TRANSLATE LWA_MTAB_PDF USING ' ~'.

CONCATENATE LV_GD_BUFFER LWA_MTAB_PDF INTO LV_GD_BUFFER.

CLEAR LWA_MTAB_PDF.

ENDLOOP.

TRANSLATE LV_GD_BUFFER USING '~ '.

DO.

LWA_MESS_ATT = LV_GD_BUFFER.

APPEND LWA_MESS_ATT TO LT_MESS_ATT.

CLEAR LWA_MESS_ATT.

SHIFT LV_GD_BUFFER LEFT BY 255 PLACES.

IF LV_GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

CLEAR: LWA_RECLIST, LT_RECLIST[],

LT_OBJHEAD, LT_OBJHEAD[],

LWA_OBJTXT, LT_OBJTXT[],

LWA_OBJBIN, LT_OBJBIN[],

LWA_OBJPACK, LT_OBJPACK[].

" CLEAR LT_OBJBIN.

REFRESH LT_OBJBIN.

LT_OBJBIN[] = LT_MESS_ATT[].

DESCRIBE TABLE LT_OBJBIN LINES LV_L_ATTACHMENT.

LWA_OBJTXT = ''.

APPEND LWA_OBJTXT TO LT_OBJTXT.

CLEAR LWA_OBJTXT.

DESCRIBE TABLE LT_OBJTXT LINES LV_L_TESTO.

LT_DOC_CHNG-OBJ_NAME = 'STATUS_REPORT'.

LT_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

LT_DOC_CHNG-OBJ_DESCR = 'Generated File'. "#EC NOTEXT

LT_DOC_CHNG-SENSITIVTY = 'F'.

LT_DOC_CHNG-SENSITIVTY = 'O'.

LT_DOC_CHNG-OBJ_PRIO = '1'.

LT_DOC_CHNG-DOC_SIZE = LV_L_TESTO * 255.

CLEAR LWA_OBJPACK-TRANSF_BIN.

LWA_OBJPACK-HEAD_START = 1.

LWA_OBJPACK-HEAD_NUM = 0.

LWA_OBJPACK-BODY_START = 1.

LWA_OBJPACK-BODY_NUM = LV_L_TESTO.

LWA_OBJPACK-DOC_TYPE = 'RAW'.

APPEND LWA_OBJPACK TO LT_OBJPACK.

CLEAR LWA_OBJPACK.

LWA_OBJPACK-TRANSF_BIN = 'X' .

LWA_OBJPACK-HEAD_START = 1.

LWA_OBJPACK-HEAD_NUM = 1.

LWA_OBJPACK-BODY_START = 1.

LWA_OBJPACK-BODY_NUM = LV_L_ATTACHMENT.

LWA_OBJPACK-DOC_TYPE = 'PDF'.

LWA_OBJPACK-OBJ_NAME ='SPOOL'.

LWA_OBJPACK-OBJ_DESCR = 'Test'.

LWA_OBJPACK-DOC_SIZE = LV_L_ATTACHMENT * 255.

APPEND LWA_OBJPACK TO LT_OBJPACK.

CLEAR LWA_OBJPACK.

CLEAR LWA_RECLIST.

LWA_RECLIST-COPY = 'X'.

LWA_RECLIST-RECEIVER = P_EMAIL.

LWA_RECLIST-REC_TYPE = 'U'.

LWA_RECLIST-NOTIF_DEL = 'X'.

LWA_RECLIST-NOTIF_NDEL = 'X'.

APPEND LWA_RECLIST TO LT_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = LT_DOC_CHNG

PUT_IN_OUTBOX = ' '

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = LT_OBJPACK

OBJECT_HEADER = LT_OBJHEAD

CONTENTS_BIN = LT_OBJBIN

CONTENTS_TXT = LT_OBJTXT

RECEIVERS = LT_RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

0 Kudos

Hi Phanandra

so you are saying the way to convert to readable PDF after convert_abapspooljob is

LOOP AT LT_MTAB_PDF INTO LWA_MTAB_PDF.

TRANSLATE LWA_MTAB_PDF USING ' ~'.

CONCATENATE LV_GD_BUFFER LWA_MTAB_PDF INTO LV_GD_BUFFER.

CLEAR LWA_MTAB_PDF.

ENDLOOP.

TRANSLATE LV_GD_BUFFER USING '~ '.

DO.

LWA_MESS_ATT = LV_GD_BUFFER.

APPEND LWA_MESS_ATT TO LT_MESS_ATT.

CLEAR LWA_MESS_ATT.

SHIFT LV_GD_BUFFER LEFT BY 255 PLACES.

IF LV_GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

if so that answers question 3 of my post

any ideas on the other 2 questions.

0 Kudos

Hi Mark,

[Submit to Spool & Spool to PDF & Send via email |http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm]

Check this link for your requirements...

Thanks & Regards,

Dileep .C

0 Kudos

Thanks guys

Looked at both your answers - unfortunately it didn't work the submit with the selection-table

does not appear to be creating the spool. tried it using GET_PRINT_PARAMETERS..before the submit

Tried using JOB_OPEN, submit JOB_CLOSE

Any other suggestions?

Thanks

0 Kudos

Hi Mark,

May if you are using smart form, i thik yu can directly capture thr spool request,

So you can debug the Smart function module if necesary for a perfect solution,

And i have seen a good examples in SAP Technical Tutorials about this spool to PDF & E-mail's.

Thanks & Regards,

Dileep .C

Former Member
0 Kudos

Hi Mark,

For your first question, try passing the parameters IMMEDIATELY & KEEP IN SPOOL flags with the SUBMIT statement, if that doesn't help, try running the program in foreground and see what the issue is and if the spool is getting created.

Answers to questions 2 & 3 can be found on SCN.

regards,

Advait

Former Member
0 Kudos

Hi Mark,

I have the same situation,

[How to Get Spool ID after PO release. (To send PDF for ext E-mail)|;

No Solution yet,

Thanks,

Dunlop.

Former Member
0 Kudos

It appears by submitting RMCB0300 this way a spool is not created so I created a custom program

Thanks'

Mark