* Only for UNICODE SYSTEM
REPORT z_barry_down .
DATA: BEGIN OF itab OCCURS 0 ,
f1(8) TYPE c,
f2(6) TYPE c,
f3(12) TYPE c,
END OF itab.
DATA: str TYPE string .
START-OF-SELECTION.
itab-f1 = 'abc '.
itab-f2 = 'def '.
itab-f3 = '啊ANTF'.
APPEND itab.
itab-f1 = '测试'.
itab-f2 = '中文'.
itab-f3 = '四啊啊'.
APPEND itab.
itab-f1 = '测'.
itab-f2 = '中文'.
itab-f3 = '四三三abc'.
APPEND itab.
PERFORM download TABLES itab
USING 'H:\test4.txt'.
*&---------------------------------------------------------------------*
*& Form download
*&---------------------------------------------------------------------*
FORM download TABLES intab
USING filename TYPE c.
DATA: BEGIN OF outtab OCCURS 0,
line TYPE string ,
END OF outtab.
DATA: BEGIN OF headtab OCCURS 0 ,
length TYPE i ,
decimals TYPE i,
type_kind TYPE c,
name(30) TYPE c,
END OF headtab.
DATA: tab_key TYPE c VALUE cl_abap_char_utilities=>horizontal_tab ,
descr_ref TYPE REF TO cl_abap_structdescr,
o_file TYPE string,
str TYPE string ,
n TYPE i ,m TYPE i.
FIELD-SYMBOLS: TYPE abap_compdescr ,
,
TYPE ANY .
descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
LOOP AT descr_ref->components ASSIGNING .
MOVE-CORRESPONDING TO headtab.
APPEND headtab.
ENDLOOP.
DESCRIBE TABLE headtab LINES n.
LOOP AT intab ASSIGNING .
DO n TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE TO .
READ TABLE headtab INDEX sy-index.
m = headtab-length / 2 .
str = .
PERFORM addspace USING str m str .
CONCATENATE outtab-line tab_key str INTO outtab-line.
ENDDO.
SHIFT outtab-line.
APPEND outtab.
CLEAR outtab.
ENDLOOP.
o_file = filename.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = o_file
filetype = 'DAT'
codepage = '8400'
trunc_trailing_blanks_eol = ' '
CHANGING
data_tab = outtab[].
ENDFORM. "download
*&---------------------------------------------------------------------*
*& Form nounicode
*&---------------------------------------------------------------------*
FORM addspace USING value(input) TYPE string
needlen TYPE i
output TYPE string.
DATA: asc(120) TYPE c,
ansilen TYPE i ,
inlen TYPE i,
n TYPE i .
CONCATENATE asc 'abcdefghijklopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' INTO asc .
CONCATENATE asc ' 0123456789,./;''[]\-=`<>?:" INTO asc .
inlen = STRLEN( input ).
DO inlen TIMES.
n = sy-index - 1.
IF NOT asc CS input+n(1).
ansilen = ansilen + 2 .
ELSE.
ansilen = ansilen + 1 .
ENDIF.
ENDDO.
n = needlen - ansilen .
output = input.
DO n TIMES.
CONCATENATE output ' ' INTO output SEPARATED BY space.
ENDDO.
ENDFORM. "addspace
此程序作废,新程序见:
阅读(5280) | 评论(11) | 转发(0) |