Application Development and Automation 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: 
Read only

FTP_CONNECT taking more time

Former Member
0 Likes
1,242

Hi Folks

I have coded in a user exit of PR application(ME51N) for downloading the PR details to other system using FTP function modules. But FTP_CONNECT function module taking much time to connect to the other system results in low performance while creating PRs.

So please suggest me how to solve this.

Is there any way to run this FTP parallel to the application without interrupting the PR creation application.

Thanks in advance.

Hi Folks

I have coded in a user exit of PR application(ME51N) for downloading the PR details to other system using FTP function modules. But FTP_CONNECT function module taking much time to connect to the other system results in low performance while creating PRs.

So please suggest me how to solve this.

Is there any way to run this FTP parallel to the application without interrupting the PR creation application.

Thanks in advance.

7 REPLIES 7
Read only

Former Member
0 Likes
1,060

Can you post your code please?

Rob

Read only

0 Likes
1,060

Hi Rob,

Thanks for your quick response. Below is the code i have in a user exit which trigger while saving the PR.

user = 'user'.

password = '******'.

host = 'host'.

rfc_destination = 'destination'.

l_pwd = password.

l_slen = STRLEN( l_pwd ).

TRANSLATE l_pwd TO LOWER CASE.

  • TRANSLATE user TO LOWER CASE.

  • HTTP_SCRAMBLE: This is used to scramble the password provided into a

  • format which is been recognized by SAP.

CALL FUNCTION 'HTTP_SCRAMBLE'

EXPORTING

SOURCE = l_pwd

sourcelen = l_slen

key = c_key

IMPORTING

destination = l_pwd.

  • FTP_CONNECT : This function module is used to connect to other system

  • from SAP with the help of Userid & amp; scrambled password & Host

  • string & destination (default 'SAPFTP').

  • To Connect to the Server using FTP

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = user

password = l_pwd

host = host

rfc_destination = rfc_destination

IMPORTING

handle = w_hdl

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.

EXIT.

ENDIF.

  • Set Passive mode

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = w_hdl

command = 'set passive on'

TABLES

data = it_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3.

IF sy-subrc EQ 0.

ENDIF.

REFRESH it_result.

  • Set ascii mode

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = w_hdl

command = 'ascii'

TABLES

data = it_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3.

IF sy-subrc EQ 0.

ENDIF.

CLEAR file.

CONCATENATE filename 'RequisitionHeader' '.csv' INTO file.

CONDENSE file NO-GAPS.

CLEAR: it_final,

it_csvfile.

REFRESH: it_final,

it_csvfile.

PERFORM upload_from_server TABLES it_final

USING file

w_hdl.

IF it_final[] IS INITIAL.

CLEAR v_line.

v_line = 'Requisition_Number,Req_Creation_Date,Requester,

RequesterPasswordAdapter,Preparer,PreparerPasswordAdapter,Title'.

CONDENSE v_line NO-GAPS.

APPEND v_line TO it_final.

ENDIF.

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = ','

TABLES

i_tab_sap_data = it_csvhead

CHANGING

i_tab_converted_data = it_csvfile

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.

LOOP AT it_csvfile INTO v_line.

APPEND v_line TO it_final.

CLEAR v_line.

ENDLOOP.

PERFORM download_to_server TABLES it_final

USING file

w_hdl.

CLEAR file.

CONCATENATE filename 'RequisitionDetail' '.csv' INTO file.

CONDENSE file NO-GAPS.

CLEAR: it_final,

it_csvfile.

REFRESH: it_final,

it_csvfile.

PERFORM upload_from_server TABLES it_final

USING file

w_hdl.

IF it_final[] IS INITIAL.

v_line = 'Requisition_Number,Line_Number,Need_By_Date,Commodity_Code,

Quantity,Unit_Price,Unit_Price_Currency,Unit_Of_Measure,Ship_To,

Deliver_To,Item_No,Item_Description,SupplierPartNumber,Account_Category,

Purchase_Group'.

CONDENSE v_line NO-GAPS.

APPEND v_line TO it_final.

ENDIF.

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = ','

TABLES

i_tab_sap_data = it_csvitem

CHANGING

i_tab_converted_data = it_csvfile

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.

LOOP AT it_csvfile INTO v_line.

APPEND v_line TO it_final.

CLEAR v_line.

ENDLOOP.

