0% found this document useful (0 votes)
150 views

MB51 Program

This document defines data types and tables used to extract material movement data from tables mkpf, mseg, and makt based on selection criteria. It then performs additional processing to populate a final table with additional fields for display or sending in an email. Key steps include getting the data, formatting dates, and preparing an ALV grid or mail components depending on a selection screen option.

Uploaded by

Om Prakash Dubey
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)
150 views

MB51 Program

This document defines data types and tables used to extract material movement data from tables mkpf, mseg, and makt based on selection criteria. It then performs additional processing to populate a final table with additional fields for display or sending in an email. Key steps include getting the data, formatting dates, and preparing an ALV grid or mail components depending on a selection screen option.

Uploaded by

Om Prakash Dubey
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/ 14

"" Input ==> Material ::==> (MSEG-MATNR)

"" Plant ::==> (MSEG-WERKS)


"" Movement Type ::==> (MSEG-BWART)
TABLES: mkpf, mseg, makt.

*INITIALIZATION.
TYPES: BEGIN OF ty_mkpf,
mblnr TYPE mkpf-mblnr,
mjahr TYPE mkpf-mjahr,
bldat TYPE mkpf-bldat,
END OF ty_mkpf.

TYPES: BEGIN OF ty_mseg,


mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
matnr TYPE mseg-matnr,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
xblnr_mkpf TYPE mseg-xblnr_mkpf,
dmbtr TYPE mseg-dmbtr,
budat_mkpf TYPE mseg-budat_mkpf,
werks TYPE mseg-werks,
lifnr TYPE mseg-lifnr,
bwart TYPE mseg-bwart,
aufnr TYPE mseg-aufnr,
ebeln TYPE mseg-ebeln,
END OF ty_mseg.

TYPES: BEGIN OF ty_final,


lifnr TYPE mseg-lifnr,
mblnr TYPE mseg-mblnr,
maktx TYPE makt-maktx,
matnr TYPE mseg-matnr,
* mjahr TYPE mseg-mjahr,
* erfmg TYPE mseg-erfmg,
erfmg TYPE char10,
erfme TYPE mseg-erfme,
xblnr_mkpf TYPE mseg-xblnr_mkpf,
* dmbtr TYPE mseg-dmbtr,
dmbtr TYPE char10,
* mjahr TYPE mkpf-mjahr,
bldat TYPE mkpf-bldat,
* mblnr TYPE mkpf-mblnr,
budat_mkpf TYPE mseg-budat_mkpf,
werks TYPE mseg-werks,
* lifnr TYPE mseg-lifnr,
bwart TYPE mseg-bwart,
aufnr TYPE mseg-aufnr,
ebeln TYPE mseg-ebeln,
adrnr TYPE adr6-addrnumber, "" Address Number
email TYPE adr6-smtp_addr, "" Email ID.
END OF ty_final.

TYPES: BEGIN OF ty_ven_email,


lifnr TYPE mseg-lifnr,
adrnr TYPE adr6-addrnumber, "" Address Number
email TYPE adr6-smtp_addr, "" Email ID.
END OF ty_ven_email.
DATA: wa_mkpf TYPE ty_mkpf,
it_mkpf TYPE TABLE OF ty_mkpf,
wa_mseg TYPE ty_mseg,
it_mseg TYPE TABLE OF ty_mseg,
wa_makt TYPE makt,
it_makt TYPE TABLE OF makt,
wa_final TYPE ty_final,
it_final TYPE TABLE OF ty_final,
it_lfa1 TYPE TABLE OF lfa1,
wa_lfa1 TYPE lfa1,
it_adr6 TYPE TABLE OF adr6,
wa_adr6 TYPE adr6,
it_ven_email TYPE TABLE OF ty_ven_email,
wa_ven_email TYPE ty_ven_email.

"" For ALV Defifnition


"------ Data Declaration for the fieldcatalog , layout, cellcolor.
DATA: wa_fcat TYPE slis_fieldcat_alv,
it_fcat TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv.

"" Data Declaration for the Mail Body


