Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to transfer sap document to file server using FTP

Former Member
0 Kudos

I have successed.But my solution is foolish.

1st: CL_CRM_DOCUMENTS=>GET_WITH_TABLE

( The file of 'CL_CRM_DOCUMENTS=>GET_WITH_FILE' is on my PC ,not on SAP server )

2nd: Save the file table to a SAP server file.

(open dataset mode BINARY)

3nd: Transfer file by ftp command.

Can we do it easy.

Thanks.

4 REPLIES 4

Former Member
0 Kudos

Use below commands :

open dataset p_file for output in text mode default binary encoding.

loop at ur int_table.

transfer int_table to p_file.

clear int_table.

endloop.

close dataset p_file

0 Kudos

Hi Seshu

Can you get the acture path of a sap document under the tcode 'AL11'? I am afraid that it is not in windows file mode. Can you get the 'document' file without the class document? Just open dataset?

0 Kudos

Hi,

Can you put the code for use the method CL_CRM_DOCUMENTS=>GET_WITH_FILE?

Thanks.

Miquel.

mnicolai_77
Active Participant
0 Kudos

hi,

there are 2 ways to transfer a file from a generic file server to another server via FTP.

i preferr to use this finction

>FUNCTION zftp_send_file_unix.

>*"----


>""Interfaccia locale:

>*" IMPORTING

>*" REFERENCE(IP) TYPE RLGRAP-FILENAME

>*" REFERENCE(USER) TYPE RLGRAP-FILENAME

>*" REFERENCE(PASSWORD) TYPE RLGRAP-FILENAME

>*" REFERENCE(COMFILE) TYPE SXPGCOLIST-PARAMETERS

>*" REFERENCE(FILESORG) TYPE RLGRAP-FILENAME

>*" REFERENCE(NO_CHANGE_DIR) TYPE XFELD DEFAULT ''

>*" REFERENCE(NEW_DIR) TYPE RLGRAP-FILENAME OPTIONAL

>*" TABLES

>*" MESSAGES STRUCTURE BTCXPM

>*" EXCEPTIONS

>*" ERROR_WRITE

<*"----


>

> DATA: strfile(150). "comand row

> DATA: name LIKE sxpgcolist-name VALUE 'ZFTP'. "name of comand defines in sm66

> <DATA w_status LIKE btcxp3-exitstat. "status

> DATA transfer_complete.

> DATA: lv_comfile TYPE sxpgcolist-parameters.

> MOVE comfile TO lv_comfile.

>*generate a command file

> OPEN DATASET lv_comfile FOR OUTPUT IN TEXT MODE.

> IF sy-subrc NE 0.

> ENDIF.

>

>* Write into the file the right sequesce of commad that we want to esecute

>

> CONCATENATE 'ftp -n' ip '<<ENDFTP' INTO strfile SEPARATED BY ' '.

> TRANSFER strfile TO lv_comfile.

>

>

> CLEAR strfile.

> CONCATENATE 'quote user' user INTO strfile SEPARATED BY ' '.

> TRANSFER strfile TO lv_comfile.

>

> CLEAR strfile.

> CONCATENATE 'quote pass' password INTO strfile SEPARATED BY ' '.

> TRANSFER strfile TO lv_comfile.

>

> CLEAR strfile.

> MOVE 'verbose' TO strfile.

> TRANSFER strfile TO lv_comfile.

>

> IF no_change_dir IS INITIAL.

> CLEAR strfile.

> CONCATENATE 'cd' new_dir INTO strfile SEPARATED BY ' '.

> TRANSFER strfile TO lv_comfile.

> ENDIF.

>

> CLEAR strfile.

> CONCATENATE 'put' filesorg INTO strfile SEPARATED BY ' '.

> TRANSFER strfile TO lv_comfile.

>

> CLEAR strfile.

> MOVE 'bye' TO strfile.

> TRANSFER strfile TO lv_comfile.

>

>

> CLOSE DATASET lv_comfile.

>

> CALL FUNCTION 'SXPG_CALL_SYSTEM' "execution of S.O. command

> EXPORTING

> commandname = name

> additional_parameters = lv_comfile

> IMPORTING

> status = w_status

> TABLES

> exec_protocol = messages

> EXCEPTIONS

> no_permission = 1

> command_not_found = 2

> parameters_too_long = 3

> security_risk = 4

> wrong_check_call_interface = 5

> program_start_error = 6

> program_termination_error = 7

> x_error = 8

> parameter_expected = 9

> too_many_parameters = 10

> illegal_command = 11

> OTHERS = 12.

> IF sy-subrc = 0.

> IF w_status = 'E'.

>*raise file_not_found.

> MESSAGE e101(ztrv) WITH 'send'.

>*error in file command

> ENDIF.

> transfer_complete = 'N'.

> LOOP AT messages.

> CASE messages-message(4).

> WHEN '250 ' OR '226 '.

> transfer_complete = 'S'.

> ENDCASE.

>*write / messages-message.

> ENDLOOP.

> IF transfer_complete = 'N' OR w_status = 'E'.

> RAISE error_write.

>*message e022(zb) with file.

>*file & not accesible.

> ENDIF.

> ELSE.

> MESSAGE e100(ztrv) WITH sy-subrc name.

>*error & to execute the external command &.

> ENDIF.

>

> DELETE DATASET lv_comfile.

>

>ENDFUNCTION.

for using this function you have to create a new entries in the transaction SM66 external command.

note this function have the sequence of FTP command for UNIX if your sistem is on WINDOWS or AS400 or other S.O. you have to change the FTP command

otherwise you can use the finction FTP_CONNECT FTP_TRANSFER FTP_COMMAND.

bye,

Marco