cancel
Showing results for 
Search instead for 
Did you mean: 

Stock on a particulare date

Former Member
0 Kudos

Hi,

i am developing a STOCk-in-transit report, wherein , i need to display stock on a date entered by the user on selection screen. The stock includes all stock type (unrestricted, quality and blocked stock). How do we calculate the stock on a particular date?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Transaction MB5B does the similar functionality.

Here is how it goes.

1. Lets take a material with plant and a storage location. Get the current stock from table MARD.

( LABST = current stock available for unrestricted usage)

2. Go to MSEG for the given material, plant and storage location.

3. Get all the records between <the day u want stockvalue> to todays date.

4. based on the movement types u may have to cancel some of the entries ( if they are return, or if some records were cancelled).

5. calcualte the quantity from field MENGE by adding up all the records.

Former Member
0 Kudos

Hi sharath,

i want the stock on date which inlcudes the unrestricted stock, blocked stock and quality inspection stock. What are the fields which map to these kind of stocks?

Former Member
0 Kudos

safty stock...

MARC-EISBE

Valuated stock with unrestricted use

MARD-LABST

Stock in quality inspection

MARD-INSME

BLOCKED STOCK...

MARD-SPEME

Former Member
0 Kudos

Hi Nishant,

Check the following procedure. It may give you an insight.

On date Stock (Un-restricted + QI):

For Materials (MARD-MATNR) selected above, Plant (MARD-WERKS) = Input Plant and Storage Location (MARD-LGORT) NOT EQUAL TO “RT01”, determine all the un-restricted quantities (MARD-LABST) and Stock in Inspection (MARD-INSME). Sum up all the quantities. Let the sum be equal to “ST”.

For Posting date (MKPF-BUDAT) = current date, determine all the Material documents (MKPF-MBLNR).

For Documents (MSEG-MBLNR) determined above, Materials (MSEG-MATNR) selected above, Storage Location (MSEG- LGORT) NOT EQUAL “RT01”, Movement type (MSEG-BWART) NOT EQUAL to “321”, Debit / Credit indicator (MSEG-SHKZG) = “H” pick up all the quantities (MSEG-MENGE). Sum up all the quantities. Let the sum be equal to “H”.

Similarly, For Documents (MSEG-MBLNR) determined above, Materials (MSEG-MATNR) selected above, Storage Location (MSEG- LGORT) NOT EQUAL “RT01” Movement type (MSEG-BWART) NOT EQUAL to “321”, Debit / Credit indicator (MSEG-SHKZG) = “S” pick up all the quantities (MSEG-MENGE). Sum up all the quantities. Let the sum be equal to “S”.

Then On date Stock (Un-restricted + QI) = “ST” + “H” – “S”

Thanks and Regards,

Bharat Kumar Reddy.V

Former Member
0 Kudos

thanks for the help everyone..

just wanted to know if there is any function module which does this job straightaway...?

Regards

Nishant

PS: points will be awarded to helpful answers

Message was edited by: Nishant Gupta

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Try using the FM 'MD_MRP_LIST_API'

DATA: it_MDPSX TYPE TABLE OF MDPS WITH HEADER LINE,

it_MDEZX TYPE TABLE OF MDEZ WITH HEADER LINE,

it_MDSUX TYPE TABLE OF MDSU WITH HEADER LINE.

DATA: acum_mng01 TYPE mng01. " Needed Quantity.

" Get all the consumptions to after filter by date

CALL FUNCTION 'MD_MRP_LIST_API'

EXPORTING

  • PLSCN =

matnr = in_matnr

werks = in_werks

  • BERID =

  • AFIBZ =

SINFG = 'X'

  • LIFNR =

  • AFHOR =

  • DTNUM =

  • INPER =

  • DISPLAY_LIST_MDPSX =

  • DISPLAY_LIST_MDEZX =

  • DISPLAY_LIST_MDSUX =

  • IMPORTING

  • E_MT61D =

  • E_MDKP =

