Application Development 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: 

how to use class for Translate..codepage/numer format

Former Member
0 Kudos

In the Unicode context, TRANSLATE... CODEPAGE/NUMBER FORMAT is not allowed.

5 REPLIES 5

Former Member
0 Kudos

this is the class to be used for Translate…Codepage/number format.statement

-


Unicode Error : In the Unicode context, TRANSLATE... CODEPAGE/NUMBER FORMAT is not allowed.

Before Unicode

TRANSLATE T143T-TBTXT FROM CODE PAGE '1100' TO CODE PAGE '1105'.

After Unicode

Use class for Translate codepage to codepage.

Data : g_codepage LIKE tcp0c-charco VALUE '1100'.

CONSTANTS: c_unicodecp(4) VALUE '1105'.

PERFORM translate_codepage USING g_codepage

c_unicodecp

CHANGING T143T.

FORM translate_codepage USING P_G_CODEPAGE

P_C_UNICODECP

CHANGING P_T143T.

DATA: converter TYPE REF TO cl_abap_conv_obj.

DATA: l_out TYPE string.

DATA: l_fromcode TYPE cpcodepage.

DATA: l_tocode TYPE cpcodepage.

l_fromcode = P_G_CODEPAGE.

l_tocode = P_C_UNICODECP.

CREATE OBJECT converter

EXPORTING

incode = l_fromcode

miss = '.'

broken = '.'

use_f1 = 'X'

outcode = l_tocode

EXCEPTIONS

invalid_codepage = 1

internal_error = 2.

IF sy-subrc <> 0.

CASE sy-subrc.

WHEN 1.

MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.

WHEN 2.

MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.

ENDCASE.

ENDIF.

CALL METHOD converter->convert

EXPORTING

inbuff = P_T143T

inbufflg = 0

outbufflg = 0

IMPORTING

outbuff = l_out

EXCEPTIONS

internal_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

CASE sy-subrc.

WHEN 1.

MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.

WHEN 2.

MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.

ENDCASE.

ENDIF.

P_T143T = l_out.

ENDFORM. " translate_codepage

0 Kudos

Hi Chaitanya,

Your post on the Unicode replacement for TRANSLATE... TO CODE PAGE was really really useful.

I had been looking for something like this with an example for a couple of days now.

I have gone through your code example and used it too. I'll now test the output of the program to check its usage.

Please share any other Unicode related tips that you may have. I am working on a Unicode upgrade assignment.

Regards,

Priya

0 Kudos

Dear chaitanya,

thanks for the inputs posted in SDN, I faced simillar problem and it solved easily. Adding to that, in my case the syntax was as below.

TRANSLATE l_tab TO CODE PAGE '1100'.

*here its not mentioned that from which code page it has to be translated.

*soln: there is a class which could help to findout the default codepage from which it has to be translated. it is as below.

data: l_codepage(4) type n.

CALL FUNCTION 'SCP_GET_CODEPAGE_NUMBER'

EXPORTING

database_also = ' '

IMPORTING

gui_codepage = l_codepage

EXCEPTIONS

internal_error = 1

OTHERS = 2.

if sy-subrc eq 0.

g_codepage = l_codepage.

endif.

This will give an information on from which codepage we have to transfer it from.

Former Member
0 Kudos

wow! thanks for the wonderful contributions! they were really very helpful..

Kindest regards,

Sheryl

Former Member
0 Kudos

Hi...If i want to convert internal table? can u give me any solution?

DATA: BEGIN OF T_KNVZ OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

KONZS LIKE KNA1-KONZS,

ADRNR LIKE KNA1-ADRNR,

BUKRS LIKE KNB1-BUKRS,

AKONT LIKE KNB1-AKONT,

NAME1 LIKE KNA1-NAME1,

NAME2 LIKE KNA1-NAME2,

STRAS LIKE KNA1-STRAS,

LAND1 LIKE KNA1-LAND1,

SPRAS LIKE KNA1-SPRAS,

PSTLZ LIKE KNA1-PSTLZ,

PLTYP LIKE KNVV-PLTYP,

ORT01 LIKE KNA1-ORT01,

LZONE LIKE KNA1-LZONE,

GRUPP LIKE KNKK-GRUPP,

VKORG LIKE KNVV-VKORG,

VTWEG LIKE KNVV-VTWEG,

SPART LIKE KNVV-SPART,

ERDAT LIKE KNA1-ERDAT,

ERNAM LIKE KNA1-ERNAM,

VKBUR LIKE KNVV-VKBUR,

WAERS LIKE KNVV-WAERS,

VSBED LIKE KNVV-VSBED,

INCO1 LIKE KNVV-INCO1,

INCO2 LIKE KNVV-INCO2,

ZTERM LIKE KNVV-ZTERM,

KTGRD LIKE KNVV-KTGRD,

KKBER LIKE KNKK-KKBER,

CTLPC LIKE KNKK-CTLPC,

UEDAT LIKE KNKK-UEDAT,

CASHD LIKE KNKK-CASHD,

CASHA LIKE KNKK-CASHA,

CASHC LIKE KNKK-CASHC,

DBPAY LIKE KNKK-DBPAY,

KLIMK LIKE KNKK-KLIMK,

KNKLI LIKE KNKK-KNKLI,

SKFOR LIKE KNKK-SKFOR,

SSOBL LIKE KNKK-SSOBL,

SAUFT LIKE KNKK-SAUFT,

CEXPO LIKE KNKK-SKFOR,

ABSBT LIKE KNKK-ABSBT,

VBALA LIKE KNKK-SKFOR,

VCURR LIKE KNKK-SKFOR,

VTR30 LIKE KNKK-SKFOR,

VTR60 LIKE KNKK-SKFOR,

VTR90 LIKE KNKK-SKFOR,

VTR9P LIKE KNKK-SKFOR,

VDOWN LIKE KNKK-SKFOR,

AUFSD LIKE KNA1-AUFSD,

LIFSD LIKE KNA1-LIFSD,

FAKSD LIKE KNA1-FAKSD,

LOEVM LIKE KNA1-LOEVM.

DATA: END OF T_KNVZ.

TRANSLATE T_KNVZ TO UPPER CASE <== problem when activate the program