2007 Feb 19 11:21 AM
Hello gurus,
I want to write a prg which will read the data .. create an excel file and
attach this excel file and send a mail to [email protected] or [email protected]
could anybody pls send me the entire source code pls.
Don;t worry full points guaranteed ...
Rgds,
Aryan
Message was edited by:
Aryan T
Hello gurus,
I want to write a prg which will read the data .. create an excel file and
attach this excel file and send a mail to [email protected] or [email protected]
could anybody pls send me the entire source code pls.
Don;t worry full points guaranteed ...
Rgds,
Aryan
Message was edited by:
Aryan T
2007 Feb 19 11:28 AM
Also, do we need to configure something before sending the mail
2007 Feb 19 11:28 AM
Hi,
REPORT ZV_REPT_CUST_LEDGER_MAIL_R2
line-size 160 line-count 65(6) no standard page heading.
************************************************************************
Report : Sending Customer Ledger Through Mail
************************************************************************
tables: kna1,
knkk,
knvv,
bkpf,
bseg,
bsid,
bsad,
vbrp,
vbrk,
konv,
s001,
t247.
Added for E-Mail
include zincusmail.
End.
selection-screen: begin of block head with frame title text-t01.
select-options: kunnr for kna1-kunnr obligatory.
parameter : spbup like s001-spbup obligatory,
gjahr like bsid-gjahr obligatory.
select-options: kdgrp for knvv-kdgrp NO INTERVALS no-extension.
selection-screen end of block head.
***Code Added by Ranga Raju Manthena
selection-screen: begin of block a with frame.
selection-screen begin of line.
selection-screen comment (32) c001.
parameter chk1 as checkbox.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment (32) c002.
parameter chk2 as checkbox.
selection-screen end of line.
selection-screen end of block a.
***End of Edition
data : begin of otab occurs 100, " For Open Items
kunnr like bsid-kunnr,
budat like bsid-budat,
belnr like bsid-belnr,
blart like bsid-blart,
bldat like bsid-bldat,
xblnr like bsid-xblnr,
shkzg like bsid-shkzg,
wrbtr like bsid-wrbtr,
fkimg like vbrp-fkimg,
fkart like vbrk-fkart,
zvonr like vbrk-zuonr,
zuonr like bseg-zuonr,
kbetr like konv-kbetr,
matnr like vbrp-matnr,
bstat like bkpf-bstat,
knuma like kona-knuma, " Rebate Agreement No
botext like kona-botext, " Agreement Description
sgtxt like bseg-sgtxt, " Credit-Debit note Description
datab like kona-datab,
datbi like kona-datbi,
end of otab.
*Modified on 24.04.2004 By Srinivas Yerra.
*data ttab like standard table of otab with header line.
data : begin of ttab occurs 100, " For Open Items
kunnr like bsid-kunnr,
budat like bsid-budat,
belnr like bsid-belnr,
blart like bsid-blart,
bldat like bsid-bldat,
xblnr like bsid-xblnr,
shkzg like bsid-shkzg,
wrbtr like bsid-wrbtr,
fkimg like vbrp-fkimg,
fkart like vbrk-fkart,
zvonr like vbrk-zuonr,
zuonr like bseg-zuonr,
kbetr like konv-kbetr,
matnr like vbrp-matnr,
bstat like bkpf-bstat,
knuma like kona-knuma, " Rebate Agreement No
botext like kona-botext, " Agreement Description
sgtxt like bseg-sgtxt, " Credit-Debit note Description
datab like kona-datab,
datbi like kona-datbi,
end of ttab.
*End Of Modification.
data : begin of ctab occurs 100, " For Closed Items
kunnr like bsad-kunnr,
budat like bsad-budat,
belnr like bsad-belnr,
blart like bsad-blart,
bldat like bsad-bldat,
xblnr like bsid-xblnr,
shkzg like bsad-shkzg,
wrbtr like bsad-wrbtr,
fkimg like vbrp-fkimg,
fkart like vbrk-fkart,
zvonr like vbrk-zuonr,
zuonr like bseg-zuonr,
kbetr like konv-kbetr,
end of ctab.
data: begin of itab occurs 50,
kunnr like kna1-kunnr, " Customer Code
name1 like kna1-name1, " Customer Name
ssobl like knkk-ssobl, " Security Deposit
klimk like knkk-klimk, " Credit Limit
opbal like bsid-wrbtr, " Opening Balance
clbal like bsid-wrbtr, " Closing Balance
Added for E-Mail
smtp like adr6-smtp_addr, " E-Mail Address
End
end of itab.
data: begin of stab occurs 50,
kunnr like kna1-kunnr, " Customer Code
shkzg like bsid-shkzg, " S/H Flag
sdamt like bsid-wrbtr, " Security Deposit
end of stab.
data: begin of atab occurs 50,
kunnr like kna1-kunnr, " Customer Code
belnr like bsid-belnr, " Document No
wrbtr like bsid-wrbtr, " Security Deposit
end of atab.
data: dd type i,
ddd(2),
flg type i,
elg type i,
glg type i,
pgno type i,
recs type i,
month type i,
jump like sy-linct,
ddate like sy-datum,
sdate like sy-datum,
edate like sy-datum,
rdate like sy-datum,
code like kna1-kunnr,
name like kna1-name1,
narr(50),
qanty like vbrp-fkimg,
ssobl like knkk-ssobl,
klimk like knkk-klimk,
csamt like bsid-wrbtr,
dramt like bsid-wrbtr,
cramt like bsid-wrbtr,
ttamt like bsid-wrbtr,
opbal like bsid-wrbtr,
dpbal like bsid-wrbtr,
clbal like bsid-wrbtr,
augdt like bsad-augdt,
aobal like bsid-wrbtr,
asbal like bsid-wrbtr,
ahbal like bsid-wrbtr,
ahbal_h like bsid-wrbtr,
ahbal_s like bsid-wrbtr,
aobal_h like bsid-wrbtr,
aobal_s like bsid-wrbtr,
lines like sy-linct,
v_matnr(2),
v_fmonth(2),
v_tmonth(2),
fmondes(10),
tmondes(10),
t_cmm type i,
t_cyy type i,
t_fyy type i,
t_dyy type i,
year(4),
mon(2),
date(2),
year1(4),
mon1(2),
date1(2),
br(2),
qty(10),
kbetr(06),
tqty(10).
data : v_gjahr like bsid-gjahr,
a_belnr like bsid-belnr,
a_wrbtr like bsid-wrbtr.
initialization.
c001 = 'For Security Deposit Information'.
c002 = 'For Quarterly Report'.
AT SELECTION-SCREEN ON spbup.
if not spbup is initial.
IF spbup+0(4) < '2004'.
MESSAGE I001(Zmessage).
MESSAGE E001(Zmessage).
ENDIF.
endif.
AT SELECTION-SCREEN ON gjahr.
if not gjahr is initial.
IF gjahr+0(4) < '2004'.
MESSAGE I001(Zmessage).
MESSAGE E001(Zmessage).
ENDIF.
endif.
at selection-screen.
t_cmm = spbup+4(2).
t_cyy = spbup(4).
t_fyy = gjahr.
t_dyy = t_cyy - 1.
if t_cmm between 04 and 12.
t_cmm = t_cmm - 3.
elseif t_cmm between 01 and 03.
t_cmm = t_cmm + 9.
endif.
if t_cmm between 01 and 09.
if t_cyy <> t_fyy.
message e008(zt).
endif.
elseif t_cmm between 10 and 12.
if t_cyy > t_fyy and t_dyy = t_fyy.
else.
message e008(zt).
endif.
endif.
top-of-page.
perform header. " Procedure to Print Header
if flg = 1.
perform d_header.
flg = 0.
endif.
end-of-page.
write: /0(157) sy-uline.
pgno = pgno + 1.
write: /110 'Page No : ', pgno.
start-of-selection.
perform get-date.
perform get-cust.
perform get-bsid.
perform get-samt.
perform get-bsad.
perform get-vbrk.
perform get-vbfa.
perform get-bkpf.
perform get-bseg.
perform get-write.
&----
*& Form GET-CUST
&----
text
----
form get-cust.
Deleted for E-Mail
select kna1~kunnr
kna1~name1
knkk~klimk
adr6~smtp_addr
into (itab-kunnr,
itab-name1,
itab-klimk,
itab-smtp)
from kna1 join knkk
on kna1kunnr = knkkkunnr
join knvv
on kna1kunnr = knvvkunnr
join adr6
on kna1adrnr = adr6addrnumber
where kna1~kunnr in kunnr and
knvv~kdgrp in kdgrp.
if sy-subrc eq 0.
append itab.
clear itab.
endif.
endselect.
*DELETE ADJACENT DUPLICATES FROM ITAB.
End
Added for E-Mail
select kna1~kunnr
kna1~name1
knkk~klimk
adr6~smtp_addr
into (itab-kunnr,
itab-name1,
itab-klimk,
itab-smtp)
from kna1 join knkk
on kna1kunnr = knkkkunnr
join knvv
on kna1kunnr = knvvkunnr
join adr6
on kna1adrnr = adr6addrnumber
where kna1~kunnr in kunnr and
knvv~kdgrp in kdgrp.
if sy-subrc eq 0.
append itab.
clear itab.
endif.
endselect.
DELETE ADJACENT DUPLICATES FROM ITAB.
delete itab where smtp is initial.
it_inad[] = itab[].
End
endform. " GET-CUST
&----
*& Form GET-BSID
&----
text
----
form get-bsid.
select kunnr
blart
bldat
budat
belnr
xblnr
shkzg
wrbtr
into (otab-kunnr,
otab-blart,
otab-bldat,
otab-budat,
otab-belnr,
otab-xblnr,
otab-shkzg,
otab-wrbtr)
from bsid
where ( umskz = ' ' or umskz = 'A' or umskz = 'E' ) and
kunnr in kunnr and
budat >= sdate and budat <= edate.
if sy-subrc eq 0.
collect otab.
clear otab.
endif.
endselect.
endform. " GET-BSID
&----
*& Form GET-BSAD
&----
text
----
--> p1 text
<-- p2 text
----
form get-bsad.
select kunnr
blart
bldat
budat
belnr
xblnr
shkzg
wrbtr
into (ctab-kunnr,
ctab-blart,
ctab-bldat,
ctab-budat,
ctab-belnr,
ctab-xblnr,
ctab-shkzg,
ctab-wrbtr)
from bsad
where ( umskz = ' ' or umskz = 'A' or umskz = 'E' )
and
kunnr in kunnr and
budat >= sdate and budat <= edate
order by kunnr.
if sy-subrc eq 0.
collect ctab.
clear ctab.
endif.
endselect.
insert lines of ctab from 1 into otab index 1.
This code DELETE all AB documents which Debit and Credit
Amounts are Equal.
*Modification on 05.05.2004 By Srinivas Yerra.
loop at otab.
atab-kunnr = otab-kunnr.
atab-belnr = otab-belnr.
if otab-shkzg = 'H'.
atab-wrbtr = - otab-wrbtr.
otab-wrbtr = otab-wrbtr * -1.
else.
atab-wrbtr = otab-wrbtr.
endif.
collect atab.
modify otab.
endloop.
loop at atab where wrbtr = 0.
delete otab where kunnr = atab-kunnr
and belnr = atab-belnr.
endloop.
endform. " GET-BSAD
&----
*& Form HEADER
&----
text
----
--> p1 text
<-- p2 text
----
form header.
write: /78 'Grasim Industries Ltd'.
write: /76 'Cement Marketing Division'.
skip 1.
write: /80 'Customer Ledger'.
write: /80 '----
'.
write:0(157) sy-uline.
endform. " HEADER
&----
*& Form GET-DATE
&----
text
----
--> p1 text
<-- p2 text
----
form get-date.
concatenate spbup0(4) spbup4(2) '01' into sdate.
concatenate spbup0(4) spbup4(2) '01' into ddate.
concatenate spbup0(4) spbup4(2) '01' into rdate.
if chk2 = 'X'.
if spbup4(2) >= 04 and spbup4(2) <= 06.
concatenate spbup+0(4) '04' '01' into sdate.
elseif spbup4(2) >= 07 and spbup4(2) <= 09.
concatenate spbup+0(4) '07' '01' into sdate.
elseif spbup4(2) >= 10 and spbup4(2) <= 12.
concatenate spbup+0(4) '10' '01' into sdate.
elseif spbup4(2) >= 01 and spbup4(2) <= 03.
concatenate spbup+0(4) '01' '01' into sdate.
endif.
endif.
call function 'RE_LAST_DAY_OF_MONTH'
exporting
i_datum = ddate
importing
e_tt = dd
exceptions
others = 1.
ddd = dd.
concatenate ddate+0(6) ddd into edate.
rdate = sdate - 1.
call function 'RE_LAST_DAY_OF_MONTH'
exporting
i_datum = rdate
importing
e_tt = dd
exceptions
others = 1.
ddd = dd.
concatenate rdate+0(6) ddd into rdate.
endform. " GET-DATE
&----
*& Form GET-WRITE
&----
text
----
form get-write.
month = sdate+4(2).
perform update_otab.
perform v_date.
perform doc_data using fmondes t_cyy.
sort otab by kunnr budat belnr.
sort ctab by kunnr budat belnr.
loop at itab.
code = itab-kunnr.
name = itab-name1.
ssobl = itab-ssobl.
klimk = itab-klimk.
at new kunnr.
pgno = 0. dramt = 0. cramt = 0.
ttamt = 0. opbal = 0. clbal = 0. dpbal = 0.
call function 'Z_GET_OPENING_BALANCE1'
exporting
kunnr = itab-kunnr
gjahr = gjahr
month = month
importing
opbal = opbal
exceptions
others = 1.
perform v_date.
perform get-abbal.
*Modified on 17.04.2004 By srinivas yerra.
opbal = opbal + aobal.
*end of Modification.
move t_cyy to v_gjahr.
****Deleting customer if opening balance is zero and no transactions
exists
if opbal = 0.
read table otab with key kunnr = itab-kunnr.
if sy-subrc <> 0.
continue.
endif.
endif.
****End of modification
Added for E-Mail
perform hide_write.
End
if chk1 = 'X'.
write: /01 sy-vline,
02 'Customer Code :', itab-kunnr,
90 'Run Date :', sy-datum,
157 sy-vline.
write: /01 sy-vline,
02 'Name :', name,
90 'Run Time :', sy-uzeit,
157 sy-vline.
write: /01 sy-vline,
02 'Security Deposit : ', ssobl left-justified,
90 'Customer Ledger : From', fmondes, v_gjahr,
157 sy-vline.
write: /01 sy-vline,
"02 'Credit Limit : ', klimk left-justified,
109 'To ', tmondes, v_gjahr,
157 sy-vline.
else.
write: /01 sy-vline,
02 'Customer Code :', itab-kunnr,
90 'Run Date :', sy-datum,
157 sy-vline.
write: /01 sy-vline,
02 'Name :', name,
90 'Run Time :', sy-uzeit,
157 sy-vline.
write: /01 sy-vline,
"02 'Security Deposit : ', ssobl left-justified,
02 'Customer Ledger : From', fmondes, v_gjahr,
157 sy-vline.
write: /01 sy-vline,
"02 'Credit Limit : ', klimk left-justified,
21 'To ', tmondes, v_gjahr,
157 sy-vline.
endif.
clear : v_fmonth, fmondes, v_tmonth, tmondes.
write:0(157) sy-uline.
write:/1 sy-vline,
2 'Document No',
14 sy-vline,
15 'Document Dt',
27 sy-vline,
28 'D T',
32 sy-vline,
33 'Ref : No',
46 sy-vline,
47 ' Narration ',
99 sy-vline,
100 'Br',
102 sy-vline,
103 ' Quantity',
113 sy-vline,
114 ' Rate ',
122 sy-vline,
123 ' Debit Amount',
139 sy-vline,
140 ' Credit Amount',
157 sy-vline.
endat.
loop at otab where kunnr = itab-kunnr.
glg = 1. flg = 1.
*if otab-blart = 'AB'.
if otab-wrbtr >= 0.
otab-shkzg = 'S'.
else.
otab-shkzg = 'H'.
otab-wrbtr = otab-wrbtr * -1.
endif.
*endif.
if otab-blart = 'DA'.
if otab-wrbtr >= 0.
otab-shkzg = 'H'.
else.
otab-shkzg = 'S'.
otab-wrbtr = otab-wrbtr * -1.
endif.
endif.
case otab-fkart.
when 'ZGB1'. " NARR = 'Rebate Credit Memo'.
select single knuma from vbrk into otab-knuma
where vbeln = otab-belnr and
fkart = 'ZGB1'.
if sy-subrc = 0.
select single botext
datab
datbi from kona into (otab-botext,
otab-datab,
otab-datbi)
where knuma = otab-knuma.
if sy-subrc = 0.
modify otab.
endif.
endif.
year = otab-datab+0(4).
mon = otab-datab+4(2).
date = otab-datab+6(2).
year1 = otab-datbi+0(4).
mon1 = otab-datbi+4(2).
date1 = otab-datbi+6(2).
concatenate otab-botext '-' date '.' mon '.' year '-' 'TO' '-'
date1 '.' mon1 '.' year1 into narr.
clear : year, mon, date, year1, mon1, date1.
when 'ZGDF'. narr = 'Frieght Debit Memo'.
when 'ZGDP'. narr = 'Depot Invoice'.
when 'ZGF2'. narr = 'Factory Invoice'.
when 'ZGG2' or 'ZGL2'.
narr = otab-sgtxt.
when 'ZGRE'. narr = 'Sales Return'.
when 'ZGRR'. narr = 'Factory Invoice'.
when 'S1'. narr = 'Sales Cancellation'.
when 'ZFS1'. narr = 'Cancellation of FInv'.
when others. narr = ' '.
endcase.
case otab-blart.
when 'SV'.
narr = otab-sgtxt.
when 'DA'. narr = 'Customer Document'.
Document Type NC,NA,NF,NE added for north Zone as requested by Sjain
by Gopal Jaiswal on 01/05/2003
when 'NC'. narr = 'Customer Document'.
when 'NA'. narr = 'Customer Document'.
when 'NF'. narr = otab-sgtxt.
when 'NE'. narr = 'Customer Document'.
when 'DC' or 'ND' or 'WD' or 'WC'.
Document type ND added for North Zone by Gopal JAiswal on 01/05/2003
if otab-shkzg = 'S' or otab-shkzg = 'H'.
narr = otab-sgtxt.
endif.
when 'DZ' or 'NP' or 'WP'.
Document type NP added for North Zone by Gopal JAiswal on 01/05/2003
if otab-sgtxt+0(1) = 'D'.
narr = 'Payment DD. No :'.
else.
narr = 'Payment Cheque. No. :'.
endif.
concatenate narr otab-zuonr into narr.
endcase.
if elg = 0.
format color 4 intensified on.
write:/ sy-vline,
14 sy-vline,
27 sy-vline,
32 sy-vline,
46 sy-vline,
'Opening Balance',
99 sy-vline,
102 sy-vline,
113 sy-vline,
122 sy-vline.
if opbal >= 0.
write: 123 opbal, 139 sy-vline,
157 sy-vline.
else.
dpbal = opbal.
dpbal = opbal * -1.
write: 139 sy-vline,
140 dpbal, sy-vline.
endif.
elg = 1.
format reset.
endif.
v_matnr = otab-matnr+3(2).
format color 2.
write:/ sy-vline,
otab-belnr, sy-vline,
otab-budat, sy-vline,
otab-blart, sy-vline.
if otab-fkart = 'ZGDF'.
write: otab-zvonr, 46 sy-vline.
else.
write: otab-xblnr, 46 sy-vline.
endif.
qty = otab-fkimg.
kbetr = otab-kbetr.
write: narr, 99 sy-vline,
100 v_matnr, 102 sy-vline,
qty, 113 sy-vline,
kbetr right-justified, 122 sy-vline.
if otab-shkzg = 'S'.
write: 123 otab-wrbtr, 139 sy-vline,
157 sy-vline.
dramt = dramt + otab-wrbtr.
else.
write: 139 sy-vline,
140 otab-wrbtr, 157 sy-vline.
format reset.
cramt = cramt + otab-wrbtr.
endif.
qanty = qanty + otab-fkimg.
endloop.
if glg eq 0.
format color 4 intensified on.
write:/ sy-vline,
14 sy-vline,
27 sy-vline,
32 sy-vline,
46 sy-vline,
'Opening Balance',
99 sy-vline,
102 sy-vline,
113 sy-vline,
122 sy-vline.
if opbal >= 0.
write: 123 opbal, 139 sy-vline,
157 sy-vline.
else.
dpbal = opbal.
dpbal = opbal * -1.
write: 139 sy-vline,
140 dpbal, sy-vline.
endif.
format reset.
endif.
write:0(157) sy-uline.
at end of kunnr.
ttamt = dramt - cramt.
format color 3 intensified on.
tqty = qanty.
write:/ sy-vline,
:53 'Totals' , 99 sy-vline, 102 sy-vline,
103 tqty right-justified,
113 sy-vline, 122 sy-vline, 123 dramt,
139 sy-vline, 140 cramt,
sy-vline.
write:0(157) sy-uline.
if ttamt >= 0.
write:/ sy-vline,
:53 'Difference Amount' , 122 sy-vline, 123 ttamt,
139 sy-vline, 157 sy-vline.
else.
ttamt = ttamt * -1.
write:/ sy-vline,
:53 'Difference Amount' , 122 sy-vline, 139 sy-vline, 140 ttamt,
sy-vline.
endif.
write:0(157) sy-uline.
clbal = opbal + dramt - cramt.
if clbal >= 0.
write:/ sy-vline,
:53 'Closing Balance ' , 122 sy-vline, 123 clbal,
139 sy-vline, 157 sy-vline.
else.
clbal = clbal * -1.
write:/ sy-vline,
:53 'Closing Balance ' , 122 sy-vline, 139 sy-vline, 140 clbal,
sy-vline.
endif.
write:0(157) sy-uline.
format color 6 intensified off.
write:/1(157) sy-uline.
write:/1 sy-vline,
2 'Note:-', text-t02,
157 sy-vline.
write:/1 sy-vline,
2 text-t03,
157 sy-vline.
format reset.
write:/1 sy-vline,
120 'For Grasim Industries Ltd',
157 sy-vline.
write:/1 sy-vline,
157 sy-vline.
write:/1 sy-vline,
157 sy-vline.
write:/1 sy-vline,
120 'C&F Agent / Accountant',
157 sy-vline.
write:/1(157) sy-uline.
write:0(157) sy-uline.
format reset.
clear tqty.
qanty = 0.
name = ''.
ssobl = 0.
klimk = 0.
elg = 0.
glg = 0.
flg = 0.
lines = sy-linct - sy-linno.
skip lines.
Added for E-Mail
perform end_write using itab-kunnr.
new-page.
End
endat.
clear : v_matnr, qty, br, kbetr.
endloop.
endform. " GET-WRITE
&----
*& Form D_HEADER
&----
text
----
--> p1 text
<-- p2 text
----
form d_header.
write: / sy-vline, 2 'Customer Code :', code,
106 'Name :', name, 157 sy-vline.
write:0(157) sy-uline.
write:/1 sy-vline,
2 'Document No',
14 sy-vline,
15 'Document Dt',
27 sy-vline,
28 'D T',
32 sy-vline,
33 'Ref : No',
46 sy-vline,
47 ' Narration ',
99 sy-vline,
100 'Br',
102 sy-vline,
103 ' Quantity',
113 sy-vline,
114 ' Rate ',
122 sy-vline,
123 ' Debit Amount',
139 sy-vline,
140 ' Credit Amount',
157 sy-vline.
write:0(157) sy-uline.
endform. " D_HEADER
&----
*& Form GET-VBRK
&----
text
----
--> p1 text
<-- p2 text
----
form get-vbrk.
loop at otab.
select * from vbrp where vbeln = otab-belnr.
if sy-subrc eq 0.
select * from vbrk where vbeln = otab-belnr.
if sy-subrc eq 0.
move vbrk-fkart to otab-fkart.
move vbrp-fkimg to otab-fkimg.
if otab-fkart = 'ZGDF'.
move vbrk-zuonr to otab-zvonr.
endif.
***Code added by Ranga Raju Manthena
if otab-fkart = 'ZGDP' or otab-fkart = 'ZGF2'.
select single xabln into otab-xblnr
from likp
where vbeln = vbrp-vgbel.
endif.
if otab-fkart = 'ZFS1'.
clear otab-fkimg.
endif.
***End of Insertion
move vbrp-matnr to otab-matnr.
modify otab.
endif.
endselect.
select single * from konv where knumv = vbrk-knumv and
kschl in ('ZTPR','ZNTP') and
kwert <> 0.
if sy-subrc eq 0.
move konv-kbetr to otab-kbetr.
modify otab.
endif.
endif.
endselect.
endloop.
endform. " GET-VBRK
&----
*& Form GET-BKPF
&----
text
----
--> p1 text
<-- p2 text
----
form get-bkpf.
loop at otab where fkart = 'ZGDP'.
select bktxt
bstat
into (otab-xblnr,
otab-bstat)
from bkpf
where belnr = otab-belnr.
if sy-subrc eq 0.
modify otab.
clear otab.
endif.
endselect.
endloop.
delete otab where blart = 'AB' and bstat = 'A'.
endform. " GET-BKPF
&----
*& Form GET-BSEG
&----
text
----
--> p1 text
<-- p2 text
----
form get-bseg.
Document type NP added for North Zone by Gopal JAiswal on 01/05/2003
loop at otab where blart = 'DZ' or blart = 'NP' or blart = 'WP'.
select zuonr sgtxt
into (otab-zuonr, otab-sgtxt)
from bseg
where belnr = otab-belnr and
bukrs = 'GMKT' and
gjahr = gjahr and
shkzg = 'S' and
koart = 'S'.
if sy-subrc eq 0.
modify otab.
endif.
endselect.
endloop.
Document type ND added for North Zone by Gopal JAiswal on 01/05/2003
loop at otab where blart = 'DZ' or blart = 'NP' or blart = 'WP'.
select sgtxt
into (otab-sgtxt)
from bseg
where belnr = otab-belnr and
bukrs = 'GMKT' and
gjahr = gjahr and
shkzg in ('S', 'H').
if sy-subrc eq 0.
modify otab.
endif.
endselect.
endloop.
Document type ND added for North Zone by Gopal JAiswal on 01/05/2003
loop at otab
where blart = 'SV'
or blart = 'DC'
or blart = 'ND'
or blart = 'NF'
or blart = 'WD'
or blart = 'WC'.
select sgtxt
into (otab-sgtxt)
from bseg
where belnr = otab-belnr and
bukrs = 'GMKT' and
gjahr = gjahr and
shkzg in ('S', 'H') and
kunnr = otab-kunnr.
if sy-subrc eq 0.
modify otab.
endif.
endselect.
endloop.
loop at otab.
if otab-fkart = 'ZGDF'.
otab-fkimg = 0.
modify otab.
elseif otab-fkart = 'ZGRE'.
otab-fkimg = otab-fkimg * -1.
modify otab.
endif.
if otab-fkart = 'S1'.
otab-fkimg = otab-fkimg * -1.
modify otab.
endif.
endloop.
endform. " GET-BSEG
&----
*& Form GET-SAMT
&----
text
----
--> p1 text
<-- p2 text
----
form get-samt.
loop at itab.
select kunnr
shkzg
wrbtr
into (stab-kunnr,
stab-shkzg,
stab-sdamt)
from bsid
where ( umskz = 'J' or umskz = 'K' ) and
kunnr = itab-kunnr and
budat <= edate.
if sy-subrc eq 0.
if stab-shkzg = 'S'.
csamt = csamt + stab-sdamt.
elseif stab-shkzg = 'H'.
csamt = csamt - stab-sdamt.
endif.
collect stab.
clear stab.
endif.
endselect.
at end of kunnr.
itab-ssobl = csamt.
modify itab transporting ssobl.
clear itab.
clear csamt.
endat.
endloop.
endform. " GET-SAMT
&----
*& Form V_DATE
&----
text
----
form v_date.
v_fmonth = sdate+4(2).
select single ltx into fmondes from t247 where spras = 'EN' and
mnr = v_fmonth.
v_tmonth = edate+4(2).
select single ltx into tmondes from t247 where spras = 'EN' and
mnr = v_tmonth.
endform. " V_DATE
&----
*& Form GET-ABBAL
&----
text
----
form get-abbal.
For considering Advance Amounts for Opening Balances.
For making diffrent H and S incase of Advances posting as a Debit
as per S Jain req as on 06.03.2003
select sum( wrbtr )
into aobal_h
from bsid
Modified on 17.04.2004 By srinivas yerra.
where ( umskz = 'A' or umskz = 'E') and
shkzg = 'H' and
kunnr = itab-kunnr and
budat <= rdate.
aobal_h = aobal_h * -1.
select sum( wrbtr )
into aobal_s
from bsid
where ( umskz = 'A' or umskz = 'E') and
shkzg = 'S' and
kunnr = itab-kunnr and
budat <= rdate.
aobal = aobal_h + aobal_s.
select sum( wrbtr )
into ahbal_h
from bsad
where ( umskz = 'A' or umskz = 'E') and
shkzg = 'H' and
kunnr = itab-kunnr and
budat <= rdate and
augdt >= sdate. " BUDAT <= RDATE and
ahbal_h = ahbal_h * -1.
select sum( wrbtr )
into ahbal_s
from bsad
where ( umskz = 'A' or umskz = 'E') and
*end of modification.
shkzg = 'S' and
kunnr = itab-kunnr and
budat <= rdate and
augdt >= sdate. " BUDAT <= RDATE and
ahbal = ahbal_h + ahbal_s.
aobal = aobal + ahbal.
endform. " GET-ABBAL
&----
*& Form GET-VBFA
&----
text
----
--> p1 text
<-- p2 text
----
form get-vbfa.
loop at otab.
if otab-fkart = 'ZGRE' or otab-fkart = 'S1'.
select single vbelv from vbfa into otab-xblnr
where vbeln = otab-belnr and
vbtyp_v = 'M'.
if sy-subrc = 0.
modify otab.
endif.
endif.
endloop.
endform. " GET-VBFA
&----
*& Form update_otab
&----
text
----
form update_otab.
ttab = otab.
ttab[] = otab[].
refresh otab.
clear otab.
*loop at ttab where blart = 'DZ'
or blart = 'NP'
or blart = 'WP'
or blart = 'DA'
or blart = 'NF'
OR BLART = 'SV'
OR BLART = 'RV'
OR BLART = 'NE'.
*
*
if ttab-shkzg = 'S'.
ttab-wrbtr = ttab-wrbtr * -1.
modify ttab.
endif.
*endloop.
sort ttab by belnr.
loop at ttab.
at new belnr.
read table ttab index sy-tabix.
sum.
collect ttab into otab.
endat.
endloop.
endform. " update_otab.
Include:
----
INCLUDE ZINCUSMAIL *
----
include <symbol>.
data : i_doc_data like sodocchgi1.
data : begin of i_pack_list occurs 0.
include structure sopcklsti1.
data : end of i_pack_list.
data : begin of i_receivers occurs 0.
include structure somlreci1.
data : end of i_receivers.
data : begin of i_contents occurs 0.
include structure solisti1.
data : end of i_contents.
data : begin of i_header occurs 0.
include structure solisti1.
data : end of i_header.
data : begin of i_att occurs 0.
include structure solisti1.
data : end of i_att.
Internal Table for Internet address.
data: begin of it_inad occurs 0,
kunnr like kna1-kunnr, " Customer Code
name1 like kna1-name1, " Customer Name
ssobl like knkk-ssobl, " Security Deposit
klimk like knkk-klimk, " Credit Limit
opbal like bsid-wrbtr, " Opening Balance
clbal like bsid-wrbtr, " Closing Balance
smtp like adr6-smtp_addr, " Internet mail (SMTP) address
end of it_inad.
data : pdf_line(134),
asdf like pdf_line occurs 0 with header line.
data : pdf_table like tline occurs 0 with header line,
pdf_fsize type i.
data : stuff(65000),
len type i,
pos type i,
tab_lines like sy-tabix.
data: spoolid type tsp01-rqident,
spdel type tsp01sys.
data: v_gjahrt like bsid-gjahr,
fmondest(10),
tmondest(10),
kunnr1 like kna1-kunnr,
gjah(4),
fmon(10).
&----
*& Form hide_write
&----
form hide_write.
new-page print on
line-size 160
line-count 58
no-title
no-heading
destination 'LOCL'
immediately ' '
new list identification 'X'
no dialog.
set blank lines on.
endform. " hide_write
&----
*& Form end_write
&----
form end_write using kunnr1.
set blank lines off.
new-page print off.
***Using Spoolid we are getting PDF formated file
spoolid = spdel-rqident = sy-spono.
spdel-sys = sy-sysid.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = spoolid
no_dialog = 'X'
importing
pdf_bytecount = pdf_fsize
tables
pdf = pdf_table
exceptions
others = 0.
***Delleting Spool request
call function 'RSPO_IDELETE_SPOOLREQ'
exporting
spoolreq = spdel
exceptions
others = 2.
***Converting PDF table line size 134 into standard list size 255
loop at pdf_table into pdf_line.
if pos = 34170.
perform attach.
endif.
stuff+pos(134) = pdf_line.
add 134 to pos.
endloop.
if not ( stuff is initial ).
perform attach.
endif.
clear pdf_line.
clear pdf_table[].
describe table i_att lines tab_lines.
i_pack_list-transf_bin = 'X'.
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'PDF'.
i_pack_list-obj_name = 'LedgerMail'.
concatenate fmon '-' gjah into i_pack_list-obj_descr.
*i_pack_list-obj_descr = '2092-Oct03'.
i_pack_list-obj_langu = 'E'.
i_pack_list-doc_size = tab_lines * 255.
append i_pack_list.
***Data for receivers list
loop at it_inad where kunnr eq kunnr1.
i_receivers-receiver = it_inad-smtp.
i_receivers-rec_type = 'U'.
i_receivers-rec_date = sy-datum.
i_receivers-express = 'X'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
append i_receivers.
endloop.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = i_doc_data
PUT_IN_OUTBOX = ' '
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
packing_list = i_pack_list
object_header = i_header
contents_bin = i_att
contents_txt = i_contents
receivers = i_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
.
refresh i_att. clear i_att.
refresh i_receivers. clear i_receivers.
delete i_pack_list where doc_type = 'PDF'.
*refresh i_header.
*refresh i_contents.
*clear i_doc_data.
endform. " end_write
&----
*& Form doc_data
&----
form doc_data using fmondest v_gjahrt.
gjah = v_gjahrt.
fmon = fmondest.
***Data for Document Data
i_doc_data-obj_name = 'LedgerMail'.
concatenate 'Customer Ledger for : ' fmondest gjah
into i_doc_data-obj_descr separated by space.
i_doc_data-obj_langu = 'E'.
i_doc_data-obj_prio = '1'.
i_doc_data-no_change = 'X'.
i_doc_data-doc_size = '5101'.
***Data for Packing list
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = '20'.
i_pack_list-doc_type = 'RAW'.
i_pack_list-obj_langu = 'E'.
append i_pack_list.
***Data for Header
i_header-line = 'Header'. append i_header.
***Data for contents
i_contents-line = 'Dear Customer,'. append i_contents.
i_contents-line = ' '. append i_contents.
concatenate 'Please find your enclosed Ledger for the month of : '
fmondest gjah into i_contents-line separated by space.
append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'This is a computer generated document and does not
require a signature.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'Note : If you do not have Acrobat Reader please click
on the below link.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'
. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
endform. " doc_data
&----
*& Form attach
&----
form attach.
clear pos.
len = strlen( stuff ).
while len > 0.
subtract 255 from len.
i_att = stuff+pos(255).
append i_att.
add 255 to pos.
endwhile.
clear pos.
clear stuff.
endform. " attach
Regrads,
Anji
2007 Feb 19 11:30 AM
Hello,
check this sample..
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
Regards,
Vasanth
2007 Feb 19 11:30 AM
2007 Feb 19 1:24 PM
Hello ,
Thanks for your reply .. the code works fine for txt extension but when I try it with
xls I get the following error
SX_OUTGOING_VERSION_BUILD No suitable conversion found for XLS
SX_GENERATE_NDR Message cannot be processed as it cannot be converted
could you please guide
2007 Feb 19 1:32 PM
Hi.,
Refer this for .XLS
http://www.sapdevelopment.co.uk/reporting/email/attachhome.htm
Reward points for those replies which helped you.
2007 Feb 19 11:44 AM
Hi
This is the sample code previously I achieved the same requirement.
FORM send_mail_2 USING msgid msgno msgv1.
mailuser oder Gruppe like sy-uname default 'Ruckerk'.
DATA: express_hold_time LIKE sovaltime.
DATA: text LIKE sotxtinfo.
DATA: receiver LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
MESSAGE ZF100 (FTP an UDB fehlgeschlagen)
text-msgid = msgid.
text-msgno = msgno.
text-msgv1 = msgv1.
text-msgv2 = ' '.
text-msgv3 = ' '.
text-msgv4 = ' '.
express_hold_time
express_hold_time-days = 01.
express_hold_time-h_min_sec = 240000.
receiver
receiver-receiver = mreceivr.
Gruppe von Empfängern
receiver-rec_type = 'C'.
und Expressmeldung ausgeben
receiver-express = 'X'.
APPEND receiver.
CALL FUNCTION 'MESSAGE_SEND_AS_MAIL'
EXPORTING
msgid = text-msgid
msgno = text-msgno
msgv1 = text-msgv1
msgv2 = text-msgv2
msgv3 = text-msgv3
TABLES
receivers = receiver.
IF sy-subrc <> 0.
WRITE:/ 'hat nicht geklappt', 'SY-SUBRC =', sy-subrc.
ENDIF.
PERFORM print_error_report.
Fehlermeldung zum Abbrechen des Report's ausgeben.
MESSAGE e398 WITH 'Jobabbruch' msgv1.
ENDFORM. " SEND_MAIL_2
Regards,
kumar
2007 Feb 19 2:25 PM
Hi,
REPORT ZEMAIL_ATTACH .
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT '[email protected]'.
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
' '
' '
' '
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
&----
*& Form BUILD_XLS_DATA_TABLE
&----
Build data table for .xls document
----
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
&----
*& Form POPULATE_EMAIL_MESSAGE_BODY
&----
Populate message body text
----
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
Hope this helps.
Regards,
Sruthi
2007 Feb 20 10:47 AM
Hello Gurus,
Things are not working creates a problem for XLS format
but when I convert it to txt format it works fine
but the layout is not proper .. what could be the probs ?
can anybody pls guide me
Thanks
Aryan
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |