We have added search box. Key in SAP issue keyword to search
TopBottom

Announcement: wanna exchange links? contact me at sapchatroom@gmail.com.

Re: [sap-dev] opening /closing stock similar to mb5b

Posted by Admin at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Posted by VARADU (ERP)
on Sep 5 at 7:54 AM
Mark this reply as helpfulMark as helpful
Hi,

Reopening the subject. Have found FM?? /OBIZ/ZUXG_GET_OPENING_STOCK for obtaining Plant stock.

Request to explore similar FM for Special stock (o-type) - stock provided to vendor? for a specific period please.

Rajan.


--- On Sun, 5/9/10, varadarajan kupparao email@removed wrote:


From: varadarajan kupparao email@removed
Subject: Re: [sap-dev] opening /closing stock similar to mb5b
To: sap-dev@Groups.ITtoolbox.com
Date: Sunday, 5 September, 2010, 12:44 PM







Hi
?
Just

--- On Thu, 26/8/10, varadarajan kupparao email@removed wrote:


From: varadarajan kupparao email@removed
Subject: Re: [sap-dev] opening /closing stock similar to mb5b
To: sap-dev@Groups.ITtoolbox.com
Date: Thursday, 26 August, 2010, 8:35 PM







Hi Mike
?
I must thank you and Horacio zapettini for giving valuable inputs in time.
?
This would help me to proceed further.
?
Thank u once again,
?
Regards,
?
Rajan
--- On Thu, 26/8/10, Mike Hammond via sap-dev <sap-dev@Groups.ITtoolbox.com>> wrote:


From: Mike Hammond via sap-dev <sap-dev@Groups.ITtoolbox.com>>
Subject: Re: [sap-dev] opening /closing stock similar to mb5b
To: "VARADU" email@removed
Date: Thursday, 26 August, 2010, 2:45 AM











Posted by Mike Hammond
on Aug 25 at 5:17 PM
Mark as helpful



Thanks again, much appreciated!

From: horacio zapettini via sap-dev <sap-dev@Groups.ITtoolbox.com>>
To: Mike Hammond email@removed
Sent: Wed, August 25, 2010 1:05:54 PM
Subject: RE: [sap-dev] opening /closing stock similar to mb5b

Posted by horacio zapettini
on Aug 25 at 4:09 PM Mark as helpful
The code is still alive in different pages on the NET. Just google with "horacio zapettini"+ ZUseOfHashedTables+toolbox and you'll get a list of pages.

I must say that I only posted it at toolbox (former ittoolbox). You can find it here: http://sap.ittoolbox.com/code/archive/332/

HTH

