DATA(lv_string) = |My string I want to convert to xstring.|.
TRY.
DATA(lv_xstring) = cl_abap_codepage=>convert_to( lv_string ).
DATA(lv_string_decoded) = cl_abap_codepage=>convert_from( lv_xstring ).
WRITE: / lv_string,
/ lv_xstring,
/ lv_string_decoded.
CATCH cx_root INTO DATA(e).
WRITE: / e->get_text( ).
ENDTRY.
Tag: convert
[ABAP] Convert table of strings to a single string
DATA(lv_string) = REDUCE #( INIT str = || FOR line IN table_of_strings NEXT str = str && line).
[JavaScript] Create date object from date string yyyyMMdd
Using regex, you can simply reorder the parts of your date string to create a compatible ISO 8601 date string which is accepted by the new Date()
constructor.
const date_string = "20220101"
const oDate = new Date(date_string.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3'))
console.log(oDate.toUTCString())
[JavaScript] Convert null to boolean using !!
As null
belongs to the JS Falsy Values, you can simply do this:
console.log(null) // null
console.log(!!null) // false
Detailed explanation: https://www.samanthaming.com/tidbits/19-2-ways-to-convert-to-boolean/
[JavaScript] Create date object from date string dd.MM.yyyy
Using regex, you can simply reorder the parts of your date string to create a compatible ISO 8601 date string which is accepted by the new Date()
constructor.
const date_string = "01.01.2022"
const oDate = new Date(date_string.replace(/(.*)\.(.*)\.(.*)/, '$3-$2-$1'))
console.log(oDate.toUTCString())
[JavaScript] Convert string array to integer array and reverse
let arrayOfStrings = ["1","2","3","4"]
let arrayOfNumbers = arrayOfStrings.map(Number)
console.log(arrayOfNumbers) // [1,2,3,4]
arrayOfStrings = arrayOfNumbers.map(String)
console.log(arrayOfStrings ) //["1","2","3","4"]
[ABAP] Convert JavaScript Timestamp to yyyy-MM-dd’T’HH:mm:ss
DATA(lv_js_timestamp) = "/Date(1615161600000)/".
"Extract /Date(1615161600000)/ to 1615161600000
FIND REGEX '([0-9]+)' IN lv_js_timestamp IGNORING CASE SUBMATCHES DATA(js_timestamp).
cl_pco_utility=>convert_java_timestamp_to_abap( EXPORTING iv_timestamp = js_timestamp
IMPORTING ev_date = DATA(lv_date)
ev_time = DATA(lv_time) ).
"2021-03-08T00:00:00
CONVERT DATE lv_date TIME lv_time INTO TIME STAMP DATA(timestamp) TIME ZONE 'UTC'.
rv_datetime = |{ timestamp TIMESTAMP = ISO }|.