cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Addition hours to timestamp

tnecnivo
Active Contributor
0 Kudos
7,086

Hi BI/Abap gurus,

I am trying to add 8 hours based on the source fields mapped.

I have google around and the FM seems promising.

sample source fields-crm_due_dt: 20141120163000

And I have tested in SE37, seems to be fine.

but loading data causes error below:-


Error
The function call of TIMESTAMP_DURATION_ADD failed; a field may have been assigned to the parameter TIMESTAMP_IN whose type is not c

Any advice please?


CALL FUNCTION 'TIMESTAMP_DURATION_ADD'

       EXPORTING

         timestamp_in  = SOURCE_FIELDS-crm_due_dt

         timezone      = 'UTC'

         duration      = '8'

         unit          = 'H'

       IMPORTING

       timestamp_out   = RESULT.

Many thanks.

Accepted Solutions (1)

Accepted Solutions (1)

anindya_bose
Active Contributor
0 Kudos

Hi Vincent

It seems to be just a data type conflict .

Define two temporary  variables to pass and collect right format .

DATA: temp1 TYPE TZNTSTMPS,

           temp2 TYPE TIMESTAMP .

Move source_fields-crm_due_dt to temp1 .

CALL FUNCTION 'TIMESTAMP_DURATION_ADD'

        EXPORTING

          timestamp_in  = temp1

          timezone      = 'UTC'

          duration      = '8'

          unit          = 'H'

        IMPORTING

        timestamp_out   = temp2.

Move temp2 to RESULT.

Clear temp1, temp2 .

Regards

Anindya

tnecnivo
Active Contributor
0 Kudos

Hi Anindya,

Thanks, the error no longer occurs, but not all figure changed.

I tried copying "20160311133741" to the FM via SE37. seems to be fine.

Please have a look at the table below.

0CRM_DUE_DT is the orginal fields

and ZDUEDATE is the transformed fields.

Any ideas?

anindya_bose
Active Contributor
0 Kudos

I would put a DTP filter to only take those values in crm_due_dt which are not getting converted.

Put a break point in the field routine and run the DTP in debug mode.

You can also put a sy-subrc check before moving the value to "Result"

Write

if sy-subrc = 0.

move temp2 to result .

else.

move source_fields-crm_due_dt to result.

endif.

Above statement would not work as a solution but can point out possible problem.

anindya_bose
Active Contributor
0 Kudos

Another important point, you need to perform Initial check before calling this function module.

If source_fields-crm_due_dt is not initial.

rest of the code

..........................

--------------------

endif .

If you pass '00000000000000' to this FM, it would take current time in UTC and add 8 hours to it.

That would be wrong calculation for you . See this portion of source code of this FM

Regards

Anindya

Answers (0)