Skip to Content
0
Former Member
May 16, 2016 at 09:01 AM

How to Update single(latest) record in ABAP Routine when there are multiple records in SOURCE-DSO.

1566 Views

Hi Experts,

I have a scenario where I need to lookup Standard price from lookup-DSO and update the std price value to only one record in Target-DSO based on Material, Plant and latest Creation date.

Example:

Lookup-DSO table: Only single record with Material and plant combination

Material

Plant

Standard Price

1000

10

20

Source-DSO table: Multiple records with Material and plant combination based on different creation dates.

Material

Plant

Createdon

1000

10

01/01/2014

1000

10

01/01/2015

1000

10

01/01/2016

Target-DSO table: In target-DSO, I need to update std price value for only one record based on latest createdon field as shown below

Material

Plant

Createdon

Standard Price

1000

10

01/01/2014

blank

1000

10

01/01/2015

blank

1000

10

01/01/2016

20

I written the below code but it’s not updating to only one latest record, rather its updating to all the record. So could you please help me with code for updating the latest record?

Start Routine:

TYPES: BEGIN OF S_SPRICE,
MATERIAL TYPE /BI0/OIMATERIAL,
PLANT TYPE /BI0/OIPLANT,
PRICE_STD TYPE /BI0/OIPRICE_STD,
END OF S_SPRICE.
DATA: IT_SPRICE TYPE STANDARD TABLE OF S_SPRICE,
WA_SPRICE TYPE S_SPRICE.

SELECT MATERIAL PLANT PRICE_STD INTO TABLE IT_SPRICE
FROM Lookup-DSO
FOR ALL ENTRIES IN SOURCE_PACKAGE
WHERE MATERIAL = SOURCE_PACKAGE-MATERIAL
AND PLANT = SOURCE_PACKAGE-PLANT.
SORT IT_SPRICE BY MATERIAL PLANT.

Field Routine for Standard Price:

CLEAR WA_SPRICE.
READ TABLE IT_SPRICE INTO WA_SPRICE
WITH KEY MATERIAL = SOURCE_FIELDS-MATERIAL
PLANT = SOURCE_FIELDS-PLANT
BINARY SEARCH.
IF SY-SUBRC = 0.
RESULT = WA_SPRICE-PRICE_STD.
ENDIF.


Please suggest me..


Thanks,

BRaj.