-
Notifications
You must be signed in to change notification settings - Fork 2
/
example rotine send_errors.txt
127 lines (99 loc) · 4.04 KB
/
example rotine send_errors.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
*&---------------------------------------------------------------------*
*& Form SEND_ERRORS
*&---------------------------------------------------------------------*
FORM send_errors
USING
it_log TYPE gtyp_tt_log.
SELECT grp,
bname
FROM yfi_t_vnrq_mail
INTO TABLE @DATA(lt_vnrq_mail).
SORT lt_vnrq_mail BY grp ASCENDING.
IF sy-subrc <> 0.
RETURN.
ENDIF.
DATA:
lv_message_subject TYPE so_obj_des,
lt_message_body TYPE soli_tab,
lt_recipient TYPE rmps_recipient_bcs,
lt_file TYPE yyt_file,
lv_ref TYPE REF TO data,
lt_xml TYPE solix_tab,
lv_size TYPE i,
lt_ret TYPE TABLE OF bapiret2,
lt_addsmtp TYPE TABLE OF bapiadsmtp,
lt_log TYPE gtyp_tt_log.
lv_message_subject = TEXT-s01.
lt_message_body = VALUE #( ( line = TEXT-b01 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b02 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b03 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b04 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b05 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b06 )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b07 )
( line = cl_abap_char_utilities=>newline )
( line = cl_abap_char_utilities=>newline )
( line = TEXT-b99 && ` ` && sy-sysid && sy-mandt ) ).
LOOP AT lt_vnrq_mail ASSIGNING FIELD-SYMBOL(<fs_vnrq_mail>).
AT NEW grp.
CLEAR lt_log.
lt_log = VALUE #( FOR wa IN it_log WHERE ( grp = <fs_vnrq_mail>-grp ) ( wa ) ).
ENDAT.
CHECK lt_log[] IS NOT INITIAL.
CLEAR:
lt_recipient,
lt_file,
lv_ref,
lt_xml,
lv_size,
lt_ret,
lt_addsmtp.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
username = <fs_vnrq_mail>-bname " User Name
TABLES
return = lt_ret " Return Structure
addsmtp = lt_addsmtp. " E-Mail Addresses BAPI Structure
CHECK lt_addsmtp[] IS NOT INITIAL.
DATA(lv_email) = lt_addsmtp[ 1 ]-e_mail.
* Send email
TRY.
DATA(lo_recipient) =
cl_cam_address_bcs=>create_internet_address( lv_email ).
APPEND lo_recipient TO lt_recipient.
CATCH cx_address_bcs.
ENDTRY.
* Attach file
lv_ref = REF #( lt_log ).
y_send_mail=>tab_to_excel_xml(
EXPORTING
ir_data = lv_ref " Any interna table
CHANGING
cv_size = lv_size " Size excel xml
ct_xml = lt_xml ). " Excel xml file
* Build file attributes
lt_file = VALUE #( ( attachment_type = 'BIN'
attachment_subject = 'Vendor_Request_Error_Log_' &&
sy-datum+6(2) &&
sy-datum+4(2) &&
sy-datum(4) &&
'_' &&
sy-uzeit(4) &&
'.xlsx'
t_file = lt_xml
attachment_size = lv_size ) ).
CALL METHOD y_send_mail=>send_mail
EXPORTING
iv_sender_user = sy-uname
iv_message_subject = lv_message_subject
it_message_body = lt_message_body
it_recipient = lt_recipient
it_file = lt_file.
ENDLOOP.
ENDFORM.