3
12/14/2015 Opening And Closing Stock For A Material ( MATN... | SCN http://scn.sap.com/docs/DOC25803 1/3 Getting Started Newsletters Store Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business UniversityAlliances Events & Webinars Innovation Log On Join Us Hi, Guest Search the Community Activity Communications Actions Brow se 0 Tw eet created by animesh sundriyal on Mar 23, 2012 9:43 PM, last modified by Thomas Zloch on Mar 23, 2012 9:55 PM Hello Folks, This document describes the code for getting the opening stock and the closing stock for a particular material ( MATNR ), plant ( WERKS ) and storage location ( LGORT ). In most of my projects i have seen Stock Report as a common requirement, so after lots of discussion i have created this subroutine for getting the stock details for a particular material, plant and storage location combination. Here is the snipped code or say subroutine for making that Use this as a input PERFORM sub_get_open_close_stock USING wa_outputmatnr wa_outputwerks wa_outputlgort CHANGING wa_outputop_stk_total wa_outputcls_stk_tot wa_outputissue wa_outputreceipt. *&* *& Form SUB_GET_OPEN_CLOSE_STOCK *&* * text ** * >P_WA_OUTPUT_MATNR text * >P_WA_OUTPUT_WERKS text * >P_WA_OUTPUT_LGORT text * <P_WA_OUTPUT_OP_STK_TOTAL text * <P_WA_OUTPUT_CLS_STK_TOT text ** FORM sub_get_open_close_stock USING p_wa_output_matnr p_wa_output_werks p_wa_output_lgort CHANGING p_wa_output_op_stk_total p_wa_output_cls_stk_tot p_issue p_receipt. DATA : it_mardv TYPE STANDARD TABLE OF mard. DATA : it_mskav TYPE STANDARD TABLE OF mska. DATA : it_wb2 TYPE STANDARD TABLE OF wb2_v_mkpf_mseg2. DATA : it_wb3 TYPE STANDARD TABLE OF wb2_v_mkpf_mseg2. DATA : wa_wb2 TYPE wb2_v_mkpf_mseg2. DATA : wa_wb3 TYPE wb2_v_mkpf_mseg2. DATA : wa_mardv TYPE mard. DATA : wa_mskav TYPE mska. DATA : w_mard TYPE labst. DATA : w_mska TYPE labst. DATA : w_mardv TYPE labst. DATA : w_mskav TYPE labst. DATA : w_mard_mska TYPE labst. DATA : w_menge1 TYPE menge_d. DATA : w_menge2 TYPE menge_d. DATA : w_menge3 TYPE menge_d. DATA : l_date_low TYPE sydatum. SELECT * FROM mard INTO TABLE it_mardv WHERE matnr = p_wa_output_matnr AND werks = p_wa_output_werks AND lgort = p_wa_output_lgort. IF sysubrc = 0. LOOP AT it_mardv INTO wa_mardv. w_mard = wa_mardvlabst + wa_mardvinsme + wa_mardveinme + wa_mardvspeme + Opening And Closing Stock For A Material ( MATNR ), Plant ( WERKS ) and Storage Location ( LGORT ) Share Version 2

Opening and Closing Stock for a Material ( MATN

Embed Size (px)

DESCRIPTION

opening and closing stock

Citation preview

Page 1: Opening and Closing Stock for a Material ( MATN

12/14/2015 Opening And Closing Stock For A Material ( MATN... |  SCN

http://scn.sap.com/docs/DOC25803 1/3

Getting Started Newsletters Store   

Products Services & Support About SCN Downloads

Industries Training & Education Partnership Developer Center

Lines of Business University Alliances Events & Webinars Innovation

Log On Join UsHi, Guest Search the Community

Activity Communications Actions

Browse

0 Tw eet

created by animesh sundriyal on Mar 23, 2012 9:43 PM, last modif ied by Thomas Zloch on Mar 23, 2012 9:55 PM

Hello Folks,This document describes the code for getting the opening stock and the closing stock for a particular material (MATNR ), plant ( WERKS ) and storage location ( LGORT ). In most of my projects i have seen Stock Report as acommon requirement, so after lots of discussion i have created this subroutine for getting the stock details for aparticular material, plant and storage location combination. Here is the snipped code or say subroutine for making thatUse this as a inputPERFORM sub_get_open_close_stock USING wa_outputmatnr

                                            wa_outputwerks

                                            wa_outputlgort

                                     CHANGING wa_outputop_stk_total

                                              wa_outputcls_stk_tot

                                              wa_outputissue

                                              wa_outputreceipt.

 *&*

*&      Form  SUB_GET_OPEN_CLOSE_STOCK

*&*

*       text

**

*      >P_WA_OUTPUT_MATNR  text

*      >P_WA_OUTPUT_WERKS  text

*      >P_WA_OUTPUT_LGORT  text

*      <P_WA_OUTPUT_OP_STK_TOTAL  text

*      <P_WA_OUTPUT_CLS_STK_TOT  text

**

FORM sub_get_open_close_stock  USING    p_wa_output_matnr

                                         p_wa_output_werks

                                         p_wa_output_lgort

                                CHANGING p_wa_output_op_stk_total

                                         p_wa_output_cls_stk_tot

                                         p_issue

                                         p_receipt.

   DATA : it_mardv TYPE STANDARD TABLE OF mard.

   DATA : it_mskav TYPE STANDARD TABLE OF mska.

   DATA : it_wb2   TYPE STANDARD TABLE OF wb2_v_mkpf_mseg2.

   DATA : it_wb3   TYPE STANDARD TABLE OF wb2_v_mkpf_mseg2.

   DATA : wa_wb2   TYPE wb2_v_mkpf_mseg2.

   DATA : wa_wb3   TYPE wb2_v_mkpf_mseg2.

   DATA : wa_mardv TYPE mard.

   DATA : wa_mskav TYPE mska.

   DATA : w_mard   TYPE labst.

   DATA : w_mska   TYPE labst.

   DATA : w_mardv  TYPE labst.

   DATA : w_mskav  TYPE labst.

   DATA : w_mard_mska  TYPE labst.

   DATA : w_menge1 TYPE menge_d.

   DATA : w_menge2 TYPE menge_d.

   DATA : w_menge3 TYPE menge_d.

   DATA : l_date_low TYPE sydatum.

   SELECT * FROM mard INTO TABLE it_mardv

                      WHERE matnr = p_wa_output_matnr

                        AND werks = p_wa_output_werks

                        AND lgort = p_wa_output_lgort.

   IF sysubrc = 0.

     LOOP AT it_mardv INTO wa_mardv.

       w_mard = wa_mardvlabst + wa_mardvinsme + wa_mardveinme + wa_mardvspeme +

Opening And Closing Stock For A Material (MATNR ), Plant ( WERKS ) and StorageLocation ( LGORT )

Share

Version 2

Page 2: Opening and Closing Stock for a Material ( MATN

12/14/2015 Opening And Closing Stock For A Material ( MATN... |  SCN

http://scn.sap.com/docs/DOC25803 2/3

                 wa_mardvretme + wa_mardvvmlab +  wa_mardvvmins +  wa_mardvvmein +

                 wa_mardvvmspe + wa_mardvvmret.

       w_mardv = w_mardv + w_mard.

       CLEAR : w_mard.

     ENDLOOP.

   ENDIF.

   SELECT * FROM mska INTO TABLE it_mskav

                      WHERE matnr = p_wa_output_matnr

                        AND werks = p_wa_output_werks

                        AND lgort = p_wa_output_lgort.

   IF sysubrc = 0.

     LOOP AT it_mskav INTO wa_mskav.

       w_mska = wa_mskavkalab + wa_mskavkains + wa_mskavkaspe + wa_mskavkavla +

wa_mskavkavin + wa_mskavkavsp.

       w_mskav = w_mskav + w_mska.

       CLEAR : w_mska.

     ENDLOOP.

   ENDIF.

   w_mard_mska = w_mardv + w_mskav. " X

* If User not entered the Date Range

   IF s_datehigh IS INITIAL.

     s_datehigh = s_datelow.

   ENDIF.

   l_date_low = s_datehigh + 1.

   SELECT * FROM wb2_v_mkpf_mseg2 INTO TABLE it_wb2

            WHERE matnr_i = p_wa_output_matnr

              AND werks_i = p_wa_output_werks

              AND lgort_i = p_wa_output_lgort

              AND budat BETWEEN l_date_low AND sydatum.

   IF sysubrc = 0.

     LOOP AT it_wb2 INTO wa_wb2.

       IF wa_wb2shkzg_i = 'S'.

         w_menge1 = w_menge1 + wa_wb2menge_i.

       ELSEIF wa_wb2shkzg_i = 'H'.

         w_menge2 = w_menge2 + wa_wb2menge_i.

       ENDIF.

     ENDLOOP.

     w_menge3 = w_menge1  w_menge2.  " Y

     CLEAR : w_menge1, w_menge2.

   ENDIF.

*  Closing Stock Z = X  Y.

   p_wa_output_cls_stk_tot = w_mard_mska  w_menge3.

   CLEAR : w_menge3.

* Opening Stock Logic

   SELECT * FROM wb2_v_mkpf_mseg2 INTO TABLE it_wb3

          WHERE matnr_i = p_wa_output_matnr

            AND werks_i = p_wa_output_werks

            AND lgort_i = p_wa_output_lgort

            AND budat BETWEEN s_datelow AND s_datehigh.

   IF sysubrc = 0.

     LOOP AT it_wb3 INTO wa_wb3.

       IF wa_wb3shkzg_i = 'S'.

         w_menge1 = w_menge1 + wa_wb3menge_i.

       ELSEIF wa_wb3shkzg_i = 'H'.

         w_menge2 = w_menge2 + wa_wb3menge_i.

       ENDIF.

     ENDLOOP.

     w_menge3  = w_menge1  w_menge2.  " A

     p_issue   = w_menge2. " Issue

     p_receipt = w_menge1. " Receipt

     CLEAR : w_menge1, w_menge2.

   ENDIF.

* Calculation for Opening Stock Z  A = B

   p_wa_output_op_stk_total = p_wa_output_cls_stk_tot  w_menge3.

   CLEAR : w_menge3.

ENDFORM.                    " SUB_GET_OPEN_CLOSE_STOCK

1186 View s   Categories: ABAP Development   Topics: abap