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: 

send mail with a pdf attachment....

Former Member
0 Kudos
118

I have a report in pdf format....how do i attach this document in a mail in SAP?

Thanks in advance.

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos
39

Hi,

Please refer this thread. This has the same example as per you requirement !!

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Best regards,

Prashant

PS : Please reward all helpful answers

11 REPLIES 11

former_member223537
Active Contributor
0 Kudos
40

Hi,

Please refer this thread. This has the same example as per you requirement !!

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Best regards,

Prashant

PS : Please reward all helpful answers

Former Member
0 Kudos
39

Chekc this program it may help u.

FORM send_mail USING p_y16m_rcp_par STRUCTURE y16m_rcp_par.

  • Have a subject for the mail

g_s_document_data-obj_name = text-t02.

g_s_document_data-obj_descr = text-t03.

  • Fill receiver information

g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.

g_s_receivers-rec_id = p_y16m_rcp_par-rec_id.

g_s_receivers-express = 'X'.

APPEND g_s_receivers TO g_t_receivers.

  • Call function to send mail

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = g_s_document_data

document_type = 'RAW'

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

  • OBJECT_HEADER =

object_content = g_t_object_content

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = g_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 sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " SEND_MAIL

Regards

Former Member
0 Kudos
39

Hi,

Check this link.

Regards,

Arun

Former Member
0 Kudos
39

hi,

Check this link

http://www.sap-basis-abap.com/abap011.htm

Regards,

Sailaja.

Former Member
0 Kudos
39

Hi,

Use this Program,There are two parts, Main and Include program just copy the programs in se38 and work with this.

*----


  • INCLUDE inclfor_mail.

*----


  • Data

*----


DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

*----


  • FORM

*----


FORM ml_customize USING objname objdesc.

*----


Clear Variables

CLEAR docdata.

REFRESH objpack.

CLEAR objpack.

REFRESH objhead.

REFRESH objtxt.

CLEAR objtxt.

REFRESH objbin.

CLEAR objbin.

REFRESH objhex.

CLEAR objhex.

REFRESH reclist.

CLEAR reclist.

REFRESH listobject.

CLEAR listobject.

CLEAR tab_lines.

CLEAR doc_size.

CLEAR att_type.

*----


Set Variables

docdata-obj_name = objname.

docdata-obj_descr = objdesc.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addrecp USING preceiver prec_type.

CLEAR reclist.

reclist-receiver = preceiver.

reclist-rec_type = prec_type.

APPEND reclist.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addtxt USING ptxt.

CLEAR objtxt.

objtxt = ptxt.

APPEND objtxt.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_prepare USING bypassmemory whatatt_type whatname.

IF bypassmemory = ''.

*----


Fetch List From Memory

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

ENDIF.

  • -----------

  • Header Data

  • Already Done Thru FM

  • -----------

  • -----------

  • Main Text

  • Already Done Thru FM

  • -----------

  • -----------

  • Packing Info For Text Data

  • -----------

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

  • -----------

  • Packing Info Attachment

  • -----------

att_type = whatatt_type..

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = whatname.

APPEND objpack.

  • -----------

  • Receiver List

  • Already done thru fm

  • -----------

ENDFORM. "ml_prepare

*----


  • FORM

*----


FORM ml_dosend.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • object_parb =

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.

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ENDIF.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_spooltopdf USING whatspoolid.

DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.

*----


Call Function

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = whatspoolid

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

OTHERS = 12.

*----


Convert

PERFORM doconv TABLES pdf objbin.

ENDFORM. "ml_spooltopdf

----


FORM

*----


FORM doconv TABLES

mypdf STRUCTURE tline

outbin STRUCTURE solisti1.

*----


Data

DATA : pos TYPE i.

DATA : len TYPE i.

*----


Loop And Put Data

LOOP AT mypdf.

pos = 255 - len.

IF pos > 134. "length of pdf_table

pos = 134.

ENDIF.

outbin+len = mypdf(pos).

len = len + pos.

IF len = 255. "length of out (contents_bin)

APPEND outbin.

CLEAR: outbin, len.

IF pos < 134.

outbin = mypdf+pos.

len = 134 - pos.

ENDIF.