DATA:it_receivers TYPE STANDARD TABLE OF somlreci1,
wa_it_receivers LIKE LINE OF it_receivers,
it_packing_list TYPE STANDARD TABLE OF sopcklsti1,
it_attachment TYPE STANDARD TABLE OF solisti1, "" Added on
15.05.2019
it_attachment_header TYPE STANDARD TABLE OF solisti1, "" Added on
15.05.2019
it_attachment_head_body TYPE STANDARD TABLE OF solisti1, "" Added on
15.05.2019
it_attachment_vendor TYPE STANDARD TABLE OF solisti1, "" Added on
15.05.2019
wa_attachment LIKE LINE OF it_attachment, "" Added on 15.05.2019
lv_format TYPE so_obj_tp , "file format "" Added on 15.03.2019
lv_attfilename TYPE so_obj_des, "file name "" Added on 15.03.2019
gd_doc_data TYPE sodocchgi1,
wa_it_packing_list LIKE LINE OF it_packing_list,
psubject(90) TYPE c,
it_message TYPE STANDARD TABLE OF solisti1,
it_message1 TYPE STANDARD TABLE OF solisti1,
wa_it_message LIKE LINE OF it_message,
c1(99) TYPE c,
c2(15) TYPE c,
lv_emp_userid TYPE fitp_user-uname,
num_lines TYPE i,
lv_msg(200),
lv_txt(50),
lv_check TYPE char1,
lv_count(3) TYPE c, "" Counter for the Asset expiry. "" to
check.
lv_email TYPE ad_smtpadr.

"" Data Declaration for the date range check.


DATA: lv_date_c TYPE scdatum, "" Holds the current system date.
lv_date_sun TYPE scdatum, "" Holds the Sunday Date
lv_date_mon TYPE scdatum, "" Holds the Saturday Date.
lv_date_sat TYPE scdatum, "" Holds the Saturday Date.
lv_date_mail TYPE scdatum, "" Holds the Saturday Date.
lv_week TYPE kweek.

DATA: lv_quarter(1) TYPE c. "" Quarter No.

DATA: wa_daterange TYPE rsdsselopt,


it_daterange TYPE TABLE OF rsdsselopt.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.


SELECTION-SCREEN SKIP.
SELECT-OPTIONS: s_matnr FOR mseg-matnr,
s_werks FOR mseg-werks,
s_bwart FOR mseg-bwart.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.


SELECTION-SCREEN SKIP.
PARAMETERS p_rad1 RADIOBUTTON GROUP r1 DEFAULT 'X'. ""Display ALV Only
PARAMETERS p_rad2 RADIOBUTTON GROUP r1. "" Send Mail
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b2.
**********************************************************************
**********************************************************************
"" S T A R T - O F - S E L E C T I O N.
**********************************************************************
**********************************************************************
START-OF-SELECTION.
lv_date_c = sy-datum. "" Current System Date.

CALL FUNCTION 'DATE_GET_WEEK'


EXPORTING
date = lv_date_c
IMPORTING
week = lv_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.

CALL FUNCTION 'WEEK_GET_FIRST_DAY'


EXPORTING
week = lv_week
IMPORTING
date = lv_date_mon
EXCEPTIONS
week_invalid = 1
OTHERS = 2.
lv_date_sun = lv_date_mon - 1. "" Holds the Sunday Date.
lv_date_sat = lv_date_mon + 5. "" Holds the Saturday.
lv_date_mail = lv_date_mon + 6. "" Holds the Sunday.

* IF sy-datum = lv_date_mail.
PERFORM get_data.
PERFORM get_final.
IF p_rad2 = 'X'.
PERFORM mail_header.
PERFORM mail_body.
ENDIF.
DESCRIBE TABLE it_final LINES DATA(lv_mail_count).
IF lv_check = 'X' AND p_rad2 = 'X'. "" Check For the mail radio button
* PERFORM send_mail.

* lv_mail_count = lv_mail_count.
WRITE:/ 'Mail Sent Successfully for ', lv_mail_count, ' Material(s)' COLOR 5.
* ENDIF.
ELSE.
* MESSAGE 'Program run Successfully' TYPE 'S'.
WRITE:/ 'Program run Successfully.'.
WRITE:/ lv_mail_count, ' Material(s) found in this Week' COLOR 5.
ENDIF.

END-OF-SELECTION.
IF p_rad1 = 'X'.
PERFORM prepare_fieldcat.
PERFORM alv_list_display.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
BREAK-POINT.
wa_daterange-sign = 'I'.
wa_daterange-option = 'BT'.
wa_daterange-low = lv_date_sun.
wa_daterange-high = lv_date_sat.
APPEND wa_daterange TO it_daterange.