Ps: not even for large sets of data. You can think a hashed table as if it were a DDic table on memory with a unique key. They don't handle indexed access (i.e read table itab index ...) so the performance to insert, update, delete records, read records with key is really improved.
They are faster compared to the other tables. (i.e. standard, sorted, any, old fashioned occurs n, ...)
Of course, they have some limitations (you must manage yourself to ensure a unique key, if you want to do a header -> items nested loop that works fast, you can do it , but... you have to use some tricks. (i've done it lot of times :). And you can treat them as if they were standard tables in loops with where clause or even in read table with key... But, doing this last things you're loosing the benefits of improved performance they have.


________________________________
De: Mike Hammond via sap-dev [mailto:sap-dev@Groups.ITtoolbox.com]]
Enviado el: Mi?rcoles, 25 de Agosto de 2010 03:51 p.m.
Para: Horacio Zapettini
Asunto: Re: [sap-dev] opening /closing stock similar to mb5b

[http://userimages.toolbox.com/user/b_849421.jpg] Posted by Mike Hammond
on Aug 25 at 2:53 PM [http://images.ittoolbox.com/vt/icons/vote.png] Mark as helpful<http://it.toolbox.com/api/ContentVote/3718103/1/1/ >
Horacio,

Will definitely check it out. I know that hashed tables are the way to go for large sets of data; haven't played with them yet. Thanks for the tip...

Mike

From: horacio zapettini via sap-dev <sap-dev@Groups.ITtoolbox.com>><http://http://http://http://Groups.ITtoolbox.com>>>
To: Mike Hammond email@removed
Sent: Wed, August 25, 2010 10:22:28 AM
Subject: RE: [sap-dev] opening /closing stock similar to mb5b

Posted by horacio zapettini
on Aug 25 at 1:24 PM Mark as helpful
My two cents here:
with regards to performance issues, some years ago I posted a code example about how to use hashed tables. This code, was also meant to show how to retrieve data from mkpf-mseg faster. Perhaps it's helpful for you and for Rajan too.

________________________________
De: Mike Hammond via sap-dev [mailto:sap-dev@Groups.ITtoolbox.com]]<http://http://http://http://Groups.ITtoolbox.com]]>
Enviado el: Mi?rcoles, 25 de Agosto de 2010 02:01 p.m.
Para: Horacio Zapettini
Asunto: Re: [sap-dev] opening /closing stock similar to mb5b

[http://userimages.toolbox.com/user/b_849421.jpg] Posted by Mike Hammond
on Aug 25 at 1:01 PM [http://images.ittoolbox.com/vt/icons/vote.png] Mark as helpful<http://it.toolbox.com/api/ContentVote/3717817/1/1/ ><http://it.toolbox.com/api/ContentVote/3717817/1/1/ >>>
Hi Varadu,
Horacio is correct; we join MKPF with MSEG. You are also obviously correct, it is a huge amount of data to weed through.

Our report begins by selecting material numbers from a join of MARA and MARC according to user selections.

SELECT
a~matnr "Material number
b~werks "Plant
b~prctr "Profit center
a~spart "Division
INTO TABLE it_material
FROM mara AS a INNER JOIN marc AS b ON a~matnr = b~matnr
WHERE a~matnr IN s_matnr
AND b~werks IN s_werks
AND b~prctr IN s_prctr
AND a~spart IN s_spart.

IF sy-subrc <> 0.
MESSAGE i004. "No records found that meet entered criteria
LEAVE LIST-PROCESSING.
ELSE.
SORT it_material BY matnr werks.
ENDIF.

We then obtain the MARD/MARDH data and match it with the records selected above into table IT_REPORT.

Then get the MKPF/MSEG data:
SELECT
a~mblnr "Material document #
a~budat "Posting date
b~zeile "Item in material doc
b~bwart "Movement type
b~matnr "Material number
b~werks "Plant
b~shkzg "debit / credit indicator
b~menge "Quantity
FROM mkpf AS a INNER JOIN mseg AS b
ON a~mblnr = b~mblnr AND
a~mjahr = b~mjahr
INTO TABLE it_mvmt
FOR ALL ENTRIES IN it_report
* WHERE a~mjahr IN gv_year "bp01
WHERE a~mjahr IN lr_year "bp01
AND a~budat IN lr_date
AND ( b~bwart IN s_ibwart OR b~bwart IN s_obwart )
and B~MATNR = IT_REPORT-MATNR
AND b~werks = it_report-werks.

IF sy-subrc = 0.
SORT it_mvmt BY matnr werks.
ENDIF.

Note: the select option s_ibwart and s_obwart are the inbound and outbound movement types that should be considered as moving into or out of blocked stock in a warehouse (this is a blocked stock report). These values were determined by one of our MM functional guys (when we still had them). When our material documents are created with new or incorrect movement types, it messes this report up, for obvious reasons. The logic that we use is below:
* Local variable declariations
lv_bedat = s_date-low.
lv_loopindx = 1.
* start of use of Parellel Cursor method
LOOP AT it_report.
lv_tabix = sy-tabix.
CLEAR lv_recfnd.
* get Moving average price when material changes.
IF lv_matnr <> it_report-matnr.
CLEAR: lv_matnr, lv_verpr.
lv_matnr = it_report-matnr.
READ TABLE it_mbew WITH KEY matnr = lv_matnr BINARY SEARCH.
IF sy-subrc = 0.
lv_verpr = it_mbew-verpr.
ENDIF.
ENDIF.
it_report-verpr = lv_verpr.
LOOP AT it_mvmt FROM lv_loopindx.
IF it_report-matnr <> it_mvmt-matnr OR
it_report-werks <> it_mvmt-werks.
lv_loopindx = sy-tabix.
lv_recfnd = 'C'.
it_report-endbalq = it_report-bebalq + it_report-instkq -
it_report-outstkq.
* calculate values
it_report-endbalv = it_report-endbalq * lv_verpr.
it_report-bebalv = it_report-bebalq * lv_verpr.
it_report-instkv = it_report-instkq * lv_verpr.
it_report-outstkv = it_report-outstkq * lv_verpr.
MODIFY it_report INDEX lv_tabix
TRANSPORTING bebalq instkq outstkq endbalq
bebalv instkv outstkv endbalv
verpr.
EXIT.
ELSE.
lv_recfnd = 'X'.
ENDIF.
* for incoming and outgoing buckets, only tally if posting date is
* within user entered date range
IF it_mvmt-budat IN s_date.
* incoming stock logic
IF it_mvmt-bwart IN s_ibwart AND it_mvmt-shkzg = lc_debit.
it_report-instkq = it_report-instkq + it_mvmt-menge.
ENDIF.
*outgoing stock logic
IF it_mvmt-bwart IN s_obwart AND it_mvmt-shkzg = lc_credit.
it_report-outstkq = it_report-outstkq + it_mvmt-menge.
ENDIF.
ENDIF.
** calculate begining stock if needed (start date not 1st of the month)
IF s_date-low+6(2) <> '01'.
IF it_mvmt-budat < lv_bedat.
* add if incoming movement type
IF it_mvmt-bwart IN s_ibwart AND it_mvmt-shkzg = lc_debit.
it_report-bebalq = it_report-bebalq + it_mvmt-menge.
ENDIF.
* subtract if outgoing movement type
IF it_mvmt-bwart IN s_obwart AND it_mvmt-shkzg = lc_credit.
it_report-bebalq = it_report-bebalq - it_mvmt-menge.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
IF lv_recfnd <> 'C'.
it_report-endbalq = it_report-bebalq + it_report-instkq -
it_report-outstkq.
* calculate values
it_report-endbalv = it_report-endbalq * lv_verpr.
it_report-bebalv = it_report-bebalq * lv_verpr.
it_report-instkv = it_report-instkq * lv_verpr.
it_report-outstkv = it_report-outstkq * lv_verpr.
MODIFY it_report INDEX lv_tabix
TRANSPORTING bebalq instkq outstkq endbalq
bebalv instkv outstkv endbalv
verpr.
?
ENDIF.
ENDLOOP.

Hope this helps, and hope the formatting is readable.

Mike


From: horacio zapettini via sap-dev <sap-dev@Groups.ITtoolbox.com>><http://http://http://http://Groups.ITtoolbox.com>>>&l t;http:// http:// http://http://http://http://Groups.ITtoolbox.com>>>
To: Mike Hammond email@removed
Sent: Wed, August 25, 2010 6:56:51 AM
Subject: RE: [sap-dev] opening /closing stock similar to mb5b

Posted by horacio zapettini
on Aug 25 at 9:59 AM Mark as helpful
I can't get your point here...
mkpf -> mseg and you go from mkpf to mseg... why don't you just do mseg inner join mkpf on ...?

________________________________
De: VARADU via sap-dev [mailto:sap-dev@Groups.ITtoolbox.com]]<http://http://http://http://Groups.ITtoolbox.com]]>&l t;http:// http:// http://http://http://http://Groups.ITtoolbox.com]]>
Enviado el: Mi?rcoles, 25 de Agosto de 2010 10:52 a.m.
Para: Horacio Zapettini
Asunto: Re: [sap-dev] opening /closing stock similar to mb5b

[http://userimages.toolbox.com/user/b_949348.jpg] Posted by VARADU (ERP)
on Aug 25 at 9:52 AM [http://images.ittoolbox.com/vt/icons/vote.png] Mark as helpful<http://it.toolbox.com/api/ContentVote/3717238/1/1/ ><http://it.toolbox.com/api/ContentVote/3717238/1/1/ ><http://it.toolbox.com/api/ContentVote/3717238/1/1/ >>>>>>
Hi Mike,
?
Thanks for your quick response. We take MBEEW/MBEWH so as to get valuated stock ie Plant stock + vendor stock. however logic should be same for MARD and MBEW.? I stuck up at mkpf/mseg documents.
?
For instance If i want a query period 01.08.2010 to current date(todays date), I need to pass all the MBLNR which is huge data. Then to go to MSEG.?can you pl tell me how you did this.
?
Rajan.

--- On Tue, 24/8/10, Mike Hammond via sap-dev <sap-dev@Groups.ITtoolbox.com>><http://http://http://http://Groups.ITtoolbox.com>>>&l t;http:// http:// http://http://http://http://Groups.ITtoolbox.com>>><http:// http:// http://http://http://http://http://http://Groups.ITtoolbox.com>>> wrote:


From: Mike Hammond via sap-dev <sap-dev@Groups.ITtoolbox.com>><http://http://http://http://Groups.ITtoolbox.com>>>&l t;http:// http:// http://http://http://http://Groups.ITtoolbox.com>>><http:// http:// http://http://http://http://http://http://Groups.ITtoolbox.com>>>
Subject: Re: [sap-dev] opening /closing stock similar to mb5b
To: "VARADU" email@removed
Date: Tuesday, 24 August, 2010, 10:46 PM

Posted by Mike Hammond
on Aug 24 at 1:18 PM
Mark as helpful



Hi Varadu,

We have a similar report that uses MARD and or MARDH for the starting point of the stock qty. Our users use this report for getting beginning and ending balances for blocked stock in our system for a user entered date range. Since these tables give the balance as of the end of a period, we use that number for the starting point, and then read all material movement documents - MKPF joined with MSEG for the interim period, looking for specific movement types (BWART) and stock types (INSMK) and debit/credit indicator (SHKZG) to make the adjustment from the MARD/H value to the beginning date entered by the user. This gives us the starting balance as of the date entered.

We then make adjustments using the same tables / fields mentioned for adding incoming stock and subtracting outgoing stock during the period, which results in the ending balance.

Hope that helps, though it is a fairly complicated task with many movement types, and the users keep changing which types they are using which fouls up the report logic.

Regards,
mike

From: VARADU via sap-dev <sap-dev@Groups.ITtoolbox.com>><http://http://http://http://Groups.ITtoolbox.com>>>&l t;http:// http:// http://http://http://http://Groups.ITtoolbox.com>>><http:// http:// http://http://http://http://http://http://Groups.ITtoolbox.com>>>
To: Mike Hammond email@removed
Sent: Tue, August 24, 2010 9:34:48 AM
Subject: [sap-dev] opening /closing stock similar to mb5b

Posted by VARADU (ERP)
on Aug 24 at 12:42 PM
Hi,

I need one help.

Want to have a opening and closing stock (valuated stock) similar to output in MB5B report. eg.,

for a given material, plant, query period wouldbe 01.08.2010 to 24.08.2010 (current date) using mbew/mbewh table. Please advise the logic/source code for getting particular period since mbew/mbewh STORES data only month-wise.

Regards,

rajan.

__.____._
Copyright © 2010 Toolbox.com and message author.

Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251
In the Spotlight
Toolbox.com for iPhone: Ask Questions & Get Answers Anywhere. Use the New iPhone App
_.____.__

0 comments:

Post a Comment

T r a n s l a t e to your language