0% found this document useful (0 votes)
97 views8 pages

ZMM

The document contains ABAP code for sending an email with purchase order details. It defines a FORM that retrieves purchase order data, creates an HTML email body with the data in a table, and sends the email. The FORM includes subroutines to get the data, create the HTML body structure and populate it, and send the email.

Uploaded by

Niroop C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views8 pages

ZMM

The document contains ABAP code for sending an email with purchase order details. It defines a FORM that retrieves purchase order data, creates an HTML email body with the data in a table, and sends the email. The FORM includes subroutines to get the data, create the HTML body structure and populate it, and send the email.

Uploaded by

Niroop C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

*----------------------------------------------------------------------*

***INCLUDE ZMM_GOOD_RECPT_CHECK_ROUTINES.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form SEND_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send_email .

REFRESH : lt_email[].
SELECT * FROM zv_good_recpt INTO TABLE lt_email WHERE eindt IN s_eindt AND ekgrp
IN s_ekgrp.
DELETE lt_email WHERE loekz IS NOT INITIAL.
IF sy-subrc IS INITIAL.
TRY.
lo_send_request = cl_bcs=>create_persistent( ).

* populate the body of the email using HTML tags


PERFORM create_body_email.

* create document
lo_document = cl_document_bcs=>create_document( "create document
i_type = 'HTM' "Type of document HTM, TXT
etc
i_text = i_text "email body internal table
i_subject = TEXT-002 ). "email subject here p_sub
input parameter

* Pass the document to send request


lo_send_request->set_document( lo_document ).

* Sender is the logged in user


lo_sender = cl_sapuser_bcs=>create( sy-uname ).

* Set sender to send request


lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).

**Set recipient
LOOP AT s_email.
lo_recipient = cl_cam_address_bcs=>create_internet_address( s_email-
low ).
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
ENDLOOP.

CALL METHOD lo_send_request->set_send_immediately


EXPORTING
i_send_immediately = abap_true.

** Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = abap_true ).
COMMIT WORK.
IF sy-subrc = 0. "mail sent successfully
MESSAGE TEXT-003 TYPE 'I'.
ELSEIF sy-subrc IS NOT INITIAL.
MESSAGE TEXT-004 TYPE 'I'.
ENDIF.
CATCH cx_bcs INTO gr_bcs_exception.
ENDTRY.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_BODY_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_body_email .
w_text = '<!DOCTYPE html>'.
APPEND w_text TO i_text.
CLEAR w_text.
w_text = '<html>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<head>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<style>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'table {'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'font-family: arial, sans-serif;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'border-collapse: collapse;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'width: 50%;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '}'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'td, th {'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'border: 1px solid #dddddd;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'text-align: left;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'padding: 10px;'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '}'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'tr:nth-child(even) {'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = 'background-color:Gray;'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '}'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</style>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</head>'.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<p>' '<font size="3">' 'The following purchase orders indicate a


goods receipt which is scheduled, but has not been posted to SAP.' '</font></p>'
INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<p>' '<font size="3">' 'Please log into SAP and review these
purchase orders to confirm whether the goods/services have been received.'
'</font></p>' INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<p>' '<font size="3">' 'Once confirmed, please perform the SAP
procedure to receive the goods into the accounting period indicated' '</font></p>'
INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.
" for spacing in email body
DO 3 TIMES.
w_text = '<br>'.
APPEND w_text TO i_text.
CLEAR w_text.
ENDDO.

w_text = '<body>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<table>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<tr>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Po Number</th>'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Po Line</th>'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Vendor</th>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Vendor Name</th>'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Item Description</th>'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<th>Line value</th>'.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</tr>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<tr>'.
APPEND w_text TO i_text.
CLEAR w_text.

* populate values in the table


LOOP AT lt_email INTO ls_email.
CONCATENATE '<td>' ls_email-ebeln '</td>' INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<td>' ls_email-ebelp '</td>' INTO w_text.


APPEND w_text TO i_text.
CLEAR w_text.

* lv_val = ls_po-netwr.
CONCATENATE '<td>' ls_email-lifnr '</td>' INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<td>' ls_email-name1 '</td>' INTO w_text.


APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<td>' ls_email-txz01 '</td>' INTO w_text.


APPEND w_text TO i_text.
CLEAR w_text.

lv_val = ls_email-netwr.
CONCATENATE '<td>' lv_val '</td>' INTO w_text.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</tr>'.
APPEND w_text TO i_text.
CLEAR w_text.
ENDLOOP.

w_text = '</table>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '<br>'.
APPEND w_text TO i_text.
CLEAR w_text.

CONCATENATE '<p>' '<font size="3">' 'With Regards' '</font></p>' INTO w_text.


APPEND w_text TO i_text.
CLEAR w_text.

* w_text = '<br>'.
* APPEND w_text TO i_text.
* CLEAR w_text.

CONCATENATE '<p>' '<font size="3">' 'ALG IT Finance' '</font></p>' INTO w_text.


APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</body>'.
APPEND w_text TO i_text.
CLEAR w_text.

w_text = '</html>'.
APPEND w_text TO i_text.
CLEAR w_text.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
REFRESH : lt_email[].
SELECT * FROM zv_good_recpt INTO TABLE lt_email WHERE eindt IN s_eindt AND ekgrp
IN s_ekgrp.
DELETE lt_email WHERE loekz IS NOT INITIAL.
IF sy-subrc IS NOT INITIAL.
MESSAGE i016(rp) WITH TEXT-001 DISPLAY LIKE 'E'.
IF sy-batch NE abap_true.
LEAVE TO CURRENT TRANSACTION.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISP_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM disp_data .
DATA message TYPE REF TO cx_salv_msg.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = alv
CHANGING
t_table = lt_email ).
CREATE OBJECT lr_handle.

