LSMW with KS02 with valid records


I am trying lsmw for ks02 transaction.
I am using recording method, here i am facing problem while selecting the valid record as of today.

for some cost centers , iam having 2 records and am facing problem in selecting the correct record through lsmw.

request you to help me in acheiving the solution.

Naga Jyothi

1 month


Jimbo's picture

Hi Naga,

Do you mean that you have cost centers with the same number in different controlling areas? If so, then the program SAPLKMA1 running in batch prompts for the controlling area and the simple solution is to pull the correct combination from the table CSSL.

If you have two records from the CSKS table with different dates, then the solution to determine which one will appear in the KS02 transaction would be to pick the one that includes today (SY-DATUM) in the range between Valid From Date (DATAB) and Valid To Date (DATBI). It may be that there are two records with ranges that include today and in that case the system will most likely display the record with the most recent Valid From date. A way to select that record is with a select statement that filters by date and sorts in order.

In Global Data add this variable.

data: lCSKS like CSKS.

Assuming that the source structure is named "KS02S" and the fields are SAP standard, then this code will populate the lCSKS variable with the contents of the record that will be shown today.

select * from CSKS into lCSKS
 where KOKRS eq KS02S-KOKRS and KOSTL eq KS02S-KOSTL
   and DATAB le sy-datum and DATBI ge sy-datum
 order by DATAB.