Skip to Content
0

How to CONVERT EBCDIC to ASCII in ABAP?

Jan 18, 2017 at 01:49 PM

277

avatar image

Hi ,

I have a requirement to read EBCDIC files in ABAP. is there any FM that converts EBCDIC to ASCII. so that we can persist the data as ASCII rather than EBCDIC.

In general suggest me what we have to do when reading EBCDIC files.

Thanks

NB

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Raymond Giuseppi
Jan 18, 2017 at 02:27 PM
1

Look at methods cl_abap_codepage=>convert_from/to. (or cl_abap_conv_in/out_ce for older versions)


Regards,
Raymond

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thanks Raymond,

any idea whats the code page name for "EBCDIC IBM-1140" in ECC?. I know IBM-1140 is equivalent to IBM-0037 and IBM-0037's code page is 0123 but its not populated in TCP00A tables. Methods you suggested requires codepage name for example. 'ibm500'.

Thanks,

NB

0

"Fun" that CL_ABAP_CODEPAGE checks this table. The obsolete class CL_ABAP_CONV_IN_CE does not check it.

DATA l_xstring TYPE xstring.
DATA l_string TYPE string.
l_xstring = '5A405A'.
PERFORM convert_xstring_to_string USING l_xstring '0123' CHANGING l_string.
ASSERT l_string = '! !'.
FORM convert_xstring_to_string
USING i_xstring TYPE xstring
i_encoding TYPE abap_encoding
CHANGING e_string TYPE string.
DATA lo_conv TYPE REF TO cl_abap_conv_in_ce.
CLEAR e_string.
lo_conv = cl_abap_conv_in_ce=>create(
encoding = i_encoding
input = i_xstring ).
CALL METHOD lo_conv->read(
IMPORTING data = e_string ).
ENDFORM.
0

Yes, also the SCP_CODEPAGE_BY_EXTERNAL_NAME FM isn't able to find the pagecode. So browse TCP00?

0

Hi Sandra Rossi,

Thanks, Yes we can use these old CLs to convert the content based on the codepage 'code'.

I'm still not getting 100% correct converted content because my source content has the COBOL "Comp-3" Data Types. Convertion routines has no idea about "Packed" decimals, I think i have to add bit of logic before / after convertion to handles these.

Any Idea about How to convert the contetnt with these special types "Packed" decimals / Comp-3 data types/ Binary Converted Decimals?.

Thanks,

NB

0

I think you can do it via method CONVERT_STRUC, and you'll need to define a target structure, defining the character and packed fields in the same sequence of the fields from the input EBCDIC bytes.

0