ā2014 Aug 04 4:47 PM
Hi,
I have two source timestamp fields of DEC-15 type in PSA having data in format 20.140.305.225.959.
Using FM which delivers output in seconds, I am trying to calculate difference through below code and put result in an Integer type infoObject.
This code is in field level routine from data source to DSO.
DATA:
assg1 TYPE TIMESTAMP,
rsld1 TYPE TIMESTAMP,
diffasrs TYPE I.
assg1 = SOURCE_FIELDS-ZZ_ASSIGNED.
rsld1 = SOURCE_FIELDS-ZZ_RESOLVED.
CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'
EXPORTING
TIMESTAMP1 = assg1
TIMESTAMP2 = rsld1
IMPORTING
DIFFERENCE = diffasrs.
IF SY-SUBRC = 0.
RESULT = diffasrs.
ENDIF.
This doesn't work. Is there any mistake in this code?
I also tried with something like:
DATA:
assg(18) TYPE c,
assg1 TYPE TIMESTAMP,
rsld(18) TYPE c,
rsld1 TYPE TIMESTAMP,
diffasrs TYPE I.
assg = SOURCE_FIELDS-ZZ_ASSIGNED.
rsld = SOURCE_FIELDS-ZZ_RESOLVED.
REPLACE ALL OCCURRENCES OF '.' IN assg WITH ''.
CONDENSE assg NO-GAPS.
assg1 = assg.
REPLACE ALL OCCURRENCES OF '.' IN rsld WITH ''.
CONDENSE rsld NO-GAPS.
rsld1 = rsld.
CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'
EXPORTING
TIMESTAMP1 = assg1
TIMESTAMP2 = rsld1
IMPORTING
DIFFERENCE = diffasrs.
IF SY-SUBRC = 0.
RESULT = diffasrs.
ENDIF.
but this also doesn't work.
could somebody please help??
Thanks
Ahmad
ā2014 Aug 04 6:53 PM
HI Ahmad,
Try getting date and time from system using SY-DATUM and SY-UZEIT
Also, use function module SCOV_TIME_DIFF to calculate days and time difference between two dates.
Cheers!
ā2014 Aug 04 7:38 PM
Hi,
What about cl_abap_tstmp=>subtract(). That should works, I believe.
PROGRAM zjbtst2.
DATA: gx_ex TYPE REF TO cx_parameter_invalid .
DATA: g_tstmp TYPE timestamp .
DATA: g_tstmp1 TYPE timestamp .
DATA: g_secs TYPE tzntstmpl .
GET TIME STAMP FIELD g_tstmp .
WAIT UP TO 5 SECONDS .
GET TIME STAMP FIELD g_tstmp1 .
TRY .
g_secs = cl_abap_tstmp=>subtract(
tstmp1 = g_tstmp1
tstmp2 = g_tstmp
).
CATCH
cx_parameter_invalid_range
cx_parameter_invalid_type
INTO gx_ex .
MESSAGE gx_ex TYPE 'E' .
ENDTRY .
WRITE: / g_secs .
cheers
JÄnis
Message was edited by: JÄnis B
ā2014 Aug 04 8:02 PM
ā2014 Aug 05 9:49 AM
Hi,
I tried this use in my routine but getting an error that 'g_tstmp' is not defined.
Tried with defining variables with other names but getting same error.
any idea??
Thanks
Ahmad
ā2014 Aug 05 9:51 AM
Hi Shree,
my source fields are already in timestamp format.
The difference calculation code is not working.
Thanks
Ahmad
ā2014 Aug 05 9:43 PM
Hi,
Well, you have to put your own variables in the method call - it's just an example demonstrating how to call the method. The method subtracts two timestamps.
In your case it would be something like this:
DATA:
assg1 TYPE TIMESTAMP,
rsld1 TYPE TIMESTAMP,
diffasrs TYPE tzntstmpl.
assg1 = SOURCE_FIELDS-ZZ_ASSIGNED.
rsld1 = SOURCE_FIELDS-ZZ_RESOLVED.
TRY .
diffasrs = cl_abap_tstmp=>subtract(
tstmp1 = assg1
tstmp2 = rsld1
).
CATCH
cx_parameter_invalid_range
cx_parameter_invalid_type
INTO gx_ex .
MESSAGE gx_ex TYPE 'E' .
ENDTRY .
Good luck with your learning
cheers
JÄnis