PERFORM download_to_server TABLES it_final

USING file

w_hdl.

CLEAR file.

CONCATENATE filename 'RequisitionSplitAccounting' '.csv' INTO file.

CONDENSE file NO-GAPS.

CLEAR: it_final,

it_csvfile.

REFRESH: it_final,

it_csvfile.

PERFORM upload_from_server TABLES it_final

USING file

w_hdl.

IF it_final[] IS INITIAL.

v_line = 'Requisition_Number,Line_Number,Split_Line_Number,Percentage,

Amount,Amt_Currency,Quantity,Account,Cost_Center,General_Ledger,Asset,

WBSElement,Internal_Order,Company_Code'.

CONDENSE v_line NO-GAPS.

APPEND v_line TO it_final.

ENDIF.

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = ','

TABLES

i_tab_sap_data = it_csvacc

CHANGING

i_tab_converted_data = it_csvfile

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.

LOOP AT it_csvfile INTO v_line.

APPEND v_line TO it_final.

CLEAR v_line.

ENDLOOP.

PERFORM download_to_server TABLES it_final

USING file

w_hdl.

  • FTP_DISCONNECT : This function module is used to disconnect the

  • connection between SAP and other system.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = w_hdl.

  • RFC_CONNECTION_CLOSE : This function module is used to disconnect the

  • RFC connection between SAP and other system.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'

EXPORTING

destination = rfc_destination

EXCEPTIONS

OTHERS = 1.

ENDIF.

ENDIF.

ENDFUNCTION.

&----


*& Form download_to_server

&----


  • text

----


  • -->IT_FILE text

  • -->FILE text

  • -->HDL text

----


FORM download_to_server TABLES it_file

USING file

hdl.

CONDENSE file NO-GAPS.

  • FTP_R3_TO_SERVER : This function module is used to transfer the

  • internal table data as a file to other system in the character mode.

CALL FUNCTION 'FTP_R3_TO_SERVER'

EXPORTING

handle = hdl

fname = file

character_mode = 'X'

TABLES

text = it_file

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. "download_to_server

&----


*& Form upload_from_server

&----


  • text

----


  • -->IT_FILE text

  • -->FILE text

  • -->HDL text

----


FORM upload_from_server TABLES it_file

USING file

hdl.

CONDENSE file NO-GAPS.

CALL FUNCTION 'FTP_SERVER_TO_R3'

EXPORTING

handle = hdl

fname = file

character_mode = 'X'

TABLES

text = it_file

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.

LOOP AT it_file.

REPLACE ALL OCCURRENCES OF '#' IN it_file WITH ''.

MODIFY it_file.

ENDLOOP.

ENDFORM. "upload_from_server

Thanks

Read only

0 Likes
1,060

Is this code being called in a loop or from a PERFORM that is called in a loop?

Rob

Read only

0 Likes
1,060

Hi Rob,

This is a function module having EBAN, EBKN, EBAN_OLD and EBKN_OLD table parameters. I have called this function module in a BADI which can be triggered while saving the PR. While debugging i found that FTP_CONNECT function module is taking around 30 sec to get connection from other server. So the PR getting delay while saving. Here my understanding is its good to avoid this accessing other server between the PR saving. It is great if you can help me by giving an idea to access other server without disturbing the PR application process either parallel to this application or something which can not delay the PR application saving.

Note: As per my understanding FTP_CONNECT function module takes time, even from CMD prompt also its taking time to connect the other server.

Thanks in Advance.

Read only

Former Member
0 Likes
1,060

Hi ,

create a new function module and set the processing type in FM attributes tab to remote enabled fM . call the FTP connect funtion module and FTP commad and FTP disconnect FM in this FM.

in the user exit call this new function module in a new task

call function ..... starting new task <taskname>

sirish

Read only

0 Likes
1,060

Hi Sirish,

Thank you vey much. Your post will solve my problem.

I have one question. why should we make the FM as remote enabled for calling in New task. What is the reason behind it?

What is the difference between New task, Separate task and background task?

Where do we use these exactly?

Thanks in advance.

Read only

0 Likes
1,060

Hi Sirish,

I tried as you told. But i cant get the files in the other server while iam getting them without new task.

I have created a FM with this code and processing mode as Remote enabled.

What might be the problem?

How can we check wether that FM is executed or not? I put a break point in that FM, but i didnt get it to debug.

Thanks in advance