Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7189138
  • 博文数量: 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-06-07 18:38:04

REPORT z_barry_itab_to_dataset_ftp .

DATA: BEGIN OF intab OCCURS 0 ,
        f1  LIKE mseg-menge,
        f2(10) TYPE c,
        f3(10) TYPE c,
        f4 TYPE c,
      END OF intab.
DATA   dname(40) TYPE c VALUE '/usr/sap/BQD/DVEBMGS00/work/0001.txt' .

PARAMETERS: suser(30) TYPE c LOWER CASE DEFAULT 'user01',
            spwd(30)  TYPE c LOWER CASE DEFAULT 'aaaaaa' ,
            shost(64) TYPE c LOWER CASE DEFAULT '192.168.242.72' ,
            spath(64) TYPE c LOWER CASE DEFAULT ''  .

START-OF-SELECTION.
  intab-f1 = '-34.32'.
  intab-f2 = ''.
  intab-f3 = 'a3'.
  APPEND intab.
  intab-f1 = '3'.
  intab-f2 = 'b2'.
  intab-f3 = 'b3'.
  intab-f4 = 'a'.
  APPEND intab.

  PERFORM itabtodataset TABLES intab[]
                        USING dname.
  PERFORM toftp.

*---------------------------------------------------------------------*
*       FORM ftoline                                                  *
*---------------------------------------------------------------------*
FORM itabtodataset TABLES intab
                   USING dname TYPE c.

  DATA: BEGIN OF outtab OCCURS 0,
          line(1000) TYPE c,
        END OF outtab.
  DATA: tab TYPE x VALUE '09',
        enter(2) TYPE x VALUE '0D0A'.
  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.

  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 .
      str = .
      READ TABLE headtab INDEX sy-index.
      IF headtab-type_kind = 'I' OR headtab-type_kind = 'P'.
        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.
      ENDIF.
      CONCATENATE outtab-line tab str INTO outtab-line.
    ENDDO.
    SHIFT outtab.
    APPEND outtab.
    CLEAR outtab.
  ENDLOOP.

  OPEN DATASET dname FOR OUTPUT IN BINARY MODE .
  IF sy-subrc NE 0.
    EXIT.
  ENDIF.
  LOOP AT outtab.
    str = outtab.
    TRANSFER str TO dname.
    TRANSFER enter TO dname.
  ENDLOOP.
  CLOSE DATASET dname.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM toftp                                                    *
*---------------------------------------------------------------------*
FORM toftp.
  DATA: text1(1) TYPE c ,
        commtext(50) .
  DATA: BEGIN OF ftp_result OCCURS 0,
          line(100),
        END OF ftp_result.

  DATA: mi_key TYPE i VALUE 26101957,
        mi_handle TYPE i,
        slen TYPE i .
  DATA : filename(128) .

  slen = strlen( spwd ).

  CALL 'AB_RFC_X_SCRAMBLE_STRING'
    ID 'SOURCE'      FIELD spwd
    ID 'KEY'         FIELD mi_key
    ID 'SCR'         FIELD 'X'
    ID 'DESTINATION' FIELD spwd
    ID 'DSTLEN'      FIELD slen.

  CALL FUNCTION 'FTP_CONNECT'
       EXPORTING
            user            = suser
            password        = spwd
            host            = shost
            rfc_destination = 'SAPFTPBARRY'
       IMPORTING
            handle          = mi_handle
       EXCEPTIONS
            not_connected   = 1
            OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'FTP_COMMAND'
       EXPORTING
            handle        = mi_handle
            command       = 'binary'
       TABLES
            data          = ftp_result
       EXCEPTIONS
            tcpip_error   = 1
            command_error = 2
            data_error    = 3
            OTHERS        = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'FTP_COMMAND'
       EXPORTING
            handle        = mi_handle
            command       = 'put 0001.txt'
       TABLES
            data          = ftp_result
       EXCEPTIONS
            tcpip_error   = 1
            command_error = 2
            data_error    = 3
            OTHERS        = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'FTP_DISCONNECT'
       EXPORTING
            handle = mi_handle
       EXCEPTIONS
            OTHERS = 1.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.

阅读(4286) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-12-25 16:06:02

非常感谢老白的分享,谢谢