ENDIF.

ENDLOOP.

IF len > 0.

APPEND outbin.

ENDIF.

ENDFORM. "doconv

*----


  • CODE FOR PROGRAM

*----


REPORT zam_temp147 .

INCLUDE inclfor_mail.

----


DATA

*----


DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : file_name TYPE string.

data : path like PCFILE-PATH.

data : extension(5) type c.

data : name(100) type c.

*----


  • SELECTION SCREEN

*----


PARAMETERS : receiver TYPE somlreci1-receiver lower case.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

PERFORM ml_customize USING 'Tst' 'Testing'.

PERFORM ml_addrecp USING receiver 'U'.

PERFORM upl.

PERFORM doconv TABLES itab objbin.

PERFORM ml_prepare USING 'X' extension name.

PERFORM ml_dosend.

*----


SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

----


FORM

*----


FORM upl.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'BIN'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

path = file_name.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

complete_filename = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

EXTENSION = extension

NAME = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

INVALID_DRIVE = 1

INVALID_EXTENSION = 2

INVALID_NAME = 3

INVALID_PATH = 4

OTHERS = 5

.

ENDFORM. "upl

PS: Reward if this solution is helpful

0 Kudos
39

I tried ur code....it says

"Document <Tst> could not be sent"

Former Member
0 Kudos
39

Hi abaper,

1. There is some trick involved

in the binary files.

2. I have made a program (and it works fantastic)

ONLY 6 LINES FOR EMAILING

BELIEVE ME

ITS A FANTASTIC PROGRAM.

IT WILL WORK LIKE OUTLOOK EXPRESS !

3. The user is provided with

a) file name

b) email address to send mail

and it sends ANY FILE (.xls,.pdf .xyz..)

Instantaneously !

-


4. Make two things first :

1. Include with the name : ZAMI_INCLFOR_MAIL

2. Report with the name : ZAM_TEMP147 (any name will do)

3. Activate both and execute (2)

4. After providing filename, email adress

5. Code for Include :

*----


  • 10.08.2005 Amit M - Created

  • Include For Mail (First Req F16)

  • Modification Log

*

*

*

*

*

*

*

*----


*----


  • Data

*----


DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

*----


  • FORM

*----


FORM ml_customize USING objname objdesc.

*----


Clear Variables

CLEAR docdata.

REFRESH objpack.

CLEAR objpack.

REFRESH objhead.

REFRESH objtxt.

CLEAR objtxt.

REFRESH objbin.

CLEAR objbin.

REFRESH objhex.

CLEAR objhex.

REFRESH reclist.

CLEAR reclist.

REFRESH listobject.

CLEAR listobject.

CLEAR tab_lines.

CLEAR doc_size.

CLEAR att_type.

*----


Set Variables

docdata-obj_name = objname.

docdata-obj_descr = objdesc.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addrecp USING preceiver prec_type.

CLEAR reclist.

reclist-receiver = preceiver.

reclist-rec_type = prec_type.

APPEND reclist.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addtxt USING ptxt.

CLEAR objtxt.

objtxt = ptxt.

APPEND objtxt.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_prepare USING bypassmemory whatatt_type whatname.

IF bypassmemory = ''.

*----


Fetch List From Memory

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

ENDIF.

  • -----------

  • Header Data

  • Already Done Thru FM

  • -----------

  • -----------

  • Main Text

  • Already Done Thru FM

  • -----------

  • -----------

  • Packing Info For Text Data

  • -----------

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

  • -----------

  • Packing Info Attachment

  • -----------

att_type = whatatt_type..

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = whatname.

APPEND objpack.

  • -----------

  • Receiver List

  • Already done thru fm

  • -----------

ENDFORM. "ml_prepare

*----


  • FORM

*----


FORM ml_dosend.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • object_parb =

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.

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ENDIF.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_spooltopdf USING whatspoolid.

DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.

*----


Call Function

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = whatspoolid

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

OTHERS = 12.

*----


Convert

PERFORM doconv TABLES pdf objbin.

ENDFORM. "ml_spooltopdf

*----


  • FORM

*----


FORM doconv TABLES

mypdf STRUCTURE tline

outbin STRUCTURE solisti1.

*----


Data

DATA : pos TYPE i.

DATA : len TYPE i.

*----


Loop And Put Data

LOOP AT mypdf.

pos = 255 - len.

IF pos > 134. "length of pdf_table

pos = 134.

ENDIF.

outbin+len = mypdf(pos).

len = len + pos.

IF len = 255. "length of out (contents_bin)

APPEND outbin.

CLEAR: outbin, len.

IF pos < 134.

outbin = mypdf+pos.

len = 134 - pos.

ENDIF.

ENDIF.

ENDLOOP.

IF len > 0.

APPEND outbin.

ENDIF.

ENDFORM. "doconv

*----


CODE FOR PROGRAM

5.

REPORT zam_temp147 .

INCLUDE zami_inclfor_mail.

*----


  • DATA

*----


DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : file_name TYPE string.

data : path like PCFILE-PATH.

data : extension(5) type c.

data : name(100) type c.

*----


  • SELECTION SCREEN

*----


PARAMETERS : receiver TYPE somlreci1-receiver lower case.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

PERFORM ml_customize USING 'Tst' 'Testing'.

PERFORM ml_addrecp USING receiver 'U'.

PERFORM upl.

PERFORM doconv TABLES itab objbin.

PERFORM ml_prepare USING 'X' extension name.

PERFORM ml_dosend.

*----


SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

*----


  • FORM

*----


FORM upl.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'BIN'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

path = file_name.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

complete_filename = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

EXTENSION = extension

NAME = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

INVALID_DRIVE = 1

INVALID_EXTENSION = 2

INVALID_NAME = 3

INVALID_PATH = 4

OTHERS = 5

.

ENDFORM. "upl

*----


regards,

amit m.

0 Kudos
39

hi amit mittal,

your fantastic code dosent work....it gives same msg...document <Tst> was not sent...

so srry no pts for u.

0 Kudos
39

Hi again,

1. Sometimes, it also depends upon the

SCOT settings.

2. In tcode SCOT

there are settings, whether

the mail is configured to go

to which which domains (eg. yahoo, rediff, all etc)

3. Please contact your basis team also,

to check & verify the scot settings.

Then it will work fine !

regards,

amit m.

0 Kudos
39

scot settings are alright....still same error msg....got ne other example?? internal/external mail??

0 Kudos
39

hi,

kindly go thru the blow code.

here i am sending a smart form as PDF attachmnt.

u can use the same logic.

REPORT y_cb_test_051 .

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

  • DATA DECLARATION

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

TYPE-POOLS: meein.

TABLES: toa_dara,

nast,

tnapr,

arc_params.

DATA: ent_retco TYPE sy-subrc,

ent_screen TYPE c,

l_xkomk LIKE TABLE OF komk WITH HEADER LINE,

xscreen. "Kz. Probeausgabe

DATA: i_texto_cuerpo LIKE solisti1 OCCURS 0 WITH HEADER LINE.

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

  • SELECT OPTIONS / PARAMETERS

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

PARAMETERS:

p_kappl LIKE nast-kappl OBLIGATORY DEFAULT 'EF',

p_objky LIKE nast-objky OBLIGATORY DEFAULT '0010001125',

p_kschl LIKE nast-kschl OBLIGATORY DEFAULT 'NEU',

p_spras LIKE nast-spras OBLIGATORY DEFAULT 'EN',

p_parnr LIKE nast-parnr OBLIGATORY DEFAULT '50009123',

p_parvw LIKE nast-parvw OBLIGATORY DEFAULT 'BA',

p_erdat LIKE nast-erdat OBLIGATORY DEFAULT '20050908',

p_eruhr LIKE nast-eruhr OBLIGATORY DEFAULT '130105',

p_aende LIKE nast-aende DEFAULT 'X',

p_nacha LIKE nast-nacha DEFAULT '1',

p_ndialo TYPE tdsfflag DEFAULT ' ',

p_telfx LIKE nast-telfx DEFAULT '1-920-721-0284',

p_tland LIKE nast-tland DEFAULT 'US',

p_sform TYPE tdsfname DEFAULT 'ZMMNABPR3PFMMPO_L3' OBLIGATORY.

*PDF TABLES