TABLES

MDPSX = it_MDPSX

MDEZX = it_mdezx

MDSUX = it_mdsux

EXCEPTIONS

MRP_LIST_NOT_FOUND = 1

MATERIAL_PLANT_NOT_FOUND = 2

ERROR = 3

OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

LOOP AT it_mdezx.

CASE it_mdezx-plumi.

WHEN '-'.

IF it_mdezx-dat00 IN DATE_RANGE. " Data range to consult

acum_mng01 = acum_mng01 + it_mdezx-mng01.

ENDIF.

ENDCASE.

ENDLOOP.

ENDIF.

Hope it helps you...

--

Alexis Sánchez

SAP ABAP Developer Consultant

Molen Services and Consulting, C.A.

former_member181962
Active Contributor
0 Kudos

MB_READ_MATERIAL_STOCKS may be useful.

Regards,

Ravi

Former Member
0 Kudos

Thanks ravi for the effort, but this Fm does not provide the stock on a particular date.

Cheers

Message was edited by: Nishant Gupta

Former Member
0 Kudos

GO TO TRANSACTION MD04.

there is sighn of sumation just click on that u get stock display by day , by month and by year . take the logic from there.....

Former Member
0 Kudos

Hello Nishant,

The tcode MB5B uses the logic of reverse calculation where it get the stock as of date and goes in reverse way by subtracting the positive mov and add to negative movements.

Former Member
0 Kudos

Hi Abhijit,

i have the parameter date on the slection screen. i need to display the stock( unrestricted, blocked, quantity) value on that date. What should be the logic applied to achieve this?

Cheers

PS: helpful answers would be rewarded

Former Member
0 Kudos

Hi Nishant,

try these BAPIs

BAPI_WHSE_STOCK_GET_DETAIL

BAPI_WHSE_STOCK_GET_LIST

Hope it helps...

Lokesh

pls. reward appropriate points

Former Member
0 Kudos

check out the logic in this program if it helps...

TABLES : MARA,MAKT,MARD,t001w,stpo,stas.

data : begin of t_mara occurs 0,

matnr like mara-matnr,

end of t_mara.

data : begin of t_mard occurs 0,

matnr like mara-matnr,

werks like mard-werks,

labst like mard-labst,

insme like mard-insme,

speme like mard-speme,

end of t_mard.

data : l_stk1 like mard-labst,

l_stk2 like mard-insme,

l_stk3 like mard-speme.

----


BOM -

DATA : BEGIN OF it_mast OCCURS 0,

matnr LIKE mast-matnr,

werks LIKE mast-werks,

stlan LIKE mast-stlan,

stlnr LIKE mast-stlnr,

stlal LIKE mast-stlal,

END OF it_mast.

DATA : BEGIN OF wa_mast OCCURS 0,

matnr LIKE mast-matnr,

werks LIKE mast-werks,

stlan LIKE mast-stlan,

stlnr LIKE mast-stlnr,

stlal LIKE mast-stlal,

END OF wa_mast.

DATA : BEGIN OF it_mast1 OCCURS 0,

matnr LIKE mast-matnr,

werks LIKE mast-werks,

stlan LIKE mast-stlan,

stlnr LIKE mast-stlnr,

stlal LIKE mast-stlal,

END OF it_mast1.

DATA : BEGIN OF it_stas OCCURS 0,

stlty LIKE stas-stlty,

stlnr LIKE stas-stlnr,

stlal LIKE stas-stlal,

stlkn LIKE stas-stlkn,

stasz LIKE stas-stasz,

datuv LIKE stas-datuv,

stvkn LIKE stas-stvkn,

END OF it_stas.

DATA : BEGIN OF it_stpo OCCURS 0,

stlty LIKE stpo-stlty,

stlnr LIKE stpo-stlnr,

stlkn LIKE stpo-stlkn,

stpoz LIKE stpo-stpoz,

idnrk LIKE stpo-idnrk,

meins LIKE stpo-meins,

menge LIKE stpo-menge,

END OF it_stpo.

DATA : BEGIN OF t_stpo OCCURS 0,

stlty LIKE stpo-stlty,

stlnr LIKE stpo-stlnr,

stlkn LIKE stpo-stlkn,

stpoz LIKE stpo-stpoz,

idnrk LIKE stpo-idnrk,

meins LIKE stpo-meins,

menge LIKE stpo-menge,

END OF t_stpo.

DATA : BEGIN OF wa_stpo1 OCCURS 0,

stlty LIKE stpo-stlty,

stlnr LIKE stpo-stlnr,

stlkn LIKE stpo-stlkn,

stpoz LIKE stpo-stpoz,

idnrk LIKE stpo-idnrk,

meins LIKE stpo-meins,

menge LIKE stpo-menge,

END OF wa_stpo1.

data: begin of it_final occurs 0,

stlnr like stpo-stlnr,

matnr like mast-matnr,

menge like stpo-menge,

end of it_final.

data: begin of it_final1 occurs 0,

stlnr like stpo-stlnr,

matnr like mast-matnr,

menge like stpo-menge,

end of it_final1.

data mult_par type c.

--


END OF BOM--

data: WA_TOTSTK like mard-speme.

data G_Matno like mara-matnr.

data bom_req_qty like mard-speme.

data WA_AVLSTUS like mard-speme.

select-options: S_Matno FOR mara-matnr.

parameterS : P_plant like t001w-werks,

P_BOM like mara-matnr.

perform validation.

perform Inputdata.

perform Calcdata.

form validation.

if S_Matno is initial.

message e001 with text-001.

ENDIF.

if P_plant is initial.

message e001 with text-002.

endif.

if P_BOM is initial.

message e001 with text-003.

endif.

select matnr from mara INTO table t_mara

where matnr in S_Matno.

if sy-subrc <> 0.

message e001 with text-004.

endif.

select single * from t001w where werks = P_plant.

if sy-subrc <> 0.

message e001 with text-005.

endif.

select single * from mara where matnr = P_BOM.

if sy-subrc <> 0.

message e001 with text-004.

endif.

endform.

form Inputdata.

select matnr from mara into table t_mara

where matnr in S_Matno.

if sy-subrc = 0.

select matnr werks labst insme speme from

mard into table t_mard

for all entries in t_mara

where matnr = t_mara-matnr and

werks = P_plant.

endif.

endform.

form Calcdata.

loop at t_mara.

select single * from makt where matnr = t_mara-matnr.

if sy-subrc = 0.

G_Matno = t_mara-matnr.

*WRITE:/ SY-ULINE(164).

WRITE:1 sy-vline.

write:2 t_mara-matnr.

write:19 sy-vline.

write:20 makt-maktx.

write:56 sy-vline.

endif.

loop at t_mard.

if t_mard-matnr = t_mara-matnr.

l_stk1 = l_stk1 + t_mard-labst.

l_stk2 = l_stk2 + t_mard-insme.

l_stk3 = l_stk3 + t_mard-speme.

endif.

endloop.

write:57 l_stk1.

write:74 sy-vline.

write:75 l_stk2.

write:92 sy-vline.

write:93 l_stk3.

write:110 sy-vline.

WA_TOTSTK = l_stk1 + l_stk2 + l_stk3.

write:111 WA_TOTSTK.

WRITE:128 SY-VLINE.

perform BOMDATA.

write:129 bom_req_qty.

write:146 sy-vline.

if bom_req_qty >= 1.

WA_AVLSTUS = ( ( 1 / bom_req_qty ) * WA_TOTSTK ).

else.

WA_AVLSTUS = '0.00'.

ENDIF.

write:147 WA_AVLSTUS.

write:164 sy-vline.

write:sy-uline(164).

clear l_stk1.

clear l_stk2.

clear l_stk3.

clear bom_req_qty.

clear WA_TOTSTK.

endloop.

endform.

FORM BOMDATA.

