‎2008 Jun 16 9:05 AM
Hi champs,
i am devloping a report in which i have to mail the
report to the conser vendor, email id.
can any one give me the code and steps for developing this
report.
<removed_by_moderator>
<removed_by_moderator>
vivek
Edited by: Julius Bussche on Aug 26, 2008 12:18 PM
‎2008 Jun 16 10:06 AM
hiiii
Check following code.
FORM send_mail_fax TABLES t_receivers STRUCTURE somlreci1
USING mail_subject LIKE sood1-objdes..
* Set initial values for data/work areas...
CLEAR: d_name_in, d_name_out, t_soos1,
t_soli, h_doc_data, t_pak_list, t_obj_head,
t_con_bin, t_con_text, t_receivers.
REFRESH: t_soos1, t_soli,
t_pak_list, t_obj_head,
t_con_bin, t_con_text.
CLEAR: t_itcoo, t_notes, d_object_type.
REFRESH: t_itcoo, t_notes.
* Store input parameters.
d_user_name = sy-uname. " Internal USER name...
d_subject = mail_subject. " Subject of email...
* d_spool_id = i_spool_id. " SAP spool-id...
* Begin of ADDS for ENABLE (3.1 to 4.7)
d_desired_type = 'PDF'. " Output attach type specific?
* h_transf_type = space. " Transfer Type (binary)?
* h_commit_wk = i_commit_work. " set commit-work on SEND!
* Check TYPE of ATTACHMENT to see if valid...
IF NOT d_desired_type IS INITIAL.
IF d_desired_type = 'PDF' OR
d_desired_type = 'ALI' OR
d_desired_type = 'RAW'.
ELSE.
RAISE type_no_match.
ENDIF.
ENDIF.
REFRESH: t_con_text.
IF sy-sysid <> 'CHS'. "TPATEL
* Begin of ADDS for ENABLE - D47K900404
t_con_text = text-t01.
REPLACE '$1' WITH sy-sysid
INTO t_con_text.
APPEND t_con_text.
CLEAR: t_con_text.
APPEND t_con_text.
ENDIF.
LOOP AT x_note.
t_con_text = x_note.
APPEND t_con_text.
ENDLOOP.
* End of MODS for ENABLE - D47K900404
* SET BODY-TEXT (if any)...
* IF NOT t_content[] IS INITIAL.
IF NOT t_con_text[] IS INITIAL.
* t_con_text[] = t_content[].
* Write Packing List (Main) for BODY-TEXT
DESCRIBE TABLE t_con_text LINES h_tab_cntr.
READ TABLE t_con_text INDEX h_tab_cntr.
h_doc_data-doc_size = ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_text ).
CLEAR t_pak_list.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = 'RAW'.
APPEND t_pak_list.
ELSE.
* Write Packing List (Main) for NO BODY-TEXT (force spaces)
t_con_text = space. APPEND t_con_text.
CLEAR t_pak_list.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = 1.
t_pak_list-doc_type = 'RAW'.
APPEND t_pak_list.
ENDIF.
* ofttab-tdprintcom = 'EP'.
* Check for OTF-2-PDF attachment (via T_ITCOO input table)...
IF NOT ofttab[] IS INITIAL. " Something passed?
h_commit_wk = space. " YES - reset commit-work
t_itcoo[] = ofttab[]. " ... - set OTF file...
PERFORM convert_otf_2_pdf. " ... - go convert to PDF...
perform conversion_of_size.
** Check for any ATTACHMENTS...
IF d_desired_type = 'RAW'. " Set to RAW?
* PERFORM convert_to_abaplist. " YES - convert it
ENDIF. " end...
IF d_desired_type = 'ALI'. " Set to ALI?
PERFORM convert_to_alilist. " YES - convert it
ENDIF. " end...
* Check for any ATTACHMENTS...
IF NOT t_soli[] IS INITIAL. " attachment?
h_real_type = d_desired_type. " ENABLE
h_transf_type = 'X'. " Transfer type BINARY...
* Write PDF/ALI formatted data to BINARY table...
t_con_bin[] = t_soli[].
* Add Packing List (attachment) for PDF...
DESCRIBE TABLE t_con_bin LINES h_tab_cntr.
READ TABLE t_con_bin INDEX h_tab_cntr.
h_doc_data-doc_size = h_doc_data-doc_size
+ ( ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_bin ) ).
h_doc_data-obj_descr = mail_subject.
h_body_start = 1.
h_body_num = h_tab_cntr.
* Write RAW data if that's what it is (adds to TEXT)...
IF h_real_type = 'RAW'.
DESCRIBE TABLE t_con_text LINES h_body_start.
h_body_start = h_body_start + 1.
h_transf_type = space. " Transfer type TEXT...
LOOP AT t_con_bin. " Zip thru TEXT stuff
t_con_text = t_con_bin. " set TEXT table header..
APPEND t_con_text. " add to what's there!
ENDLOOP.
CLEAR: t_con_bin. " clear BINARY header..
REFRESH: t_con_bin. " reset BINARY table...
ENDIF.
CLEAR t_pak_list.
IF h_transf_type = 'X'. " Binary=PDF/ALI?
t_pak_list-transf_bin = 'X'.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = h_real_type.
t_pak_list-obj_name = 'ATTACHMENT'.
t_pak_list-obj_descr = 'Document'(001).
t_pak_list-doc_size = ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_bin ).
ELSE.
DESCRIBE TABLE t_con_text LINES h_tab_cntr.
READ TABLE t_con_text INDEX h_tab_cntr.
t_pak_list-transf_bin = ' '. " Binary=RAW
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = h_body_start.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = h_real_type.
t_pak_list-obj_name = 'ATTACHMENT'(002).
t_pak_list-obj_descr = 'Report'(003).
t_pak_list-doc_size = ( h_body_num - 1 )
* 255 + STRLEN( t_con_text ).
ENDIF.
APPEND t_pak_list.
ENDIF.
* Send the EMAIL out with SAP function...
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = h_doc_data
put_in_outbox = 'X'
* commit_work = 'X'
TABLES
packing_list = t_pak_list
contents_bin = t_con_bin
contents_txt = t_con_text
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.
IF syst-subrc NE 0.
* RAISE send_failed.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = '00'
msg_nr = '001'
msg_ty = 'E'
msg_v1 = 'O/P Could not be issued '(001)
msg_v2 = ' Due to No Mail ID'(002)
msg_v3 = syst-msgv3
msg_v4 = syst-msgv4
EXCEPTIONS
OTHERS = 1.
* Check General incompletion status of the header
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE : 'SENT'.
ENDIF.
ELSE.
* commit work.
ENDIF.
ENDFORM. " SEND_MAIL_FAX
*&---------------------------------------------------------------------*
*& Form convert_otf_2_pdf
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_otf_2_pdf .
DATA: "t_line LIKE tline OCCURS 0 WITH HEADER LINE,
t_objcont LIKE soli OCCURS 0 WITH HEADER LINE,
d_doc_size(12) TYPE c,
d_fle1(2) TYPE p,
d_fle2(2) TYPE p,
d_off1 TYPE p,
d_hltlines TYPE i,
d_hfeld(500) TYPE c,
w_indx LIKE sy-tabix.
CLEAR: t_line, t_objcont, d_off1.
REFRESH: t_line, t_objcont.
* Check/set DEFAULT Desired-type attachment...
IF d_desired_type IS INITIAL. " Entered Desired type?
d_desired_type = 'PDF'. " NO - default to PDF
ENDIF. "
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = d_desired_type
IMPORTING
bin_filesize = d_doc_size
TABLES
otf = t_itcoo
lines = t_line
EXCEPTIONS
*&---------------------------------------------------------------------*
*& Form convert_otf_2_pdf_sx
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_otf_2_pdf_sx .
DATA:
t_otf LIKE solisti1 OCCURS 0 WITH HEADER LINE,"ENABLE
t_pdf LIKE tline OCCURS 0 WITH HEADER LINE,"ENABLE
doc_size(12) TYPE n,
len_out TYPE i,
x_real LIKE soodk-objtp,
x_idx_b LIKE sy-tabix,
x_idx_e LIKE sy-tabix.
IF d_desired_type = 'PDF'.
d_desired_type = 'OTF'.
ENDIF.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = d_spool_id
desired_type = d_desired_type
IMPORTING
real_type = x_real
TABLES
buffer = t_otf
buffer_pdf = t_pdf
EXCEPTIONS
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
OTHERS = 8.
IF sy-subrc <> 0.
IF sy-subrc = 1.
RAISE invalid_spool_id.
ELSE.
RAISE otf_convert_failed.
ENDIF.
ENDIF.
* Check Desired-Type vs. Real-Type (if any)...
IF d_desired_type IS INITIAL.
IF x_real = 'OTF'.
d_desired_type = 'PDF'.
ELSE.
d_desired_type = x_real.
ENDIF.
ELSE.
IF ( d_desired_type = 'PDF' OR
d_desired_type = 'OTF' ) AND
( x_real = 'OTF' OR
x_real = 'PDF' ).
d_desired_type = 'PDF'.
ELSE.
IF d_desired_type <> x_real.
RAISE type_no_match.
ENDIF.
ENDIF.
IF ( d_desired_type = 'ALI' OR
d_desired_type = 'RAW' ) AND
x_real = 'OTF'.
RAISE type_no_match.
ENDIF.
ENDIF.
* Check if ABAP-LIST and not SapScript...
IF d_desired_type = 'ALI' OR
d_desired_type = 'RAW'.
t_soli[] = t_otf[].
EXIT.
ENDIF.
* Load OTF data gotten from spool...
LOOP AT t_otf.
t_itcoo = t_otf.
APPEND t_itcoo.
* if Vendor P/O (SapScript = Z_MEDRUCK) then
* trap INDEX for "Terms & Conditions" on BACK...
IF t_itcoo-tdprintcom = 'IN' AND
t_itcoo-tdprintpar = '01EZ_MEDRUCK BACK'.
x_idx_b = sy-tabix.
ENDIF.
IF t_itcoo-tdprintcom = 'IN' AND
t_itcoo-tdprintpar = '01EZ_MEDRUCK NEXT'.
x_idx_e = ( sy-tabix - 1 ).
ENDIF.
ENDLOOP.
* Drop from table if INDEX'S are set (see above)...
IF ( x_idx_b > 0 AND
( x_idx_e > x_idx_b ) ) .
DELETE t_itcoo FROM x_idx_b
TO x_idx_e.
ENDIF.
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc > 0.
RAISE otf_convert_failed.
ENDIF.<removed_by_moderator>
thx
twinkal.
Edited by: Julius Bussche on Aug 26, 2008 12:49 PM
‎2008 Jun 16 9:07 AM
Hi,
Use FM SO_NEW_DOCUMENT_ATT_SEND_API1.Refer its documentation.
‎2008 Jun 16 9:10 AM
Hi,
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Sample Code
*-----Start of changes vikranth - CQ5142
*--Data declearation
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
DATA: L_MSG(100) TYPE C.
* Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'Z2318S1B01'.
DOC_CHNG-OBJ_DESCR = EMSUBJ .
*- Begin of update By NDASARI 05/17/2007 --------------------*
*OBJTXT = 'your report from apple vacations is enclosed as
* ATTACHMENT'.
OBJTXT = 'your report from apple vacations is enclosed as ATTACHMENT'.
*- End of update By NDASARI 05/17/2007 ----------------------*
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
* Creation of the entry for the compressed document
CLEAR OBJPACK.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
* Creation of the document attachment
LOOP AT IT_ATTACHMENT.
OBJBIN = IT_ATTACHMENT-EMAIL.
APPEND OBJBIN.
CLEAR OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Airport Mainfest'.
APPEND OBJHEAD.
* Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
OBJPACK-OBJ_NAME = 'ANLAGE'.
OBJPACK-OBJ_DESCR = 'Representation of object 138'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
* Completing the recipient list
CLEAR EMAILID.
LOOP AT EMAILID.
TRANSLATE EMAILID-LOW TO LOWER CASE.
RECLIST-RECEIVER = EMAILID-LOW.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
CLEAR RECLIST.
ENDLOOP.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = 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.
LOOP AT RECLIST.
IF RECLIST-RETRN_CODE = 0.
CONCATENATE RECLIST-RECEIVER ':'
'The document was sent' INTO L_MSG.
MESSAGE S656 WITH L_MSG.
ELSE.
CONCATENATE RECLIST-RECEIVER ':'
'The document was sent' INTO L_MSG.
MESSAGE E656 WITH L_MSG.
ENDIF.
ENDLOOP.
ELSE.
CONCATENATE RECLIST-RECEIVER ':'
'error occurred in sending mail' INTO L_MSG.
MESSAGE S656 WITH L_MSG.
ENDIF.Thanks
Vikranth
‎2008 Jun 16 9:14 AM
hi get the email addresses of the concern persons from the table adr6
‎2008 Jun 16 10:00 AM
Hi Vivek,
Check out the following program which creates report output as pdf format and sends to mentioned mail id. Change according to ur requirment .
I hope that it helps u .
Regards,
Venkat.O
REPORT zvenkat_mai_pdf_attach.
*--------------------------------------------------------*
" Data retrieval related declarations
*--------------------------------------------------------*
"Variables
DATA:
g_spool_no TYPE TSP01-RQIDENT.
"Types
TYPES:
BEGIN OF t_emp_dat,
pernr TYPE pa0001-pernr,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
plans TYPE pa0001-plans,
stell TYPE pa0001-stell,
END OF t_emp_dat.
"Work area
DATA:
w_emp_data TYPE t_emp_dat.
"Internal tables
DATA:
i_emp_data TYPE STANDARD TABLE OF t_emp_dat.
*--------------------------------------------------------*
" Mai related declarations
*--------------------------------------------------------*
"Variables
DATA :
g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.
"Types
TYPES:
t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.
"Workareas
DATA :
w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
"Internal Tables
DATA :
i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
parameters:p_mai_id(99) type c.
*--------------------------------------------------------*
"Top-of-page.
*--------------------------------------------------------*
TOP-OF-PAGE.
PERFORM top_of_page.
*--------------------------------------------------------*
"Start-of-selection.
*--------------------------------------------------------*
START-OF-SELECTION.
PERFORM get_data.
IF i_emp_data[] IS INITIAL.
PERFORM test_data.
ENDIF.
PERFORM do_print_n_get_spoolno.
*--------------------------------------------------------*
"End-of-selection.
*--------------------------------------------------------*
END-OF-SELECTION.
PERFORM send_mai.
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
DATA: inc_colnum TYPE i.
ULINE.
inc_colnum = sy-linsz - 60.
WRITE: / 'Report: ', sy-repid(18).
WRITE AT 30(inc_colnum) sy-title CENTERED.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Page: ', (11) sy-pagno RIGHT-JUSTIFIED.
WRITE: / 'Client: ', sy-mandt.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Date: ', sy-datum.
WRITE: / 'User : ', sy-uname.
inc_colnum = sy-linsz - 60.
WRITE AT 30(inc_colnum) 'Company Confidential' CENTERED.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Time: ', (10) sy-uzeit RIGHT-JUSTIFIED.
ULINE .
SKIP.
ULINE AT /(127).
WRITE:/ sy-vline,'pernr' COLOR COL_HEADING,13
sy-vline,'persg' COLOR COL_HEADING,20
sy-vline,'persk' COLOR COL_HEADING,26
sy-vline,'plans' COLOR COL_HEADING,35
sy-vline,'stell' COLOR COL_HEADING,46
sy-vline.
ULINE AT /(46).
ENDFORM. "top_of_page
*&--------------------------------------------------------*
"Form get_data from PA0001
*&--------------------------------------------------------*
FORM get_data.
SELECT pernr
persg
persk
plans
stell
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE i_emp_data
UP TO 4 ROWS.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
"Form do_print_n_get_spoolno
*&---------------------------------------------------------------------*
FORM do_print_n_get_spoolno.
"Display Output
LOOP AT i_emp_data INTO w_emp_data .
AT FIRST.
PERFORM get_print_parameters.
ENDAT.
WRITE:/ sy-vline,w_emp_data-pernr,13
sy-vline,w_emp_data-persg,20
sy-vline,w_emp_data-persk,26
sy-vline,w_emp_data-plans,35
sy-vline,w_emp_data-stell,46
sy-vline.
ULINE AT /(46).
AT LAST.
g_spool_no = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
ENDAT.
ENDLOOP.
ENDFORM. "do_print_n_get_spoolno
*&----------------------------------------------------------*
"Form send_mai
"---------------
"PACKING LIST
"This table requires information about how the data in the
"tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to
"be distributed to the documents and its attachments.The first
"row is for the document, the following rows are each for one
"attachment.
*&-----------------------------------------------------------*
FORM send_mai .
"Subject of the mai.
w_document_data-obj_name = 'MAI_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mai Program by SAP ABAP'.
"Body of the mai
PERFORM build_body_of_mai
USING:space,
'Hi,',
'I am fine. How are you? How are you doing ? ',
'This program has been created to send simple mai',
'with Subject,Body with Address of the sender. ',
'Regards,',
'Venkat.O,',
'SAP HR Technical Consultant.'.
"Convert ABAP Spool job to PDF
PERFORM convert_spool_2_pdf TABLES i_attachment.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'U'. "Internet address
w_receivers-receiver = p_mai_id. "specify ur mai id here
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
"Function module to send mai to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_body_msg
receivers = i_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.
IF sy-subrc = 0 .
MESSAGE i303(me) WITH 'Mai has been Successfully Sent.'.
ELSE.
WAIT UP TO 2 SECONDS.
"This program starts the SAPconnect send process.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ENDFORM. " send_mai
*&-----------------------------------------------------------*
" Form build_body_of_mai
*&-----------------------------------------------------------*
FORM build_body_of_mai USING l_message.
w_body_msg = l_message.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
ENDFORM. " build_body_of_mai
*&---------------------------------------------------------------------*
*& Form get_print_parameters
*&---------------------------------------------------------------------*
FORM get_print_parameters .
"Variables
DATA:
l_lay TYPE pri_params-paart,
l_lines TYPE pri_params-linct,
l_cols TYPE pri_params-linsz,
l_val TYPE c.
*Types
TYPES:
t_pripar TYPE pri_params,
t_arcpar TYPE arc_params.
"Work areas
DATA:
lw_pripar TYPE t_pripar,
lw_arcpar TYPE t_arcpar.
l_lay = 'X_65_132'.
l_lines = 65.
l_cols = 132.
"Read, determine, change spool print parameters and archive parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = lw_arcpar
in_parameters = lw_pripar
layout = l_lay
line_count = l_lines
line_size = l_cols
no_dialog = 'X'
IMPORTING
out_archive_parameters = lw_arcpar
out_parameters = lw_pripar
valid = l_val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF l_val <> space AND sy-subrc = 0.
lw_pripar-prrel = space.
lw_pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS lw_pripar
ARCHIVE PARAMETERS lw_arcpar
NO DIALOG.
ENDIF.
ENDFORM. " get_print_parameters
*&---------------------------------------------------------------------*
*& Form convert_spool_2_pdf
*&---------------------------------------------------------------------*
FORM convert_spool_2_pdf TABLES l_attachment .
"Variables
DATA:
l_no_of_bytes TYPE i,
l_pdf_spoolid LIKE tsp01-rqident,
l_jobname LIKE tbtcjob-jobname,
l_jobcount LIKE tbtcjob-jobcount.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool_no
no_dialog = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_jobname
btc_jobcount = l_jobcount
TABLES
pdf = i_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.
CASE sy-subrc.
WHEN 0.
WHEN 1.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf
content_out = l_attachment
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
ENDFORM. " convert_spool_2_pdf
*&---------------------------------------------------------------------*
*& Form test_data
*&---------------------------------------------------------------------*
FORM test_data .
DO 10 TIMES.
w_emp_data-pernr = sy-index.
w_emp_data-persg = '2'.
w_emp_data-persk = '93'.
w_emp_data-plans = '99999999'.
w_emp_data-stell = '31414144'.
APPEND w_emp_data TO i_emp_data.
CLEAR w_emp_data.
ENDDO.
ENDFORM. " test_data
‎2008 Jun 16 10:06 AM
hiiii
Check following code.
FORM send_mail_fax TABLES t_receivers STRUCTURE somlreci1
USING mail_subject LIKE sood1-objdes..
* Set initial values for data/work areas...
CLEAR: d_name_in, d_name_out, t_soos1,
t_soli, h_doc_data, t_pak_list, t_obj_head,
t_con_bin, t_con_text, t_receivers.
REFRESH: t_soos1, t_soli,
t_pak_list, t_obj_head,
t_con_bin, t_con_text.
CLEAR: t_itcoo, t_notes, d_object_type.
REFRESH: t_itcoo, t_notes.
* Store input parameters.
d_user_name = sy-uname. " Internal USER name...
d_subject = mail_subject. " Subject of email...
* d_spool_id = i_spool_id. " SAP spool-id...
* Begin of ADDS for ENABLE (3.1 to 4.7)
d_desired_type = 'PDF'. " Output attach type specific?
* h_transf_type = space. " Transfer Type (binary)?
* h_commit_wk = i_commit_work. " set commit-work on SEND!
* Check TYPE of ATTACHMENT to see if valid...
IF NOT d_desired_type IS INITIAL.
IF d_desired_type = 'PDF' OR
d_desired_type = 'ALI' OR
d_desired_type = 'RAW'.
ELSE.
RAISE type_no_match.
ENDIF.
ENDIF.
REFRESH: t_con_text.
IF sy-sysid <> 'CHS'. "TPATEL
* Begin of ADDS for ENABLE - D47K900404
t_con_text = text-t01.
REPLACE '$1' WITH sy-sysid
INTO t_con_text.
APPEND t_con_text.
CLEAR: t_con_text.
APPEND t_con_text.
ENDIF.
LOOP AT x_note.
t_con_text = x_note.
APPEND t_con_text.
ENDLOOP.
* End of MODS for ENABLE - D47K900404
* SET BODY-TEXT (if any)...
* IF NOT t_content[] IS INITIAL.
IF NOT t_con_text[] IS INITIAL.
* t_con_text[] = t_content[].
* Write Packing List (Main) for BODY-TEXT
DESCRIBE TABLE t_con_text LINES h_tab_cntr.
READ TABLE t_con_text INDEX h_tab_cntr.
h_doc_data-doc_size = ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_text ).
CLEAR t_pak_list.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = 'RAW'.
APPEND t_pak_list.
ELSE.
* Write Packing List (Main) for NO BODY-TEXT (force spaces)
t_con_text = space. APPEND t_con_text.
CLEAR t_pak_list.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = 1.
t_pak_list-doc_type = 'RAW'.
APPEND t_pak_list.
ENDIF.
* ofttab-tdprintcom = 'EP'.
* Check for OTF-2-PDF attachment (via T_ITCOO input table)...
IF NOT ofttab[] IS INITIAL. " Something passed?
h_commit_wk = space. " YES - reset commit-work
t_itcoo[] = ofttab[]. " ... - set OTF file...
PERFORM convert_otf_2_pdf. " ... - go convert to PDF...
perform conversion_of_size.
** Check for any ATTACHMENTS...
IF d_desired_type = 'RAW'. " Set to RAW?
* PERFORM convert_to_abaplist. " YES - convert it
ENDIF. " end...
IF d_desired_type = 'ALI'. " Set to ALI?
PERFORM convert_to_alilist. " YES - convert it
ENDIF. " end...
* Check for any ATTACHMENTS...
IF NOT t_soli[] IS INITIAL. " attachment?
h_real_type = d_desired_type. " ENABLE
h_transf_type = 'X'. " Transfer type BINARY...
* Write PDF/ALI formatted data to BINARY table...
t_con_bin[] = t_soli[].
* Add Packing List (attachment) for PDF...
DESCRIBE TABLE t_con_bin LINES h_tab_cntr.
READ TABLE t_con_bin INDEX h_tab_cntr.
h_doc_data-doc_size = h_doc_data-doc_size
+ ( ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_bin ) ).
h_doc_data-obj_descr = mail_subject.
h_body_start = 1.
h_body_num = h_tab_cntr.
* Write RAW data if that's what it is (adds to TEXT)...
IF h_real_type = 'RAW'.
DESCRIBE TABLE t_con_text LINES h_body_start.
h_body_start = h_body_start + 1.
h_transf_type = space. " Transfer type TEXT...
LOOP AT t_con_bin. " Zip thru TEXT stuff
t_con_text = t_con_bin. " set TEXT table header..
APPEND t_con_text. " add to what's there!
ENDLOOP.
CLEAR: t_con_bin. " clear BINARY header..
REFRESH: t_con_bin. " reset BINARY table...
ENDIF.
CLEAR t_pak_list.
IF h_transf_type = 'X'. " Binary=PDF/ALI?
t_pak_list-transf_bin = 'X'.
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = 1.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = h_real_type.
t_pak_list-obj_name = 'ATTACHMENT'.
t_pak_list-obj_descr = 'Document'(001).
t_pak_list-doc_size = ( h_tab_cntr - 1 )
* 255 + STRLEN( t_con_bin ).
ELSE.
DESCRIBE TABLE t_con_text LINES h_tab_cntr.
READ TABLE t_con_text INDEX h_tab_cntr.
t_pak_list-transf_bin = ' '. " Binary=RAW
t_pak_list-head_start = 1.
t_pak_list-head_num = 0.
t_pak_list-body_start = h_body_start.
t_pak_list-body_num = h_tab_cntr.
t_pak_list-doc_type = h_real_type.
t_pak_list-obj_name = 'ATTACHMENT'(002).
t_pak_list-obj_descr = 'Report'(003).
t_pak_list-doc_size = ( h_body_num - 1 )
* 255 + STRLEN( t_con_text ).
ENDIF.
APPEND t_pak_list.
ENDIF.
* Send the EMAIL out with SAP function...
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = h_doc_data
put_in_outbox = 'X'
* commit_work = 'X'
TABLES
packing_list = t_pak_list
contents_bin = t_con_bin
contents_txt = t_con_text
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.
IF syst-subrc NE 0.
* RAISE send_failed.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = '00'
msg_nr = '001'
msg_ty = 'E'
msg_v1 = 'O/P Could not be issued '(001)
msg_v2 = ' Due to No Mail ID'(002)
msg_v3 = syst-msgv3
msg_v4 = syst-msgv4
EXCEPTIONS
OTHERS = 1.
* Check General incompletion status of the header
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE : 'SENT'.
ENDIF.
ELSE.
* commit work.
ENDIF.
ENDFORM. " SEND_MAIL_FAX
*&---------------------------------------------------------------------*
*& Form convert_otf_2_pdf
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_otf_2_pdf .
DATA: "t_line LIKE tline OCCURS 0 WITH HEADER LINE,
t_objcont LIKE soli OCCURS 0 WITH HEADER LINE,
d_doc_size(12) TYPE c,
d_fle1(2) TYPE p,
d_fle2(2) TYPE p,
d_off1 TYPE p,
d_hltlines TYPE i,
d_hfeld(500) TYPE c,
w_indx LIKE sy-tabix.
CLEAR: t_line, t_objcont, d_off1.
REFRESH: t_line, t_objcont.
* Check/set DEFAULT Desired-type attachment...
IF d_desired_type IS INITIAL. " Entered Desired type?
d_desired_type = 'PDF'. " NO - default to PDF
ENDIF. "
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = d_desired_type
IMPORTING
bin_filesize = d_doc_size
TABLES
otf = t_itcoo
lines = t_line
EXCEPTIONS
*&---------------------------------------------------------------------*
*& Form convert_otf_2_pdf_sx
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_otf_2_pdf_sx .
DATA:
t_otf LIKE solisti1 OCCURS 0 WITH HEADER LINE,"ENABLE
t_pdf LIKE tline OCCURS 0 WITH HEADER LINE,"ENABLE
doc_size(12) TYPE n,
len_out TYPE i,
x_real LIKE soodk-objtp,
x_idx_b LIKE sy-tabix,
x_idx_e LIKE sy-tabix.
IF d_desired_type = 'PDF'.
d_desired_type = 'OTF'.
ENDIF.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = d_spool_id
desired_type = d_desired_type
IMPORTING
real_type = x_real
TABLES
buffer = t_otf
buffer_pdf = t_pdf
EXCEPTIONS
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
OTHERS = 8.
IF sy-subrc <> 0.
IF sy-subrc = 1.
RAISE invalid_spool_id.
ELSE.
RAISE otf_convert_failed.
ENDIF.
ENDIF.
* Check Desired-Type vs. Real-Type (if any)...
IF d_desired_type IS INITIAL.
IF x_real = 'OTF'.
d_desired_type = 'PDF'.
ELSE.
d_desired_type = x_real.
ENDIF.
ELSE.
IF ( d_desired_type = 'PDF' OR
d_desired_type = 'OTF' ) AND
( x_real = 'OTF' OR
x_real = 'PDF' ).
d_desired_type = 'PDF'.
ELSE.
IF d_desired_type <> x_real.
RAISE type_no_match.
ENDIF.
ENDIF.
IF ( d_desired_type = 'ALI' OR
d_desired_type = 'RAW' ) AND
x_real = 'OTF'.
RAISE type_no_match.
ENDIF.
ENDIF.
* Check if ABAP-LIST and not SapScript...
IF d_desired_type = 'ALI' OR
d_desired_type = 'RAW'.
t_soli[] = t_otf[].
EXIT.
ENDIF.
* Load OTF data gotten from spool...
LOOP AT t_otf.
t_itcoo = t_otf.
APPEND t_itcoo.
* if Vendor P/O (SapScript = Z_MEDRUCK) then
* trap INDEX for "Terms & Conditions" on BACK...
IF t_itcoo-tdprintcom = 'IN' AND
t_itcoo-tdprintpar = '01EZ_MEDRUCK BACK'.
x_idx_b = sy-tabix.
ENDIF.
IF t_itcoo-tdprintcom = 'IN' AND
t_itcoo-tdprintpar = '01EZ_MEDRUCK NEXT'.
x_idx_e = ( sy-tabix - 1 ).
ENDIF.
ENDLOOP.
* Drop from table if INDEX'S are set (see above)...
IF ( x_idx_b > 0 AND
( x_idx_e > x_idx_b ) ) .
DELETE t_itcoo FROM x_idx_b
TO x_idx_e.
ENDIF.
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc > 0.
RAISE otf_convert_failed.
ENDIF.<removed_by_moderator>
thx
twinkal.
Edited by: Julius Bussche on Aug 26, 2008 12:49 PM
‎2008 Jun 16 11:15 AM
thanks twinkle
your answers are very helpfull.
pls keep in touch.
vivek srivastava
spentex