‎2008 Aug 05 11:24 AM
Hi,
I have a selection that retrieves the data like this:
Product Prod.Name Product Price
101 A 100
101 A 125
202 B 200
202 B 250
303 C 300
303 C 350
The structure that are to receive the data needs to hold it like this
Product Prod.Name Prod.Price1 Prod.Price2
101 A 100 125
202 B 200 250
303 C 300 350
How can the selected data be written to the structure within my FM so it is in the format with one line per product ?
‎2008 Aug 05 11:53 AM
Peter,
Check the below code, assuming only two prices will be there for a product:
LOOP AT t_select.
AT new of prod_name.
clear lw_count.
fill all other fields
endat.
if lw_count eq 1.
t_final-price1 = t_select-price.
else.
t_final-price2 = t_select-price.
endif.
lw_count = lw_count + 1.
AT END OF prod_name.
Append t_final.
ENDAT.
ENDLOOP.
Regards,
Kiran
Edited by: kiran Bobbala on Aug 5, 2008 12:53 PM
‎2008 Aug 05 11:53 AM
Peter,
Check the below code, assuming only two prices will be there for a product:
LOOP AT t_select.
AT new of prod_name.
clear lw_count.
fill all other fields
endat.
if lw_count eq 1.
t_final-price1 = t_select-price.
else.
t_final-price2 = t_select-price.
endif.
lw_count = lw_count + 1.
AT END OF prod_name.
Append t_final.
ENDAT.
ENDLOOP.
Regards,
Kiran
Edited by: kiran Bobbala on Aug 5, 2008 12:53 PM
‎2008 Aug 05 12:01 PM
hi peter.
create another internal table itab2. and use the following logic:
loop at itab1.
at end of field1.
itab2-field1 = ita1-field1.
itab2-field2 = ita1-field2.
itab2-field3 = ita1-field3.
append itab2.
endloop.
‎2008 Aug 05 12:03 PM
Hi Peter .,
I think the price variation depends on Some pricing condition ( May be time Period ) .
if so , it may require to put the oldest price in Price1 and the latest in Price2 .
if this is the case then you can achive it .
Select Prod Prod.name Price (pricing conditon)
into itab .
sort itab by prod (pricing Conditon) .
loop at itab .
wa_final-prod = itab-prod .
wa_final-prod.name = itab-prod.name .
if wa_final-pric1 is initial .
wa_final-Price1 = itab-price .
else .
wa_final-Price2 = itab-price .
append wa_final to it_final .
clear wa_final .
endif .
endloop .
if it is not sure that for each prod there would be 2 prices . we can use at end of prod event .
thanks
Sreenivas Reddy
‎2008 Aug 05 12:04 PM
Hi Peter .,
I think the price variation depends on Some pricing condition ( May be time Period ) .
if so , it may require to put the oldest price in Price1 and the latest in Price2 .
if this is the case then you can achive it .
Select Prod Prod.name Price (pricing conditon)
into itab .
sort itab by prod (pricing Conditon) .
loop at itab .
wa_final-prod = itab-prod .
wa_final-prod.name = itab-prod.name .
if wa_final-pric1 is initial .
wa_final-Price1 = itab-price .
else .
wa_final-Price2 = itab-price .
append wa_final to it_final .
clear wa_final .
endif .
endloop .
if it is not sure that for each prod there would be 2 prices . we can use at end of prod event .
thanks
Sreenivas Reddy
‎2008 Aug 05 12:10 PM
Hi,
Check the following code:
DATA: BEGIN OF LINE,
COL1(10) TYPE N,
COL2(10) TYPE C,
END OF LINE.
DATA ITAB LIKE STANDARD TABLE OF LINE
WITH NON-UNIQUE KEY COL2.
LINE-COL1 = 4500000327.
LINE-COL2 = '5000000539'.
APPEND LINE TO ITAB.
LINE-COL1 = 4500000327. LINE-COL2 = '5000000542'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000327. LINE-COL2 = '5000000543'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000329. LINE-COL2 = '5000000554'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000329. LINE-COL2 = '5000000554'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000303. LINE-COL2 = '5000000550'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000303. LINE-COL2 = '5000000551'. APPEND LINE TO ITAB.
LINE-COL1 = 4500000334. LINE-COL2 = '5000000556'. APPEND LINE TO ITAB.
PERFORM LIST.
FORM LIST.
data: cl like line-col1.
SKIP TO LINE 3.
LOOP AT ITAB INTO LINE.
if cl NE line-col1.
write : / line-col1.
else.
write : ''.
endif.
write : line-col2.
cl = line-col1.
ENDLOOP.
ENDFORM.
Regards,
Bhaskar
Edited by: Bhaskar Chikine on Aug 5, 2008 4:41 PM