Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7189691
  • 博文数量: 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)

分类:

2007-08-29 15:30:29

FORM itabtodataset TABLES intab
                   USING dname TYPE c.
  DATA: tab TYPE x VALUE '09',
        enter(2) TYPE x VALUE '0D0A',
        count(8) TYPE n.
  DATA: BEGIN OF headtab OCCURS 0 ,
          length    TYPE i ,
          decimals  TYPE i,
          type_kind TYPE c,
          name(30)  TYPE c,
        END OF headtab.
  DATA n TYPE i .
  DATA descr_ref TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS: TYPE abap_compdescr ,
                 ,
                 TYPE ANY .
  DATA:str TYPE string ,
       text1 TYPE c.
  DATA:runtime TYPE int4,
       repid LIKE sy-repid.
  DATA: flen TYPE i.
  FIELD-SYMBOLS: TYPE STANDARD TABLE,
               ,
               .
  DATA: dy_table TYPE REF TO data,
        dy_line  TYPE REF TO data,
        xfc TYPE lvc_s_fcat,
        ifc TYPE lvc_t_fcat.

  descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
  LOOP AT descr_ref->components ASSIGNING .
    MOVE-CORRESPONDING TO headtab.
    APPEND headtab.
  ENDLOOP.
  LOOP AT headtab.
    flen = flen + headtab-length + headtab-DECIMALS + 1.
  ENDLOOP.
  CLEAR xfc.
  xfc-fieldname = 'LINE' .
  xfc-datatype = 'CHAR'.  "或者 xfc-inttype = 'C' .
  xfc-intlen = flen.
  APPEND xfc TO ifc.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
               EXPORTING
                  it_fieldcatalog = ifc
               IMPORTING
                  ep_table        = dy_table.
  ASSIGN dy_table->* TO .
  CREATE DATA dy_line LIKE LINE OF .
  ASSIGN dy_line->* TO .
  ASSIGN COMPONENT 'LINE' OF STRUCTURE TO .

  DESCRIBE TABLE headtab LINES n.

  LOOP AT intab ASSIGNING .
    DO n TIMES.
      ASSIGN COMPONENT sy-index OF STRUCTURE TO .
      str = .
      READ TABLE headtab INDEX sy-index.
      IF headtab-type_kind = 'I' OR headtab-type_kind = 'P'
                                 OR headtab-type_kind = 'F'.
        SEARCH str FOR '-'.
        IF sy-subrc = 0 AND sy-fdpos <> 0.
          SPLIT str AT '-' INTO str text1.
          CONDENSE str.
          CONCATENATE '-' str INTO str.
        ELSE.
          CONDENSE str.
        ENDIF.
      ELSE.
*        SHIFT str LEFT DELETING LEADING '0' .
      ENDIF.
      CONCATENATE tab str INTO .
    ENDDO.
    SHIFT .
    APPEND TO .
    CLEAR .
    count = count + 1 .
  ENDLOOP.

  OPEN DATASET dname FOR OUTPUT IN BINARY MODE .
  IF sy-subrc NE 0.
  ENDIF.

  LOOP AT INTO .
    str = .
    TRANSFER str TO dname.
    TRANSFER enter TO dname.
  ENDLOOP.
  CLOSE DATASET dname.
ENDFORM.

 
 
FOR ECC6

REPORT z_barry_test.

DATA: BEGIN OF itab OCCURS 0 ,
        txt(10) ,
        menge LIKE ekpo-menge,
        datum LIKE sy-datum,
      END OF itab.

itab-txt = 'Lin1'.
itab-menge = '123.45'.
itab-datum = sy-datum.
APPEND itab.
itab-txt = '第二行'.
itab-menge = '0.45'.
itab-datum = sy-datum.
APPEND itab.
itab-txt = '第三行'.
itab-menge = '0.45'.
itab-datum = sy-datum.
APPEND itab.

PERFORM itabtodataset TABLES itab USING 'testbarry.txt'.

