SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

How to Convert Timestamp to String in ABAP

SAP timestamp values are stored in fields with decimal data types. In ABAP to convert timestamp to string programmer can use function modules.
ABAP function module RRBA_CONVERT_TIMESTAMP_TO_STR given in this tutorial is an example to display time stamp field values in character or string data representations.

In SAP sales documents VBAK table, there is a field named UPD_TMSTMP with data element TIMESTAMPL for storing last change date and time in UTC time stamp long form (YYYYMMDDhhmmssmmmuuun).
In my development SAP system, in VBAK table you can see sample rows with timestamp values in below screenshot.

convert timestamp to string using ABAP function module

ABAP programmers can work on such sample sales order data to convert timestamp field to string expression as we will do in this ABAP tutorial using below shared codes.


ABAP Function Module to Convert Timestamp to String

ABAP developers can use the function module RRBA_CONVERT_TIMESTAMP_TO_STR to convert timestamp values to string easily.

Let's make a test.
In this example, since ABAP function module RRBA_CONVERT_TIMESTAMP_TO_STR accepts timestamp input parameter in short form we will convert UPD_TMSTMP field value from long form to short form.

DATA lv_vbeln TYPE vbeln VALUE '0100001415'.
DATA lv_timestamp_string TYPE string.
DATA lv_timestamp_short TYPE rs_timestmp.

SELECT SINGLE upd_tmstmp INTO @DATA(lv_timestamp)
 FROM vbak WHERE vbeln = @lv_vbeln.

" convert timestamp in long form to timestamp in short form
lv_timestamp_short = lv_timestamp.

" ABAP function module accepts timestamp input parameter in short form
CALL FUNCTION 'RRBA_CONVERT_TIMESTAMP_TO_STR'
 EXPORTING
  i_timestamp = lv_timestamp_short
 IMPORTING
  e_output = lv_timestamp_string.

WRITE lv_timestamp_string.
Code

The output is as "22.03.2016 08:32:44" for the above ABAP code execution which programmers can use to convert timestamp to string or character variable.

convert timestamp to string in ABAP

You can check your ABAP code test results by switching to VA03 Sales Order Display transaction with your sample VBELN number. Then following top menu options "Environment > Changes" display changes on sales document sorted by "time of change". The last change will be the output of above ABAP function module RRBA_CONVERT_TIMESTAMP_TO_STR.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.