cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI/Function module TO block material which is mentioned in sales order

Former Member
0 Kudos

Hi All

Is there any BAPI to block material which is mationed in sales order....

I am using BAPI_MATERIAL_AVAILABILITY to check material availibility

how to block quantity if it is available whicl creating sales order via

"BAPI_SALESORDER_CREATEFROMDATA2"

..Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks

Former Member
0 Kudos

The normal SAP ATP done in the sales orders use the figure ''committed qty'' meaning that if the ATP has been done and confirmed, that quantity will not appear in the next sales order as available.

So if You're using the normal BAPI to create the sales order, the normal ATP function will be called in the processing.

Nevertheless another solution to this issue is to have the MTO (Make-to-order) solution where the requirements are ''attached'' to one sales order/line only.....like this the problem of the stock being taken to another customer disappears.

To do this you'll have to configure the following :

- Go to SPRO and go to Sales and distribution -> Basic functions -> Availability check and transfer of requirements -> Determination of requirements using transaction - Here insert the entry with your sales order type - MRP type (from material master - you might want to consider create one only for this solution) and you should use one of the following:

- KEL Make-to-order, mat. variants

- KELV Make-to-ord.variant + consump

- KP Make-to-order with project

and choose the origin of your requirement - 1 - Item category + MRP Type

- Than configure the association of the requirement type above to the requirement class (normally is the same code) transaction *OVZH*

- Than configure the requirement class (this is what will tell the system the MTO) transaction *OVZG* - On the screen in the field Special stock - E - Sales order stock and please ask for help from an FI consultant because the area of *Account assignment is very important to be well configured*

About the BAPI you're using - Its correct - That's the normal BAPI to be used, taking only into consideration the product allocation issue - MARA-KOSCH

Explaining a little the BAPI you're using :

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

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.