SAP FTP
 
 
 
 
*&---------------------------------------------------------------------*
*& Report  Z_BARRY_FTP                                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  Z_BARRY_FTP   .
TYPE-POOLS truxs.
DATA: BEGIN OF btab OCCURS 10 ,
        date TYPE d ,
        cdc(10) TYPE c,
        mat LIKE mard-matnr ,
        dj(3) TYPE c ,
        xx TYPE i ,
      END OF btab .
DATA: BEGIN OF ctab OCCURS 10 ,
        date TYPE d ,
        cdc(10) TYPE c,
        mat LIKE mard-matnr ,
        dj(3) TYPE c ,
        xx(5) TYPE c ,
      END OF ctab .
DATA: mi_key TYPE i VALUE 26101957,
      mi_handle TYPE i,
      slen TYPE i .
DATA: csvtab TYPE truxs_t_text_data  .
DATA : filename(128) .
CONCATENATE 'Csv' sy-datum sy-uzeit  '.csv' INTO filename .
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.1.54' .
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-name = 'SPWD' .
      screen-invisible = '1'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
 
END-OF-SELECTION .
  slen = STRLEN( spwd ).
  btab-date = '20050223'.
  btab-cdc = 'HDC1CDC'.
  btab-mat = '1BP2181BCN1A0'.
  btab-dj = '1'.
  btab-xx = '14' .
  APPEND btab .
  btab-date = '20040513'.
  btab-cdc = 'HDC1CDC'.
  btab-mat = '1BP2181BCN1A0'.
  btab-dj = '1'.
  btab-xx = '265' .
  APPEND btab .
  btab-date = '20050205'.
  btab-cdc = 'HDC1CDC'.
  btab-mat = '1BP2181BCN1A0'.
  btab-dj = '1'.
  btab-xx = '4' .
  APPEND btab .

  LOOP AT btab .
    MOVE-CORRESPONDING btab TO ctab .
    APPEND ctab .
  ENDLOOP .
  CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
    TABLES
      i_tab_sap_data       = ctab
    CHANGING
      i_tab_converted_data = csvtab
    EXCEPTIONS
      conversion_failed    = 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 '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 'HTTP_SCRAMBLE'
    EXPORTING
      SOURCE      = spwd
      sourcelen   = slen
      key         = mi_key
    IMPORTING
      destination = spwd.
  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_CONNECT'
    EXPORTING
      user            = suser
      password        = spwd
      host            = shost
      rfc_destination = 'SAPFTP' "SAPFTPA
    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.
  CHECK sy-subrc = 0.
  CALL FUNCTION 'FTP_R3_TO_SERVER'
    EXPORTING
      handle         = mi_handle
      fname          = filename
      character_mode = 'X'
    TABLES
      text           = csvtab.
  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.