Posted: Sat Sep 22, 2007 4:40 pm Post subject: BAPI_MATERIAL_AVAILABILITY
BAPI_MATERIAL_AVAILABILITY
ATP and Allocation Check for the Unconfirmed Items Report
The program should check if the selected material is allocated or non-allocated.
This information is stored in a field MARA-KOSCH.
We should check this field and if the field is not empty then material is allocated, otherwise is not:
select kosch into l_kosch
from mara
where matnr = <VBAP-MATNR>. " Selected material
if subrc = 0.
if l_kosch is initial.
" Perform calculation for non-allocated materials
else.
" Perform calculation for allocated materials
endif.
else.
" Material not found, skip it ...
endif.
For allocated materials it will be checked allocation for the netting market of that Order.
The calculation rules for allocated and non-allocated materials are different.
For Non-allocated materials
BAPI 'BAPI_MATERIAL_AVAILABILITY' should be used for getting the ATP quantity.
Bapi should be called as follows --
Code:
data: lfl_bapiwmdvs type bapiwmdvs,
lit_bapiwmdvs type standard table of bapiwmdvs,
lfl_bapiwmdve type bapiwmdve,
lit_bapiwmdve type standard table of bapiwmdve,
l_dialogflag type bapicm61v-diafl.
Please note that table lit_bapiwmdvs is the input table and to this following input should be passed -
lfl_bapiwmdvs-req_date = sy-datum. "Current date
lfl_bapiwmdvs- REQ_QTY = <Unconfirmed Quantity> in Sales Order Unit
append lfl_bapiwmdvs to lit_bapiwmdvs.
The return value l_dailog will be --
' ' --- Quantity can be Delivered -- Item to be displayed in the Report!
'X' --- Complete quantity cannot be delivered -- ATP failed, Item not to be displayed.
'N' --- Material not relevant for ATP --- Item not to be displayed in the Report.
For Allocated materials
For the allocated Materials, we have to first do the ATP check in same fashion as for Non-allocated Materials and then in addition to this ATP check, we have to also check for Allocation from SIS table S941.
If ATP check fails, straight away the Item should be ignored from Output display.
If ATP check passes, we further check allocation as follows --
Valid entry should select from S941 as -
data: l_period like s941-spbup,
l_BUPER LIKE T009B-POPER,
l_GJAHR LIKE T009B-BDATJ,
lfl_s941 type t_s941.
data: l_bukrs type tvko-bukrs,
l_periv type t001-periv.
* Select company code
select single bukrs into l_bukrs
from tvko
where vkorg = <VBAK-VKORG>.
* Select fiscal year variant
select single periv into l_periv
from t001
where bukrs = l_bukrs.
* Get Period
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
I_DATE = sy-datum
I_PERIV = l_periv
IMPORTING
E_BUPER = l_buper
E_GJAHR = l_gjahr
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4
.
IF SY-SUBRC <> 0.
*** Ignore entry and skip further processing
ENDIF.
concatenate l_gjahr l_buper+1(2) into l_period.
select single kcqty aemenge from s941
into corresponding fields of lfl_s941
where SPBUP = l_period
and KONOB = 'OBJ_ALL_MATERIALS'
AND MATNR = <VBAP-MATNR>
and zzcnetmark = <VBAK-ZZCNETMARK>
and VRSIO EQ '000'.
IF SY-SUBRC <> 0.
*** Ignore entry and skip further processing
ENDIF.
Remaining Allocation = difference between product allocation quantity and incoming order quantity
i.e. (S941-KCQTY - S941-AEMENGE). Now we have to compare this qty with the Unconfirmed qty.
Ensure same Material UOM for quantity comparison as follows --
IF <VBAP-VRKME> NE <S941-BASME>.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr = <VBAP-MATNR>
i_in_me = <VBAP-VRKME>
i_out_me = <S941-BASME>
i_menge = <Unconfirmed qty in Sales UOM>
IMPORTING
e_menge = l_menge
EXCEPTIONS
error_in_application = 1
error = 2
OTHERS = 3.
IF sy-subrc <> 0.
*** Ignore entry and skip further processing
ENDIF.
ELSE.
***If both Units are same no need for conversion
l_menge = <Unconfirmed qty in Sales UOM>
ENDIF.
Then, compare --
If Remaining Allocation > = l_menge i.e. Unconfirmed quantity converted to S941-BASME unit,
then there is enough allocation for this Material for the Unconfirmed quantity and should be displayed in the report.
Else, the Item should be ignored.
Code:
*&---------------------------------------------------------------------*
*& Form determine_mat_avail
*&---------------------------------------------------------------------*
* Call the FM AVAILIBILITY_CHECK to find the ATP Qty and Qty
* Received
* Author: syd, Sydney, Australia
*----------------------------------------------------------------------*
* -->P_MATNR Material
* -->P_WERKS Plant
* <--P_QTY ATP Qty
* <--P_QTY_O Qty Received
* <--P_MEINS Base UoM
*----------------------------------------------------------------------*
form determine_mat_avail using p_matnr
p_werks
changing p_qty
p_qty_o
p_meins.
* Structure to hold ATP Controller: Control Parameters
data: begin of st_atpca.
include structure atpca.
data: end of st_atpca.
* Table to hold ATP: Requirements to be Checked/Considered
data: begin of tbl_atpcs occurs 0.
include structure atpcs.
data: end of tbl_atpcs.
* Table to hold ATP Server: ATP data for display
data: begin of tbl_atpds occurs 0.
include structure atpds.
data: end of tbl_atpds.
* Table to hold ATP Server: Material Table
data: begin of tbl_atpmat occurs 0.
include structure atpmat.
data: end of tbl_atpmat.
* Get the Base UoM
read table tbl_atpmat with key matnr = p_matnr.
if sy-subrc eq 0.
tbl_mat_avail-meins = tbl_atpmat-meins.
p_meins = tbl_atpmat-meins.
endif.
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 cannot 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.