Friday, September 4, 2009

Function Module

I created my second Function Module. Yesterday after searching nearly the whole day for a BAPI or a Function Module to determine Customer Discounts. So I thought I would post the code just in case anyone else is looking for the same thing.
Here is a link on creating function modules SAP Tutorial it's better then anything I could do.


OK now on to some source code. Well first we need to define the import parameters.

Now for the output.

Now we can create the source.
First the data section
  types:
begin of type_bsid,
zterm type bsid-zterm,
wrbtr type bsid-wrbtr,
sknto type bsid-sknto,
budat type bsid-budat,
end of type_bsid,

begin of type_zterm,
zterm type t052-zterm,
zdart type t052-zdart,
zfael type t052-zfael,
ztag1 type t052-ztag1,
zprz1 type t052-zprz1,
ztag2 type t052-ztag2,
zprz2 type t052-zprz2,
end of type_zterm.

data:
global_tab_bsid type table of type_bsid with header line,
global_tab_zterm type table of type_zterm with header line,
local_date type sy-datum.

Now for the logic
  select single zterm wrbtr sknto budat from bsid into global_tab_bsid
where belnr = belnr
and kunnr = kunnr.
clear: zterm,
wrbtr.

if sy-subrc = 0.
select single zterm zdart zfael ztag1 zprz1
ztag2 zprz2
from t052 into global_tab_zterm
where zterm = global_tab_bsid-zterm.
if sy-subrc = 0.
local_date = global_tab_bsid-budat + global_tab_zterm-zfael.
if local_date > sy-datum and global_tab_zterm-zfael <> 0.
wrbtr = ( global_tab_bsid-wrbtr * global_tab_zterm-zprz1 ) / 100.
else.
local_date = global_tab_bsid-budat + global_tab_zterm-ztag1.
if local_date > sy-datum and global_tab_zterm-ztag1 <> 0.
wrbtr = ( global_tab_bsid-wrbtr * global_tab_zterm-zprz1 ) / 100.
else.
local_date = global_tab_bsid-budat + global_tab_zterm-ztag2.
if local_date > sy-datum and global_tab_zterm-ztag2 <> 0.
wrbtr = ( global_tab_bsid-wrbtr * global_tab_zterm-zprz2 ) / 100.
endif.
endif.
zterm = global_tab_zterm-zterm.
endif.

endif.
endif.

Well I hope this helps if you see anything that I forgot to do or if you think of anything that would make it better drop me a note and let me know.






Reblog this post [with Zemanta]