select matnr werks stlan stlnr stlal from mast into

table it_mast

where matnr = P_BOM and stlal = '01' and stlan = '1'

and werks = P_plant.

if sy-subrc = 0.

select stlty stlnr stlal stlkn stasz datuv stvkn from stas

into table it_stas

for all entries in it_mast

where stlnr = it_mast-stlnr and

stlal = it_mast-stlal and

stlty = 'M'.

if sy-subrc = 0.

SELECT stlty stlnr stlkn stpoz idnrk meins menge from stpo into table it_stpo

for all entries in it_stas

where stlty = 'M' and

stlnr = it_stas-stlnr and

stlkn = it_stas-stlkn.

endif.

endif.

perform get_data.

perform process_data.

perform display_data.

ENDFORM.

form process_data.

if mult_par = 'Y'.

refresh it_stpo.

loop at wa_mast.

select matnr werks stlan stlnr stlal from mast into table it_mast

where matnr = wa_mast-matnr

and stlal = '01' and stlan = '1'.

if sy-subrc = 0.

loop at it_mast.

SELECT stlty stlnr stlkn stpoz idnrk meins menge from stpo into table wa_stpo1

where stlnr = it_mast-stlnr.

if sy-subrc = 0.

clear wa_stpo1.

loop at wa_stpo1.

read table t_stpo with key idnrk = wa_mast-matnr.

if t_stpo-menge > 1.

it_stpo-stlty = wa_stpo1-stlty.

it_stpo-stlnr = wa_stpo1-stlnr.

it_stpo-stlkn = wa_stpo1-stlkn.

it_stpo-idnrk = wa_stpo1-idnrk.

it_stpo-meins = wa_stpo1-meins.

it_stpo-menge = wa_stpo1-menge * 2.

else.

move-corresponding wa_stpo1 to it_stpo.

endif.

append it_stpo.

clear wa_stpo1.

clear it_stpo.

endloop.

refresh wa_stpo1.

clear wa_mast.

endif.

endloop.

endif.

endloop.

refresh wa_mast.

perform get_data.

ELSE.

perform display_data.

endif.

endform. "process_data

form get_data.

loop at it_stpo.

select matnr werks stlan stlnr stlal from mast into

table it_mast

where matnr = it_stpo-idnrk

and stlal = '01' and stlan = '1'.

if not it_mast[] is initial.

loop at it_mast.

move-corresponding it_mast to wa_mast.

append wa_mast.

move-corresponding it_stpo to t_stpo.

append t_stpo.

endloop.

clear t_stpo.

else.

it_final-stlnr = it_stpo-stlnr.

it_final-matnr = it_stpo-idnrk.

it_final-menge = it_stpo-menge.

append it_final.

endif.

endloop.

if not wa_mast[] is initial.

mult_par = 'Y'.

clear it_stpo.

else.

mult_par = ''.

endif.

loop at it_final.

move-corresponding it_final to it_final1.

append it_final1.

endloop.

refresh it_final.

refresh it_mast.

perform process_data.

endform. "get_data

form display_data.

sort it_final1 by matnr.

loop at it_final1.

if it_final1-matnr = G_Matno.

bom_req_qty = bom_req_qty + it_final1-menge.

endif.

endloop.

refresh it_stpo.

refresh it_mast.

clear it_final1.

REFRESH it_final1.

endform. "display_data

TOP-OF-PAGE.

WRITE:/ SY-ULINE(164).

WRITE:/1 SY-VLINE,

2 'Part Number',

19 sy-vline,

20 'Description',

56 sy-vline,

57 'Unrestricted Qty',

74 sy-vline,

75 'Quality Qty',

92 sy-vline,

93 'Blocked Qty',

110 sy-vline,

111 'Tot. Avl. Stk',

128 sy-vline,

129 ' Q/E ',

146 SY-VLINE,

147 'Avl Status',

164 sy-vline.

WRITE:SY-ULINE(164).

Regards,

Bikash