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

Issue with traditional Chinese characters when downloaded in text file

premal_mistry2
Active Participant
0 Likes
6,155

Hi,

I am facing an when mixed contents (English & chinese) are downloaded to a text file. The issue is with the material description field.. My main requirement is that the full field length should be preserved when the data is downloaded either in English or Chinese. For that I am making use of offset and passing that internal table to gui_download.. Now for English every thing works fine, but as soon as some Chinese characters appear in the mat desc field the immediate field to its right gets shifted to 3 to 4 characters. Now this is annoying to the customer.. I have made use of codepage 8300 while downloading but it is not serving any purpose apart from translating.. I suspect that this is due to 2 byte storage of unicode characters.

The file output is like this

mat1 some description ins eng X 20120326

mat2 <some Chinese text>               X 20120328

The file output should be, even the mat desc is not full 40 chars.

mat1 some description ins eng X 20120326

mat2 <some Chinese text>      X 20120328

Any help to resolve this issue would be much appreciated.. Thanks

Message was edited by: Premal Mistry Guys any help !!!

12 REPLIES 12
Read only

gaurab_banerji
Active Participant
0 Likes
4,253

if you are downloading as tab delimited file then it is nothing to be considered about, tab delimitations in notepad often do not show the correct spacing. try opening the file in ms excel. if it comes correctly then its fine....

also, for chinese, i think codepage 8400 is best. also set filetype as 'ASC'.

else, see example below....


      begin of rec_output2,
        hkont(10),
        dmbtr(18),                                          "3 decimals
        shkzg,           "S=D others=C
        sgtxt(25),
        bewar(1),       "V/I/D
        waers(5),
      end of rec_output2,
      begin of rec_output3,
        hkont(10) type x,
        dmbtr(18) type x,                                   "3 decimals
        shkzg type x,           "S=D others=C
        sgtxt(25) type x,
        bewar(1) type x,       "V/I/D
        waers(5) type x,
      end of rec_output3,
      begin of rec_output,
        record(59) type x,
      end of rec_output,
      it_output like standard TABLE OF rec_output.
field-SYMBOLS: <fs_output> like line of it_output.

...

    PERFORM translate_codepage using rec_output2 rec_output3.
    append INITIAL LINE TO it_output ASSIGNING <fs_output>.
    <fs_output> = rec_output3.

...

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
    EXPORTING
      FILENAME                = p_file
      CONFIRM_OVERWRITE       = 'X'
    CHANGING
      DATA_TAB                = it_output
    EXCEPTIONS
      FILE_WRITE_ERROR        = 1
     others                  = 24.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  translate_codepage
*&---------------------------------------------------------------------*
* The output file must be fixed lengt file with fixed field lenght, so
* a special code page translation is required
* Demo program RSCP0032 is used as inspiration for this rutine
*----------------------------------------------------------------------*
FORM translate_codepage using p_recin p_recout.
  FIELD-SYMBOLS: <FS_inFIELD> TYPE ANY,
                 <fs_outfield> type any.
  DATA: conv_obj TYPE REF TO cl_abap_conv_obj,
        L_FIELDLENGTH TYPE I,
        L_OUT_XSTRING TYPE XSTRING.


  w_in_codepage = '4103'.    "system code page
  w_out_codepage = '8400'.  "Chinese code page

  DO.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE p_recin TO <FS_inFIELD>.
    IF SY-SUBRC NE 0.
      EXIT.
    ENDIF.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE p_recout TO <FS_outfield>.
    IF SY-SUBRC NE 0.
      EXIT.
    ENDIF.

    DESCRIBE FIELD <FS_inFIELD> LENGTH L_FIELDLENGTH IN CHARACTER MODE.

    CREATE OBJECT conv_obj
      EXPORTING
        incode           = W_in_codepage
        outcode          = W_out_cODEpAGE
        ctrlcode         = '.'
        sapownch         = '.'
      EXCEPTIONS
        invalid_codepage = 1
        internal_error   = 2
        others           = 3.

    CALL METHOD conv_obj->convert
      EXPORTING
        inbuff         = <FS_inFIELD>
        outbufflg      = L_FIELDLENGTH
      IMPORTING
        outbuff        = L_out_xstring
      EXCEPTIONS
        internal_error = 1
        OTHERS         = 2.
    MOVE L_OUT_XSTRING TO <FS_outFIELD>.
    FREE conv_obj.
  ENDDO.
ENDFORM. " translate_codepage

Read only

0 Likes
4,253

Hi Guarav,

I have used this same example yesterday which I found from SCN. That issue is now solved ... but it has generated new issue.

Now the field value after the mat description is shifting 3 char to left (earlier it was shifting to right)...

mat1 some description ins eng X 20120326

mat2 <some Chinese text>    X 20120328

Read only

0 Likes
4,253

hmm interesting..

perhaps if you change the font in notepad ( to lucida console, regular, 10) you might see them correctly..

i hope the text looks okay when you open as tab delimited file in excel?

Read only

0 Likes
4,253

nopes .. changing font also won't work. In-fact my default font is Lucida Console/regular/10.

Yeah, when I open the same text file in excel with encoding fo traditional chinese the text looks ok. However, please note that the text in notepad is in proper alingement (the way I want), but when I open the same text file in excel it shift's to the left a bit.

My client when tries to open the downloaded text file in notepad on his machine, he can directly see that the text is shifting to left a little bit.

Message was edited by: Premal Mistry

Here's one example ...

As you can see frist screenshot is when text file is opened in excel, just after the mat description you can see that 'X' is not aligned with the upper row. However, in notepad the 'X' is properly aligned.

Read only

Former Member
0 Likes
4,253

Hi,

Identify the device

Please change the code page(8400) at device level in t-code SPAD difinately it will work. there is no need to change at code level.

Regards,

Sateesh.

Read only

0 Likes
4,253

Hi Sateesh,

This is related to file download and not a issue with printing. I think in my case your solution is not applicable. Though thanks for the reply, it might help in future.

Read only

0 Likes
4,253

Hi,

I too face the same problem and i too thought that in code we have to change in code nothing will change you can check by changing code also.

Solution is

go to SPAD t-code ->click on full admin button->in device types tab give your device type->click on display->go to print controls for  SLINE name in control character sequence give 0D0A

your problem will be solved.

REgards,

Sateesh.

Read only

0 Likes
4,253

HI Sateesh,

Which device type I should select (I presume SWIN) from the list. I went into the "Print Contro" for SWIN but did not find SLINE in it.

Any advice ?

Read only

0 Likes
4,253

Hi,

Please check the below screen shot which i had changed

above are the changes we have done

Regards,

Sateesh.

Read only

0 Likes
4,253

Hi Sateesh,

Just wanted to confirm that first I need to create a custom device type and make settings that you have shown?

Also how would I make surethat the file that is downloaded will use that device type?

Read only

0 Likes
4,253

Hi,

First you have to create 'z' page format before this one and assign the page format to your script or

smartform and also to zdevice type

Regards,

Sateesh.

Read only

0 Likes
4,253

Hi Sateesh,

That's the issue here.  My problem is not related to any sort of printing but related to downloading the data in a file.  So in that case I cannot use a custom device type which will help in adjusting the characters.