Posted: Tue Nov 20, 2007 2:14 pm Post subject: Mailing from ALV with HTML
Code:
TYPE-POOLS: sdydo.
DATA: do TYPE REF TO cl_dd_document.
DATA: is_displayed.
DATA: v_email_sent TYPE c,
v_attached TYPE c.
DATA: BEGIN OF gt_extab OCCURS 0,
fcode LIKE rsmpe-func,
END OF gt_extab.
TYPES: BEGIN OF t_data,
matnr TYPE matnr,
zzdaycod TYPE zzdaycod,
zzgroes TYPE groes,
zzcsstrttm TYPE zzcsstrttm,
zzcsendtm TYPE zzcsendtm,
zzstkhld TYPE zzstkhld,
END OF t_data,
BEGIN OF t_comp,
field TYPE rollname,
text(30) TYPE c,
END OF t_comp.
DATA: gt_data TYPE STANDARD TABLE OF t_data,
gs_data TYPE t_data,
gt_comp TYPE STANDARD TABLE OF t_comp,
gs_comp TYPE t_comp.
PARAMETERS: p_qmnum LIKE qmel-qmnum OBLIGATORY
DEFAULT '000000402194'.
PARAMETERS: p_mailid(255) TYPE c OBLIGATORY
DEFAULT '[email protected]' LOWER CASE.
SELECT matnr zzdaycod zzgroes zzcsstrttm zzcsendtm zzstkhld
FROM viqmel
INTO TABLE gt_data
WHERE refnum = '402194'.
* Event Handler Definition, handling changes of GUI fonts, colors,...
CLASS cl_my_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
use_new_resources FOR EVENT resources_changed OF cl_gui_resources.
ENDCLASS. "cl_my_event_handler DEFINITION
DATA: my_handler TYPE REF TO cl_my_event_handler.
CREATE OBJECT my_handler.
* Call Screen
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'BRP' EXCLUDING gt_extab.
IF is_displayed IS INITIAL.
SET HANDLER my_handler->use_new_resources.
* create document
CREATE OBJECT do.
* fill document
* PERFORM dd_add_text USING do.
PERFORM zf_dd_add_text USING do.
* merge document
CALL METHOD do->merge_document.
* display document
CALL METHOD do->display_document
EXPORTING
container = 'HTML'
EXCEPTIONS
html_display_error = 1.
" do some exception handling ...
is_displayed = 'X'.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'. "Beenden
LEAVE PROGRAM.
WHEN 'ATTACH'.
PERFORM zf_attach_html.
APPEND 'ATTACH' TO gt_extab.
WHEN 'EMAIL'.
PERFORM zf_send_email.
* perform zf_send_email2.
APPEND 'EMAIL' TO gt_extab.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form DD_ADD_TEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM dd_add_text USING p_do TYPE REF TO cl_dd_document.
DATA ta TYPE REF TO cl_dd_table_element.
DATA col1 TYPE REF TO cl_dd_area.
DATA col2 TYPE REF TO cl_dd_area.
DATA text TYPE sdydo_text_element.
DATA text1 TYPE sdydo_text_element.
DATA text2 TYPE sdydo_text_element.
DATA text3 TYPE sdydo_text_element.
DATA texttable TYPE sdydo_text_table.
DATA buffer(4).
* set Heading
text = 'Text display in dynamic documents'(001).
CALL METHOD p_do->add_text
EXPORTING
text = text
sap_style = 'heading'.
CALL METHOD p_do->new_line.
CALL METHOD p_do->new_line.
text = 'Methods ADD_TEXT, NEW_LINE, UNDERLINE; Rel99'(002).
CALL METHOD p_do->add_text
EXPORTING
text = text.
CALL METHOD p_do->new_line.
CALL METHOD p_do->underline.
CALL METHOD p_do->new_line.
* create table
CALL METHOD p_do->add_table
EXPORTING
no_of_columns = 2
cell_background_transparent = space
IMPORTING
table = ta.
* set columns
CALL METHOD ta->add_column
EXPORTING
width = '70%' "'30%'
IMPORTING
column = col1.
CALL METHOD ta->add_column
EXPORTING
width = '30%' "70%'
IMPORTING
column = col2.
CALL METHOD ta->set_column_style
EXPORTING
col_no = 1
sap_color = cl_dd_area=>list_key.
* fill columns
text = 'Passing a text element - recommended for' &
'texts that need translation'(003).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
text = '(ADD_TEXT, Parameter: TEXT )'(018).
CALL METHOD col1->add_text
EXPORTING
text = text.
text = 'Text elem.'(500).
CALL METHOD col2->add_text
EXPORTING
text = text.
CALL METHOD ta->new_row.
text = 'Text originates in a field (up to 255 chars)'(004).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
text = '(ADD_TEXT, Parameter: TEXT )'(005).
CALL METHOD col1->add_text
EXPORTING
text = text.
text =
'111111111 222222222 333333333 444444444 555555555 ' &
'666666666 777777777 888888888 999999999 000000000 ' &
'111111111 222222222 333333333 444444444 555555555 ' &
'666666666 777777777 888888888 999999999 000000000 ' &
'111111111 222222222 333333333 444444444 555555555 '.
CALL METHOD col2->add_text
EXPORTING
text = text.
CALL METHOD ta->new_row.
text =
'Text originates in a table and is displayed as continuous text'(007).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
text = '(ADD_TEXT, Parameter: TEXT_TABLE )'(008).
CALL METHOD col1->add_text
EXPORTING
text = text.
DO 30 TIMES.
text = 'Text display...'(009).
buffer = sy-index.
CONCATENATE text buffer INTO text.
APPEND text TO texttable.
ENDDO.
CALL METHOD col2->add_text
EXPORTING
text_table = texttable.
CALL METHOD ta->new_row.
text =
'Text originates in a table and is displayed in lines'(017).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
text = '(ADD_TEXT, Parameter: TEXT_TABLE und FIX_LINES )'(010).
CALL METHOD col1->add_text
EXPORTING
text = text.
CLEAR texttable.
DO 10 TIMES.
text = 'Text display....'(009).
buffer = sy-index.
CONCATENATE text buffer INTO text.
APPEND text TO texttable.
ENDDO.
CALL METHOD col2->add_text
EXPORTING
text_table = texttable
fix_lines = 'X'.
CALL METHOD ta->new_row.
text = 'Hard line feed between texts'(011).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
CALL METHOD col1->add_text
EXPORTING
text = '(NEW_LINE)'.
text1 = 'First line ...'(012).
CALL METHOD col2->add_text
EXPORTING
text = text1.
CALL METHOD col2->new_line.
text2 = 'Second line ...'(013).
CALL METHOD col2->add_text
EXPORTING
text = text2.
CALL METHOD col2->new_line.
text3 = 'Third line ...'(014).
CALL METHOD col2->add_text
EXPORTING
text = text3.
CALL METHOD ta->new_row.
text = 'Blank line between texts'(015).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
CALL METHOD col1->add_text
EXPORTING
text = '(NEW_LINE)'.
CALL METHOD col2->add_text
EXPORTING
text = text1.
CALL METHOD col2->new_line
EXPORTING
repeat = 1.
CALL METHOD col2->add_text
EXPORTING
text = text2.
CALL METHOD col2->new_line
EXPORTING
repeat = 2.
CALL METHOD col2->add_text
EXPORTING
text = text3.
CALL METHOD ta->new_row.
text = 'Underscore between texts'(016).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
CALL METHOD col1->add_text
EXPORTING
text = '(UNDERLINE)'.
CALL METHOD col2->add_text
EXPORTING
text = text1.
CALL METHOD col2->underline.
CALL METHOD col2->add_text
EXPORTING
text = text2.
CALL METHOD col2->underline.
CALL METHOD col2->add_text
EXPORTING
text = text3.
CALL METHOD ta->new_row.
text = 'Space between text output'(019).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col1->new_line.
text = '(ADD_GAP, Parameter: WIDTH)'(020).
CALL METHOD col1->add_text
EXPORTING
text = text.
CALL METHOD col2->add_text
EXPORTING
text = text1.
CALL METHOD col2->add_gap.
CALL METHOD col2->add_text
EXPORTING
text = text1.
CALL METHOD col2->new_line.
CALL METHOD col2->add_text
EXPORTING
text = text2.
CALL METHOD col2->add_gap
EXPORTING
width = 10.
CALL METHOD col2->add_text
EXPORTING
text = text2.
CALL METHOD col2->new_line.
CALL METHOD col2->add_text
EXPORTING
text = text3.
CALL METHOD col2->add_gap
EXPORTING
width = 20.
CALL METHOD col2->add_text
EXPORTING
text = text3.
ENDFORM. "dd_add_text
* CLASS cl_my_event_handler IMPLEMENTATION.
CLASS cl_my_event_handler IMPLEMENTATION.
METHOD use_new_resources.
IF is_displayed = 'X'.
* initialize document
CALL METHOD do->initialize_document.
* fill document
PERFORM dd_add_text USING do.
* merge document
CALL METHOD do->merge_document.
* display document
CALL METHOD do->display_document
EXPORTING
reuse_control = 'X'
reuse_registration = 'X'.
ENDIF.
ENDMETHOD. "use_new_resources
ENDCLASS. "cl_my_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Form zf_attach_html
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM zf_attach_html.
DATA: i_files LIKE bapifiles OCCURS 1 WITH HEADER LINE,
i_signature LIKE bapisignat OCCURS 1 WITH HEADER LINE,
i_components LIKE bapicompon OCCURS 1 WITH HEADER LINE,
lv_logsys TYPE tbdls-logsys,
lv_objectkey TYPE bapibds01-objkey.
DATA: lt_doc_content1 TYPE
STANDARD TABLE OF bapiconten WITH HEADER LINE.
DATA: g_numbytes TYPE i.
DATA: lt_ascii TYPE STANDARD TABLE OF bapiascont WITH HEADER LINE.
DATA: v_binary_flag TYPE bapibds01-x.
DATA: wa_html TYPE w3html.
*
LOOP AT do->html_table INTO wa_html.
lt_ascii = wa_html.
APPEND lt_ascii.
ENDLOOP.
*
*****Convert lt_ascii into stream format
DATA: ld_content_string TYPE string.
DATA: ld_charsize_uc TYPE i. "unicode
DATA: ld_size TYPE sy-tabix,
ld_length TYPE i,
lt_content LIKE bapiascont OCCURS 1,
ls_content_line LIKE LINE OF lt_content.
FIELD-SYMBOLS: <ld_html_c> TYPE c. "unicode
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: lv_doc_id TYPE bapibds01-doc_id.
LOOP AT i_signature.
lv_doc_id = i_signature-doc_id.
EXIT.
ENDLOOP.
CALL FUNCTION 'BDS_DOCUMENT_DISPLAY'
EXPORTING
* CLIENT = SY-MANDT
doc_id = lv_doc_id
* TABLES
* SIGNATURE =
EXCEPTIONS
nothing_found = 1
parameter_error = 2
not_allowed = 3
error_kpro = 4
internal_error = 5
not_authorized = 6
OTHERS = 7
.
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. " zf_attach_html
*&---------------------------------------------------------------------*
*& Form zf_send_email
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM zf_send_email .
DATA: i_content TYPE STANDARD TABLE OF soli WITH HEADER LINE,
i_recipients TYPE STANDARD TABLE OF soli WITH HEADER LINE,
l_subject(200) TYPE c.
DATA: wa_html TYPE w3html.
CALL FUNCTION 'Z_BC_ABAP_EXTERNAL_SENDMAIL'
EXPORTING
l_subject = l_subject
l_html_content = 'X'
l_return_address = p_mailid
TABLES
i_content = i_content
i_recipients = i_recipients
EXCEPTIONS
send_failed = 1
* FILENAME_INUSE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE e006(z1) WITH 'Send Failed'.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE i004(zbc) WITH 'Content has sent as email to' p_mailid.
ENDIF.
ENDFORM. " zf_send_email
*&---------------------------------------------------------------------*
*& Form zf_dd_add_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM zf_dd_add_text USING p_do TYPE REF TO cl_dd_document.
DATA ta TYPE REF TO cl_dd_table_element.
DATA col1 TYPE REF TO cl_dd_area.
DATA col2 TYPE REF TO cl_dd_area.
DATA col3 TYPE REF TO cl_dd_area.
DATA col4 TYPE REF TO cl_dd_area.
DATA col5 TYPE REF TO cl_dd_area.
DATA col6 TYPE REF TO cl_dd_area.
DATA col7 TYPE REF TO cl_dd_area.
DATA col8 TYPE REF TO cl_dd_area.
DATA lv_col TYPE REF TO object.
DATA text TYPE sdydo_text_element.
DATA: lt_comp TYPE STANDARD TABLE OF rstrucinfo,
lv_program TYPE sy-repid,
lv_structure TYPE tfdir-funcname,
comp1 TYPE i.
DATA: lv_cols TYPE i,
lv_percent(03) TYPE n,
lv_colw TYPE sdydo_value,
lv_coln(04) TYPE c,
lv_idx TYPE sy-tabix.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = lv_program
fieldname = lv_structure
TABLES
components = lt_comp[].
SELECT rollname ddtext
FROM dd04t
INTO TABLE gt_comp
FOR ALL ENTRIES IN lt_comp
WHERE rollname = lt_comp-compname
AND ddlanguage = sy-langu.
* set Heading
text = 'EMAIL TO WMS SITES (DETAIL LEVEL)'.
CALL METHOD p_do->add_text
EXPORTING
text = text
sap_style = 'heading'.
CALL METHOD p_do->new_line.
CALL METHOD p_do->new_line.
text = '** This is a test **'.
CALL METHOD p_do->add_text
EXPORTING
text = text.
CALL METHOD p_do->new_line.
CALL METHOD p_do->underline.
CALL METHOD p_do->new_line.
DATA: v_url TYPE string.
DATA v_name TYPE sdydo_element_name.
* Portal links
CASE sy-sysid.
WHEN 'ERD' OR 'ERX'.
text = text-042.
WHEN 'ERQ'.
text = 'http://gmlinkqa.genmills.com/irj'(043).
WHEN 'ERP'.
text = 'http://gmlink.genmills.com/irj/index.html'(044).
ENDCASE.
* call method p_do->add_text
* exporting
* text = text.
v_name = 'Joe_Link'.
v_url = 'http://sapportaldev2.genmills.com/irj/portal'.
*v_url = 'http://www.google.com'.
* SAP users title link line
text = 'Link Test'.
CALL METHOD p_do->add_link
EXPORTING
text = text
url = v_url.
ENDFORM. " zf_dd_add_text
*&---------------------------------------------------------------------*
*& Form zf_send_email2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM zf_send_email2 .
DATA: g_lines TYPE i,
g_numbytes TYPE i,
g_form_name TYPE rs38l_fnam,
g_pdfspoolid LIKE tsp01-rqident,
g_jobname LIKE tbtcjob-jobname,
g_jobcount LIKE tbtcjob-jobcount,
g_otfspoolid LIKE tsp01-rqident,
g_control_param TYPE ssfctrlop,
g_output_options TYPE ssfcompop,
g_document_data LIKE sodocchgi1,
g_filename TYPE string.
DATA:
i_contents LIKE solisti1 OCCURS 1 WITH HEADER LINE,
wa_html TYPE solisti1,
i_packing_list LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
i_object_header LIKE solisti1 OCCURS 1 WITH HEADER LINE,
i_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
l_sender_address LIKE soextreci1-receiver,
l_sender_adr_type LIKE soextreci1-adr_typ.
DATA: lv_length TYPE i,
lv_size LIKE sodocchgi1-doc_size.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.