tables: vbak,
adr6,
trdyse01cm.
---------------------------------------------------------------------
*INCLUDE
---------------------------------------------------------------------
*INCLUDE ZZUTI_STD_HEADER_FOOTER. "Standard header and footer
----------------------------------------------------------------------
*TYPES DECLARATION
----------------------------------------------------------------------
types:
begin of t_crmemo,
vbeln type vbak-vbeln,
posnr type vbap-posnr,
erdat type vbak-erdat,
auart type vbak-auart,
augru type vbak-augru,
waerk type vbak-waerk,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
vdatu type vbak-vdatu,
bstnk type vbak-bstnk,
bsark type vbak-bsark,
bstdk type vbak-bstdk,
aedat type vbak-aedat,
bukrs_vf type vbak-bukrs_vf,
matnr type vbap-matnr,
zmeng type vbap-zmeng,
zieme type vbap-zieme,
end of t_crmemo,
begin of t_crmemo_change,
vbeln(90) type c,
posnr type vbap-posnr,
erdat type vbak-erdat,
auart type vbak-auart,
augru type vbak-augru,
waerk type vbak-waerk,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
vdatu type vbak-vdatu,
bstnk type vbak-bstnk,
bsark type vbak-bsark,
bstdk type vbak-bstdk,
aedat type vbak-aedat,
bukrs_vf type vbak-bukrs_vf,
matnr type vbap-matnr,
zmeng type vbap-zmeng,
zieme type vbap-zieme,
end of t_crmemo_change,
begin of t_mvke,
matnr type mvke-matnr,
vkorg type mvke-vkorg,
vtweg type mvke-vtweg,
mtpos type mvke-mtpos,
end of t_mvke,
begin of t_orders,
vbelv type vbfa-vbelv,
posnv type vbfa-posnv,
vbeln type vbfa-vbeln,
posnn type vbfa-posnn,
vbtyp_n type vbfa-vbtyp_n,
end of t_orders,
begin of t_ekpo,
ebeln type ekko-ebeln,
ebelp type ekpo-ebelp,
waers type ekko-waers,
menge type ekpo-menge,
meins type ekpo-meins,
netpr type ekpo-netpr,
peinh type ekpo-peinh,
mwskz type ekpo-mwskz,
txjcd type ekpo-txjcd,
end of t_ekpo,
begin of t_ekbe,
ebeln type ekbe-ebeln,
ebelp type ekbe-ebelp,
zekkn type ekbe-zekkn,
vgabe type ekbe-vgabe,
gjahr type ekbe-gjahr,
belnr type ekbe-belnr,
buzei type ekbe-buzei,
end of t_ekbe,
begin of t_rbkp,
belnr type rbkp-belnr,
gjahr type rbkp-gjahr,
bldat type rbkp-bldat,
budat type rbkp-budat,
xblnr type rbkp-xblnr,
lifnr type rbkp-lifnr,
rmwwr type rbkp-rmwwr,
wmwst1 type rbkp-wmwst1,
xrech type rbkp-xrech,
stblg type rbkp-stblg,
end of t_rbkp,
begin of t_cdhdr,
objectclas type cdhdr-objectclas,
objectid type cdhdr-objectid,
changenr type cdhdr-changenr,
udate type cdhdr-udate,
utime type cdhdr-utime,
end of t_cdhdr,
begin of t_cdpos,
objectclas type cdhdr-objectclas,
objectid type cdhdr-objectid,
changenr type cdhdr-changenr,
tabname type cdpos-tabname,
tabkey type cdpos-tabkey,
fname type cdpos-fname,
chngind type cdpos-chngind,
value_new type cdpos-value_new,
value_old type cdpos-value_old,
end of t_cdpos,
begin of t_change_docs,
objectclas type cdhdr-objectclas,
objectid type cdhdr-objectid,
changenr type cdhdr-changenr,
udate type cdhdr-udate,
utime type cdhdr-utime,
tabname type cdpos-tabname,
tabkey type cdpos-tabkey,
fname type cdpos-fname,
chngind type cdpos-chngind,
value_new type cdpos-value_new,
value_old type cdpos-value_old,
end of t_change_docs,
begin of t_success,
crmemo type vbak-vbeln,
cmemo type vbak-vbeln,
orders type vbak-vbeln,
po type vbak-vbeln,
miro_no type vbak-vbeln,
text(20) type c,
end of t_success,
begin of t_error,
crmemo type vbak-vbeln,
cmemo type vbak-vbeln,
orders type vbak-vbeln,
po type vbak-vbeln,
miro_no type vbak-vbeln,
text(100) type c,
end of t_error.
----------------------------------------------------------------------
*WORKAREA DECLARATION
----------------------------------------------------------------------
data:
wa_crmemo type t_crmemo,
wa_crmemo_change type t_crmemo_change,
wa_mvke type t_mvke,
wa_orders type t_orders,
wa_cmemo type t_orders,
wa_po type t_orders,
wa_ekpo type t_ekpo,
wa_ekbe type t_ekbe,
wa_ekbe_temp type t_ekbe,
wa_rbkp type t_rbkp,
wa_rbkp_tmp type t_rbkp,
wa_cdhdr type t_cdhdr,
wa_cdpos type t_cdpos,
wa_change_docs type t_change_docs,
wa_crmemo_mr8m type t_crmemo,
wa_success type t_success,
wa_error type t_error,
wa_success_mr8m type t_success,
wa_error_mr8m type t_error.
*--Work area for all the internal tables used for Sending Mail
data :
wa_objpack type sopcklsti1,
wa_objhead type solisti1,
wa_objbin type solisti1,
wa_objtxt type solisti1,
wa_reclist type somlreci1 .
data:
*
*
*Structure to hold Invoice Header Data
x_docheader like bapi_incinv_create_header,
*
*
*Structure to hold Reversal Posting Data
x_rev_post like bapi_incinv_fld.
----------------------------------------------------------------------
*INTERNAL TAABLE DECLARATION
----------------------------------------------------------------------
data:
it_crmemo type standard table of t_crmemo with header line,
it_crmemo_change type standard table of t_crmemo_change with header
line,
it_mvke type standard table of t_mvke with header line,
it_crmemo_miro type standard table of t_crmemo with header line,
it_crmemo_mr8m type standard table of t_crmemo with header line,
it_orders type standard table of t_orders with header line,
it_cmemo type standard table of t_orders with header line,
it_po type standard table of t_orders with header line,
it_ekpo type standard table of t_ekpo with header line,
it_ekbe type standard table of t_ekbe with header line,
it_ekbe_temp type standard table of t_ekbe with header line,
it_rbkp type standard table of t_rbkp with header line,
it_cdhdr type standard table of t_cdhdr with header line,
it_cdpos type standard table of t_cdpos with header line,
it_change_docs type standard table of t_change_docs with header line,
it_success type standard table of t_success with header line,
it_error type standard table of t_error with header line,
it_success_mr8m type standard table of t_success with header line,
it_error_mr8m type standard table of t_error with header line.
*
*
*Internal table to hold Invoice Item Data
data:begin of it_itemdata occurs 0.
include structure bapi_incinv_create_item.
data:end of it_itemdata.
*
*
*Internal table to hold Invoice Acct Assignment Data
data:begin of it_accountingdata occurs 0.
include structure bapi_incinv_create_account.
data:end of it_accountingdata.
*
*
*Internal table to hold BAPI return data
data: begin of it_return occurs 0.
include structure bapiret2. "Return Parameter.
data: end of it_return.
*
*
*Internal table to hold BAPI return data
data: begin of it_return_mr8m occurs 0.
include structure bapiret2. "Return Parameter.
data: end of it_return_mr8m.
*--MAIL related Internal tables
data: x_doc_chng type sodocchgi1, " document
*attributes
it_objpack type standard table of sopcklsti1, " attachment
*table
it_objhead type standard table of solisti1, " object header
*table
it_objbin type standard table of solisti1, " binary table
it_objtxt type standard table of solisti1, " object text
it_reclist type standard table of somlreci1, " mail recipients
it_compressed_list type standard table of soli,
it_pdf_list type standard table of tline,
it_pdf type tline occurs 10 with header line,
it_html type solisti1 occurs 10 with header line,
*
*
*Internal table for MIME data (in CHAR format)
it_temp type bapiqcmime occurs 10 with header line,
*
*
*Internal table for storing data
it_mime(255) type c occurs 10 with header line.
----------------------------------------------------------------------
*GLOBAL VARIABLES *
----------------------------------------------------------------------
data: v_pgm_id type sy-repid, " Program id
v_zterm type lfb1-zterm, " Payment Terms
v_text(75) type c, " To store error or success text
v_itemno(6) type n, " To Increment Item No. for BAPI
v_docnr like bapi_incinv_fld-inv_doc_no,
" For MIRO document number
v_year1 like bapi_incinv_fld-fisc_year,
" For MIRO Fiscal year
v_spono type tsp01-rqident, " For Spool No.
v_type type soodk-objtp, " For Spool Type
v_crmemo_qty type vbap-zmeng, " For CR Memo Qty.
v_line_amount type ekpo-netpr, " For CR Memo Item Qty.
v_grossamt type ekpo-netpr, " For CR Memo Grand Qty.
v_tax_per(3) type n, " For CR Memo Tax amount %
v_tax_amt type ekpo-netpr, " For CR Memo Tax amount
v_flag(1) type c, " Flag to process fruther
v_tot_s_mr8m type i, " For MR8M Success Records
v_tot_e_mr8m type i, " For MR8M Error Records
v_date type sy-datum, " For Sel. Screen Date
v_date2(10) type c, " For EMail Date
v_time(10) type c, " For EMail Time
v_time2(10) type c, " For EMail Time
v_info(100) type c, " For EMail Body Text
v_table_lines type sy-tabix, " To Increment Email Count
v_text2 type string , " For EMail Id text
v_lines type i, " To Store PDF Lines
v_temp(500) type c, " To Convert to 255 char format
v_offset type p, " To Convert to 255 char format
v_lineslen type i, " To Convert to 255 char format
v_mimelen type i, " To Convert to 255 char format
v_tabix type sy-tabix. " To Convert to 255 char format
----------------------------------------------------------------------
*CONSTANTS *
----------------------------------------------------------------------
constants:
c_x(1) type c value 'X', " Constant X or Flag
c_e(1) type c value 'E', " For Error check
c_v(1) type c value 'V', " For PO Docs
c_o(1) type c value 'O', " For Order Docs
c_c(1) type c value 'C', " For Credit Memo Docs
c_k(1) type c value 'K', " For CR Memo Docs
c_u(1) type c value 'U', " For Change tables
c_ali(3) type c value 'ALI', " For ALI Format
c_vbak(4) type c value 'VBAK', " For Change docs
c_01(2) type c value '01', " For Serial No. &
c_02(2) type c value '02', " For Reversal
c_blart type bkpf-blart value 'RE', " Document type
c_mtpos type mvke-mtpos value 'BANS', " Item Category
c_augru(5) type c value 'AUGRU', " Reason Code
c_0000500205(10) type c value '0000500205', " GL Account #
c_verkbeleg(9) type c value 'VERKBELEG'.
" For Object Class
*
*
*Horizontal tab & line feed constants
class cl_abap_char_utilities definition load.
constants:
c_tab type c value cl_abap_char_utilities=>horizontal_tab,
c_cr_lf type c value cl_abap_char_utilities=>cr_lf .
----------------------------------------------------------------------
*SELECTION SCREEN
----------------------------------------------------------------------
*
*
*Select Optons
selection-screen: begin of block b01 with frame title text-001.
select-options: s_auart for vbak-auart obligatory no intervals,
" Sales Document Type
s_augru for vbak-augru obligatory no intervals,
" Order reason
s_erdat for vbak-erdat obligatory.
" Date on which the record was created
selection-screen: end of block b01.
*
*
*Mail Sending Options
selection-screen begin of block b2 with frame title text-004.
parameters:p_email as checkbox default space user-command v_com .
parameters : p_mode type so_escape default 'U' modif id us1.
select-options: s_email for adr6-smtp_addr
no intervals modif id us2.
*SELECT-OPTIONS: S_EMAIL FOR TRDYSE01CM-USERNAME
*NO INTERVALS MODIF ID US2.
selection-screen: begin of line.
selection-screen: comment 55(40) text-019 modif id us2.
selection-screen: end of line.
selection-screen end of block b2.
----------------------------------------------------------------------
*WORK AREA for SELECT-OPTIONS
----------------------------------------------------------------------
data : x_email like s_email. "Work area for EMAIL select-options
----------------------------------------------------------------------
*INITIALIZATION
----------------------------------------------------------------------
initialization.
*
*
*Default values for Sales Document Type
----------------------------------------------------------------------
*A T S E L E C T I O N S C R E E N O U T P U T
----------------------------------------------------------------------
*
*
*For modifying the selection screen layout
at selection-screen output.
perform f_modify_screen.
----------------------------------------------------------------------
*AT SELECTION SCREEN. *
----------------------------------------------------------------------
at selection-screen.
*
*
*Subroutine to Validate selection screen fields
perform f_get_credit_memo_request.
if not it_crmemo[] is initial.
*
*
*Fetch Item Category Group
perform f_get_mvke_docs.
*
*
*Fetch Sales Order documents, PO Documents and Credit Memos
perform f_get_so_po_docs.
endif.
*
*
*If Credit memo request internal table have an change records then
*fetch the change documents from CDHDR and CDPOS
if not it_crmemo_change[] is initial.
*
*
*Fetch Change Documents for CR Memos from CDHDR and CDPOS tables
perform f_get_changed_docs.
endif.
*
*
*Fetch Purchasing Document Item Details
if not it_po[] is initial.
perform f_get_ekpo.
endif.
*
*
*Fetch MIRO Vendor based on the PO Details
if not it_ekpo[] is initial.
perform f_get_vendor.
endif.
----------------------------------------------------------------------
*END-OF-SELECTION *
----------------------------------------------------------------------
if v_flag is initial.
*
*
*Process Vendor Debit Postings
perform f_process_miro.
*Process Reversal Postings of Vendor Automatic Debits using TCODE MR8M
perform f_process_mr8m.
*
*
*Send mail,if user enters Email id's and Email Mode is not initial
if p_email = c_x and p_mode is not initial and s_email[] is not
initial.
*
*
*Get spool id
perform f_spool_id.
*
*
*EMail Logic
perform f_mail_logic.
endif.
*display the EMail RSCONN01 and Sussess and Error records of MIRO and
*MR8M
perform f_display_report.
else.
*
*
*Else exit the process
exit.
endif.
&---------------------------------------------------------------------
*& Form F_MODIFY_SCREEN
&---------------------------------------------------------------------
*A Form routine to modify the screen
----------------------------------------------------------------------
form f_modify_screen .
*
*
*To Modify Mail Sending Options
loop at screen.
if p_email = c_x.
if screen-group1 = 'US1' .
screen-invisible = 0.
screen-active = 1.
screen-input = 0.
modify screen.
endif.
if screen-group2 = 'US2' .
screen-invisible = 0.
screen-active = 1.
modify screen.
endif.
elseif p_email = space.
if screen-group1 = 'US1' .
screen-invisible = 1.
screen-active = 0.
modify screen.
endif.
if screen-group1 = 'US2' .
screen-invisible = 1.
screen-active = 0.
modify screen.
endif.
endif.
endloop.
endform. " F_MODIFY_SCREEN
&---------------------------------------------------------------------
*& Form f_validate
&---------------------------------------------------------------------
*Validation of Selection-Screen Inputs
----------------------------------------------------------------------
form f_validate .
*
*
*Validate Sales Document Type
if not s_auart[] is initial.
select auart
into s_auart-low
from tvak up to 1 rows
where auart in s_auart.
endselect.
if sy-subrc 0.
message e000 with 'Invalid Sales Document Type'(e01) .
endif.
endif.
*
*
*Validate Order reason (reason for the business transaction)
if not s_augru[] is initial.
select augru
into s_augru-low
from tvau up to 1 rows
where augru in s_augru.
endselect.
if sy-subrc 0.
message e000 with 'Invalid Order reason'(e02) .
endif.
endif.
endform. " f_validate
&---------------------------------------------------------------------
*& Form F_GET_CREDIT_MEMO_REQUEST
&---------------------------------------------------------------------
*Fetch Credit memo requests from VBAK & VBAP
----------------------------------------------------------------------
form f_get_credit_memo_request .
select a~vbeln
b~posnr
a~erdat
a~auart
a~augru
a~waerk
a~vkorg
a~vtweg
a~spart
a~vdatu
a~bstnk
a~bsark
a~bstdk
a~aedat
a~bukrs_vf
b~matnr
b~zmeng
b~zieme
into table it_crmemo
from ( vbak as a
inner join vbap as b on a~vbeln = b~vbeln )
where ( a~erdat in s_erdat
or a~aedat in s_erdat )
and a~auart in s_auart.
if sy-subrc = 0.
sort it_crmemo by vbeln posnr.
else.
message i000 with 'No Credit Memo Request selected'(002).
v_flag = c_x.
stop.
endif.
endform. " F_GET_CREDIT_MEMO_REQUEST
&---------------------------------------------------------------------
*& Form F_GET_MVKE_DOCS
&---------------------------------------------------------------------
*Fetch Sales Data for Material
----------------------------------------------------------------------
form f_get_mvke_docs .
data: lv_tabix type sy-tabix.
*
*
*Fetch Sales Data for Material
select matnr " Material Number
vkorg " Sales Organization
vtweg " Distribution Channel
mtpos " Item category group from material master
from mvke " Sales Data for Material
into table it_mvke
for all entries in it_crmemo
where matnr = it_crmemo-matnr
and vkorg = it_crmemo-vkorg
and vtweg = it_crmemo-vtweg.
if sy-subrc = 0.
sort it_mvke by matnr vkorg vtweg mtpos.
endif.
*
*
*Validate Item category group if MVKE-MTOPS 'BANS' then ignore CM
*Request line item
loop at it_crmemo into wa_crmemo.
lv_tabix = sy-tabix.
read table it_mvke into wa_mvke with key matnr = wa_crmemo-matnr
vkorg = wa_crmemo-vkorg
vtweg = wa_crmemo-vtweg
mtpos = c_mtpos
binary search.
if sy-subrc 0.
delete it_crmemo index lv_tabix. " Delete CR memo records
else.
*
*
*Else check for credit memo request change date is not initial, and
*append those records to IT_CRMEMO_CHANGE internal table to retrive
*change documents
if not wa_crmemo-aedat is initial.
wa_crmemo_change-vbeln = wa_crmemo-vbeln.
wa_crmemo_change-posnr = wa_crmemo-posnr.
wa_crmemo_change-erdat = wa_crmemo-erdat.
wa_crmemo_change-auart = wa_crmemo-auart.
wa_crmemo_change-augru = wa_crmemo-augru.
wa_crmemo_change-waerk = wa_crmemo-waerk.
wa_crmemo_change-vkorg = wa_crmemo-vkorg.
wa_crmemo_change-vtweg = wa_crmemo-vtweg.
wa_crmemo_change-spart = wa_crmemo-spart.
wa_crmemo_change-vdatu = wa_crmemo-vdatu.
wa_crmemo_change-bstnk = wa_crmemo-bstnk.
wa_crmemo_change-bsark = wa_crmemo-bsark.
wa_crmemo_change-bstdk = wa_crmemo-bstdk.
wa_crmemo_change-aedat = wa_crmemo-aedat.
wa_crmemo_change-bukrs_vf = wa_crmemo-bukrs_vf.
wa_crmemo_change-matnr = wa_crmemo-matnr.
wa_crmemo_change-zmeng = wa_crmemo-zmeng.
wa_crmemo_change-zieme = wa_crmemo-zieme.
append wa_crmemo_change to it_crmemo_change.
clear wa_crmemo_change.
endif.
endif.
endloop.
endform. " F_GET_MVKE_DOCS
&---------------------------------------------------------------------
*& Form F_GET_SO_PO_DOCS
&---------------------------------------------------------------------
*Fetch the Sales Order documents, PO documents, & Credit Memo
----------------------------------------------------------------------
form f_get_so_po_docs.
*
*
*Fetch Preceding sales orders based on the credit memo request
select vbelv
posnv
vbeln
posnn
vbtyp_n
from vbfa
into table it_orders
for all entries in it_crmemo
where vbeln = it_crmemo-vbeln
and posnn = it_crmemo-posnr
and vbtyp_n = c_k
and vbtyp_v = c_c.
if sy-subrc = 0.
sort it_orders by vbelv posnv.
*
*
*Fetch Subsequent PO documents & Credit Memo based on the sales
*orders
select vbelv
posnv
vbeln
posnn
vbtyp_n
from vbfa
into table it_po
for all entries in it_orders
where vbelv = it_orders-vbelv
and posnv = it_orders-posnv
and vbtyp_n in (c_v,c_o)
and vbtyp_v = c_c.
if sy-subrc = 0.
sort it_po by vbtyp_n.
*
*
*Copy the IT_PO internal table contents to IT_CMEMO internal table
it_cmemo] = it_po[.
*
*
*Delete PO documents from IT_CMEMO internal table
delete it_cmemo where vbtyp_n = c_v.
sort it_cmemo by vbeln posnn.
if it_cmemo[] is initial.
message i000 with 'No Credit Memo are available for CM
Request'(003).
*v_flag = c_x.
*stop.
endif.
*
*
*Delete Credit Memo documents from IT_PO internal table
delete it_po where vbtyp_n = c_o.
sort it_po by vbeln posnn.
endif.
endif.
endform. " F_GET_SO_PO_DOCS
&---------------------------------------------------------------------
*& Form F_GET_CHANGED_DOCS
&---------------------------------------------------------------------
*Fetch Change Documents for CR Memos from CDHDR and CDPOS tables
----------------------------------------------------------------------
form f_get_changed_docs .
*
*
*Fetch Change Documents for CR Memos from CDHDR
select objectclas
objectid
changenr
udate
utime
from cdhdr
into table it_cdhdr
for all entries in it_crmemo_change
where objectclas = c_verkbeleg
and objectid = it_crmemo_change-vbeln
*AND UDATE = IT_CRMEMO_CHANGE-AEDAT
.
if sy-subrc = 0.
sort it_cdhdr by objectclas objectid changenr.
*
*
*Fetch Change Documents for CR Memos from CDPOS
select objectclas
objectid
changenr
tabname
tabkey
fname
chngind
value_new
value_old
from cdpos
into table it_cdpos
for all entries in it_cdhdr
where objectclas = c_verkbeleg
and objectid = it_cdhdr-objectid
and changenr = it_cdhdr-changenr
and tabname = c_vbak
and fname = c_augru
and chngind = c_u.
if sy-subrc = 0.
sort it_cdpos by objectclas objectid changenr.
endif.
endif.
endform. " F_GET_CHANGED_DOCS
&---------------------------------------------------------------------
*& Form F_GET_EKPO
&---------------------------------------------------------------------
*Fetch Purchasing Document Item Details
----------------------------------------------------------------------
form f_get_ekpo .
*
*
*Fetch Purchasing Document Item Details
select a~ebeln
b~ebelp
a~waers
b~menge
b~meins
b~netpr
b~peinh
b~mwskz
b~txjcd
into table it_ekpo
from ( ekko as a
inner join ekpo as b on a~ebeln = b~ebeln )
for all entries in it_po
where a~ebeln = it_po-vbeln
and b~ebelp = it_po-posnn+1(5).
if sy-subrc = 0.
sort it_ekpo by ebeln ebelp.
endif.
endform. " F_GET_EKPO
&---------------------------------------------------------------------
*& Form F_GET_VENDOR
&---------------------------------------------------------------------
*Fetch MIRO Vendor details based on the PO Details
----------------------------------------------------------------------
form f_get_vendor .
data: lv_tabix type sy-tabix.
*
*
*Fetch History per Purchasing Document records for all the PO records
select ebeln
ebelp
zekkn
vgabe
gjahr
belnr
buzei
from ekbe
into table it_ekbe
for all entries in it_ekpo
where ebeln = it_ekpo-ebeln
and ebelp = it_ekpo-ebelp
and vgabe = '2'.
*and STBLG = space.
if sy-subrc = 0.
sort it_ekbe by belnr gjahr.
*
*
*Fetch the vendor details based on table IT_EKBE internal table
select belnr
gjahr
bldat
budat
xblnr
lifnr
rmwwr
wmwst1
xrech
stblg
from rbkp
into table it_rbkp
for all entries in it_ekbe
where belnr = it_ekbe-belnr
and gjahr = it_ekbe-gjahr.
if sy-subrc = 0.
sort it_rbkp by belnr gjahr.
endif.
endif.
*
*
*Sort PO History documents based on PO # and PO Item
sort it_ekbe by ebeln ebelp.
*
*
*Copy the PO History documents into IT_EKBE_TEMP internal table
it_ekbe_temp] = it_ekbe[.
*
*
*Delete PO History documents from IT_EKBE_TEMP internal table
*comparing with IT_RBKP where (STBLG) Reversal document number
*is initial
loop at it_ekbe_temp into wa_ekbe_temp.
lv_tabix = sy-tabix.
read table it_rbkp into wa_rbkp with key belnr = wa_ekbe_temp-belnr
gjahr = wa_ekbe_temp-gjahr
*XRECH = SPACE
stblg = space.
if sy-subrc 0.
delete it_ekbe_temp index lv_tabix.
endif.
clear: wa_ekbe_temp, wa_rbkp.
endloop.
endform. " F_GET_VENDOR
&---------------------------------------------------------------------
*& Form F_PROCESS_MIRO
&---------------------------------------------------------------------
*Process MIRO
----------------------------------------------------------------------
form f_process_miro .
data:
lv_itemno type i,
lv_tabix type sy-index,
lc_check(1) type c value 'X',
v_fill_item,
lv_rbkp_bldat type sy-datum.
clear : it_itemdata, it_accountingdata, it_crmemo_miro, it_crmemo_mr8m
.
refresh : it_itemdata, it_accountingdata, it_crmemo_miro,
it_crmemo_mr8m.
*
*
*Copy all the CR Memo Docs and delete order reason not in S_AUGRU
it_crmemo_mr8m] = it_crmemo[.
*
*
*Delete Reversal postings which are not in S_AUGRU
delete it_crmemo_mr8m where augru in s_augru.
*
*
*Delete Reversal postings where AEDAT is initial
delete it_crmemo_mr8m where aedat is initial.
*
*
*Delete order reason which are not in S_AUGRU
delete it_crmemo where augru not in s_augru.
*
*
*Loop through the credit memo request records
loop at it_crmemo into wa_crmemo.
lv_tabix = sy-tabix.
*
*
*If credit memo request change date is not initial then
*send change date (AEDAT) to lv_rbkp_bldat
if not wa_crmemo-aedat is initial.
lv_rbkp_bldat = wa_crmemo-aedat.
else.
*
*
*If credit memo request change date is initial then
*send create date (ERDAT) to lv_rbkp_bldat
lv_rbkp_bldat = wa_crmemo-erdat.
endif.
read table it_orders into wa_orders with key vbeln = wa_crmemo-vbeln
posnn = wa_crmemo-posnr
.
if sy-subrc = 0.
read table it_po into wa_po with key vbelv = wa_orders-vbelv
posnv = wa_orders-posnv.
if sy-subrc = 0.
read table it_ekpo into wa_ekpo with key ebeln = wa_po-vbeln
ebelp = wa_po-posnn.
if sy-subrc = 0.
*
*
*Read IT_EKBE_TEMP internal table which contains records which are
*not reversed
read table it_ekbe_temp into wa_ekbe_temp with key ebeln =
wa_ekpo-ebeln
ebelp =
wa_ekpo-ebelp.
if sy-subrc = 0.
*
*
*Read IT_RBKP internal table with XRECH (Indicator: post invoice) =
*'X' ,
*check for invoice records for the correspnding CR Memo records
read table it_rbkp into wa_rbkp with key belnr =
wa_ekbe_temp-belnr
gjahr =
wa_ekbe_temp-gjahr
xrech = c_x.
if sy-subrc = 0.
*
*
*Read IT_RBKP internal table with XRECH (Indicator: post invoice) =
*SPACE,
*and document date = CR Memo creation date
*and reference document number = PO number
read table it_rbkp into wa_rbkp_tmp with key belnr =
wa_ekbe_temp-belnr
gjahr =
wa_ekbe_temp-gjahr
bldat =
wa_crmemo-erdat
xrech = ' '
xblnr+0(10) =
wa_ekbe_temp-ebeln.
*STBLG =
*SPACE.
if sy-subrc = 0.
continue.
else.
*
*
*Quantity Conversion (Get the Credit Memo Quantity by passing CMR
*
*
*Create a new spool from the data in data_tab
*new-page line-size sy-linsz print on
new-page line-size 255 print on
destination 'LOCL'(p19) "<<== my printer
*
*
*receiver 'TJOSVOB'
cover text 'Spool title'(p20) " <<== Title or Spool req. name
list name 'List name'(p21)
list dataset 'List Dataset'(p22)
immediately ' ' " X means print now
keep in spool c_x " X means keep spool
new list identification c_x
no dialog .
*
*
*Writing Report
*In this perform you will write the code for displaying the list
perform f_display_report.
*
*
*new-page print off
new-page print off.
endform. " F_spool_id
&---------------------------------------------------------------------
*& Form F_MAIL_LOGIC
&---------------------------------------------------------------------
*Logic to send a mail for the given Email ID's
----------------------------------------------------------------------
form f_mail_logic .
data : wa_tsp01sys type tsp01sys.
clear v_spono.
v_spono = sy-spono.
*v_attach_desc = sy-title.
*
*Convert the Spool ID into PDF format
perform f_pdf_conversion tables it_compressed_list
it_pdf_list
using v_spono.
*
*
*Send the Mail in PDF Format
perform f_send_mail.
endform. " F_MAIL_LOGIC
&---------------------------------------------------------------------
*& Form f_pdf_conversion
&---------------------------------------------------------------------
*Read the spool and convert into PDF format
----------------------------------------------------------------------
*-->P_ITAB_COMPRESSED_LIST text
*-->P_ITAB_PDF_LIST text
*-->P_V_SPONO text
----------------------------------------------------------------------
form f_pdf_conversion tables it_compressed_list structure soli
it_pdf_list structure tline
using lv_spooln type tsp01-rqident.
clear: it_compressed_list, it_pdf_list.
refresh: it_compressed_list, it_pdf_list.
*
*
*Call the FM "RSPO_RETURN_SPOOLJOB" to read the spool by passing the
*
*
*If the List type is ALI call the FM "CONVERT_ABAPSPOOLJOB_2_PDF"
*to convert list into PDF Format
if v_type = c_ali. " for List it is ALI
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = lv_spooln
tables
pdf = it_pdf
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
if sy-subrc 0.
message e000
with'Error in convertion of list into PDF format'(018).
endif.
*
*
*Logic to convert the given format into 255 character format in
*IT_PDF
describe table it_pdf lines v_lines.
describe field it_pdf length v_lineslen in character mode.
describe field it_temp length v_mimelen in character mode.
loop at it_pdf.
v_tabix = sy-tabix.
move it_pdf to v_temp+v_offset.
if v_tabix = v_lines.
v_lineslen = strlen( it_pdf ).
endif.
v_offset = v_offset + v_lineslen.
if v_offset ge v_mimelen.
clear it_temp.
it_temp = v_temp(v_mimelen).
append it_temp.
shift v_temp by v_mimelen places.
v_offset = v_offset - v_mimelen.
endif.
if v_tabix = v_lines.
if v_offset gt 0.
clear it_temp.
it_temp = v_temp(v_offset).
append it_temp.
endif.
endif.
endloop.
loop at it_temp.
it_mime(255) = it_temp-line.
append it_mime.
endloop.
*
*
*Final Data to send to EMail
it_html] = it_mime[.
endif.
endform. " f_pdf_conversion
&---------------------------------------------------------------------
*& Form f_send_mail
&---------------------------------------------------------------------
*Send EMail Logic
----------------------------------------------------------------------
form f_send_mail .
data : wa_tsp01sys type tsp01sys.
*
*
*Call the RSCONN01 (SAPconnect: Start Send Process)
submit rsconn01 with mode = 'INT'
*WITH output = 'X'
and return.
perform f_display_sent_mail_status.
endif.
*To delete the spool request
wa_tsp01sys-rqident = sy-spono.
call function 'RSPO_IDELETE_SPOOLREQ'
exporting
spoolreq = wa_tsp01sys.
if sy-subrc 0.
endif.
endform. " f_send_mail
&---------------------------------------------------------------------
*& Form F_DISPLAY_SENT_MAIL_STATUS
&---------------------------------------------------------------------
*Display Mail Sent status to the user
----------------------------------------------------------------------
form f_display_sent_mail_status .
uline at /1(60).
write :/ sy-vline,
'Mail sent Successfully to'(016)
color 5 intensified on,
60 sy-vline.
loop at s_email into x_email.
v_table_lines = strlen( x_email-low ).
move x_email-low+0(v_table_lines) to v_text2.
write :/ sy-vline,
2 sy-tabix left-justified,
5 ')',
v_text2,
60 sy-vline.
endloop.
uline at /1(60).
endform. " F_DISPLAY_SENT_MAIL_STATUS
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.