DATA: tb_pdf LIKE tline OCCURS 0.

DATA: tb_pdf255 TYPE so_text255 OCCURS 0.

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

  • MAIN PROCESSING SECTION

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

START-OF-SELECTION.

  • SELECT SINGLE *

  • INTO nast

  • FROM nast

  • WHERE kappl = p_kappl

  • AND objky = p_objky

  • AND kschl = p_kschl

  • AND spras = p_spras

  • AND parnr = p_parnr

  • AND parvw = p_parvw

  • AND erdat = p_erdat

  • AND eruhr = p_eruhr.

*

  • IF sy-subrc <> 0.

MESSAGE s000(00) WITH 'Record in NAST not found.'.

nast-kappl = p_kappl.

nast-objky = p_objky.

nast-kschl = p_kschl.

nast-spras = p_spras.

nast-parnr = p_parnr.

nast-parvw = p_parvw.

nast-erdat = p_erdat.

nast-eruhr = p_eruhr.

nast-nacha = p_nacha.

nast-telfx = p_telfx.

nast-tland = p_tland.

  • ENDIF.

nast-aende = p_aende.

tnapr-sform = p_sform.

PERFORM entry_neu

USING

ent_retco

ent_screen.

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

  • FORMS

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

&----


*& Form entry_neu

&----


  • text

----


  • -->ENT_RETCO text

  • -->ENT_SCREEN text

----


FORM entry_neu

USING

ent_retco

ent_screen.

DATA: l_druvo LIKE t166k-druvo,

l_nast LIKE nast,

l_from_memory,

l_doc TYPE meein_purchase_doc_print.

DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.

DATA: ls_bil_invoice TYPE lbbil_invoice.

DATA: lf_fm_name TYPE rs38l_fnam.

DATA: ls_control_param TYPE ssfctrlop.

DATA: ls_composer_param TYPE ssfcompop.

DATA: ls_recipient TYPE swotobjid.

DATA: ls_sender TYPE swotobjid.

DATA: lf_formname TYPE tdsfname.

DATA: ls_addr_key LIKE addr_key.

  • xscreen = ent_screen.

  • clear ent_retco.

IF nast-aende EQ space.

l_druvo = '1'.

ELSE.

l_druvo = '2'.

ENDIF.

CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'

EXPORTING

ix_nast = nast

ix_screen = ent_screen

IMPORTING

ex_retco = ent_retco

ex_nast = l_nast

doc = l_doc

CHANGING

cx_druvo = l_druvo

cx_from_memory = l_from_memory.

CHECK ent_retco EQ 0.

IF nast-adrnr IS INITIAL.

PERFORM get_addr_key

CHANGING ls_addr_key.

ELSE.

ls_addr_key = nast-adrnr.

ENDIF.

*Set the print Parameters

PERFORM set_print_param USING ls_addr_key

CHANGING ls_control_param

ls_composer_param

ls_recipient

ls_sender

ent_retco.

*Get the Smart Form name.

IF NOT tnapr-sform IS INITIAL.

lf_formname = tnapr-sform.

ELSE.

lf_formname = tnapr-fonam.

ENDIF.

  • determine smartform function module for invoice

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = lf_formname

IMPORTING

fm_name = lf_fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • error handling

ent_retco = sy-subrc.

  • perform protocol_update_i.

ENDIF.

ls_control_param-getotf = 'X'.

DATA: l_document_output_info TYPE ssfcrespd,

l_job_output_info TYPE ssfcrescl,

l_job_output_options TYPE ssfcresop.

CALL FUNCTION lf_fm_name

EXPORTING

archive_index = toa_dara

archive_parameters = arc_params

control_parameters = ls_control_param

mail_recipient = ls_recipient

mail_sender = ls_sender

output_options = ls_composer_param

user_settings = ' '

zxekko = l_doc-xekko

zxpekko = l_doc-xpekko

  • zxaend = l_doc-xaend

IMPORTING

document_output_info = l_document_output_info

job_output_info = l_job_output_info

job_output_options = l_job_output_options

TABLES

l_xekpo = l_doc-xekpo[]

l_xekpa = l_doc-xekpa[]

l_xpekpo = l_doc-xpekpo[]