SELECT
mblnr
mjahr
matnr
erfmg
erfme
xblnr_mkpf
dmbtr
budat_mkpf
werks
lifnr
bwart
aufnr
ebeln
FROM mseg
INTO TABLE it_mseg
WHERE matnr IN s_matnr
AND werks IN s_werks
AND bwart IN s_bwart
AND cpudt_mkpf IN it_daterange. """Doc. Date between Sunday and Saturday.
SORT it_mseg.

IF it_mseg IS NOT INITIAL.

SELECT
mblnr
mjahr
bldat
FROM mkpf
INTO TABLE it_mkpf
FOR ALL ENTRIES IN it_mseg
WHERE mblnr = it_mseg-mblnr
AND mjahr = it_mseg-mjahr.
"" AND bldat BETWEEN lv_date_sun AND lv_date_sat. """Doc Date between Sunday
and Saturday.

SORT it_mkpf.

SELECT *
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_mseg
WHERE spras IN ('EN', 'E')
AND matnr = it_mseg-matnr.
SORT it_makt.

SELECT * FROM lfa1 INTO TABLE it_lfa1 FOR ALL ENTRIES IN it_mseg WHERE lifnr =
it_mseg-lifnr.
IF it_lfa1 IS NOT INITIAL.
SELECT * FROM adr6 INTO TABLE it_adr6 FOR ALL ENTRIES IN it_lfa1 WHERE
addrnumber = it_lfa1-adrnr.
ENDIF.

ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FINAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_final .

LOOP AT it_mseg INTO wa_mseg.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_mseg-matnr
IMPORTING
output = wa_mseg-matnr.

wa_final-matnr = wa_mseg-matnr.
wa_final-erfmg = wa_mseg-erfmg.
wa_final-erfme = wa_mseg-erfme.
wa_final-xblnr_mkpf = wa_mseg-xblnr_mkpf.
wa_final-dmbtr = wa_mseg-dmbtr.
wa_final-budat_mkpf = wa_mseg-budat_mkpf.
wa_final-werks = wa_mseg-werks.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'


EXPORTING
input = wa_mseg-lifnr
IMPORTING
output = wa_mseg-lifnr.
wa_final-lifnr = wa_mseg-lifnr.
wa_final-bwart = wa_mseg-bwart.
wa_final-aufnr = wa_mseg-aufnr.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'


EXPORTING
input = wa_mseg-ebeln
IMPORTING
output = wa_mseg-ebeln.

wa_final-ebeln = wa_mseg-ebeln.

wa_ven_email-lifnr = wa_mseg-lifnr. "" Vendor email details.

READ TABLE it_mkpf INTO wa_mkpf WITH KEY mblnr = wa_mseg-mblnr


mjahr = wa_mseg-mjahr BINARY SEARCH.
IF sy-subrc = 0.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'


EXPORTING
input = wa_mseg-mblnr
IMPORTING
output = wa_mseg-mblnr.

wa_final-mblnr = wa_mkpf-mblnr.
wa_final-bldat = wa_mkpf-bldat.
ENDIF.

READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mseg-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_final-maktx = wa_makt-maktx.
ENDIF.

DATA: lv_lifnr TYPE elifn.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_mseg-lifnr
IMPORTING
output = lv_lifnr.

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = lv_lifnr.


IF sy-subrc = 0.
READ TABLE it_adr6 INTO wa_adr6 WITH KEY addrnumber = wa_lfa1-adrnr.
IF sy-subrc = 0.

wa_final-adrnr = wa_lfa1-adrnr.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'


EXPORTING
input = wa_final-adrnr
IMPORTING
output = wa_final-adrnr.

wa_final-email = wa_adr6-smtp_addr.

wa_ven_email-adrnr = wa_lfa1-adrnr.
wa_ven_email-email = wa_adr6-smtp_addr.
ENDIF.
ENDIF.

APPEND wa_final TO it_final.


APPEND wa_ven_email TO it_ven_email.
CLEAR: wa_makt, wa_mkpf, wa_mseg, wa_final, wa_ven_email, lv_lifnr.
ENDLOOP.
* WRITE: 'Program run success.'.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form PREPARE_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM prepare_fieldcat .

CLEAR wa_fcat.
REFRESH it_fcat.

IF it_final IS NOT INITIAL.


