Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Spool no. data to PDF and then to mail

Hi all ,

My requirement is i have to display all the spool request no.'s for the particular user and from that user will select the particular spool no. . and that particular data has to convert into PDF and that PDF should go to mail id specified in selection screen.

now my prob. is when i am downloading the PDF on desktop it is opening with right data and when i am sending to mail id with the same internal table with PDF format , the file is corrupted and giving some error.

for ur reference here i am sending my code , please check and let me know .

thanks & regards,

Anil kumar .

TABLES: tsp01,

soextreci1.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-020.

SELECT-OPTIONS : so_date1 FOR sy-datum OBLIGATORY,

so_time1 FOR sy-uzeit,

so_name1 FOR sy-uname,

so_splno FOR tsp01-rqident.

  • so_email FOR soextreci1-receiver OBLIGATORY.

PARAMETER : so_email TYPE soextreci1-receiver OBLIGATORY.

SELECTION-SCREEN : END OF BLOCK b1.

DATA : l_addrnumber TYPE adr7-addrnumber,

l_persnumber TYPE adr7-persnumber,

l_mail TYPE adr6-smtp_addr.

DATA : BEGIN OF it_tsp01 OCCURS 0,

rqident TYPE tsp01-rqident,

rqowner TYPE tsp01-rqowner,

rqcretime TYPE tsp01-rqcretime,

rqclient TYPE tsp01-rqclient,

rqo1name TYPE tsp01-rqo1name,

END OF it_tsp01.

DATA : l_date_low TYPE char8,

l_date_high TYPE char8,

l_time_low TYPE char8,

l_time_high TYPE char8,

l_final_low TYPE char16,

l_final_high TYPE char16,

markfield VALUE ' '.

DATA : BEGIN OF l_final OCCURS 0,

sig TYPE c,

opt TYPE char2,

low TYPE char16,

high TYPE char16,

END OF l_final.

*PARAMETERS:

  • spoolno LIKE tsp01-rqident,

  • download AS CHECKBOX DEFAULT 'X',

DATA : p_file TYPE rlgrap-filename VALUE 'C:\temp\file.pdf'."#EC NOTEXT

DATA otf LIKE itcoo OCCURS 100 WITH HEADER LINE.

DATA cancel.

DATA pdf LIKE tline OCCURS 100 WITH HEADER LINE.

DATA it_pdf LIKE pdf OCCURS 0 WITH HEADER LINE.

DATA doctab LIKE docs OCCURS 1 WITH HEADER LINE.

DATA: numbytes TYPE i,

arc_idx LIKE toa_dara,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

AT SELECTION-SCREEN OUTPUT.

SELECT SINGLE addrnumber

persnumber

FROM adr7

INTO (l_addrnumber,l_persnumber)

WHERE uname = sy-uname.

SELECT SINGLE smtp_addr

FROM adr6

INTO l_mail

WHERE addrnumber = l_addrnumber

AND persnumber = l_persnumber.

so_date1-sign = so_name1-sign = 'I'. "so_email-sign = 'I'.

so_date1-option = so_name1-option = 'BT'. "so_email-option = 'BT'.

so_date1-low = so_date1-high = sy-datum.

so_name1-low = so_name1-high = sy-uname.

  • so_email-low = so_email-high = l_mail.

APPEND : so_date1,so_name1.",so_email.

START-OF-SELECTION.

IF so_date1-low IS NOT INITIAL.

l_date_low = so_date1-low.

ENDIF.

IF so_date1-high IS NOT INITIAL.

l_date_high = so_date1-high.

ENDIF.

IF so_time1-low IS NOT INITIAL.

l_time_low = so_time1-low.

l_time_low+6(2) = '00'.

ENDIF.

IF so_time1-high IS NOT INITIAL.

l_time_high = so_time1-high.

l_time_high+6(2) = '00'.

ENDIF.

IF l_time_low IS NOT INITIAL.

CONCATENATE l_date_low l_time_low INTO l_final_low.

ELSE.

CONCATENATE l_date_low '00000000' INTO l_final_low.

ENDIF.

IF l_time_high IS NOT INITIAL .

IF so_date1-high IS NOT INITIAL.

CONCATENATE l_date_high l_time_high INTO l_final_high.

ENDIF.

ELSE.

CONCATENATE l_date_low '23595959' INTO l_final_high.

ENDIF.

l_final-sig = so_date1-sign.

l_final-opt = so_date1-option.

l_final-low = l_final_low.

l_final-high = l_final_high.

APPEND l_final.

CLEAR l_final.

SELECT rqident

rqowner

rqcretime

rqclient

rqo1name

FROM tsp01 INTO TABLE it_tsp01

WHERE rqcretime IN l_final

AND rqowner IN so_name1.

IF sy-subrc NE 0.

MESSAGE 'No data for the entered values' TYPE 'E'.

EXIT.

ENDIF.

CLEAR : so_name1,so_name1[],it_tsp01.

SORT it_tsp01 BY rqident.

LOOP AT it_tsp01.

WRITE : /1 sy-vline,

3 markfield AS CHECKBOX,

5(16) it_tsp01-rqident, 22 sy-vline,

23(10) it_tsp01-rqowner, 34 sy-vline,

35(16) it_tsp01-rqcretime, 52 sy-vline.

HIDE it_tsp01-rqident.

AT LAST.

WRITE : /1(52) sy-uline.

ENDAT.

ENDLOOP.

TOP-OF-PAGE.

WRITE: /1(52) sy-uline.

WRITE: /1 sy-vline,

5(16) 'Spool No.' COLOR COL_POSITIVE CENTERED , 22 sy-vline,

23(10) 'User' COLOR COL_POSITIVE CENTERED , 34 sy-vline,

35(16) 'Date' COLOR COL_POSITIVE CENTERED , 52 sy-vline.

WRITE: /1(52) sy-uline.

END-OF-SELECTION.

SET PF-STATUS '/BAY4/PDF'.

DATA : l_rqident TYPE tsp01-rqident,

l_count TYPE i VALUE '0'.

AT USER-COMMAND.

CASE sy-ucomm.

WHEN 'PDF'.

CLEAR l_count.

DO.

CLEAR : markfield.

READ LINE sy-index FIELD VALUE markfield.

IF sy-subrc NE 0.

EXIT.

ENDIF.

CHECK markfield NE space.

IF l_count GT 0.

MESSAGE 'Please select only one check box' TYPE 'E'.

EXIT.

ENDIF.

l_rqident = it_tsp01-rqident.

l_count = l_count + 1.

ENDDO.

PERFORM get_pdf.

WHEN 'MAIL'.

CLEAR l_count.

DO.

CLEAR : markfield.

READ LINE sy-index FIELD VALUE markfield.

IF sy-subrc NE 0.

EXIT.

ENDIF.

CHECK markfield NE space.

IF l_count GT 0.

MESSAGE 'Please select only one check box' TYPE 'E'.

EXIT.

ENDIF.

l_rqident = it_tsp01-rqident.

l_count = l_count + 1.

ENDDO.

PERFORM get_pdf.

PERFORM send_mail.

ENDCASE.

&----


*& Form get_pdf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_pdf .

READ TABLE it_tsp01 WITH KEY rqident = l_rqident.

  • LOOP AT it_tsp01.

client = it_tsp01-rqclient.

name = it_tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

  • CHARCO =

  • CREATER =

  • CREDATE =

  • DELDATE =

  • MAX_CREDATE =

  • MAX_DELDATE =

  • NON_UNIQ =

  • NOOF_PARTS =

  • RECTYP =

  • SIZE =

  • STOTYP =

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = l_rqident

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • OTF_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 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.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = l_rqident

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • LIST_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = 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.

ENDIF.

PERFORM download_w_ext(rstxpdft) TABLES pdf

USING p_file

'.pdf'

'BIN'

numbytes

cancel.

ENDFORM. " get_pdf

&----


*& Form send_mail

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM send_mail .

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.

*DATA: PIT_ATTACH LIKE table of IT_ATTACH.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA : w_cnt TYPE i,

w_sent_all(1) TYPE c,

w_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

DATA: a TYPE string,

t TYPE string.

a = 'FILE.PDF'.

t_object_header = a .

APPEND t_object_header.

DATA: p_email TYPE string.

CONSTANTS:

con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

LOOP AT pdf.

TRANSLATE pdf USING ' ~'.

CONCATENATE pdf-tdformat pdf-tdline INTO it_attach SEPARATED BY space.

APPEND it_attach.

CLEAR : it_attach,pdf.

ENDLOOP.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam,

p_attdescription LIKE ld_attdescription,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

p_sender_address LIKE ld_sender_address,

ld_sender_address_type LIKE soextreci1-adr_typ,

p_sender_addres_type LIKE ld_sender_address_type,

ld_receiver LIKE sy-subrc.

  • RANGES : ld_email FOR somlreci1-receiver OCCURS 0.

  • ld_email[] = so_email[].

  • append ld_email.

ld_email = so_email.

ld_mtitle = 'PDF file for the Spool no'.

ld_format = 'pdf'.

ld_attfilename = 'filename'.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = it_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

object_header = t_object_header

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_receivers

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.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

SUBMIT rsconn01

  • WITH mode = 'INT'

WITH output = 'X'

AND

RETURN.

IF sy-subrc EQ 0.

MESSAGE 'PDF sent to specified mail id' TYPE 'I'.

LEAVE SCREEN.

ENDIF.

Tags:
Not what you were looking for? View more on this topic or Ask a question