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 upload excel file to SAP in Background?

suresh_mamilla
Participant
0 Kudos

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.

12 REPLIES 12

former_member202771
Contributor
0 Kudos

Hi Suresh,

FM : ARCHIVFILE_CLIENT_TO_SERVER

tcode. cg3y and cg3z

Thanks,

Anil

Former Member
0 Kudos

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

Former Member
0 Kudos

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,

0 Kudos

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.

Former Member
0 Kudos

I can see that there is some confusion about your using a CSV instead of XLS or XLSX.  Which would you be requiring?

Neal

0 Kudos

Hi Neal,

Thanks for your valuable suggestions,

I am uploading .xls file.

Regards,

Suresh

Former Member
0 Kudos

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.

Ryan-Crosby
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

It needs to get the file from presentation server(Desktop) and process the program in the background.

Regards,

Suresh

0 Kudos

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