‎2007 Apr 23 12:51 PM
I am not sure what the best approach would be so i am hoping you can help me out. I have a pretty simple scenario but I am not sure the best way to collect the data.
I have a table that contains material data except prices. I need to go to another table and see if their is a material price for the current period. If so I just need to modify the package. If not I need to keep looping back through the table for prior months until I find a price. i will never go back more than 1 year. My link will be
what is the best design? I was thinking of getting 2 internal tables. 1 with current prices for all the materials in my table and one with prior prices
‎2007 Apr 23 12:54 PM
Hi,
I think you can use the Tables MBEWH and MARDH for this purpose to find the prices by looping into internal table till you get some price.
These tables stores the previous values for that material.
use them
reward if useful
regards,
ANJI
‎2007 Apr 23 12:54 PM
Hi,
I think you can use the Tables MBEWH and MARDH for this purpose to find the prices by looping into internal table till you get some price.
These tables stores the previous values for that material.
use them
reward if useful
regards,
ANJI
‎2007 Apr 23 12:57 PM
Hi,
Try like this...
Val_date = sy-datum - 365.
Use Select MAX(DATE) price from table2 into table itab2 for all entries in itab1
where matnr = itab1-matnr
and date GE Val_DATE.
‎2007 Apr 23 1:06 PM
Then how do I get the loop to work and grap the latest day with the orice?
‎2007 Apr 23 1:12 PM
Hi,
Max(date) itself will fetch the latest day ,latest month, latest year.
If am wrong please clarify.
‎2007 Apr 23 1:25 PM
My date field is int he format mmm/yyyy. I don't have the day. will this work?
‎2007 Apr 23 1:43 PM
No it won't work.Try like this.
Select MAX(DATE) matnr from table2 into table itab2 for all entries in itab1
where matnr = itab1-matnr
and date GE Val_DATE.
select max(day) matnr price from table2 into table itab3 for all entries in itab2
where matnr = itab2-matnr and date = itab2-date.
now itab3 will contain price for the latest period for each material..
‎2007 Apr 23 1:46 PM
Here is waht i tried with MAX and this is the error
Unknown column name "MAX(FISCPER)". not determined until runtime
select MAX(FISCPER) MATERIAL PLANT FISCPER PRICE_STD PRICE_BASE INTO TABLE
T_MATPRICE_DATA
FROM /BIC/AZCO_O0100
FOR ALL ENTRIES IN DATA_PACKAGE
WHERE
MATERIAL = DATA_PACKAGE-MATERIAL AND
PLANT = DATA_PACKAGE-PLANT and
FISCPER = DATA_PACKAGE-FISCPER.
FISCYEAR = DATA_PACKAGE-FISCYEAR.
FISCPER GE VAL_DATE.
‎2007 Apr 23 2:00 PM
But you are uisng GE so it should grab the max date correct?
‎2007 Apr 23 2:07 PM
Now I get this error below.
The addition "FOR ALL ENTRIES" excludes all aggregate functions with the exception of "COUNT( * )", as the single element of the SELECT clause
here is my code
Select MATERIAL PLANT MAX( FISCPER ) PRICE_STD PRICE_BASE INTO TABLE
T_MATPRICE_DATA
FROM /BIC/AZCO_O0100
FOR ALL ENTRIES IN DATA_PACKAGE
WHERE
MATERIAL = DATA_PACKAGE-MATERIAL AND
PLANT = DATA_PACKAGE-PLANT and
FISCPER GE VAL_DATE.
‎2007 Apr 23 2:57 PM
Hi Mick,
Sorry for the mistaken Code syntax .'for all entries' won't work while using Aggregate fn.Check if the following code work for u.
SELECT material plant fiscper day INTO TABLE
t_matprice_data
FROM /bic/azco_o0100
FOR ALL ENTRIES IN data_package
WHERE
material = data_package-material AND
plant = data_package-plant AND
fiscper GE val_date.
SORT t_matprice_data BY material plant fiscper DESCENDING day DESCENDING.
DELETE ADJACENT DUPLICATES FROM t_matprice_data COMPARING material plant.
Now t_matprice_data will contain latest price for the material.
‎2007 Apr 23 3:09 PM
I will try it out. what does the 2 descending statements do/ Do you need both or just the one
‎2007 Apr 23 3:20 PM
I assume that <b>t_matprice_data</b> table contains "Period" field(MM/YYYY)
and DAY field. DESCENDING is needed for both PERIOD and DAY. To sort the specific field according to our need we can use like this.These descending stmnt. will sort both PERIOD field and DAY field in Descending order to move latest Date into Top.This will be helpful while using DELETE ADJACENT DUPLICATES stmnt.
‎2007 Apr 23 3:27 PM
No it just contains Period" field(MM/YYYY) so would I change that to be below or do i take out the 2nd
SORT T_CMATPRICE_DATA BY material plant fiscper PRICE_STD PRICE_BASE
DESCENDING FISCPER DESCENDING.
DELETE ADJACENT DUPLICATES FROM T_CMATPRICE_DATA COMPARING material
plant.
‎2007 Apr 23 3:35 PM
I wonder how do u fetch latest day for the corresponding latest period.
Is ther no 'day' field in Table.If u dont want latest 'day' for the latest 'period'
then do like below.And no need to give PRICE_STD PRICE_BASE while sorting the ITAB .
jus do like this.
SORT T_CMATPRICE_DATA BY material plant fiscper DESCENDING .
DELETE ADJACENT DUPLICATES FROM T_CMATPRICE_DATA COMPARING material plant.
Message was edited by:
Vigneswaran S
‎2007 Apr 23 7:39 PM
this will work but i need to a FM that will calculate 12 months back
‎2007 Apr 23 12:58 PM
MIck ,
u cannt this into Coding , better to get going on Avg.Price of Material ?
u can also check MARDMBEW for current , MBEWHMARDH for History.
y i am telling this one is , Some times these table will not Updateded, due to SAP system settings , so better to go for moving avg.price of MARD.
Regards
prabhu
‎2007 Apr 23 1:05 PM
No the design they want is the way I described. they do not want avg. price. We already loded the prices inot an ODS in BW so i will be reading from this table.
why can't i do this in coding? I've done this type of logic before so why is it an issue?
‎2007 Apr 23 1:35 PM
Hi Mick,
Using two internal tables is a good approach:
- 1st table for current prices & 2nd for prior prices
- sort the two tables by period field descending
- calculate the validity_period
one example is : val_period = sy-datum - 365!
- set ld_index = 0.
- Loop at first table where period > val_period into wa_area
Loop at second table from ld_index
if period < wa_area-period.
continue.
elseif period > wa_area-period.
exit.
else period = wa_area-period.
process modifications
endif.
Reward if helpful.
Regards ,
Sooness
endloop.
endloop.
‎2007 Apr 23 1:41 PM
Ps: you may exit from both loops by setting a flag in 2nd loop then putting a check for it after 1st endloop