10-24-2014 3:57 PM
Hello all,
I have to upload excel file to SAP in Background. I have searched a lot in Google, but I can't find the appropriate one. So, could any one suggest me how to achieve this functionality.
Thanks in advance,
Regards,
Suresh.
10-24-2014 4:12 PM
Hi Suresh,
FM : ARCHIVFILE_CLIENT_TO_SERVER
tcode. cg3y and cg3z
Thanks,
Anil
10-24-2014 4:39 PM
Hello
Use FM ALSM_EXCEL_TO_INTERNAL_TABLE if your file is in presentation server , else use instructions ( for file in application server ) :
- OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT
DO.
- READ DATASET P_FILE INTO WA_TAB.
APPEND WA_TAB TO WT_TAB .
if sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
-CLOSE DATASET P_FILE
with WA_TAB and WT_TAB have structure ALSMEX_TABLINE.
Regards
10-24-2014 5:05 PM
Hello Suresh,
Check the below sample code for uploading data into an excel file in background. Here I am saving contents fetched from vbak table into an excel file.
REPORT ztest.
DATA: v_file_path TYPE string VALUE '/tmp/my_excel_file.xls',
v_file_contnt TYPE string.
DATA: itab_vbak TYPE STANDARD TABLE OF vbak WITH HEADER LINE.
SELECT * UP TO 50 ROWS
FROM vbak
INTO TABLE itab_vbak.
OPEN DATASET v_file_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
LOOP AT itab_vbak.
CONCATENATE itab_vbak-vbeln itab_vbak-erdat itab_vbak-erzet itab_vbak-ernam
INTO v_file_contnt SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
TRANSFER v_file_contnt TO v_file_path.
ENDLOOP.
ENDIF.
CLOSE DATASET '/tmp/my_excel_file.xls'.
In v_file_path, give the file path and name where you want to save the excel file (only application server).
Also it is important to separate the contents using cl_abap_char_utilities=>horizontal_tab.
Let me know if this helps
Regards,
10-24-2014 5:24 PM
Hi Rojer,
Thanks for your valuable suggestions,
But my file is located in presentation server. So, in this case once if I schedule the program in background then how the system is going to access the file from the front end(Presentation server).
Regards,
Suresh.
10-24-2014 5:15 PM
I can see that there is some confusion about your using a CSV instead of XLS or XLSX. Which would you be requiring?
Neal
10-24-2014 5:27 PM
Hi Neal,
Thanks for your valuable suggestions,
I am uploading .xls file.
Regards,
Suresh
10-24-2014 6:18 PM
Suresh,
When a program is run in background, it is completely disconnected from all presentation servers (your PC). About the only way I am aware of a background job is able to access data on a presentation server is via FTP transfer. If you set up an FTP server and then put your xls file in a directory assigned to that server, it is possible to transfer that file into your abap program. Other than that, I know of no way to do what you are trying to do.
I would be very interested in learning of an alternative to FTP transfer.
10-24-2014 6:59 PM
Hi Suresh,
Larry is right with respect to accessing file data from SAP in the background. At that point the SAP system is completely disconnected from any presentation server in question. For you to achieve such a file transfer back into SAP you would need a serving mechanism like FTP as Larry has suggested or some other options would be SFTP, HTTP. At that point SAP becomes the client and the location where you going to gather the file data becomes the server.
Regards,
Ryan Crosby
10-24-2014 7:49 PM
Hi Ryan,
Thanks for your reply,
Can I use EXPORT TO Database and IMPORT FROM Database. Could you please suggest any idea on this.
Regards,
Suresh
10-24-2014 7:54 PM
Hi Suresh,
Hmmm, can you explain conceptually the end to end flow of the SAP system going out and gathering this file? At the moment you have mentioned that it is in the background but where does the system need to go to get this file?
Regards,
Ryan Crosby
10-24-2014 8:22 PM
It needs to get the file from presentation server(Desktop) and process the program in the background.
Regards,
Suresh
10-24-2014 8:29 PM
Hi Suresh,
In that case the desktop needs to be serving that file in some manner as myself or Larry has mentioned previously for you to be able to retrieve the file and bring it into the system for processing. Otherwise you would need to manage the connection into the system in the foreground when you have a session open with the system.
Regards,
Ryan Crosby