Sending Mail Using Oo (2) - Smartforms _ SCN
-
Upload
hatshepsutk -
Category
Documents
-
view
245 -
download
1
Transcript of Sending Mail Using Oo (2) - Smartforms _ SCN
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 1/15
created by Frédéric Girod on May 30, 2013 8:23 PM, last modified by Frédéric Girod on May 31, 2013 11:13 AM
Creation of a simple Smartform
Import of a logo
Transaction SE78
Double-click on the line BMAP
Enter a name for your logo, select the color BitMap Image and press the Import button.
Enter the file name, and press Enter.
Smartform creation
Transaction SmartForms
Enter a name and press the button Create
Sending Mail using Oo (2) - Smartforms Version 2
Sending Mail using Oo (2) - Smartforms 1/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 2/15
Select the Main Window, click on the right button, select Create --> Graphic
Enter the graphic name, the object and the ID (GRAPHICS / BMAP), select the Color BitMap Image
Select the main window, click on the right button, select Create --> Text
Enter a text ..
Press the Activate icon.
Now we could test our Smartform, press the Test button (F8).
SAP launch the SE37 transaction (Function module) with the function generated by the Smartforms.Press again the test button (F8)
Press now execute (F8)
Choose a printer and press the button Print Preview
Sending Mail using Oo (2) - Smartforms 2/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 3/15
It works !
Creation of a simple calling program for the Smartform.
DATA : w_f or mname TYPE t dsf name ,
w_f uncname TYPE t dsf name ,
i s_cont rol _param TYPE ssf ctr l op ,
i s_params TYPE pri _params .
START- OF- SELECTI ON.
* My Smartforms. MOVE ' ZMY_SMARTFORMS' TO w_f or mname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTI ON ' SSF_FUNCTI ON_MODULE_NAME'
EXPORTI NG
f or mname = w_f or mname
I MPORTI NG
f m_name = w_f uncname
EXCEPTI ONS
OTHERS = 3.
CHECK sy - subrc EQ space.
* Set the parameters of the forms.
MOVE : ' X' TO i s_cont rol _param- no_di al og ,
' X' TO i s_cont r ol _par am- previ ew ,
' ' TO i s_cont r ol _par am- get ot f ,
sy - l angu TO i s_cont r ol _par am- l angu .
CALL FUNCTI ON w_f uncname
EXPORTI NG
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
contr ol _par ameter s = i s_cont r ol _par am* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* output_options =
USER_SETTI NGS = ' '
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTI ONS
f or mat t i ng_er r or = 1
i nternal _err or = 2
Sending Mail using Oo (2) - Smartforms 3/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 4/15
send_err or = 3
user _cancel ed = 4
OTHERS = 5.
END- OF- SELECTI ON.
With this code you could print or preview the form.
Send the Smartform by email
* Need for the macro to build Mail_Appl_Obj.
I NCLUDE <cnt n01>.
DATA : w_f or mname TYPE t dsf name ,
w_f uncname TYPE t dsf name ,
w_borkey TYPE swo_t ypei d ,
w_year TYPE so_doc_yr ,
w_number TYPE so_doc_no ,
i s_cont rol _param TYPE ssf ctr l op ,
i s_params TYPE pri _par ams ,
i s_reci pi ent TYPE swotobj i d ,
i s_sender TYPE swotobj i d ,
i s_mai l obj TYPE swotobj i d ,
i s _f ol der TYPE swc_obj ect ,
i s_sof mk TYPE sof mk .
START- OF- SELECTI ON.
* My Smartforms.
MOVE ' ZMY_SMARTFORMS' TO w_f or mname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTI ON ' SSF_FUNCTI ON_MODULE_NAME'
EXPORTI NG
f or mname = w_f or mname
I MPORTI NG
f m_name = w_f uncname
EXCEPTI ONS
OTHERS = 3.
CHECK sy - subrc EQ space.
* Set the parameters of the forms.
MOVE : ' X' TO i s_cont rol _param- no_di al og ,
' ' TO i s_cont r ol _par am- previ ew , ' ' TO i s_cont r ol _par am- get ot f ,
sy - l angu TO i s_cont r ol _par am- l angu ,
' MAI L ' TO i s_cont r ol _par am- devi ce.
* Create the Recipient.
CALL FUNCTI ON ' CREATE_RECI PI ENT_OBJ _PPF'
EXPORTI NG
i p_mai l addr = ' f r ederi c. gi r od@everywher e. com'
I MPORTI NG
ep_reci pi ent _i d = i s_reci pi ent
EXCEPTI ONS
i nval i d_reci pi ent = 1
OTHERS = 2.
* Create the Sender
CALL FUNCTI ON ' CREATE_SENDER_OBJ ECT_PPF'
EXPORTI NG
i p_sender = sy - uname
I MPORTI NG
ep_sender _i d = i s_sender
EXCEPTI ONS
i nval i d_sender = 1
OTHERS = 2.
* Create the Mail Obj.
SELECT SI NGLE i nbyr i nbno
Sending Mail using Oo (2) - Smartforms 4/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 5/15
I NTO ( w_year , w_number )
FROM soud
WHERE sapnam EQ sy - uname.
CHECK sy - subrc EQ space.
MOVE : ' FOL' TO i s_sof mk- doctp ,
w_number TO i s_sof mk- docyr ,
w_year TO i s_sof mk- docno .
MOVE i s_sof mk TO w_bor key.
swc_creat e_obj ect i s_f ol der ' SOFMFOL' w_bor key.
swc_obj ect_t o_per si st ent i s_f ol der i s_mai l obj .
CALL FUNCTI ON w_f uncname
EXPORTI NG
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
contr ol _par ameter s = i s_cont r ol _par am
mai l _appl _obj = i s_mai l obj
mai l _reci pi ent = i s_reci pi ent
mai l _sender = i s_sender
* output_options =
user_sett i ngs = ' '* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTI ONS
f or mat t i ng_er r or = 1
i nternal _err or = 2
send_err or = 3
user _cancel ed = 4
OTHERS = 5.
I F sy - subrc EQ space.
COMMI T WORK AND WAI T.
ENDI F.
END- OF- SELECTI ON.
If you haven't entry in the SOUD table you could add-it dynamically with the function
SO_USER_AUTOMATIC_INSERT.
If you use an entry of the NAST table (configuration with the NACE transaction ..), instead of creating manually the
MAIL_APPL_OBJ, MAIL_RECIPIENT, MAIL_SENDER, you only have to use the function
WFMC_PREPARE_SMART_FORM.
Result
In the SOST transaction :
And the mail :
The attachment :
Sending Mail using Oo (2) - Smartforms 5/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 6/15
Each time I show that to my users, they didn't want to use that for external mails.
Send the Smartform inside the email.
Code
DATA : w_f or mname TYPE t dsf name ,
w_f uncname TYPE t dsf name ,
w_st atus TYPE bcs_rqst ,
w_html _xt xt TYPE xstr i ng ,
w_html _t xt TYPE s tr i ng ,
w_ht ml _l en TYPE i ,
w_gr _xtxt TYPE xstr i ng ,
w_of f set TYPE i ,
w_l en TYPE i ,
w_di f f TYPE i ,
w_ f i l e TYPE s tr i ng ,
w_content _t ype TYPE w3cont t ype ,
w_obj _l en TYPE so_obj _l en ,
w_cont ent _i d TYPE s tr i ng ,
w_ t i t l e TYPE so_obj _des ,
w_docno TYPE so_obj _no ,
i s_cont rol _param TYPE ssf ctr l op ,
i s_composer_param TYPE ss f compop ,
i s_sol i TYPE sol i ,
i s_j ob_ i nf o TYPE ssf crescl ,
i s_xf sparam TYPE ssfxsfp ,
i s_ht ml _r aw LI KE LI NE OF i s_j ob_ i nf o- xml output - t r f resul t - cont ent ,
i s_graphi c TYPE ssf_xsf _gr ,
i s_gr _r aw TYPE bapi cont en , i s _s ol i x TYPE s ol i x ,
i t _sol i TYPE TABLE OF sol i ,
i t _graphi cs TYPE tsf _xsf_gr ,
i t _ sol i x TYPE sol i x_tab ,
obj _mi me_hel per TYPE REF TO cl _gbt _mul t i r el at ed_ser vi ce ,
obj _bcs TYPE REF TO cl _bcs ,
obj _doc_bcs TYPE REF TO cl _document _bcs ,
obj _reci pi ent TYPE REF TO i f _reci pi ent_bcs .
Sending Mail using Oo (2) - Smartforms 6/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 7/15
START- OF- SELECTI ON.
* My Smartforms.
MOVE ' ZMY_SMARTFORMS' TO w_f or mname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTI ON ' SSF_FUNCTI ON_MODULE_NAME'
EXPORTI NG
f or mname = w_f or mname
I MPORTI NG
f m_name = w_f uncname
EXCEPTI ONS
OTHERS = 3.
CHECK sy - subrc EQ space.
* Set the parameters of the forms. MOVE : ' X' TO i s_cont r ol _par am- no_di al og ,
' ' TO i s_cont r ol _param- previ ew ,
' X' TO i s_cont r ol _par am- get ot f ,
sy - l angu TO i s_cont r ol _par am- l angu ,
' PRI NTER' TO i s_cont r ol _par am- devi ce ,
' X' TO i s_composer_param- t dnopri nt ,
' X' TO i s_composer_param- t dnopr ev ,
' X' TO i s_composer_param- tdf i nal ,
' X' TO i s_composer_param- xdf cmode ,
' ' TO i s_composer_param- xdf ,
' X' TO i s_composer_param- xsf cmode ,
' X' TO i s_composer_param- xs f ,
' ' TO i s_composer_param- xsf out dev ,
' A' TO i s_composer_param- xsf outmode ,
' X' TO i s_composer_param- xsf f ormat ,
' My Mai l ' TO i s_composer_param- t dt i t l e.
* For the Graphics
MOVE : ' GRAPHI CS' TO i s_xf spar am- name ,
' EXTRACT' TO i s_xf spar am- val ue.
APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
MOVE : ' GRAPHI CS- DI RECTORY' TO i s_xf sparam- name ,
' MyDi r Y TO i s_xf sparam- val ue.
APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
MOVE : ' CONTENT- I D' TO i s_xf sparam- name ,
' ENABLE' TO i s_xf spar am- val ue. APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
* Call the Smartforms
CALL FUNCTI ON w_f uncname
EXPORTI NG
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
contr ol _par ameter s = i s_cont r ol _par am
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER = out put _opt i ons = i s_composer_param
user_sett i ngs = ' '
I MPORTI NG
* DOCUMENT_OUTPUT_INFO =
j ob_out put _i nf o = i s_j ob_ i nfo
* JOB_OUTPUT_OPTIONS =
EXCEPTI ONS
f or mat t i ng_er r or = 1
i nternal _err or = 2
send_err or = 3
user _cancel ed = 4
OTHERS = 5.
* Conversion du HTML Hex en Text.
LOOP AT i s_j ob_ i nf o- xml output - t r f resul t - content
I NTO i s_ht ml _r aw.
CONCATENATE w_ht ml _xt xt
i s_ht ml _r aw
I NTO w_ht ml _xt xt
I N BYTE MODE.
ENDLOOP.
w_html _xt xt = w_ht ml _xt xt ( i s _j ob_ i nf o- xml output - t r f resul t - l engt h) .
CALL FUNCTI ON ' SCP_TRANSLATE_CHARS'
Sending Mail using Oo (2) - Smartforms 7/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 8/15
EXPORTI NG
i nbuf f = w_ht ml _xt xt
i ncode = ' 4110'
out code = ' 0000'
csubst = ' X'
s ubst c_space = ' X'
I MPORTI NG
out buf f = w_ht ml _t xt
out used = w_ht ml _l en
EXCEPTI ONS
OTHERS = 5.
REPLACE ALL OCCURRENCES OF ' ut f - 8' I N w_html _t xt WI TH ' l at i n1' .
w_ht ml _l en = s t r l en( w_html _t xt ) .
* Creation objet pour mail.
CREATE OBJ ECT obj _mi me_hel per .
* Récupère les graphiques.
i t_graphi cs = i s_j ob_ i nf o- xml output - xsf gr[ ] .
LOOP AT i t_graphi cs
I NTO i s_gr aphi c .
CLEAR w_gr_xt xt . LOOP AT i s_graphi c - content
I NTO i s_gr_r aw.
CONCATENATE w_gr _xt xt
i s_gr_r aw- l i ne
I NTO w_gr_xt xt
I N BYTE MODE.
ENDLOOP.
w_gr_xt xt = w_gr _xt xt ( i s_gr aphi c - l engt h) .
w_of f set = 0.
w_l en = 255.
CLEAR i t _ sol i x[ ] .
WHI LE w_off set < i s_graphi c - l engt h.
w_di f f = i s_gr aphi c - l engt h - w_of f set . I F w_di f f > w_l en.
i s_ sol i x- l i ne = w_gr _xt xt +w_of f set ( w_l en) .
ELSE.
i s_ sol i x- l i ne = w_gr _xt xt +w_of f set ( w_di f f ) .
ENDI F.
APPEND i s _s ol i x TO i t _ sol i x.
ADD w_l en TO w_of f set .
ENDWHI LE.
CONCATENATE ' MyDi r '
i s_graphi c - gr aphi cs
' . bmp'
I NTO w_f i l e.
CONCATENATE ' MyDi r '
i s_graphi c - gr aphi cs
' . bmp'
I NTO w_cont ent _i d.
w_content _t ype = i s_gr aphi c - ht t pt ype.
w_obj _l en = i s_gr aphi c - l engt h.
CALL METHOD obj _mi me_hel per - >add_bi nar y_part
EXPORTI NG
cont ent = i t _ sol i x
f i l ename = w_f i l e
extensi on = ' BMP'
descri pti on = ' Gr aphi c i n BMP f ormat'
content_t ype = w_content _t ype
l engt h = w_obj _l en
cont ent _i d = w_cont ent _i d. ENDLOOP.
w_of f set = 0.
w_l en = 255.
WHI LE w_of f set < w_html _l en.
w_di f f = w_ht ml _l en - w_of f set .
I F w_di f f > w_l en.
i s _sol i - l i ne = w_ht ml _t xt+w_of f set ( w_l en) .
ELSE.
i s _sol i - l i ne = w_ht ml _t xt+w_of f set ( w_di f f ) .
ENDI F.
APPEND i s_sol i TO i t _ sol i .
ADD w_l en TO w_of f set . ENDWHI LE.
* Ajoute le corps.
CALL METHOD obj _mi me_hel per - >set _mai n_ht ml
EXPORTI NG
cont ent = i t _ sol i
f i l ename = ' '
descri pt i on = ' My mai l ' .
* Ajoute le titre
Sending Mail using Oo (2) - Smartforms 8/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 9/15
MOVE i s_composer _param- t dt i t l e TO w_ t i t l e.
obj _doc_bcs = cl _document_bcs =>create_f r om_mul t i r el ated(
i _subj ect = w_ t i t l e
i _i mpor t ance = ' 9' " 1 / 5 / 9
i _mul t i rel _servi ce = obj _mi me_hel per ) .
CALL METHOD obj _doc_bcs- >get _docno
RECEI VI NG
resul t = w_docno.
obj _bcs = cl _bcs=>cr eat e_persi st ent ( ) .
obj _bcs- >set _document ( i _document = obj _doc_bcs ) .
* add the email address.
obj _reci pi ent = cl _cam_addr ess_bcs =>cr eate_i nt ernet _addr ess(
i _addr ess_str i ng = ' f r ederi c. gi r od@everywhere. com' ) .
obj _bcs- >add_r eci pi ent ( i _ reci pi ent = obj _reci pi ent ) .
* Statut change MOVE ' N' TO w_st atus.
CALL METHOD obj _bcs- >set _status_at t ri but es
EXPORTI NG
i _r equested_st at us = w_st atus.
* Send the mail.
obj _bcs- >send( ) .
* Commit Work.
I F sy - subrc EQ space.
COMMI T WORK AND WAI T.
ELSE.
ROLLBACK WORK .
ENDI F.
END- OF- SELECTI ON.
The code is little more complex.
First, we need to execute the Smartform, but without printing it. We asked SAP to create XDF and XSF, the result was
store in the JOB_OUTPUT_INFO.
The form is in Hex format, we used the function SCP_TRANSLATE_CHARS to convert to a text format.
We need also to include the logo in the mail, but not as attachment, so we used the ADD_BINARY_PART method
instead of ADD_ATTACHMENT.
Result
Sending Mail using Oo (2) - Smartforms 9/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 10/15
Send the Smartform in PDF attachment with a textmessage.
Create a new Smartform
I need a simple Smartform to put-it in the text message of the email.
The code need to be organized ...
The data :
TYPES : tt_docs TYPE TABLE OF docs .
DATA : w_f or mname TYPE t dsf name ,
w_f uncname TYPE t dsf name ,
w_st atus TYPE bcs_rqst ,
w_html _xt xt TYPE xstr i ng ,
w_html _t xt TYPE s tr i ng ,
w_ht ml _l en TYPE i ,
w_gr _xtxt TYPE xstr i ng ,
w_of f set TYPE i ,
w_l en TYPE i ,
w_di f f TYPE i ,
w_ f i l e TYPE s tr i ng ,
w_content _t ype TYPE w3cont t ype ,
w_obj _l en TYPE so_obj _l en ,
w_cont ent _i d TYPE so_obj _des ,
w_cont ent _i d2 TYPE s tr i ng ,
w_ t i t l e TYPE so_obj _des ,
w_docno TYPE so_obj _no ,
w_doc_si ze TYPE i ,
w_xtxt TYPE xstr i ng ,
i s_cont rol _param TYPE ssf ctr l op ,
i s_composer_param TYPE ss f compop ,
i s_sol i TYPE sol i ,
i s_j ob_ i nf o TYPE ssf crescl ,
i s_xf sparam TYPE ssfxsfp ,
i s_ht ml _r aw LI KE LI NE OF i s_j ob_ i nf o- xml output - t r f resul t - cont ent ,
i s_graphi c TYPE ssf_xsf _gr ,
i s_gr _r aw TYPE bapi cont en ,
i s _s ol i x TYPE s ol i x ,
i s_t l i ne TYPE t l i ne ,
i t _sol i TYPE TABLE OF sol i ,
i t _graphi cs TYPE tsf _xsf_gr ,
i t _ sol i x TYPE sol i x_tab ,
i t _docs TYPE tt_docs ,
i t _t l i ne TYPE tl i ne_tab ,
Sending Mail using Oo (2) - Smartforms 10/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 11/15
obj _mi me_hel per TYPE REF TO cl _gbt _mul t i r el at ed_ser vi ce ,
obj _bcs TYPE REF TO cl _bcs ,
obj _doc_bcs TYPE REF TO cl _document _bcs ,
obj _reci pi ent TYPE REF TO i f _reci pi ent_bcs ,
obj _conv TYPE REF TO cl _abap_conv_obj .
First part, create the mail with the text message :
START- OF- SELECTI ON.
*---------------------------------------------------------------------*
* Create the text message *
*---------------------------------------------------------------------*
* My Smartforms.
MOVE ' ZMY_SMARTFORMS_002' TO w_f or mname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTI ON ' SSF_FUNCTI ON_MODULE_NAME'
EXPORTI NG
f or mname = w_f or mname
I MPORTI NG
f m_name = w_f uncname
EXCEPTI ONS
OTHERS = 3.
CHECK sy - subrc EQ space.
* Set the parameters of the forms.
MOVE : ' X' TO i s_cont r ol _par am- no_di al og ,
' ' TO i s_cont r ol _param- previ ew ,
' X' TO i s_cont r ol _par am- get ot f ,
sy - l angu TO i s_cont r ol _par am- l angu , ' PRI NTER' TO i s_cont r ol _par am- devi ce ,
' X' TO i s_composer_param- t dnopri nt ,
' X' TO i s_composer_param- t dnopr ev ,
' X' TO i s_composer_param- tdf i nal ,
' X' TO i s_composer_param- xdf cmode ,
' ' TO i s_composer_param- xdf ,
' X' TO i s_composer_param- xsf cmode ,
' X' TO i s_composer_param- xs f ,
' ' TO i s_composer_param- xsf out dev ,
' A' TO i s_composer_param- xsf outmode ,
' X' TO i s_composer_param- xsf f ormat ,
' My Mai l ' TO i s_composer_param- t dt i t l e.
* For the Graphics
MOVE : ' GRAPHI CS' TO i s_xf spar am- name ,
' EXTRACT' TO i s_xf spar am- val ue.
APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
MOVE : ' GRAPHI CS- DI RECTORY' TO i s_xf sparam- name ,
' MyDi r Y TO i s_xf sparam- val ue.
APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
MOVE : ' CONTENT- I D' TO i s_xf sparam- name ,
' ENABLE' TO i s_xf spar am- val ue.
APPEND i s_xf spar am TO i s_composer _param- xsfpar s .
* Call the Smartforms
CALL FUNCTI ON w_f uncname
EXPORTI NG
contr ol _par ameter s = i s_cont r ol _par am
out put _opt i ons = i s_composer _param
user_sett i ngs = ' '
I MPORTI NG
j ob_out put _i nf o = i s_j ob_ i nf o
EXCEPTI ONS
f or mat t i ng_er r or = 1
i nternal _err or = 2
send_err or = 3
user _cancel ed = 4
OTHERS = 5.
* Conversion du HTML Hex en Text.
LOOP AT i s_j ob_ i nf o- xml output - t r f resul t - content
I NTO i s_ht ml _r aw.
CONCATENATE w_ht ml _xt xt
i s_ht ml _r aw
I NTO w_ht ml _xt xt
I N BYTE MODE.
ENDLOOP.
w_html _xt xt = w_ht ml _xt xt ( i s _j ob_ i nf o- xml output - t r f resul t - l engt h) .
CALL FUNCTI ON ' SCP_TRANSLATE_CHARS'
Sending Mail using Oo (2) - Smartforms 11/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 12/15
EXPORTI NG
i nbuf f = w_ht ml _xt xt
i ncode = ' 4110'
out code = ' 0000'
csubst = ' X'
s ubst c_space = ' X'
I MPORTI NG
out buf f = w_ht ml _t xt
out used = w_ht ml _l en
EXCEPTI ONS
OTHERS = 5. REPLACE ALL OCCURRENCES OF ' ut f - 8' I N w_html _t xt WI TH ' l at i n1' .
w_ht ml _l en = s t r l en( w_html _t xt ) .
* Creation objet pour mail.
CREATE OBJ ECT obj _mi me_hel per .
* Récupère les graphiques.
i t_graphi cs = i s_j ob_ i nf o- xml output - xsf gr[ ] .
LOOP AT i t_graphi cs
I NTO i s_gr aphi c .
CLEAR w_gr_xt xt . LOOP AT i s_graphi c - content
I NTO i s_gr_r aw.
CONCATENATE w_gr _xt xt
i s_gr_r aw- l i ne
I NTO w_gr_xt xt
I N BYTE MODE.
ENDLOOP.
w_gr_xt xt = w_gr _xt xt ( i s_gr aphi c - l engt h) .
w_of f set = 0.
w_l en = 255.
CLEAR i t _ sol i x[ ] .
WHI LE w_off set < i s_graphi c - l engt h.
w_di f f = i s_gr aphi c - l engt h - w_of f set .
I F w_di f f > w_l en.
i s_ sol i x- l i ne = w_gr _xt xt +w_of f set ( w_l en) .
ELSE.
i s_ sol i x- l i ne = w_gr _xt xt +w_of f set ( w_di f f ) .
ENDI F.
APPEND i s _s ol i x TO i t _ sol i x.
ADD w_l en TO w_of f set .
ENDWHI LE.
CONCATENATE ' MyDi r '
i s_graphi c - gr aphi cs
' . bmp'
I NTO w_f i l e.
CONCATENATE ' MyDi r '
i s_graphi c - gr aphi cs ' . bmp'
I NTO w_cont ent _i d.
w_content _t ype = i s_gr aphi c - ht t pt ype.
w_obj _l en = i s_gr aphi c - l engt h.
CALL METHOD obj _mi me_hel per - >add_bi nar y_part
EXPORTI NG
cont ent = i t _ sol i x
f i l ename = w_f i l e
extensi on = ' BMP'
descri pti on = ' Gr aphi c i n BMP f ormat'
content_t ype = w_content _t ype
l engt h = w_obj _l en
cont ent _i d = w_cont ent _i d2. ENDLOOP.
w_of f set = 0.
w_l en = 255.
WHI LE w_of f set < w_html _l en.
w_di f f = w_ht ml _l en - w_of f set .
I F w_di f f > w_l en.
i s _sol i - l i ne = w_ht ml _t xt+w_of f set ( w_l en) .
ELSE.
i s _sol i - l i ne = w_ht ml _t xt+w_of f set ( w_di f f ) .
ENDI F.
APPEND i s_sol i TO i t _ sol i .
ADD w_l en TO w_of f set .
ENDWHI LE.
* Ajoute le corps.
CALL METHOD obj _mi me_hel per - >set _mai n_ht ml
EXPORTI NG
cont ent = i t _ sol i
f i l ename = ' '
descri pt i on = ' My mai l ' .
* Ajoute le titre
MOVE i s_composer _param- t dt i t l e TO w_ t i t l e.
Sending Mail using Oo (2) - Smartforms 12/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 13/15
obj _doc_bcs = cl _document_bcs =>create_f r om_mul t i r el ated(
i _subj ect = w_ t i t l e
i _i mpor t ance = ' 9' " 1 / 5 / 9
i _mul t i rel _servi ce = obj _mi me_hel per ) .
CALL METHOD obj _doc_bcs- >get _docno
RECEI VI NG
resul t = w_docno.
obj _bcs = cl _bcs=>cr eat e_persi st ent ( ) .
obj _bcs- >set _document ( i _document = obj _doc_bcs ) .
Second part, create the PDF and add in attachment of the mail.
*---------------------------------------------------------------------*
* Create the attachment. *
*---------------------------------------------------------------------*
* My Smartforms.
MOVE ' ZMY_SMARTFORMS' TO w_f or mname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTI ON ' SSF_FUNCTI ON_MODULE_NAME'
EXPORTI NG
f or mname = w_f or mname
I MPORTI NG
f m_name = w_f uncname
EXCEPTI ONS
OTHERS = 3. CHECK sy - subrc EQ space.
* Set the parameters of the forms.
CLEAR : i s_cont r ol _par am, i s_composer _param.
MOVE : ' X' TO i s_cont r ol _par am- no_di al og ,
' ' TO i s_cont r ol _param- previ ew ,
' X' TO i s_cont r ol _par am- get ot f ,
sy - l angu TO i s_cont r ol _par am- l angu ,
' PRI NTER' TO i s_cont r ol _par am- devi ce ,
' X' TO i s_composer_param- t dnopri nt ,
' X' TO i s_composer_param- t dnopr ev ,
' X' TO i s_composer_param- t df i nal .
* Call the Smartforms
CALL FUNCTI ON w_f uncname
EXPORTI NG
contr ol _par ameter s = i s_cont r ol _par am
out put _opt i ons = i s_composer _param
user_sett i ngs = ' '
I MPORTI NG
j ob_out put _i nf o = i s_j ob_ i nf o
EXCEPTI ONS
f or mat t i ng_er r or = 1
i nternal _err or = 2
send_err or = 3
user _cancel ed = 4
OTHERS = 5.
br eak f gi .
* Convert the OTF to PDF.
CALL FUNCTI ON ' CONVERT_OTF_2_PDF'
I MPORTI NG
bi n_ f i l es i ze = w_doc_si ze
TABLES
ot f = i s_j ob_ i nf o- ot f data
doctab_ar chi ve = i t _docs
l i nes = i t _ t l i ne
EXCEPTI ONS OTHERS = 3.
CLEAR w_gr _xt xt .
CREATE OBJ ECT obj _conv.
* Change the output format.
LOOP AT i t _t l i ne
I NTO i s_ t l i ne.
CALL METHOD obj _conv- >convert
EXPORTI NG
i nbuf f = i s_t l i ne
out buf f l g = 2500
I MPORTI NG
Sending Mail using Oo (2) - Smartforms 13/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 14/15
out buf f = w_xt xt .
CONCATENATE w_gr_xt xt
w_xt xt
I NTO w_gr_xt xt
I N BYTE MODE.
ENDLOOP.
w_gr _xtxt = w_gr_xt xt ( w_doc_si ze) .
w_of f set = 0.
w_l en = 255.
CLEAR i t _ sol i x[ ] .
WHI LE w_of f set < w_doc_si ze. w_di f f = w_doc_si ze - w_of f set .
I F w_di f f > w_l en.
i s _sol i x- l i ne = w_gr_xt xt+w_of f set ( w_l en) .
ELSE.
i s _sol i x- l i ne = w_gr_xt xt+w_of f set ( w_di f f ) .
ENDI F.
APPEND i s _s ol i x TO i t _ sol i x.
ADD w_l en TO w_of f set .
ENDWHI LE.
MOVE : ' At t achment ' TO w_t i t l e ,
' At t achment . pdf ' TO w_cont ent _i d.
w_content _t ype = ' ' . w_obj _l en = w_doc_si ze.
* Add as attachment the PDF
CALL METHOD obj _doc_bcs- >add_at t achment
EXPORTI NG
i _at t achment _t ype = ' PDF'
i _att achment _subj ect = w_cont ent _i d
i _att achment _si ze = w_obj _l en
i _at t _cont ent _hex = i t _ sol i x.
And finaly send the mail .
* add the email address.
obj _reci pi ent = cl _cam_addr ess_bcs =>cr eate_i nt ernet _addr ess(
i _addr ess_str i ng = ' f r eder i c. gi r od@sap. com' ) .
obj _bcs- >add_r eci pi ent ( i _ reci pi ent = obj _reci pi ent ) .
* Statut change
MOVE ' N' TO w_st atus.
CALL METHOD obj _bcs- >set _status_at t ri but es
EXPORTI NG i _r equested_st at us = w_st atus.
* Send the mail.
obj _bcs- >send( ) .
* Commit Work.
I F sy - subrc EQ space.
COMMI T WORK AND WAI T.
ELSE.
ROLLBACK WORK .
ENDI F.
END- OF- SELECTI ON.
It's a little bit long, but the result is better for the end user.
Result
Sending Mail using Oo (2) - Smartforms 14/15
8/13/2019 Sending Mail Using Oo (2) - Smartforms _ SCN
http://slidepdf.com/reader/full/sending-mail-using-oo-2-smartforms-scn 15/15
858 Views Topics: abap Tags: email, abap_objects
(next step : result of a report ..)
Fred
Sending Mail using Oo (2) - Smartforms 15/15