‎2012 Mar 26 3:33 PM
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 !!!
‎2012 Mar 27 11:21 AM
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
‎2012 Mar 27 12:58 PM
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
‎2012 Mar 27 1:57 PM
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?
‎2012 Mar 28 3:59 AM
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.
‎2012 Mar 27 11:32 AM
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.
‎2012 Mar 27 12:59 PM
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.
‎2012 Mar 27 2:27 PM
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.
‎2012 Mar 28 4:04 AM
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 ?
‎2012 Mar 28 10:32 AM
Hi,
Please check the below screen shot which i had changed
above are the changes we have done
Regards,
Sateesh.
‎2012 Mar 28 4:59 PM
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?
‎2012 Mar 29 2:05 PM
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.
‎2012 Mar 29 2:39 PM
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.