SAP ABAP : ME47 - Maintain Quotation Price With Custom Function Module
function z_vim_rfq_price.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(RFQ_NUMBER) TYPE EBELN
*" REFERENCE(RFQ_ITEM) TYPE EBELP
*" REFERENCE(PRICE) TYPE NETPR
*" REFERENCE(CURRENCY) TYPE WAERS
*" TABLES
*" RETURN STRUCTURE BDCMSGCOLL
*"----------------------------------------------------------------------
data :
i_ebeln type ebeln,
i_ebelp type ebelp,
ynetpr type char15,
xwaers type waers,
xnetpr type netpr,
wa_ekko type ekko,
wa_ekpo type ekpo.
data lt_bdcdata type table of bdcdata with header line.
data lt_bdcmsg type table of bdcmsgcoll with header line.
data ls_bdcopt type ctu_params.
data ls_sy type sy.
ls_sy = sy.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = rfq_number
importing
output = i_ebeln.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = rfq_item
importing
output = i_ebelp.
clear : wa_ekpo, wa_ekko.
select single * from ekko into wa_ekko
where ebeln = rfq_number and loekz = ''.
if wa_ekko is initial.
clear lt_bdcmsg.
lt_bdcmsg-msgtyp = 'E'.
lt_bdcmsg-msgv1 = 'RFQ Not found'.
append lt_bdcmsg to return.
exit.
endif.
select single * from ekpo into wa_ekpo
where ebeln = rfq_number and
ebelp = rfq_item.
"ME47
clear lt_bdcdata.
lt_bdcdata-program = 'SAPMM06E'.
lt_bdcdata-dynpro = '0305'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_CURSOR'.
lt_bdcdata-fval = 'RM06E-ANFNR'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '/00'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'RM06E-ANFNR'.
lt_bdcdata-fval = rfq_number.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-program = 'SAPMM06E'.
lt_bdcdata-dynpro = '0323'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_CURSOR'.
lt_bdcdata-fval = 'RM06E-EBELP'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '/00'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'RM06E-EBELP'.
lt_bdcdata-fval = rfq_item.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-program = 'SAPMM06E'.
lt_bdcdata-dynpro = '0323'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_CURSOR'.
lt_bdcdata-fval = 'RM06E-ANFPS(01)'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '=KO'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'RM06E-TCSELFLAG(01)'.
lt_bdcdata-fval = 'X'.
append lt_bdcdata.
data wa_cdpos type cdpos.
data _tabkey type char70.
clear _tabkey.
concatenate rfq_number rfq_item into _tabkey.
select single * from cdpos into wa_cdpos
where objectclas = 'EINKBELEG' and objectid = rfq_number and tabkey = _tabkey and fname = 'NETPR'.
if wa_ekpo-netpr > 0 or wa_cdpos is not initial.
clear lt_bdcdata.
lt_bdcdata-program = 'SAPLV14A'.
lt_bdcdata-dynpro = '0102'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_CURSOR'.
lt_bdcdata-fval = 'VAKE-DATAB(01)'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '=PICK'.
append lt_bdcdata.
endif.
* clear lt_bdcdata.
* lt_bdcdata-program = 'SAPMV13A'.
* lt_bdcdata-dynpro = '0201'.
* lt_bdcdata-dynbegin = 'X'.
* append lt_bdcdata.
* clear lt_bdcdata.
* lt_bdcdata-fnam = 'BDC_CURSOR'.
* lt_bdcdata-fval = 'KONP-KBETR(01)'.
* append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-program = 'SAPMV13A'.
lt_bdcdata-dynpro = '0201'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '/00'.
append lt_bdcdata.
xnetpr = price.
if currency = 'IDR'.
xnetpr = xnetpr / 100.
endif.
write xnetpr to ynetpr currency currency.
clear lt_bdcdata.
lt_bdcdata-fnam = 'KONP-KBETR(01)'.
lt_bdcdata-fval = ynetpr.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-program = 'SAPMV13A'.
lt_bdcdata-dynpro = '0201'.
lt_bdcdata-dynbegin = 'X'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_CURSOR'.
lt_bdcdata-fval = 'KONP-KBETR(01)'.
append lt_bdcdata.
clear lt_bdcdata.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = '=SICH'.
append lt_bdcdata.
"BDC Options
ls_bdcopt-dismode = 'N'. "A=FOREGROUND N=BACKGROUND E=ERROR
ls_bdcopt-updmode = 'S'. "S=SYNCHRONOUS A=ASYNCHRONOUS L=LOCAL
ls_bdcopt-defsize = 'X'.
ls_bdcopt-racommit = 'X'.
* ls_bdcopt-nobinpt = 'X'.
* ls_bdcopt-nobiend = 'X'.
update ekpo set agmem = '' bednr = '1' where ebeln = i_ebeln and ebelp = i_ebelp.
call transaction 'ME47'
* without authority-check
using lt_bdcdata
messages into lt_bdcmsg
options from ls_bdcopt.
return = lt_bdcmsg.
if lt_bdcmsg[] is initial.
commit work and wait.
append LINES OF lt_bdcmsg[] to return[].
else.
rollback work.
endif.
endfunction.
Comments
Post a Comment