DATA: lv_col TYPE i VALUE 0.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'LIFNR'.
wa_fcat-seltext_m = 'Vendor'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MAKTX'.
wa_fcat-seltext_m = 'Material Description'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERFMG'.
wa_fcat-seltext_m = 'Quantity'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERFME'.
wa_fcat-seltext_m = 'Unit of Entry'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'XBLNR_MKPF'.
wa_fcat-seltext_m = 'Refrence'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'BMBTR'.
wa_fcat-seltext_m = 'Currency'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'BLDAT'.
wa_fcat-seltext_m = 'Doc. Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MBLNR'.
wa_fcat-seltext_m = 'Material Doc.'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'BUDAT_MKPF'.
wa_fcat-seltext_m = 'Posting Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'Werks'.
wa_fcat-seltext_m = 'Plant'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

* lv_col = 1 + lv_col.
* wa_fcat-col_pos = lv_col.
* wa_fcat-fieldname = 'LIFNR'.
* wa_fcat-seltext_m = 'Vendor'.
* APPEND wa_fcat TO it_fcat.
* CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'BWART'.
wa_fcat-seltext_m = 'Movement Type'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'AUFNR'.
wa_fcat-seltext_m = 'Order'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'EBELN'.
wa_fcat-seltext_m = 'PO'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ADRNR'.
wa_fcat-seltext_m = 'Address Number'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'EMAIL'.
wa_fcat-seltext_m = 'Email ID'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDIF.

wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_LIST_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_list_display .

IF it_final IS NOT INITIAL.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_callback_user_command = 'USER_COMMAND' "" Added By Sheoshankar on
21.12.2018
is_layout = wa_layout
it_fieldcat = it_fcat
i_save = 'X' "" Added to check the save .
* it_special_groups = lt_fieldgroups_tab
TABLES
t_outtab = it_final.
ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM mail_header .

CLEAR wa_it_message.
c1 = 'Dear Sir / Madam'.
CONCATENATE c1 ',' INTO wa_it_message-line. " SEPARATED BY space.
APPEND wa_it_message TO it_message.

wa_it_message-line = ''.
APPEND wa_it_message TO it_message.

lv_msg = 'Please find attachment for the Material Document'.


wa_it_message-line = lv_msg.
APPEND wa_it_message TO it_message.
CLEAR: wa_it_message, lv_msg.

wa_it_message-line = ''.
APPEND wa_it_message TO it_message.

wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = 'Thanks and Regards,'.
APPEND wa_it_message TO it_message.
wa_it_message-line = 'HITPA of India Pvt Ltd'.
APPEND wa_it_message TO it_message.
wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = ''.
APPEND wa_it_message TO it_message.
wa_it_message-line = '*** Note:- This is a system generated mail, please do not
reply.'.
APPEND wa_it_message TO it_message.

CONCATENATE 'Se.No'
'Material'
'Material Desc.'
'Quantity'
'Unit of Entry'
'Reference'
'Loc. Currency Amount'
'Doc. Date'
'Material Document'
'Posting Date'
'Plant'
'Vendor'
'Movement Type'
'Order'
'PO No.'
INTO wa_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
* CONCATENATE cl_abap_char_utilities=>cr_lf wa_attachment INTO wa_attachment.
APPEND wa_attachment TO it_attachment_header. "" Added to the Header in
Attachment file.
CLEAR: wa_attachment.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_BODY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM mail_body .
DATA: lv_count_new TYPE i VALUE 5.
SORT it_final BY lifnr ASCENDING.
SORT it_ven_email BY lifnr ASCENDING.
DELETE ADJACENT DUPLICATES FROM it_ven_email COMPARING lifnr.
LOOP AT it_final INTO wa_final.
BREAK-POINT.
lv_count = lv_count + 1.

ON CHANGE OF wa_final-lifnr. "" Logic to send the mail to all the Vendor .
REFRESH : it_attachment_vendor.
* APPEND LINES OF it_attachment_header TO it_attachment_vendor.
it_attachment_vendor = it_attachment.
REFRESH it_attachment.
IF lv_email NE ''.
PERFORM mail_footer.
PERFORM send_mail.
ENDIF.
ENDON.

CONCATENATE
lv_count
wa_final-matnr
wa_final-maktx
wa_final-erfmg
wa_final-erfme
wa_final-xblnr_mkpf
wa_final-dmbtr
wa_final-bldat
wa_final-mblnr
wa_final-budat_mkpf
wa_final-werks
wa_final-lifnr
wa_final-bwart
wa_final-aufnr
wa_final-ebeln
INTO wa_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>cr_lf wa_attachment INTO wa_attachment.
APPEND wa_attachment TO it_attachment.
CLEAR: wa_attachment.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = wa_final-adrnr
IMPORTING
output = wa_final-adrnr.

