Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to CONVERT EBCDIC to ASCII in ABAP?

p1024029
Participant
0 Kudos
2,667

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

7 REPLIES 7
Read only

RaymondGiuseppi
Active Contributor
1,616

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


Regards,
Raymond

Read only

0 Kudos
1,616

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

Read only

0 Kudos
1,616

"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.
Read only

0 Kudos
1,616

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

Read only

0 Kudos
1,616

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

Read only

1,616

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.

Read only

0 Kudos
1,422

Hello,

Were you able to find a solution for this? We have requirement to read EBCIDC file with COMP3 values.

 

Thanks, Anzari