Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7189699
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2008-03-19 13:27:08

 
* 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
 
 
此程序作废,新程序见:
阅读(5245) | 评论(11) | 转发(0) |
给主人留下些什么吧!~~

yimeng802008-03-19 14:24:42

奇怪,在我这里还是不行..我给你发TXT文件