SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_MATERIAL_AVAILABILITY



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 22, 2007 4:40 pm    Post subject: BAPI_MATERIAL_AVAILABILITY Reply with quote

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.

call function 'BAPI_MATERIAL_AVAILABILITY'
  exporting
    plant = <VBAP-WERKS>
    material = <VBAP-MATNR>
    unit = <VBAP- VRKME>
    check_rule = 'A'
* STGE_LOC =
* BATCH =
* CUSTOMER =
  importing
* ENDLEADTME =
* av_qty_plt =
    DIALOGFLAG = l_dialog
* RETURN =
  tables
    wmdvsx = lit_bapiwmdvs
    wmdvex = lit_bapiwmdve.


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.

* Populate ST_ATPCA
  clear st_atpca.
  st_atpca-anwdg  = '8'.    "Calling App - Explaination
  st_atpca-azerg  = 'T'.    "ATP Display Result
  st_atpca-rdmod  = 'A'.    "Read Mode - Totals
  st_atpca-xenqmd = 'N'.    "Do not read Blocks

* Populate TBL_ATPCS
  clear tbl_atpcs.
  refresh tbl_atpcs.

  tbl_atpcs-matnr  = p_matnr.  "Material
  tbl_atpcs-werks  = p_werks.  "Plant
  tbl_atpcs-prreg  = 'A'.      "Checking Rule for Avail Check
  tbl_atpcs-chmod  = 'EXP'.    "ATP: Check mode
  tbl_atpcs-delkz  = 'VC'.     "MRP element indicator
  tbl_atpcs-bdter  = sy-datum. "Requirements date for the component
  tbl_atpcs-xline  = '1'.
  tbl_atpcs-trtyp  = 'A'.      "Transaction type - Display
  tbl_atpcs-idxatp = '1'.
  tbl_atpcs-resmd  = 'X'.      "Mode for Results of Check - Proposal
  tbl_atpcs-chkflg = 'X'.
  append tbl_atpcs.

  call function 'AVAILABILITY_CHECK'
       tables
            p_atpcsx  = tbl_atpcs
            p_atpdsx  = tbl_atpds
            p_atpmatx = tbl_atpmat
       changing
            p_atpca   = st_atpca
       exceptions
            error     = 1
            others    = 2.

  check sy-subrc eq 0.

  read table tbl_atpds with key delkz = 'WB'.  "Plant Stock
  if sy-subrc eq 0.
    tbl_mat_avail-matnr = p_matnr.
    tbl_mat_avail-werks = p_werks.
    tbl_mat_avail-qty   = tbl_atpds-qty.
    tbl_mat_avail-qty_o = tbl_atpds-qty_o.

* 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.

    insert table tbl_mat_avail.

    p_qty   = tbl_atpds-qty.
    p_qty_o = tbl_atpds-qty_o.
  endif.

endform.                    " determine_mat_avail
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.