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

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

上一篇:SESSION方式的BDC

下一篇:选择界面LISTBOX

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

sytrydor2008-04-18 18:30:44

An exception occurred that is explained in detai The exception, which is assigned to class 'CX_SY caught in procedure "ITABTODATASET" "(FORM)", nor was it p Since the caller of the procedure could not have exception would occur, the current program is te The reason for the exception is: It was tried to assign a reference to a rerefere 'CAST' operation ('?=' or 'MOVE ?TO'). However, the current content of the source varia the target variable. source type: "\CLASS=CL_ABAP

sytrydor2008-04-18 16:54:02

FORM itabtodataset TABLES intab USING dname TYPE c. 这里的 intab是我们要将里面的每个字段都加上‘|’的内表吗?如果是,那应该传什么样的值给参数dname?

sytrydor2008-04-18 16:36:39

老白,FORM itabtodataset 这个FORM的主要作用是什么?是为了加一些字符到一个内表中的每个字段后面去吗?