DATA layout_settings TYPE REF TO cl_salv_layout.


DATA layout_key TYPE salv_s_layout_key.
layout_settings = alv->get_layout( ).
layout_key-report = sy-repid.
layout_settings->set_key( layout_key ).
layout_settings->set_save_restriction( if_salv_c_layout=>restrict_none ).

columns = alv->get_columns( ).
columns->set_optimize( ).

DATA functions TYPE REF TO cl_salv_functions_list.


functions = alv->get_functions( ).
functions->set_all( ).

CALL METHOD alv->get_event RECEIVING value = lo_event.


SET HANDLER lr_handle->pushbutton FOR lo_event.

DATA not_found TYPE REF TO cx_salv_not_found.


columns = alv->get_columns( ).

TRY.
column = columns->get_column( 'EBELN' ).
column->set_medium_text( 'PO Number' ).
column->set_long_text( 'PO Number' ).
column->set_output_length( 15 ) .
CATCH cx_salv_not_found INTO not_found.
ENDTRY.

TRY.
column = columns->get_column( 'MBLNR' ).
column->set_visible( abap_false ).
CATCH cx_salv_not_found INTO not_found.
ENDTRY.

TRY.
column = columns->get_column( 'MANDT' ).
column->set_visible( abap_false ).
CATCH cx_salv_not_found INTO not_found.
ENDTRY.
TRY.
column = columns->get_column( 'LOEKZ' ).
column->set_visible( abap_false ).
CATCH cx_salv_not_found INTO not_found.
ENDTRY.

TRY.
column = columns->get_column( 'EKGRP' ).
column->set_visible( abap_false ).
CATCH cx_salv_not_found INTO not_found.
ENDTRY.
TRY.
column = columns->get_column( 'EINDT' ).
column->set_visible( abap_false ).
CATCH cx_salv_not_found INTO not_found.
ENDTRY.

TRY.
column = columns->get_column( 'EBELP' ).
column->set_medium_text( 'PO Item No' ).
column->set_long_text( 'PO Item No' ).
column->set_output_length( 10 ) .
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.

TRY.
column = columns->get_column( 'LIFNR' ).
column->set_medium_text( 'Vendor No' ).
column->set_long_text( 'Vendor No' ).
column->set_output_length( 15 ) .
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.

TRY.
column = columns->get_column( 'NAME1' ).
column->set_medium_text( 'Name' ).
column->set_long_text( 'Name' ).
column->set_output_length( 25 ) .
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.

TRY.
column = columns->get_column( 'TXZ01' ).
column->set_medium_text( 'Short Text' ).
column->set_long_text( 'Short Text' ).
column->set_output_length( 25 ) .
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.

TRY.
column = columns->get_column( 'NETWR' ).
column->set_medium_text( 'Net Value' ).
column->set_long_text( 'Net Value' ).
column->set_output_length( 15 ) .
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.

alv->set_screen_status(
pfstatus = 'ZMENU'
report = 'ZMM_GOOD_RECEIPT_CHECK').

alv->display( ).
CATCH cx_salv_msg INTO message.
ENDTRY.
ENDFORM.

You might also like