2007 Oct 17 9:19 AM
Hi,
I have an interface, which is reading XML files, selecting data from sap tables and send a result in XML back.
I now wanted to log the incoming requests and also the processing time, used by SAP.
Therefore I have made a table, which is saving the request typ, time, date, and a field called processing time.
When the function is going to be called, I´m filling the fields date and time directly with sy-date and sy-uzeit.
After processing, I´m subtracting the old sy-uzeit from the new sy-uzeit and save that into the processing time field.
that works sometimes, but sometimes not.... I thought, I´m getting the difference in seconds later on in the field processing time. What am I doing wrong? Or how to record the processing time better?
The field processing time is an int4 field.
Thank you for you help.
Reward points guaranteed!
2007 Oct 17 10:22 AM
Hi Arne,
Integer type should be fine.
The inconsistency in calculation is bcz the time taken for the processing is very less & hence the start & end time dont have any difference.
I have create a sample program & tested out.
REPORT ztest11111111111.
DATA : l_time1 TYPE syuzeit,
l_time2 TYPE syuzeit,
l_ans TYPE syuzeit,
l_int TYPE i.
l_time1 = sy-uzeit.
WAIT UP TO 2 SECONDS. " 1st execute with this as Uncommented
*do 10 times. " for 1st time this should be commented
*write :/ ' '. " When WAIT UP TO is commented .. Uncomment DO..ENDDO
*enddo
l_time2 = sy-uzeit.
l_ans = l_time2 - l_time1.
l_int = l_time2 - l_time1.
WRITE :/ 'ANS with SYUZEIT datatype' , l_ans.
WRITE :/ 'ANS with INT datatype' , l_int.
2007 Oct 17 9:26 AM
data: a type sy-uzeit,
b type sy-datum,
c type sy-uzeit,
endtime type sy-uzeit,
enddate type sy-datum.
a = sy-uzeit.
b = sy-datum.
c = sy-uzeit.
CALL FUNCTION 'C14B_ADD_TIME'
EXPORTING
i_starttime = a
i_startdate = b
i_addtime = c
IMPORTING
E_ENDTIME = endtime
E_ENDDATE = enddate
.
write : endtime, enddate, a , c.
2007 Oct 17 9:34 AM
Hi, thank you for the answer. But I just need the processing time in seconds...
How to do that?
2007 Oct 17 9:39 AM
Hi Arne,
If you simply want to subtract the time, then
" l_time1 has old sy-uzeit value
l_time2 = sy-uzeit.
l_time = l_time2 - l_time1.
Above code should work fine everytime.
If the time zone of TIME1 and TIME2 are different, then you need to use sy-timlo instead of sy-uzeit.
Best regards,
Prashant
2007 Oct 17 9:43 AM
Ok, and thats the way I have done it.
At first, I have written the time into a field and after all processing, I have subtracted that from the actual time into an integer field.
Data: timeFirst LIKE sy-uzeit,
proc_time TYPE i.
timeFirst = sy-uzeit.
.... processing ....
proc_time = sy-uzeit - timeFirst.
But that seems not to work in all cases and I don´t know why! Because, sometimes I don´t have any value in the proc_time field, but the XML had been processed and has needed many seconds....
2007 Oct 17 9:47 AM
Hi,
Two things are possible:
1. processing time is very less.. fraction of second..
FIRST TIME = SY-UZEIT. "101010
...
Process Time = sy-uzeit - first time. " Here value could be zero.. bcz of fast processing
2. The code is not executed ...
May be that the code is not executed..
Could you please put a breakpoint & debug. That should help to identify the bug.
Best regards,
Prashant
2007 Oct 17 9:50 AM
Yes, sometimes, it is very less....
The function is going to be called over RFC from an external application. EVERYTIME, when I run the function manually, it records the right time. But often, when I run it from the external program, it is not working. But it is always writing the logging line to the database table...
Strange thing! At first, the field for processing time was of type NUMC, but now I have changed it to integer. Could that be a problem?
2007 Oct 17 9:53 AM
Hi,
I hope the RFC is hit everytime correctly & the code of processing time calculation is not inside any IF condition which would fail occasionaly.
Please change the data type of TIme fields to SYUZEIT.
Data : l_time1 type syuzeit,
l_time2 type syuzeit.Best regards,
Prashant
2007 Oct 17 10:04 AM
Here is the part of my code:
* Read incoming XML request
PERFORM read_xml_request USING i_streamin.
gs_request_data-req_date = sy-datum.
gs_request_data-req_time = sy-uzeit.
gs_request_data-req_type = g_request_type.
.........
.....
...
* Add request information to the log table
PERFORM log_request.
FORM log_request.
* Update log with processing time
gs_request_data-proc_time = sy-uzeit - gs_request_data-req_time.
CALL METHOD g_log_instance->write_request_to_log
EXPORTING
it_request_detail = lt_request_detail
IMPORTING
e_return_code = l_return_code
CHANGING
is_request_info = gs_request_data.
ENDFORM
For the time, I have made an own data element, but with the same domain like syuzeit: sytime
so that should definately not be the problem...
2007 Oct 17 10:08 AM
I hope gs_request_data-proc_time also has syuzeit as data type.
2007 Oct 17 10:15 AM
No! Because I would like to have the proecssing seconds....
It is of type integer. What I want to have in this field, are the seconds used by the function.
2007 Oct 17 10:22 AM
Hi Arne,
Integer type should be fine.
The inconsistency in calculation is bcz the time taken for the processing is very less & hence the start & end time dont have any difference.
I have create a sample program & tested out.
REPORT ztest11111111111.
DATA : l_time1 TYPE syuzeit,
l_time2 TYPE syuzeit,
l_ans TYPE syuzeit,
l_int TYPE i.
l_time1 = sy-uzeit.
WAIT UP TO 2 SECONDS. " 1st execute with this as Uncommented
*do 10 times. " for 1st time this should be commented
*write :/ ' '. " When WAIT UP TO is commented .. Uncomment DO..ENDDO
*enddo
l_time2 = sy-uzeit.
l_ans = l_time2 - l_time1.
l_int = l_time2 - l_time1.
WRITE :/ 'ANS with SYUZEIT datatype' , l_ans.
WRITE :/ 'ANS with INT datatype' , l_int.
2007 Oct 17 10:31 AM
Thank you for the help!
So it should be ok... Maybe it is now working, after I have set it from NUMC5 to integer. Hope so!
Cheers