2019 Dec 20 3:38 AM
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"
2020 Jan 01 3:55 PM
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).
2019 Dec 20 3:45 AM
Hi
Check this thread Invalid FTP handle.
2019 Dec 20 3:48 AM
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.
2019 Dec 20 11:49 AM
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.
2019 Dec 20 1:01 PM
hi,
check whether your background user has authorization for the destination system or not.
2019 Dec 29 6:22 AM
HI MR. cdprasanna
Checked authorization level also. and gone through the thread mentioned you :Invalid FTP handle.
facing the same issue.
2019 Dec 20 8:39 AM
I think that it's probably a bug in your code.
2019 Dec 20 2:56 PM
abaplearner,
It depends on what user you have used for running the Job in background.
Check if the background user have sufficient privileges.
2019 Dec 29 11:15 AM
and what error message said? i guest fm you used not for background
2019 Dec 29 3:23 PM
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
2019 Dec 31 5:30 AM
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
2019 Dec 31 8:57 AM
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).
2020 Jan 01 5:11 AM
For .TXT AND .CSV file with SAPFTPA it is working fine in foreground and background.
But for excel is not working in background.
2019 Dec 31 6:44 AM
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.
2019 Dec 31 8:31 AM
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....
2019 Dec 31 8:42 AM
Hi ABAP learner,
Can you Paste all the code here. SO that i can help you after reviewing the code.
Regards,
Shekar.
2019 Dec 31 9:01 AM
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
2019 Dec 31 9:29 AM
Hi ABAP Learner,
If it is working in Foreground then change RFCDestination to SAPFTPA from SAPFTP and Check.
2019 Dec 31 9:41 AM
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 .
2019 Dec 31 12:25 PM
Hi ABAP Learner,
Try to do same with CSV instead of Excel and Check once.
2020 Jan 01 3:48 AM
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
2020 Jan 01 5:11 AM
For .TXT AND .CSV file with SAPFTPA it is working fine in foreground and background.
But for excel is not working in background.
2019 Dec 31 1:46 PM
Convert your Excel file to a text file & a CSV file, and then run in background with text file, & your CSV file
2020 Jan 01 3:49 AM
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"
2020 Jan 01 3:15 PM
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
2020 Jan 01 3:55 PM
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).
2020 Jan 06 3:46 AM
background job is working fine. when replaced x by c....
Thanks