CLEAR: lv_email.
READ TABLE it_ven_email INTO wa_ven_email WITH KEY adrnr = wa_final-adrnr
lifnr = wa_final-lifnr
email = wa_final-email.
IF sy-subrc = 0 AND wa_ven_email-email NE ''.
lv_email = wa_ven_email-email.
ELSE.
lv_email = 'dummy@gmail.com'.
ENDIF.
lv_check = 'X'.

AT LAST. "" Logic to send mail with of the last vendor.


REFRESH : it_attachment_vendor.
* APPEND LINES OF it_attachment_header TO it_attachment_vendor.
it_attachment_vendor = it_attachment.
REFRESH it_attachment.
IF lv_email NE ''.
PERFORM mail_footer.
PERFORM send_mail.
ENDIF.
ENDAT.

ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_FOOTER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM mail_footer .

*** wa_it_message-line = ''.


*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = ''.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = ''.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = ''.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = 'Thanks and Regards,'.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = 'HITPA of India Pvt Ltd'.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = ''.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = ''.
*** APPEND wa_it_message TO it_message.
*** wa_it_message-line = '*** Note:- This is a system generated mail, please do
not reply.'.
*** APPEND wa_it_message TO it_message.
*&-- Assign the Email id and User id to Whom you want to Send -------------&
FREE wa_it_receivers.
REFRESH: it_receivers.
* LOOP AT it_email INTO wa_email.
* wa_it_receivers-receiver = 'sheoshankar.kumar@wipro.com'. "&---- Assign Email
id
wa_it_receivers-receiver = lv_email. "&---- Assign Email id
* wa_it_receivers-copy = 'sheoshankar.kumar@wipro.com'. "&---- CC Email id.
wa_it_receivers-rec_type = 'U'. "&---- Send to External
Email id
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
* ENDLOOP.
FREE wa_it_receivers.

"&--- Read the Number of lines in the Internal Table


DESCRIBE TABLE it_receivers LINES num_lines.
"&--- Check the Sender Email id or SAP User id is got or not.
IF num_lines IS NOT INITIAL.
*&---------------------------------------------------------------------
* Add thetext to mail text table
*&----------------------------------------------------------------------
*&-- Subject of the mail -------------&*

psubject = 'Material Document Report'.

CLEAR wa_it_message.
ENDIF.

**********& Send EMAIL MESSAGE &*********************************


lv_format = 'XLS'.
lv_attfilename = 'Material_Docu'.

gd_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
*Describe the body of the message
CLEAR wa_it_packing_list.
REFRESH it_packing_list.
wa_it_packing_list-transf_bin = space.
wa_it_packing_list-head_start = 1.
wa_it_packing_list-head_num = 0.
wa_it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES wa_it_packing_list-body_num.
wa_it_packing_list-doc_type = 'RAW'.
APPEND wa_it_packing_list TO it_packing_list.

**Describe the attachment info


wa_it_packing_list-transf_bin = 'X'.
wa_it_packing_list-head_start = 1.
wa_it_packing_list-head_num = 1.
wa_it_packing_list-body_start = 1.

"" Added By Sheo on 24.05.2019


REFRESH: it_attachment_head_body.
it_attachment_head_body[] = it_attachment_header[].
APPEND LINES OF it_attachment_vendor TO it_attachment_head_body.

DESCRIBE TABLE it_attachment_head_body LINES wa_it_packing_list-body_num.


wa_it_packing_list-doc_type = lv_format.
wa_it_packing_list-obj_name = lv_attfilename.
wa_it_packing_list-obj_descr = lv_attfilename.
wa_it_packing_list-doc_size = wa_it_packing_list-body_num * 255.
APPEND wa_it_packing_list TO it_packing_list.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send_mail .

*&------ Call the Function Module to send the message to External and SAP Inbox
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
* contents_bin = it_attachment_vendor "" Added on 15.05.2019
contents_bin = it_attachment_head_body "" Added on 15.05.2019
contents_txt = it_message
receivers = it_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.
ELSEIF sy-subrc = 0.
MESSAGE 'Mail Sent' TYPE 'S'.
ENDIF.

ENDFORM.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy