Monday, 17 April 2017

SAP to FTP Transfer via ABAP Code



Go to Tcode AL11

Find the available sap directories.



FORM SAP_TO_FTP_SERVER .

typesbegin of t_file,
        text(1000type c,
  end of t_file.

DATAgt_file type table of t_file,
      gs_file type t_file.

*DATA: FILE TYPE STRING VALUE 'TEST.CSV'.

DATAe_file like rlgrap-filename  value '/tmp/mnt_test_nfs/file.xls'.



*DATA: l_user(30) type c value 'testftp',
*      l_pwd(30) type c value 'S@pc$$fTp15#',
*      l_host(64) type c value '10.2.52.144',
*      l_dest like rfcdes-rfcdest value 'SAPFTPA'.
*
*DATA:
*      w_hdl type i,
*      c_key type i value 26101957,
*      l_slen type i.
*
clear gs_final1.





loop at gt_final1 into gs_final1.
*
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
      INPUT         gs_final1-g1
   IMPORTING
     OUTPUT        gs_final1-g1
            .

*
 CONDENSEgs_final1-g1gs_final1-g2gs_final1-g3gs_final1-g4gs_final1-g5gs_final1-g6gs_final1-g7gs_final1-g8,
  gs_final1-g9gs_final1-g10gs_final1-g11gs_final1-g12gs_final1-g13gs_final1-g14gs_final1-g15gs_final1-g16gs_final1-g17gs_final1-g18,
  gs_final1-g19gs_final1-g20gs_final1-g21gs_final1-g22gs_final1-g23gs_final1-g24gs_final1-g25gs_final1-g26,
  gs_final1-g27gs_final1-g28gs_final1-g29gs_final1-g30gs_final1-g31gs_final1-g32gs_final1-g33gs_final1-g34,
  gs_final1-g35gs_final1-g36gs_final1-g37gs_final1-g38gs_final1-g39gs_final1-g40gs_final1-g41gs_final1-g42gs_final1-g43,
  gs_final1-g44gs_final1-g45gs_final1-g46gs_final1-g47 no-gaps.


  concatenate gs_final1-g1 gs_final1-g2 gs_final1-g3 gs_final1-g4 gs_final1-g5 gs_final1-g6 gs_final1-g7 gs_final1-g8
  gs_final1-g9 gs_final1-g10 gs_final1-g11 gs_final1-g12 gs_final1-g13 gs_final1-g14 gs_final1-g15 gs_final1-g16 gs_final1-g17 gs_final1-g18
  gs_final1-g19 gs_final1-g20 gs_final1-g21 gs_final1-g22 gs_final1-g23 gs_final1-g24 gs_final1-g25 gs_final1-g26
  gs_final1-g27 gs_final1-g28 gs_final1-g29 gs_final1-g30 gs_final1-g31 gs_final1-g32 gs_final1-g33 gs_final1-g34
  gs_final1-g35 gs_final1-g36 gs_final1-g37 gs_final1-g38 gs_final1-g39 gs_final1-g40 gs_final1-g41 gs_final1-g42 gs_final1-g43
  gs_final1-g44 gs_final1-g45 gs_final1-g46 gs_final1-g47 into gs_file separated by ','.
  append gs_file to gt_file.
  cleargs_filegs_final1.
endloop.

*concatenate '/tmp/mnt_test_nfs/test_' so_org-low '.csv' into e_file.

open dataset e_file  for output in text mode encoding default.

if sy-subrc ne 0.
  write'error opening file'.
endif.


loop at gt_file into gs_file.
  transfer gs_file to e_file.
endloop.

*endloop.

close dataset e_file.
refresh gt_file.

*endif.

*
*set extended check off.
*
*l_slen = strlen( l_pwd ).
*
*CALL FUNCTION 'HTTP_SCRAMBLE'
*  EXPORTING
*    SOURCE            = l_pwd
*    SOURCELEN         = l_slen
*    KEY               = c_key
* IMPORTING
*   DESTINATION       = l_pwd
*          .
*
*CALL FUNCTION 'FTP_CONNECT'
*  EXPORTING
*    USER                   = l_user
*    PASSWORD               = l_pwd
**   ACCOUNT                =
*    HOST                   = l_host
*    RFC_DESTINATION        = l_dest
**   GATEWAY_USER           =
**   GATEWAY_PASSWORD       =
**   GATEWAY_HOST           =
* IMPORTING
*   HANDLE                 = w_hdl
** EXCEPTIONS
**   NOT_CONNECTED          = 1
**   OTHERS                 = 2
*          .
*IF SY-SUBRC <> 0.
** Implement suitable error handling here
*ENDIF.
*
*CALL FUNCTION 'FTP_R3_TO_SERVER'
*  EXPORTING
*    HANDLE               = w_hdl
*    FNAME                = '/Remedy'
**   BLOB_LENGTH          =
**   CHARACTER_MODE       =
* TABLES
**   BLOB                 =
*   TEXT                 =  gt_file
* EXCEPTIONS
*   TCPIP_ERROR          = 1
*   COMMAND_ERROR        = 2
*   DATA_ERROR           = 3
*   OTHERS               = 4
*          .
*IF SY-SUBRC <> 0.
** Implement suitable error handling here
*
*  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 RAISING invalid_output_file.
*ENDIF.
*
*CALL FUNCTION 'FTP_DISCONNECT'
*  EXPORTING
*    HANDLE        = w_hdl
*          .
*
*CALL FUNCTION 'RFC_CONNECTION_CLOSE'
* EXPORTING
*   DESTINATION                = l_dest
**   TASKNAME                   =
* EXCEPTIONS
*   DESTINATION_NOT_OPEN       = 1
*   OTHERS                     = 2
*          .
*IF SY-SUBRC <> 0.
** Implement suitable error handling here
*ENDIF.
*



ENDFORM.

No comments:

Post a Comment