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: 

Background Scheduling Excel File Program(SAP-FTP) :Invalid FTP handle

former_member605939
Participant
2,519

My program to send the EXCEL file from SAP to FTP and FROM FTP to SAP is working Fine in front end.(When execute manualy)

But when i execute the Program in background scheduling from SAP to FTP, I am facing the the following Error:

"Job started

Step 001 started (program ZMM_TEST, variant &0000000000002, user ID )

Invalid FTP handle

Job cancelled after system exception ERROR_MESSAGE"

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
1,377

If now, you run it in dialog (RFC destination SAPFTP) and background (RFC destination SAPFTPA), and it works in both cases except the character encoding which is incorrect when you run it in background (ऀ instead of tab character hex '09' for separating values), then it's probably due to a difference between the two RFC destinations in SM59, "Unicode" tab: SAPFTP uses the client code page, while SAPFTPA uses Unicode.

What is the code page of your frontend? Check it in transaction SNLS.

Try in background with the frontend code page: copy SAPFTPA, force this code page instead of Unicode, edit your program to use this new RFC destination. If it works, you have found the culprit. Tell us so that to propose a workaround (my opinion is that you should define WRK_DELIM1/4 as TYPE C instead of TYPE X and initialize them as follows:

...
      BEGIN OF EXCEL_ST,
      MATNR           TYPE        MARA-MATNR,             "MATERIAL CODE
      WRK_DELIM1      TYPE        C, " <==== don't use X
      MTART           TYPE        MARA-MTART,            "Plant
      WRK_DELIM2      TYPE        C, " <==== don't use X
      MATKL           TYPE        MARA-MATKL,
      WRK_DELIM3      TYPE        C, " <==== don't use X
      MEINS           TYPE        MARA-MEINS,            "Distribution Channel
      WRK_DELIM4      TYPE        C, " <==== don't use X
      MBRSH           TYPE        MARA-MBRSH,                        "Material Description (Short Text)
      END OF EXCEL_ST.
...
WA_EXCEL-WRK_DELIM1  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM2  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM3  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM4  = cl_abap_char_utilities=>horizontal_tab. " or |\t| 

NB: I think that the issue was that you transfer the file as Unicode text, each character being on two bytes, but you defined the tabulation character insert as 1 byte only instead of 2, consequently there's a shift of one byte (or something like that).

26 REPLIES 26

cdprasanna
Active Participant
1,377

Hi

Check this thread Invalid FTP handle.

0 Kudos
1,377

Or you try to understand problem by debugging.To debug background job you can follow below steps

goto SM37

Execute

Select the check box of your job

in the COMMAND Prompt type JDBG

Hit Enter

SAP will get into Debug mode for your job

Debug the job, till the point where it dumps.

0 Kudos
1,377

Hi Mr. cdprasanna

Gone through the debugging process as you suggested and found that

the function module : FTP_R3_TO_SERVER

and found that SY-SUBRC 2

SY-MSGID 04

SY-MSGTY E

SY-MSGNO 209

and control passed to

sy-debug = 'N'.

CALL 'BatchDebugging' ID 'FLAG' FIELD switch_btc_dbg_off.

which statement causing an error.

0 Kudos
1,377

hi,

check whether your background user has authorization for the destination system or not.

1,377

HI MR. cdprasanna

Checked authorization level also. and gone through the thread mentioned you :Invalid FTP handle.

facing the same issue.

Sandra_Rossi
Active Contributor
1,377

I think that it's probably a bug in your code.

former_member1716
Active Contributor
1,377

abaplearner,

It depends on what user you have used for running the Job in background.

Check if the background user have sufficient privileges.

DoanManhQuynh
Active Contributor
1,377

and what error message said? i guest fm you used not for background

former_member602690
Active Participant
1,377

A. First:

1 Ask a Basis person for a userid which has all authority, to test your program, in SAP Development or Sandbox system. Setup job using that userid

2 what variant are you using

3 run in debug mode

4 run a trace

*

B. use SAPFTPA

Transaction SM59 trace checkbox file dev_ftp (current work directory)

*

or

C. Without SAPFTPA

1 Install WINSCP (does not need SAPFTPA)

2 Download Winscp onto SAP server

3 Verify you have a connection between Winscp and 'CMD' 3 Transaction SM69: Create command calling Winscp

4 Call command (from C.3. above) with function module sxpg_command_execute

1,377

Hi jcouto!

Gone through the following thread

"Check the RFC Destination Settings (SM59 -> Technical Settings -> Activation Type) of RFC Connection used to sending the data to FTP. It should be Start on Application Server"

And in background file transfered to FTP server but the format of file totally converted.output-format-data.png

1,377

abaplearner Did you solve the FTP connectivity problem by using SAPFTPA instead of SAPFTP? (NB: in case of issue persisting with SAPFTPA, run the program RSFTP005 to recreate SAPFTPA, it may be buggy sometimes)

NB: now, your issue is not the same as your question, the character encoding of value separators is wrong ("totally converted" is really an extreme point of view).

1,377

For .TXT AND .CSV file with SAPFTPA it is working fine in foreground and background.

But for excel is not working in background.

mantrishekar
Active Participant
1,377

Hello ABAP Learner,

If you have your excel file in in your Presentation Server and you are scheduling a background job it wont work.

If you want to schedule a background job with file. The file need to be Placed in AL11 Path only.

Regards,

Shekar.

1,377

Thanks sir,

I am fetching material master data from mara table into internal table.

Defining the path like '\\MM\Material.xls'. and using function modules

HTTP_SCRAMBLE

FTP_CONNECT

'FTP_R3_TO_SERVER'
I have to send file to FTP and then receive from FTP to further processing.

M i following the wrong approach to achieve. plz let me know the correct way....

mantrishekar
Active Participant
1,377

Hi ABAP learner,

Can you Paste all the code here. SO that i can help you after reviewing the code.

Regards,

Shekar.

1,377

Yes Sure..the attached code is demo-code-31.txtworking fine to send the file to FTP server in foreground and its not working in background.

Thanks sir

mantrishekar
Active Participant
1,377

Hi ABAP Learner,

If it is working in Foreground then change RFCDestination to SAPFTPA from SAPFTP and Check.

1,377

Yes file is transferring to FTP but not in same language some different format

000000000000080400ऀZFRTऀ1007 ऀST ऀM

but when we use SAPFTP it is exactly same format as desired .

mantrishekar
Active Participant
1,377

Hi ABAP Learner,

Try to do same with CSV instead of Excel and Check once.

0 Kudos
1,377

As you suggested , i tried text file in foreground and background.

Foreground is working fine. But when we do in background the status shows finished in green. but when we click on spool it shows

"Error in FTP Command"background-job-status.pngjob-status.png

1,377

For .TXT AND .CSV file with SAPFTPA it is working fine in foreground and background.

But for excel is not working in background.

former_member602690
Active Participant
0 Kudos
1,377

Convert your Excel file to a text file & a CSV file, and then run in background with text file, & your CSV file

former_member605939
Participant
1,377

As you suggested , i tried text file in foreground and background.

Foreground is working fine. But when we do in background the status shows finished in green. but when we click on spool it shows

"Error in FTP Command"

former_member602690
Active Participant
0 Kudos
1,377

A. I had to change my code, first to upload file in new custom background job i created:

1. insert new first step in SAP background job, which runs SAP standard program, only uploads file from PC to SAP. (I had to change mine, to upload CSV or TXT file in background (not Excel in background))

2. 2nd step of SAP background job runs your program (using file you uploaded in step1 above)

B. check out

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

Call Function 'GUI_UPLOAD'

References

https://answers.sap.com/questions/871715/guiupload.html

https://answers.sap.com/questions/4470016/program-to-upload-a-excel-file-into-z-table.html

https://answers.sap.com/questions/5892051/reading-excel-file-on-application-server.html

https://www.erpgreat.com/abap/sample-abap-code-on-bapi-po-change.htm

https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap

Sandra_Rossi
Active Contributor
1,378

If now, you run it in dialog (RFC destination SAPFTP) and background (RFC destination SAPFTPA), and it works in both cases except the character encoding which is incorrect when you run it in background (ऀ instead of tab character hex '09' for separating values), then it's probably due to a difference between the two RFC destinations in SM59, "Unicode" tab: SAPFTP uses the client code page, while SAPFTPA uses Unicode.

What is the code page of your frontend? Check it in transaction SNLS.

Try in background with the frontend code page: copy SAPFTPA, force this code page instead of Unicode, edit your program to use this new RFC destination. If it works, you have found the culprit. Tell us so that to propose a workaround (my opinion is that you should define WRK_DELIM1/4 as TYPE C instead of TYPE X and initialize them as follows:

...
      BEGIN OF EXCEL_ST,
      MATNR           TYPE        MARA-MATNR,             "MATERIAL CODE
      WRK_DELIM1      TYPE        C, " <==== don't use X
      MTART           TYPE        MARA-MTART,            "Plant
      WRK_DELIM2      TYPE        C, " <==== don't use X
      MATKL           TYPE        MARA-MATKL,
      WRK_DELIM3      TYPE        C, " <==== don't use X
      MEINS           TYPE        MARA-MEINS,            "Distribution Channel
      WRK_DELIM4      TYPE        C, " <==== don't use X
      MBRSH           TYPE        MARA-MBRSH,                        "Material Description (Short Text)
      END OF EXCEL_ST.
...
WA_EXCEL-WRK_DELIM1  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM2  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM3  = cl_abap_char_utilities=>horizontal_tab. " or |\t|
WA_EXCEL-WRK_DELIM4  = cl_abap_char_utilities=>horizontal_tab. " or |\t| 

NB: I think that the issue was that you transfer the file as Unicode text, each character being on two bytes, but you defined the tabulation character insert as 1 byte only instead of 2, consequently there's a shift of one byte (or something like that).

0 Kudos
1,377

background job is working fine. when replaced x by c....

Thanks