来源资料待手动核验
项目简介
Codepage polyfill
Codepage polyfill
It never happened and it happened again. Clean core requires a new class for code page and the old class is not allowed.
CLABAPCODEPAGE was a class SAP introduced long time ago and it was efficiently handling string binary conversion for UTF-8 documents such as XML or JSON or whatever else.
We can see that is still present in a new ABAP documentation snippets. image
However it turned out to be one more example when "Clean Core" concept simply prevented us from using this class: The use of Class CLABAPCODEPAGE is not permitted
image
So what should we use instead? Well there is another nice class which we can use: CLABAPCONVCODEPAGE
Introducing one class in a new environment which is not present in the old environment prevents us from reusing the code. Polyfill approach allows us to use one class which will work in any system.
Rountrip example from the unit test
data(test) = |This is a sample string|.
" String to xstring ( to codepage )
data(lv_binary) = zcl_abap_codepage=>to( test ).
" Xstring to string ( from codepage )
assert( zcl_abap_codepage=>from( lv_binary ) )->eq( test ).