Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Calling BAPI_MATERIAL_AVAILABILITY in Z_FUNC_MODULE

Former Member
0 Likes
1,055

Hi,

I want to know how to call a BAPI in a user-defined function module....

Can u send me with code please.... Its urgent.

My Requirement is

<b>Import parameters - Plant, Material Num, Unit, Qty

Export parameters - Status </b>

I want to send the First 3 parameters of Import parameters to BAPI and get response Qty from it, compare both Quantities and tell the status...

If user requested for quantity which is more than available we have to send status no to user...

Please suggest how to proceed...

Regards,

Pushparaju.B.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
539

Try like this, i should help,


call function 'BAPI_MATERIAL_AVAILABILITY'
  exporting
    plant            = p_werks
    material         = p_matnr
    unit             = p_meins
*   CHECK_RULE       =
*   STGE_LOC         =
*   BATCH            =
*   CUSTOMER         =
*   DOC_NUMBER       =
*   ITM_NUMBER       =
*   WBS_ELEM         =
*   STOCK_IND        =
 IMPORTING
*   ENDLEADTME       = 
   AV_QTY_PLT       = v_AV_QTY_PLT
*   DIALOGFLAG       =
*   RETURN           =
  tables
    wmdvsx           = iwmdvsx
    wmdvex           = iwmdvex.
 
if sy-subrc = 0.

if v_AV_QTY_PLT lt <Requested Quantity>.
* Set Status as NO
else.
* Set Status as YES
endif.

endif.

Regards

Kathirvel

2 REPLIES 2
Read only

Former Member
0 Likes
540

Try like this, i should help,


call function 'BAPI_MATERIAL_AVAILABILITY'
  exporting
    plant            = p_werks
    material         = p_matnr
    unit             = p_meins
*   CHECK_RULE       =
*   STGE_LOC         =
*   BATCH            =
*   CUSTOMER         =
*   DOC_NUMBER       =
*   ITM_NUMBER       =
*   WBS_ELEM         =
*   STOCK_IND        =
 IMPORTING
*   ENDLEADTME       = 
   AV_QTY_PLT       = v_AV_QTY_PLT
*   DIALOGFLAG       =
*   RETURN           =
  tables
    wmdvsx           = iwmdvsx
    wmdvex           = iwmdvex.
 
if sy-subrc = 0.

if v_AV_QTY_PLT lt <Requested Quantity>.
* Set Status as NO
else.
* Set Status as YES
endif.

endif.

Regards

Kathirvel

Read only

Former Member
0 Likes
539

Hi take this as an example..

As you want to compare quantity.you need to give delivary date also.

i used the fields to create FM. I dont know the exact field you required..try to give your fields in IMPORT and EXPORT.

Change the code accordingly..

After FM inside subrc check you can write your logic for returning status to user.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(PLANT) LIKE MARC-WERKS

*" REFERENCE(MATNR) LIKE MARA-MATNR

*" REFERENCE(UNIT) LIKE MARA-MEINS

*" REFERENCE(QUANT) LIKE MBEW-LBKUM

*" REFERENCE(DELIV_DATE) LIKE MARA-ERSDA

*" EXPORTING

*" REFERENCE(STATUS) LIKE MARC-PSTAT

*"----


DATA : NEW_QUANT LIKE MBEW-LBKUM .

DATA: LV_TABIX LIKE SY-TABIX,

LT_WMDVSX LIKE BAPIWMDVS OCCURS 0 WITH HEADER LINE,

LT_WMDVEX LIKE BAPIWMDVE OCCURS 0 WITH HEADER LINE.

LV_TABIX = SY-TABIX.

CLEAR: LT_WMDVSX, LT_WMDVEX.

REFRESH: LT_WMDVSX, LT_WMDVEX.

  • Fill communication table

LT_WMDVSX-REQ_DATE = DELIV_DATE.

LT_WMDVSX-REQ_QTY = QUANT.

APPEND LT_WMDVSX.

CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'

EXPORTING

PLANT = PLANT

MATERIAL = MATNR

UNIT = UNIT

CHECK_RULE = '03'

TABLES

WMDVSX = LT_WMDVSX

WMDVEX = LT_WMDVEX

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC EQ 0.

READ TABLE LT_WMDVEX WITH KEY

COM_DATE = DELIV_DATE.

IF SY-SUBRC EQ 0.

IF LT_WMDVEX-COM_QTY > quant.

STATUS = 1.

ELSE.

STATUS = 0.

ENDIF.

ENDIF.

ENDIF.

ENDFUNCTION.

This is only source code.

Try this.