cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate number of days between two posting dates

0 Kudos
135

Hi Experts,

I need to develop a report which gives number of days of a material in each storage location. Or based on movement type for eg if a material has movement type 101, then i need that posting date and when the same material has movement type 311 i need that posting date and find the number of days between the two posting dates.

In my first level DSO i already have posting date material and movement type fields. How do i calculate the number of days. If i have a cube above it with a field 'Lead time' then this field should have th number of days populating through a routine.

Can someone please help me with the routine.

Regards,

Kshama.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

Use the standard FM /SDF/CMO_DATETIME_DIFFERENCE to get the number of days between the two dates.

hope this helps.

thanks,

rahul

Answers (3)

Answers (3)

0 Kudos

Hi Balaji,

Thanks for your response, but in this code where are we considering movement type as there could be various movement types for a material and i am calculating various lead times which will all be my characteristics in the final cube. e.g Bulk Lead time, bulk transportation time, bulk inventory time etc. You suggested another DSO any particular reason behind that can we not write the start routine in the cube.

Your help is greatly appreciated.

Regards,

Kshama.

former_member189406
Active Participant
0 Kudos

Hi Kshama,

The below logic should work.

Consider you have data in DSO-1 in the below format.

Material_______Posting Date_______Movement Type

M1___________05/15/2010______________101

M1___________06/25/2010______________311

When loading the data from DSO-1 to DSO-2, have the below code in the Start Routine. (Preferably load the data from DSO-1 to DSO-2, before loading it to the Cube)

-


(Check the DSO-2 to see if the Material is already loaded)

SELECT * from DSO-2 in itab_1 WHERE Material = SOURCE_PACKAGE-Material.

If Sy-subrc = 0 (The Material is present in DSO-2)

Read table itab_1 into wa_itab_1.

If SOURCE_PACKAGE-Material = wa_itab_1-Material.

Lead Time = (wa_itab_1-Posting Date) - (SOURCE_PACKAGE-Posting Date).

Else. (Materials are not the same. So do not calculate Lead Time)

Do Nothing.

Else. (The Material is not present in DSO-2. Hence no need to calculate Lead Time)

Do Nothing.

-


0 Kudos

Hi Balaji,

Thanks for your response, but in this code where are we considering movement type as there could be various movement types for a material and i am calculating various lead times which will all be my characteristics in the final cube. e.g Bulk Lead time, bulk transportation time, bulk inventory time etc. You suggested another DSO any particular reason behind that can we not write the start routine in the cube.

Also, if DSO2 is getting populated from DSO1 then it will have the material in DSO1 right so why are we keeping that check.

Your help is greatly appreciated.

Regards,

Kshama.

Former Member
0 Kudos

Hi,

I Assume that movement type 101 occures prior to 311 and likewise. If not then you can use the time field to identify the chronological sequence.

In Start Routine

Create 3 variables of type material, movement type and time to hold their previous values.

Sort source package by material no. movement type ascending.

look at source package assigning source fields

if <source-fields>-materialno = temp_material AND <source_fields>-movemnt type NE temp_movement type.

leadtime = <source-fields>-time - temp_time.

endif.

temp_material = <source_fields>-material.

temp_movmnt type = source_fields>-movemen type.

temp_time = <source_fields>-time

endloop.

Best Wishes,

Mayank

0 Kudos

Hi Mayank,

Thanks that was very helpful but in my cube i have a field 'bulk lead time' this i wanna populate by writing a field routine. from my source i am getting material, posting date, batch and movement type. now for this lead time field i want the difference of the first posting date for a material-batch of movement type 101 and first posting date for a material-batch of movement type 311.and this number of days should populate the lead time field. its the routine i need help with as logic i have understood.

Kindly help me with the same.

Thanks,

Kshama.

former_member181964
Active Contributor
0 Kudos

Hi,

If possible do such kind of calculations in report level using some exits, and avoid the date calculations at DSO level, see the following url for Customer exit codes at report level, and also you can find some importent FM's for your requirements.

Check in Blogs and Articles.

http://wiki.sdn.sap.com/wiki/display/profile/Surendra+Reddy

Thanks

Reddy

Former Member
0 Kudos

use function module /SDF/CMO_DATETIME_DIFFERENCE to calculate date difference

Regards,

Sharayu