l_xeket = l_doc-xeket[]

l_xtkomv = l_doc-xtkomv[]

l_xekkn = l_doc-xekkn[]

l_xekek = l_doc-xekek[]

l_xaend = l_doc-xaend[]

l_xkomk = l_xkomk

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.

BREAK-POINT.

ENDIF.

  • Converts OTF to PDF

DATA: v_len_in TYPE i.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = l_job_output_info-otfdata

lines = tb_pdf

EXCEPTIONS

err_max_linewidth = 0

err_format = 1

err_conv_not_possible = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Change the PDF format from 132 to 255.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

  • line_width_src =

  • line_width_dst =

transfer_bin = 'X'

TABLES

content_in = tb_pdf

content_out = tb_pdf255

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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

DATA: lw_subject TYPE so_obj_des.

DATA: lwa_body TYPE solisti1.

DATA: ltb_body TYPE TABLE OF solisti1.

DATA: lw_filename TYPE char100.

DATA: ltb_recipients TYPE TABLE OF somlreci1.

DATA: lwa_recipients TYPE somlreci1.

lw_subject = 'This is the email subject'.

lwa_body-line = 'This is the email body - Line1'.

APPEND lwa_body TO ltb_body.

lwa_body-line = 'This is the email body - Line2'.

APPEND lwa_body TO ltb_body.

lwa_body-line = 'This is the email body - Line3'.

APPEND lwa_body TO ltb_body.

lwa_body-line = 'This is the email body - Line4'.

APPEND lwa_body TO ltb_body.

lw_filename = 'Contract'.

*RECIPIENTS

lwa_recipients-rec_type = 'U'.

lwa_recipients-express = 'X'.

lwa_recipients-receiver = sy-uname.

lwa_recipients-copy = ''.

APPEND lwa_recipients TO ltb_recipients.

  • RECIPIENTS

lwa_recipients-rec_type = 'U'.

lwa_recipients-express = 'X'.

lwa_recipients-receiver = 'john.doe@abc.com'.

lwa_recipients-copy = ''.

APPEND lwa_recipients TO ltb_recipients.

  • RECIPIENTS

lwa_recipients-rec_type = 'U'.

lwa_recipients-express = 'X'.

lwa_recipients-receiver = 'john.doe@gmail.com'.

lwa_recipients-copy = ''.

APPEND lwa_recipients TO ltb_recipients.

  • Sends the PDF by email.

PERFORM f_send_pdf_by_email

TABLES

tb_pdf255

ltb_body

ltb_recipients

USING

lw_subject

lw_filename.

ENDFORM. "entry_neu

&----


*& Form ZCA_MAIL_BIN

&----


  • text

----


FORM f_send_pdf_by_email

TABLES

ptb_pdf255 STRUCTURE solisti1

ptb_body STRUCTURE solisti1

ptb_recipients STRUCTURE somlreci1

USING

pw_subject TYPE so_obj_des

pw_filename TYPE char100.

*-DATA DECLARATION----


  • Variables y tablas internas.

DATA: BEGIN OF ltb_objbin OCCURS 0.

INCLUDE STRUCTURE solisti1.

DATA: END OF ltb_objbin.

DATA: lwa_doc_chng LIKE sodocchgi1,

lw_tab_lines LIKE sy-tabix,

ltb_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

ltb_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

*-MAIN PROCESSING SECTION----


clear: ltb_objbin, ltb_objtxt, ltb_objpack, lwa_doc_chng.

refresh: ltb_objbin, ltb_objtxt, ltb_objpack.

  • Control Data

lwa_doc_chng-obj_name = 'URGENT'.

lwa_doc_chng-sensitivty = 'P'.

lwa_doc_chng-no_change = 'X'.

lwa_doc_chng-priority = '1'.

lwa_doc_chng-obj_prio = '1'.

lwa_doc_chng-obj_langu = sy-langu.

lwa_doc_chng-no_change = 'X'.

  • Email Subject

lwa_doc_chng-obj_descr = pw_subject.

  • Email Body

ltb_objtxt[] = ptb_body[].

CLEAR ltb_objtxt.

DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines.

IF lw_tab_lines GT 0.

