cancel
Showing results for 
Search instead for 
Did you mean: 

Can a spool file be sent as an attachment in the decision step?

Former Member
0 Kudos

Hi,

I have z program that runs in background and produces a spool file. Normally, I can use tcode SP01 to display this file. At the end of this z program, I call SWW_WI_START_SIMPLE to send a workflow into SAP inbox. I want to know if I somhow can send the spool file along also? I read about attachment and SOFM object but still can't figure out what I need to do yet. Please help.

Thank you,

TH

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Th,

Check this code if helpful.

FORM pdf_conversion.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

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.

ENDFORM. " PDF_CONVERSION

----


  • FORM SPOOL *

----


  • ........ *

----


FORM spool.

PERFORM display.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

  • destination = 'LOCL'

immediately = ' '

new_list_id = 'X'

expiration = '9'

in_parameters = p_pripar

layout = 'X_65_132'

line_count = 65

line_size = 132

mode = 'DEFVALS'

no_dialog = 'X'

IMPORTING

out_parameters = p_pripar

valid = val

EXCEPTIONS

archive_info_not_found = 1

invalid_print_params = 2

invalid_archive_params = 3

OTHERS = 4.

NEW-PAGE PRINT ON NEW-SECTION PARAMETERS p_pripar NO DIALOG.

PERFORM display.

NEW-PAGE PRINT OFF.

CLEAR t_filename_tx.

CONCATENATE 'c:\temp\' p_mat '.pdf' INTO t_filename_tx.

CONDENSE t_filename_tx.

SELECT * FROM tsp01 INTO TABLE t_tsp01

WHERE rqowner EQ sy-uname.

SORT t_tsp01 BY rqcretime DESCENDING.

LOOP AT t_tsp01.

spoolno = t_tsp01-rqident.

EXIT.

ENDLOOP.

IF sy-subrc EQ 0.

PERFORM pdf_conversion.

ENDIF.

******************************************

sending that inernal to mail

FUNCTION z_p_traveler_workflow.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(V_FILE_PATH) LIKE RLGRAP-FILENAME

*" REFERENCE(DOKNR) LIKE CRVD_A-DOKNR

*" REFERENCE(DOKVR) LIKE CRVD_A-DOKVR

*" TABLES

*" PDF STRUCTURE TLINE

*"----


************************************************************************

  • D A T A

************************************************************************

DATA: w_gd_doc_data LIKE sodocchgi1.

  • internal table for body content of the email

DATA: t_message LIKE solisti1 OCCURS 0 WITH HEADER LINE.

  • internal table for receivers of email

DATA: t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

  • internal table for attachment data

DATA: t_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.

*internal table for Information about structure of data tables

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

  • internal tables for attachment data

DATA: t_xi_pdf LIKE tline OCCURS 0 WITH HEADER LINE,

t_xi_temp LIKE bapiqcmime OCCURS 0 WITH HEADER LINE,

t_xi_mime(255) TYPE c OCCURS 0 WITH HEADER LINE,

t_html LIKE solisti1 OCCURS 0 WITH HEADER LINE.

  • for splitting of the filepath

DATA : BEGIN OF t_split OCCURS 0,

row(50),

END OF t_split.

DATA: w_tab_lines LIKE sy-tabix,

w_subject TYPE so_obj_des, " for email header

w_file_path1 TYPE string. "file path

DATA : w_lines TYPE i,

w_temp(500) TYPE c,

w_offset TYPE p,

w_lineslen(2) TYPE p,

w_mimelen(2) TYPE p,

w_tabix LIKE sy-tabix.

DATA : w_len TYPE i,

w_index LIKE sy-index,

w_doc_type TYPE so_obj_tp,

w_filename TYPE so_obj_des .

  • internal table for gettting personal numbers of quality engineers

DATA: BEGIN OF t_ztptwf2 OCCURS 0,

pernr LIKE ztptwf2-pernr, "personal number

END OF t_ztptwf2.

  • internal table for gettting userids of quality engineers

DATA: BEGIN OF t_pa0105 OCCURS 0,

usrid LIKE pa0105-usrid, " user id of the quality engineer

END OF t_pa0105.

  • move file path to w_file_path

w_file_path1 = v_file_path.

*assign subject of the email

w_subject = text-006. "Travaler Document to Approve

  • refreshing the internal tables

REFRESH : t_objbin, t_packing_list, t_split.

CLEAR : t_objbin, t_packing_list, t_split.

CLEAR : t_xi_pdf, t_xi_temp.

REFRESH : t_xi_pdf, t_xi_temp.

CLEAR: w_temp, w_offset, t_xi_temp.

  • move attachment data to t_xi_pdf[].

t_xi_pdf[] = pdf[].

  • Reformat the line to 255 characters wide

DESCRIBE TABLE t_xi_pdf LINES w_lines.

DESCRIBE FIELD t_xi_pdf LENGTH w_lineslen.

DESCRIBE FIELD t_xi_temp LENGTH w_mimelen.

LOOP AT t_xi_pdf.

w_tabix = sy-tabix.

MOVE t_xi_pdf TO w_temp+w_offset.

IF w_tabix = w_lines.

w_lineslen = strlen( t_xi_pdf ).

ENDIF.

w_offset = w_offset + w_lineslen.

IF w_offset GE w_mimelen.

CLEAR t_xi_temp.

t_xi_temp = w_temp(w_mimelen).

APPEND t_xi_temp.

SHIFT w_temp BY w_mimelen PLACES.

w_offset = w_offset - w_mimelen.

ENDIF.

IF w_tabix = w_lines.

IF w_offset GT 0.

CLEAR t_xi_temp.

t_xi_temp = w_temp(w_offset).

APPEND t_xi_temp.

ENDIF.

ENDIF.

ENDLOOP.

*move data from t_xi_temp to t_xi_mime

LOOP AT t_xi_temp.

t_xi_mime(255) = t_xi_temp-line.

APPEND t_xi_mime.

CLEAR t_xi_mime.

ENDLOOP.

*move data from t_xi_mime[] to t_html[]

t_html[] = t_xi_mime[].

*move data from t_html[] to t_objbin.

LOOP AT t_html.

t_objbin-line = t_html-line.

APPEND t_objbin.

CLEAR t_objbin.

ENDLOOP.

*fill the body of email

t_message = text-005. "Mail with PDF attachment

APPEND t_message.

CLEAR t_message.

t_message = text-004. "Please double click the attachment to verify

APPEND t_message.

CLEAR t_message.

concatenate 'COPY FOR VIEWING ONLY-NOT TO BE'

'USED/PRINTED FOR PRODUCTION' into t_message separated by

space.

APPEND t_message.

CLEAR t_message.

IF NOT doknr IS INITIAL.

CONCATENATE text-001 "The Document

doknr

text-002 "and Version

dokvr

text-003 INTO "is changed

t_message SEPARATED BY space.

APPEND t_message.

CLEAR t_message.

ENDIF.

DESCRIBE TABLE t_message LINES w_tab_lines.

READ TABLE t_message INDEX w_tab_lines.

w_gd_doc_data-doc_size = ( w_tab_lines - 1 ) *

255 + STRLEN( t_message ).

w_gd_doc_data-obj_langu = sy-langu.

w_gd_doc_data-obj_name = 'SENDFILE'.

w_gd_doc_data-obj_descr = w_subject.

w_gd_doc_data-sensitivty = 'O'.

CLEAR t_packing_list.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

t_packing_list-doc_type = 'RAW'.

t_packing_list-body_num = w_tab_lines.

APPEND t_packing_list.

IF NOT w_file_path1 IS INITIAL.

w_len = strlen( w_file_path1 ) - 3.

w_doc_type = w_file_path1+w_len(3) .

TRANSLATE w_doc_type TO UPPER CASE .

SPLIT w_file_path1 AT '\' INTO TABLE t_split .

DESCRIBE TABLE t_split LINES w_index .

READ TABLE t_split INDEX w_index .

w_filename = t_split-row .

w_len = strlen( w_filename ) - 4.

w_filename = w_filename(w_len) .

DESCRIBE TABLE t_objbin LINES w_tab_lines.

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

t_packing_list-doc_type = w_doc_type.

t_packing_list-body_num = w_tab_lines.

t_packing_list-doc_size = w_tab_lines * 255.

t_packing_list-obj_descr = w_filename.

APPEND t_packing_list.

ENDIF.

  • fill the Receivers

SELECT * FROM ztptwf2 INTO TABLE t_ztptwf2.

IF NOT t_ztptwf2[] IS INITIAL.

SELECT usrid FROM pa0105 INTO TABLE t_pa0105 FOR ALL ENTRIES IN

t_ztptwf2 WHERE pernr = t_ztptwf2-pernr AND subty = '0001' .

LOOP AT t_pa0105.

t_receivers-receiver = t_pa0105-usrid.

t_receivers-rec_type = 'B'.

APPEND t_receivers .

CLEAR t_receivers.

ENDLOOP.

ENDIF.

IF NOT t_receivers[] IS INITIAL.

  • Call the FM to post the message to SAPMAIL

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_gd_doc_data

commit_work = 'X'

TABLES

packing_list = t_packing_list

contents_txt = t_message

contents_bin = t_objbin

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.

ENDIF.

FREE: t_objbin,t_message,t_packing_list,t_receivers.

i hope this code will solve your problem.

Sankar

Former Member
0 Kudos

Hi Sankar,

Thank you very much for your reply.

I'm still struggling with the Display routine. I tried to use the spool display fm, but it did not work. Will you please kindly walk me through the display routine as well. I just need to know what FM do I use to display the file.

Thank you,

TH

Former Member
0 Kudos

Just want to let you know I found a solution without having to convert the file into PDF or calling the FM to send message. I was able to get the spool back to an internal table and basically create an SOFM object and bind to the Attach_Obj. It's simpler than I thought.

One question though if I was to use that FM to send attachment: I have to pass the receiver info. However, in my decision step, there's already role resolution to find receiver of a work item. Will this produce 2 seperated work items: one for the inbox mail with the attachment and the other is a workflow item with nothing attached? Or do they actually go together with 1 workflow? Maybe one of these days I can try and see how that works.

Anyway, thanks again for your input.

Have a nice day,

TH

Former Member
0 Kudos

Hi ,

I am lookin out for a similar code .. can you send me the sample code for

spool back to an internal table and basically create an SOFM object and bind to the Attach_Obj

Regards

Abhilash