ZMIGO - Email Send With Attachment
ZMIGO - Email Send With Attachment
ZMIGO - Email Send With Attachment
REPORT ZMIGO.
TABLES: lfa1, mseg, adr6, mkpf, ekko, ekpo, zcont_dept_data, anla, ankt.
PARAMETERS : p_attach TYPE char200 OBLIGATORY, " Select the Folder on the
Desktop from F4 help
p_subj TYPE char50 NO-DISPLAY. " Subject of the Email
SELECT
dmbtr
a~menge
a~meins
a~mblnr
werks
a~waers
a~ebeln
ebelp
lfbnr
a~anln1
sgtxt
b~xblnr
c~zzdeptnr
c~aedat
* ebelp
d~dept_name
e~anlkl
e~txt50
f~txk50
FROM mseg
AS a INNER JOIN mkpf AS b
ON a~mblnr = b~mblnr
INNER JOIN ekko AS c
ON a~ebeln = c~ebeln
INNER JOIN zcont_dept_data AS d
ON c~zzdeptnr = d~zdeptnr
INNER JOIN anla AS e
ON a~anln1 = e~anln1
INNER JOIN ankt AS f
ON e~anlkl = f~anlkl
INTO CORRESPONDING FIELDS OF TABLE i_emp_data "UP TO 500 ROWS
WHERE a~mblnr IN grn
if sy-subrc NE 0.
** Begin of modification by Bablu on 22.08.2022 after version comparision b/w
SND and QA.
*** Old Code
* MESSAGE 'Asset Code/s is/are not insurable through this process...' TYPE 'E'.
** New Code
message 'Sorry, Asset Code/s is/are not insurable through SAP.' type 'E'.
** End of modification by Bablu on 22.08.2022 after version comparision b/w SND
and QA.
endif.
**added todat 21 july, 21 at 2.39 pm
** Preare the fieldcat for output structure.
APPEND INITIAL LINE TO i_fldcat ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'ANLN1'. "Fieldname
<fs_fieldcat>-outputlen = 10. "Output length
<fs_fieldcat>-dd_outlen = 10. "Input length
<fs_fieldcat>-reptext = 'Asset Code'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
*<fs_fieldcat>-datatype = 'NUMC'. "Numbering zero removals
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-
msgv3 sy-msgv4.
ELSE.
p_attach = lv_string.
ENDIF.
START-OF-SELECTION.
** CHECK IF THE FOLDER PATH IS INITIAL, IF INITIAL LEAVE THE PROGRAM, ELSE COPY THE
SUBJECT. ---> IT ALL DEPENDS ON HOW YOU VALIDATE.
IF p_attach IS INITIAL.
LEAVE LIST-PROCESSING.
ELSE.
l_subject = p_subj.
ENDIF.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-
msgv3 sy-msgv4.
ENDIF.
** get the version from Abstract Super Class for All Transformations
CLEAR: l_version.
l_version = cl_salv_bs_a_xml_base=>get_version( ).
* You can set a file name with a freely selectable file name extension separately
from the document description. For this, use the header table
* of the document or the attachment with the key word '&SO_FILENAME='.
CONCATENATE '&SO_FILENAME=' l_filename INTO l_text_line.
APPEND l_text_line TO i_att_head.
** * ATTACH THE FILE, THE ATTACHMENT TYPE SHOULD BE BIN TO ACCEPT ANY KIND OF
ATTACHMENT, INCLUDING VIDEOS, AUDIO FILES ETC...
lv_attach_name = file_table.
CALL METHOD l_document->add_attachment "#EC CI_IMUD_NESTED "ADD ON
23-06-2022 BY ZEBA ATC CORRECTED
EXPORTING
i_attachment_type = 'BIN'
i_attachment_subject = lv_attach_name
i_att_content_hex = t_mailhex.
* * CREATING PERSISTENT OBJECT WILL ALLOW YOU TO SET THE DOCUMENT IN THE MAIL
w_document = cl_bcs=>create_persistent( ).
CALL METHOD w_document->set_document( l_document ). "#EC
CI_IMUD_NESTED "ADD ON 23-06-2022 BY ZEBA ATC CORRECTED
gr_recipient1 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient1
i_express = 'X'
i_copy = 'X'.
gr_recipient2 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient2
i_express = 'X'
i_copy = 'X'.
gr_recipient3 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient3
i_express = 'X'
i_copy = 'X'.
gr_recipient4 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient4
i_express = 'X'
i_copy = 'X'.
gr_recipient5 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient5
i_express = 'X'
i_copy = 'X'.
gr_recipient6 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient6
i_express = 'X'
i_copy = 'X'.
gr_recipient7 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient7
i_express = 'X'
i_copy = 'X'.
gr_recipient8 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient8
i_express = 'X'
i_copy = 'X'.
gr_recipient9 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient9
i_express = 'X'
i_copy = 'X'.
gr_recipient10 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient10
i_express = 'X'
i_copy = 'X'.
gr_recipient11 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient11
i_express = 'X'
i_copy = 'X'.
gr_recipient16 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient16
i_express = 'X'
i_copy = 'X'.
gr_recipient17 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient17
i_express = 'X'
i_copy = 'X'.
gr_recipient19 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient19
i_express = 'X'
i_copy = 'X'.
* gr_recipient12 =
cl_cam_address_bcs=>create_internet_address( '[email protected]'
)."(-)
gr_recipient12 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)
Added by Bablu on 29.09.2022
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient12
i_express = 'X'
i_copy = 'X'.
* gr_recipient13 =
cl_cam_address_bcs=>create_internet_address( '[email protected]'
)."(-)
gr_recipient13 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )
."(+) Added by Bablu on 29.09.2022
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient13
i_express = 'X'
i_copy = 'X'.
* gr_recipient14 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(-)
gr_recipient14 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)
Added by Bablu on 29.09.2022
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient14
i_express = 'X'.
* gr_recipient15 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(-)
gr_recipient15 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)
Added by Bablu on 29.09.2022
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient15
i_express = 'X'.
gr_recipient18 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+) Added by
Bablu on 29.09.2022
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient15
i_express = 'X'.
endif.
* gr_recipient2 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
* "Add recipient to send request
* CALL METHOD w_document->add_recipient
* EXPORTING
* i_recipient = gr_recipient2
* i_express = 'X'
* i_copy = 'X'.
gr_recipient3 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient3
i_express = 'X'
i_copy = 'X'.
gr_recipient4 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient4
i_express = 'X'
i_copy = 'X'.
gr_recipient5 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient5
i_express = 'X'
i_copy = 'X'.
gr_recipient6 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient6
i_express = 'X'
i_copy = 'X'.
gr_recipient7 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient7
i_express = 'X'
i_copy = 'X'.
gr_recipient8 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient8
i_express = 'X'
i_copy = 'X'.
gr_recipient9 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient9
i_express = 'X'
i_copy = 'X'.
gr_recipient10 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient10
i_express = 'X'
i_copy = 'X'.
* gr_recipient11 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
* "Add recipient to send request
* CALL METHOD w_document->add_recipient
* EXPORTING
* i_recipient = gr_recipient11
* i_express = 'X'
* i_copy = 'X'.
gr_recipient16 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient16
i_express = 'X'
i_copy = 'X'.
gr_recipient17 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient17
i_express = 'X'
i_copy = 'X'.
gr_recipient19 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient19
i_express = 'X'
i_copy = 'X'.
* gr_recipient12 =
cl_cam_address_bcs=>create_internet_address( '[email protected]'
)."(-)
gr_recipient12 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)Chan
ged the emial ID as per business requirements
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient12
i_express = 'X'
i_copy = 'X'.
* gr_recipient13 =
cl_cam_address_bcs=>create_internet_address( '[email protected]'
)."(-)Changed the emial ID as per business requirements
gr_recipient13 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )
."(+)Changed the emial ID as per business requirements
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient13
i_express = 'X'
i_copy = 'X'.
* gr_recipient14 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(-)Ch
anged the emial ID as per business requirements
gr_recipient14 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)
Changed the emial ID as per business requirements
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient14
i_express = 'X'.
* gr_recipient15 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(-)Chan
ged the emial ID as per business requirements
gr_recipient15 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+)Ch
anged the emial ID as per business requirements
"Add recipient to send request
call method w_document->add_recipient
exporting
i_recipient = gr_recipient15
i_express = 'X'.
gr_recipient11 =
cl_cam_address_bcs=>create_internet_address( '[email protected]' )."(+) Added
email id as per business requirement.
"Add recipient to send request
CALL METHOD w_document->add_recipient
EXPORTING
i_recipient = gr_recipient11
i_express = 'X'
i_copy = 'X'.
** YOU CAN VERIFY THE STATUS IN THE LIST, YOU CAN ALSO SUBMIT THIS AS A BACKGROUND
JOB.
IF l_result = 'X'.
WRITE :/ , 1(9) lv_count, 10(55) file_table-pathname.
WRITE : 56(1) '-', 58(20) 'mail sent for insurance'(003).
COMMIT WORK.
ELSE.
WRITE :/ , 1(9) lv_count, 10(55) file_table-pathname.
WRITE : 56(1) '-', 58(30) 'Error in sending mail'(004).
ROLLBACK WORK.
ENDIF.
REFRESH it_contents[].
ENDLOOP.