*&---------------------------------------------------------------------*
*&      Form  itabtodataset
*&---------------------------------------------------------------------*
FORM itabtodataset TABLES intab
                   USING dname TYPE c.
  DATA: tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab ,
        count(8) TYPE n.
  DATA: BEGIN OF headtab OCCURS 0 ,
          length    TYPE i ,
          decimals  TYPE i,
          type_kind TYPE c,
          name(30)  TYPE c,
        END OF headtab.
  DATA n TYPE i .
  DATA descr_ref TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS: TYPE abap_compdescr ,
                 ,
                 TYPE ANY .
  DATA:str TYPE string ,
       cha(100) type c,
       text1 TYPE c.
  DATA:runtime TYPE int4,
       repid LIKE sy-repid.
  DATA: flen TYPE i.
  FIELD-SYMBOLS: TYPE STANDARD TABLE,
               ,
               .
  DATA: dy_table TYPE REF TO data,
        dy_line  TYPE REF TO data,
        xfc TYPE lvc_s_fcat,
        ifc TYPE lvc_t_fcat.

  descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
  LOOP AT descr_ref->components ASSIGNING .
    MOVE-CORRESPONDING TO headtab.
    APPEND headtab.
  ENDLOOP.
  LOOP AT headtab.
    flen = flen + headtab-length + headtab-decimals + 1.
  ENDLOOP.
  CLEAR xfc.
  xfc-fieldname = 'LINE' .
  xfc-datatype = 'CHAR'.  "或者 xfc-inttype = 'C' .
  xfc-intlen = flen.
  APPEND xfc TO ifc.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table        = dy_table.
  ASSIGN dy_table->* TO .
  CREATE DATA dy_line LIKE LINE OF .
  ASSIGN dy_line->* TO .
  ASSIGN COMPONENT 'LINE' OF STRUCTURE TO .

  DESCRIBE TABLE headtab LINES n.

  LOOP AT intab ASSIGNING .
    DO n TIMES.
      ASSIGN COMPONENT sy-index OF STRUCTURE TO .
      str = .
      READ TABLE headtab INDEX sy-index.
      IF headtab-type_kind = 'I' OR headtab-type_kind = 'P'
                                 OR headtab-type_kind = 'F'.
        SEARCH str FOR '-'.
        IF sy-subrc = 0 AND sy-fdpos <> 0.
          SPLIT str AT '-' INTO str text1.
          CONDENSE str.
          CONCATENATE '-' str INTO str.
        ELSE.
          CONDENSE str.
        ENDIF.
      ELSEIF headtab-type_kind = 'D'.
         write to cha using edit mask '____-__-__' .
         str = cha .
      ELSE.
*        SHIFT str LEFT DELETING LEADING '0' .
      ENDIF.
      CONCATENATE tab str INTO .
    ENDDO.
    SHIFT .
    APPEND TO .
    CLEAR .
    count = count + 1 .
  ENDLOOP.

  OPEN DATASET dname FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE '8401' WITH WINDOWS LINEFEED.
*  OPEN DATASET dname FOR OUTPUT IN TEXT MODE ENCODING UTF-8 WITH WINDOWS LINEFEED .
  IF sy-subrc NE 0.
  ENDIF.

  LOOP AT INTO .
    str = .
    TRANSFER str TO dname.
  ENDLOOP.
  CLOSE DATASET dname.
ENDFORM.                    "itabtodataset

 
阅读(6621) | 评论(14) | 转发(0) |
0

上一篇:SESSION方式的BDC

下一篇:选择界面LISTBOX

给主人留下些什么吧!~~

sytrydor2008-04-18 18:54:10

看出是什么问题了吗?

sytrydor2008-04-18 18:53:43

我的zisbib0010是一个自定义的客户化表

sytrydor2008-04-18 18:52:48

还有,我把DATA: tab TYPE c VALUE '9', tab这个类型改为C 了,原来是DATA: tab TYPE X VALUE '09', 但不能激活

sytrydor2008-04-18 18:51:05

PERFORM itabtodataset USING i_zbill_main 'X'. FORM itabtodataset USING intab type i_zbill_main_type dname TYPE c. TYPES i_zbill_main_type TYPE zisbib0010 OCCURS 0. "内表类型 DATA: i_zbill_main TYPE zisbib0010 OCCURS 0, "主文件内表 我数据的定义与调用是这样的

qdbarry2008-04-18 18:38:30

itabtodataset,顾名思义,就是把内表的数据放到Dataset,也就是应用服务器上的文件。至于字段间用什么分隔符,由字段Tab决定。 这个是46C版本用的,如果是更高版本使用,得改一下。 传入参数intab就是一个Standard table,标准内表。 你出这个错误可能是传入参数错了。