READ TABLE ltb_objtxt INDEX lw_tab_lines.

lwa_doc_chng-doc_size =

( lw_tab_lines - 1 ) * 255 + STRLEN( ltb_objtxt ).

CLEAR ltb_objpack-transf_bin.

ltb_objpack-body_start = 1.

ltb_objpack-body_num = lw_tab_lines.

ltb_objpack-doc_type = 'RAW'.

APPEND ltb_objpack.

ENDIF.

  • Attachment

  • Move the binary attachment to other internal table.

ltb_objbin[] = ptb_pdf255[].

ltb_objpack-transf_bin = 'X'.

ltb_objpack-body_start = 1.

  • Get the number of lines in the Attachment (PDF FILE)

DESCRIBE TABLE ltb_objbin LINES lw_tab_lines.

ltb_objpack-body_num = lw_tab_lines.

ltb_objpack-doc_type = 'PDF'.

ltb_objpack-obj_descr = pw_filename.

ltb_objpack-obj_name = pw_filename.

ltb_objpack-doc_size = lw_tab_lines * 255.

APPEND ltb_objpack.

  • Call the function to send the PDF file by email

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = ltb_objpack

contents_bin = ltb_objbin

contents_txt = ltb_objtxt

receivers = ptb_recipients

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.

CASE sy-subrc.

WHEN 0.

WHEN 1. RAISE too_many_receivers.

WHEN 2. RAISE document_not_sent .

WHEN 3. RAISE document_type_not_exist.

WHEN 4. RAISE operation_no_authorization.

WHEN 5. RAISE parameter_error.

WHEN 7. RAISE enqueue_error .

WHEN OTHERS. RAISE x_error.

ENDCASE.

COMMIT WORK.

ENDFORM. "ZCA_MAIL_BIN

&----


*& Form get_addr_key

&----


  • text

----


  • -->P_CS_BIL_INVOICE_HD_ADR text

  • <--P_CS_ADDR_KEY text

----


FORM get_addr_key

CHANGING l_addr_key LIKE addr_key.

DATA: l_lfa1 LIKE lfa1.

SELECT SINGLE * FROM lfa1 INTO l_lfa1

WHERE lifnr = nast-parnr.

IF sy-subrc = 0.

MOVE l_lfa1-adrnr TO l_addr_key.

ENDIF.

ENDFORM. " get_addr_key

&----


*& Form set_print_param

&----


  • text

----


  • -->P_LS_ADDR_KEY text

  • <--P_LS_CONTROL_PARAM text

  • <--P_LS_COMPOSER_PARAM text

  • <--P_LS_RECIPIENT text

  • <--P_LS_SENDER text

  • <--P_CF_RETCODE text

----


FORM set_print_param USING is_addr_key LIKE addr_key

CHANGING cs_control_param TYPE ssfctrlop

cs_composer_param TYPE ssfcompop

cs_recipient TYPE swotobjid

cs_sender TYPE swotobjid

cf_retcode TYPE sy-subrc.

DATA: ls_itcpo TYPE itcpo.

DATA: lf_repid TYPE sy-repid.

DATA: lf_device TYPE tddevice.

DATA: ls_recipient TYPE swotobjid.

DATA: ls_sender TYPE swotobjid.

lf_repid = sy-repid.

  • CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'

CALL FUNCTION 'Z_MMNA_WFMC_PREPARE_SMART_FORM'

EXPORTING

pi_nast = nast

pi_addr_key = is_addr_key

pi_repid = lf_repid

IMPORTING

pe_returncode = cf_retcode

pe_itcpo = ls_itcpo

pe_device = lf_device

pe_recipient = cs_recipient

pe_sender = cs_sender.

IF cf_retcode = 0.

MOVE-CORRESPONDING ls_itcpo TO cs_composer_param.

cs_composer_param-tdimmed = ' '.

cs_control_param-device = lf_device.

cs_control_param-no_dialog = 'X'.

  • cs_control_param-no_dialog = p_ndialo.

cs_control_param-preview = xscreen.

cs_control_param-getotf = ls_itcpo-tdgetotf.

cs_control_param-langu = nast-spras.

ENDIF.

ENDFORM. "set_print_param

rgds

anver

if helped mark points