Application Development 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: 

Material Number Stock

Former Member
0 Kudos

Hi,

Is there any table in R/3 or a function module that will

give the opening balance for the material number related to a particular plant.

Regards,

Amit.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, check table MARD. This will give you the stock of the material for the plant/storage location.

You could also get the total stock for the material/plant from MBEW.

Welcome to SDN!! Please remember to award points for helpful answers and mark your posts as solved when answered completely. Thanks.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, check table MARD. This will give you the stock of the material for the plant/storage location.

You could also get the total stock for the material/plant from MBEW.

Welcome to SDN!! Please remember to award points for helpful answers and mark your posts as solved when answered completely. Thanks.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

Opening stock as of a particular date? No, there is no table that gives you this information, you have calculate it. I don't remember any function module either that will give you this information, but I will look.

Srinivas

Former Member
0 Kudos

hi Amit,

Pls check the tables S031, S032.

But I don't think we have any direct approach,we have to calculate based on movement types from table MSEG.

Regards

Sirish

Former Member
0 Kudos

Hi Amit,

The below Custom FM will give you the material stock based on key date and plant.

Hope it serves your requirement.

Regards,

Raj

FUNCTION ZMM_OPBAL_KEYDATE.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(I_MATNR) LIKE MARA-MATNR

*" REFERENCE(I_PLANT) LIKE T001W-WERKS

*" REFERENCE(I_KEYDT) LIKE BSIM-BUDAT

*" EXPORTING

*" REFERENCE(E_STK_OPBAL) LIKE BSIM-MENGE

*" REFERENCE(E_STK_VAL) LIKE BSIM-DMBTR

*"----


DATA : V_STK_OPBAL LIKE BSIM-MENGE,

V_STK_VAL LIKE BSIM-DMBTR,

V_KEYDT LIKE BSIM-BUDAT.

DATA : BEGIN OF IT_BSIM OCCURS 0,

MATNR LIKE BSIM-MATNR,

SHKZG LIKE BSIM-SHKZG,

MENGE LIKE BSIM-MENGE,

DMBTR LIKE BSIM-DMBTR,

END OF IT_BSIM.

DATA: BEGIN OF IT_MARD OCCURS 0,

MATNR LIKE MARD-MATNR, " Material

LABST LIKE MARD-LABST, " Unrestricted

END OF IT_MARD.

TYPES: BEGIN OF ST_MSEG,

MATNR LIKE MSEG-MATNR,

SHKZG LIKE MSEG-SHKZG,

MENGE LIKE MSEG-MENGE,

DMBTR LIKE MSEG-DMBTR,

BWART LIKE MSEG-BWART,

LGORT LIKE MSEG-LGORT,

END OF ST_MSEG.

DATA : IT_MSEG TYPE ST_MSEG OCCURS 0 WITH HEADER LINE,

TMP_MSEG TYPE ST_MSEG OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF IT_MBEW OCCURS 0,

MATNR LIKE MBEW-MATNR,

LBKUM LIKE MBEW-LBKUM,

SALK3 LIKE MBEW-SALK3,

END OF IT_MBEW.

V_KEYDT = I_KEYDT + 1.

SELECT MATNR

SHKZG

SUM( MENGE )

SUM( DMBTR )

INTO TABLE IT_BSIM

FROM BSIM

WHERE MATNR EQ I_MATNR

AND BWKEY EQ I_PLANT

AND BUDAT GE V_KEYDT

AND BLART IN ('RE','WE','WA','PR')

GROUP BY MATNR SHKZG.

SELECT MATNR

SUM( LBKUM )

SUM( SALK3 )

INTO TABLE IT_MBEW

FROM MBEW

WHERE MATNR EQ I_MATNR

AND BWKEY EQ I_PLANT

AND VPRSV EQ 'V'

AND BWTAR EQ ''

GROUP BY MATNR VPRSV.

SELECT MATNR

SUM( LABST )

INTO TABLE IT_MARD

FROM MARD

WHERE MATNR EQ I_MATNR

AND WERKS EQ I_PLANT

GROUP BY MATNR LABST.

SELECT A~MATNR

A~SHKZG

SUM( A~MENGE )

SUM( A~DMBTR )

A~BWART

A~LGORT

INTO TABLE IT_MSEG

FROM MKPF AS B

JOIN MSEG AS A

ON BMBLNR EQ AMBLNR

AND BMJAHR EQ AMJAHR

WHERE A~MATNR EQ I_MATNR

AND A~WERKS EQ I_PLANT

AND A~KZBEW IN (' ','B')

AND A~BWART NOT IN ('541','542','321','322','121')

AND A~KZVBR NOT IN ('A')

AND B~BUDAT GE V_KEYDT

GROUP BY AMATNR ASHKZG ABWART ALGORT.

LOOP AT IT_MSEG WHERE BWART EQ '544' AND LGORT EQ ''.

TMP_MSEG = IT_MSEG.

APPEND TMP_MSEG.

ENDLOOP.

DELETE IT_MSEG WHERE ( BWART EQ '309' AND DMBTR EQ 0 ).

DELETE IT_MSEG WHERE ( BWART NE '543' AND LGORT EQ '' ).

LOOP AT TMP_MSEG.

IT_MSEG = TMP_MSEG.

APPEND IT_MSEG.

ENDLOOP.

READ TABLE IT_MBEW WITH KEY MATNR = I_MATNR.

V_STK_OPBAL = IT_MBEW-LBKUM.

V_STK_VAL = IT_MBEW-SALK3.

*- If Read on MBEW fails, Get data from IT_MARD

READ TABLE IT_MARD WITH KEY MATNR = I_MATNR.

IF SY-SUBRC = 0.

V_STK_OPBAL = IT_MARD-LABST.

ENDIF.

LOOP AT IT_MSEG.

IF IT_MSEG-SHKZG EQ 'S'.

V_STK_OPBAL = V_STK_OPBAL - IT_MSEG-MENGE.

ELSE.

V_STK_OPBAL = V_STK_OPBAL + IT_MSEG-MENGE.

ENDIF.

ENDLOOP.

LOOP AT IT_BSIM.

IF IT_BSIM-SHKZG EQ 'S'.

  • V_STK_OPBAL = V_STK_OPBAL - IT_BSIM-MENGE.

V_STK_VAL = V_STK_VAL - IT_BSIM-DMBTR.

ELSE.

  • V_STK_OPBAL = V_STK_OPBAL + IT_BSIM-MENGE.

V_STK_VAL = V_STK_VAL + IT_BSIM-DMBTR.

ENDIF.

ENDLOOP.

E_STK_OPBAL = V_STK_OPBAL.

E_STK_VAL = V_STK_VAL.

ENDFUNCTION.