cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI for downloading a file from AL11

Hi Team,

I have a requirement where I need to access/download the file stored at a AL11 directory via RFC. Is there any existing BAPI to do it in the background?

Language : C#

I followed this BCXBPTCV2V3.pdf document but could not find any relevant BAPI for the above.

I'm able to perform operations like logon, creating a job, getting the status, spool reading but unable to download the file. Any help or reference will help.

Sandra_Rossi
Active Contributor
0 Kudos

"A11" !?

Do you mean AL11?

Or do you mean a SAP system at your client SAP system landscape, named "A11"? In that case, it's useless information when asking.

Do you mean the file is stored on the SAP application server? (and that you can see in AL11)

Or is it somewhere else?

You need an ABAP developer or SAP practitioner at your client location to help you.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

sandra.rossi The OP mentions "Language: C#", so I would say an ABAP developer cannot help here. 🙂

The way I understood this scenario is: there is an ABAP Report which does something and then writes a "result file" into the local file system (DIR_DATA?!). OP has now written a C# program (perhaps running as a desktop application on some Windows frontend PC), which

  1. Log's into the SAP system via RFC (using NCo)
  2. Calls BAPI_XBP_JOB_OPEN (and other XBP BAPIs for adding job steps etc.) to schedule this Report as a batch job
  3. Calls other XBP BAPIs to check the status of the batch job, and once the job is finished, wants to download that "result file" to the frontend PC.

If that is indeed the case, then GUI_DOWNLOAD should work ok, as far as I can see. (Though I haven't tried it out yet...)

Sandra_Rossi
Active Contributor
0 Kudos

Let's wait for OP feedback.

Hi ulrich.schmidt and sandra.rossi

Yes I meant AL11. Updated the post.

Ulrich understanding is correct. We have a background job that we are running which creates a text file and stores it at a location which can be accessed via AL11. But we don't want to do it via GUI, so was looking for some BAPI which can help here.

We are using BAPIs for login, job open, job start, get status, reading spool ( as it has the path of result file location) and logoff.

Sandra_Rossi
Active Contributor
0 Kudos

The XBP library is meant only for background job processing, anything a little bit different is not part of XBP (like downloading a file stored on the server to a laptop).

You may use SXPG function modules to run commands at the operating system level to work with files on the application server, but they cannot be used to interact with files on the laptop, unless you simply store on a network server which is accessible both from the server and the laptop.

Otherwise, the answer will depend on the context where you are running the BAPI from. For instance, with the programming language VBA (and many others) you can login through RFC with connection to SAP GUI (to be installed where the script runs), and you can then run commands interacting with the laptop.

Sandra_Rossi
Active Contributor
0 Kudos

Concerning SXPG function modules to run OS commands, you may also define a command through BAPI_XBP_JOB_ADD_EXT_STEP (to run an OS command that you must first define in SM49).

View Entire Topic
Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

Try function module GUI_DOWNLOAD. It reads a file into an internal table and returns it. Can be used for binary files as well as text files. The FM documentation has a bit of sample code, how to use it.

Sandra_Rossi
Active Contributor
0 Kudos

I guess the OP means "AL11" when talking about "A11", so GUI_DOWNLOAD is incorrect.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

Why? GUI_DOWNLOAD can access any file in the physical file system, and AL11 is only another (restricted) frontend to the physical file system?! So any file visible in AL11 should be downloadable by that FM, not?

(Edit: of course you cannot use a path like "DIR_HOME/abc.xyz", you would need to resolve DIR_HOME to the real path, e.g. "/usr/sap/SID/D00/work/abc.xyz".)

Sandra_Rossi
Active Contributor
0 Kudos

Let's wait for OP feedback.

0 Kudos

I will look into the GUI_DOWNLOAD and update if this works

0 Kudos

We tried GUI_DOWNLOAD, and it downloads the file but the contents are missing. It downloads a black text file.

Sandra_Rossi
Active Contributor
0 Kudos

saurabh.srivastava2009 I guess you mean "blank text file", not "black text file" 😉

0 Kudos

sandra.rossi

yes it is a blank text file 😛
The file has contents and it is visible when we download it normally, but with the above BAPI, its not working manually.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hmm, this can have only three reasons:

  1. ABAP job has created the file, but not yet flushed the changes out to disc. (Not sure about the ABAP syntax of OPEN DATASET here, but I guess that CLOSE DATASET would flush and close the file handle?!)
  2. Incorrect inputs for GUI_DOWNLOAD
  3. Bug in GUI_DOWNLOAD... 🙂

Perhaps you can try with a standard file that is always there in the SAP installation (e.g. the reginfo file). And what happens, if you execute GUI_DOWNLOAD from SE37 instead of the .NET Client?

If all else fails, you could set an external breakpoint in GUI_DOWNLOAD and then call it from .NET and see what happens. E.g. whether the data is not correctly read from the file, or whether the data is read from file ok, but not transferred correctly via RFC.

0 Kudos

Hi ulrich.schmidt

This did not work for us.

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

GUI_DOWNLOAD is not remote-enabled, so it cannot directly be called via RFC.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hmm, the problem could be: it is not remote-enabled... 😞

I searched a bit more, but didn't find anyone that's remote-enabled. So I guess you just have to write your own...