cancel
Showing results for 
Search instead for 
Did you mean: 

Opening Stock and closing Stock

Former Member
0 Kudos

Hi Abapers ,

                  I have a requirement of opening stock and closing .

I have records in my internal table like this ,

                     material          doc.no          openingqty          closing qty

                     ------------------------------------------------------------------------------------

                      100-100          101               50                         70

                       100-100          102               60                         80

100-101      201            60                         90

                        100-101          202          40                              20

My requirement is the output should appear as follows that the closing qty  should be the opening qty of next doc no .

                   material               doc no               openingqty               closingqty

                 ------------------------------------------------------------------------------------------------------

                    100-100                 101                    50                         70   

                     100-100               102                   70                         80

                      100-101               201                    60                        90

                      100-101               202                   90                         20

Regards ,

Rocky

<thread locked by moderator, spoonfeeding is bad for health>

Message was edited by: Manish Kumar

Accepted Solutions (0)

Answers (3)

Answers (3)

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

Pass the contents of internal table to another internal table.

it_temp[]  = itab[].

Sort it_temp by matnr doc.

Delete adjacent duplicates comparing matnr.

loop at itab into wa.

read table it_temp into wa_temp with key matnr = wa-matnr.

if sy-subrc = 0.

wa-openingstock  = wa_temp-closingstock.

endif.

modify itab from wa.

endloop.

Hope it helpful.

Regards,

Venkat.

ipravir
Active Contributor
0 Kudos

Hi raj,

Please find below the logic to arrange the information as per your requirement.

sort internal_table by Material mov._type.

data: mat type matnr,

        closing_val type related_data_type.

Loop at Internal_table in wa.

     if mat is initial.

          mat = wa-matrn.

          closing_val = wa-closingqty.

     elseif mat eq wa-matner.

          wa-openingQty = closing_val.

          modify internal_table from wa index sy-tabix.

         closing_val = wa-closingqty.

     elseif mat ne wa-matnr.

           mat = wa-matrn.

          closing_val = wa-closingqty.

     endif.

endloop.

Regards.

Praveer.

Former Member
0 Kudos

   Hi Praveen ,

i have to do the calcultaions also based on debit and crdit quantity .

how can i do the calculations for the values .

                material               doc no               openingqty     shkzg             qty      closingqty

                 ------------------------------------------------------------------------------------------------------

                    100-100                 101                    50              S              20           70    

                     100-100               102                   70               S              10            80

                      100-101               201                    60              S             30            90

                      100-101               202                   90              H              70           20

kindly give me sme code for the output with calculation based on debit and credit .

final output should look like above.

Thanks & Regards ,

Rocky

ipravir
Active Contributor
0 Kudos

Hi Raj,

In the sme logic you can do the Calculation.

Loop at Internal_table in wa.

     if mat is initial.

          mat = wa-matrn.

           if H.

               closing_val = wa-closingqty - qty.

          elseif S

               closing_val = wa-closingqty + qty.

          endif.    

          wa-closingqty = closing_val.

          modify internal_table from wa index sy-tabix.

     elseif mat eq wa-matner.

          wa-openingQty = closing_val.

     

           if H.

               closing_val = wa-closingqty - qty.

          elseif S

               closing_val = wa-closingqty + qty.

          endif.

       

     

wa-closingqty = closing_val.

      modify internal_table from wa index sy-tabix.

     elseif mat ne wa-matnr.

           mat = wa-matrn.

           if H.

               closing_val = wa-closingqty - qty.

          elseif S

               closing_val = wa-closingqty + qty.

          endif.

        wa-closingqty = closing_val.

          modify internal_table from wa index sy-tabix.

     endif.

endloop.

Regards.

Praveer

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Rocky,

For every record you need to check whether previous document number for the same material is exist or not. (Check Doc.No = (Doc.No - 1)). If you find the record, change the opening stock with closing stock of record found.

Regards,

Vijay

Former Member
0 Kudos

Can u pls send the code ?

Regards ,

Rocky

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Rocky,

SORT ITAB BY MATNR DOC.

LOOP AT ITAB INTO WA.

     LV_DOC = WA_DOC - 1. " LV_DOC TYPE I.

   

     READ ITAB INTO WA1 WITH KEY MATNR = WA-MATNR DOC = LV_DOC

     BINARY SEARCH.

   

     IF SY-SUBRC = 0.

          WA-OPEN = WA1-CLOSE.

     ENDIF.

ENDLOOP.

Regards,

Vijay

Former Member
0 Kudos

Hi Vijay ,

               When ever the read is performing it doesnot match the doc_no condition .

Thanks & Regards

Rocky

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Rocky,

Convert that Integer DOC number into Character.

LV_DOC1 = LV_DOC. " LV_DOC1 TYPE C. (Document number type).

     READ ITAB INTO WA1 WITH KEY MATNR = WA-MATNR DOC = LV_DOC1

     BINARY SEARCH.

Don't forget to sort the table before you loop.

Regards,

Vijay

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Rocky,

I am sorry, I made it so complex. Please change it.

SORT ITAB BY MATNR DOC.

LOOP AT ITAB INTO WA.

     LV_DOC = WA_DOC - 1. " LV_DOC TYPE C (as doc type).

  

     READ ITAB INTO WA1 WITH KEY MATNR = WA-MATNR DOC = LV_DOC

     BINARY SEARCH.

  

     IF SY-SUBRC = 0.

          WA-OPEN = WA1-CLOSE.

     ENDIF.

ENDLOOP.

Regards,

Vijay