Make SAP Report available via RFC - abap

One customer wants to access a SAP report via RFC.
Steps:
Third party application connects to SAP via RFC
RFC call gets transmitted
SAP runs the report
SAP returns the report.
How can this be implement the part inside SAP?
I am using PyRFC as client library. But AFAIK this does not matter at all for this question. This question is only about the server part inside SAP.
In this case it is the report RM07MLBS which should be made available via RFC.

You need an ABAPer to make a function to you, I think there's no way without it.
If you have a ABAPer just do something like this:
SUBMIT <REPORT_NAME> ... EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobj.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_ascilist
listobject = t_listobj.
Now you have the list in ASCII format, you can convert it to what you want.
Another way is send the report result to spool, get the spool and convert it to HTML/PDF.
To convert Spool you can use this functions:
RSPO_RETURN_ABAP_SPOOLJOB
RSPO_RETURN_SPOOLJOB_DAT
RSPO_RETURN_SPOOLJOB_HTML

In a perfect world, you'd have the report logic encapsulated in an abap class or a dedicated function module and use that as the basis for both your report and the RFC calls. But if this is a standard SAP report and SAP themselves weren't nice enough to provide said function module, you may not have this option.
I don't think this is the best solution for your request, but just to add another option to the ones already mentioned in other answers: the commercial product Theobald Xtract Universal can execute reports and return the results using several available destination types. Xtract is a windows service that offers connectivity to several target database types as well as a http based result stream. It isn't cheap though, and it essentially only can connect to SAP Netweaver based systems as its data source (at least S/4 is already supported). Target destinations have to be purchased extra, but at least not per system, only per destination type (Oracle, MySQL, MSSQL...).
https://theobald-software.com/en/xtract-universal/
Xtract Universal uses a number of customer function modules to execute the report in the target system, catch the output and return it, essentially as a wall of text. You'll have to parse that result yourself, you won't get a nice pre-parsed table with data in it.
Just to make sure there's no misunderstanding about a possible conflict of interest: I don't work for Theobald, but we are a paying customer and use Xtract for our own data extractions. It is very simple to use, can be executed in scripts, but as said, just does that one job.

As far as I know there is a limited possibility to trigger a report via a rfc-enabled function module. Otherwise try triggering a transaction (based on your report) via function module.
Also check: https://archive.sap.com/discussions/thread/811196
I dont think that you are able to respond the report result to your third party system.
From consulting perspective I would recommend running the report periodically, write results in a table, fetch data from table (from third party system) via RFC-enabled function module.

The best way to do this would be to wrap your report in a bespoke Function Module that is RFC Enabled, then give them access to run that RFC Function Module.

Related

Best way to export data from other company's SAP

I need to extract some data from my client's SAP ECC (the SUIM -> Users by Complex Selection Criteria -program RSUSR002)
Normally I give them a table of values that I they have to fill some field to extract what I need.
They have to make 63 different extractions (with different values of objects, for example - but inside the same transaction - you can see in the print) from their SAP, to later send to me all extracted files.
Do you know if there is an automated way to extract that, so they don't have to make 63 extractions?
My biggest problem is that every time they make mistakes. It's a lot of things to fill..
Can I create a variant and send it to them? Is it possible to export my variant so they can import it without the need to fill 63x different data?
Thank you.
When this is a task which takes considerable effort by multiple people each year, then it is something which might be worth automatizing.
First you need to find out where that transaction gets its data from. If you spend some time analyzing and debugging the program behind the transaction, you will surely find which SELECT's on which database table(s) provide that data. If you are lucky, there might even be a function module for it.
Then you just need to write an own ABAP program which performs the same selections.
Now about the interesting part: How to get that data to you. There are several approaches here. The best one depends on your requirements and your technical infrastructure. Some possibilities are:
Let users run the program in foreground, use the method cl_gui_frontend_services=>gui_download to save the data to a file on the user's PC and ask them to send it to you via email
Run the program in background and save the file on the application server. Then ask your sysadmins how to get that file from their application server to you. The simplest way would be to just map a network fileserver so they all write to the same place, but there might be some organizational hurdles in the way which prevent that. (Our security people would call me crazy if I proposed to allow access to SMB shares from outside of our network, but your mileage may vary)
Have the program send the data to you directly via email. You can send emails from an SAP system using the function module SO_NEW_DOCUMENT_ATT_SEND_API1. This of course requires that the system was configured to be able to send emails (which you can do with transaction code SCOT). Again, security considerations apply. When it's PII or other confidential data, then you should not send it in an unencrypted email.
Use an RFC call to send the data to your own SAP system which aggregates the data
Use a webservice call to send the data to your own non-SAP system which aggregates the data
You can create a recording in transaction SM35.
There you fill a tcode (SUIM), start recording, make some input in transaction SUIM and then press 'Execute'. Then you can go back to recording (F3 multiple times) and the system will generate some table with commands (structure is BDCDATA). You can delete unnecessary part (i.e. BACK button click) and save it to use as a 'macro'. Then you can replay this recording and it will do exactly what you did.
Also it's possible to export/import the recording to text file, so you can explore it's structure, write some VBA script to create such recording from your parameters and sent it to users. But keep in mind that blanks are meaningful.
It's a standard tools so there's no any coding in the system.
You can save the selection as a variant.
Fill in the selection criteria and press Save.
It can be reused.
You can also transport Variants if the they have a special name

SAP BAPI for vendor creation and editing

Has anyone ever created a BAPI to create or edit a vendor in SAP R/3 4.6c in the background? I found two BAPIs: BAPI_VENDOR_CREATE and BAPI_VENDOR_EDIT, but both only work online (they call transactions XK01 and XK02).
Basically I need a way to call a function module that would do the same work as transactions XK01 and XK02 but don't need to be called online.
Looking on the SAP community forums, I found a lot of people with the same needs as me, but the answer was never complete.
Could someone give me a suggestion?
As you have discovered, SAP doesn't provide BAPIs for vendor creation/change that can be called in the background (this is, unfortunately, still the case in newer releases).
You have a few possible options:
Create your own BAPI, using (unreleased) SAP function modules for the vendor update.
Create your own BAPI, creating/changing the vendor via a BDC session.
I'd go with option 2. No, BDCs are never ideal and they have a lot of downsides but even a lot of SAP standard function modules for vendor creation seem to go that route and you'll at least be certain that the data in your system is consistent, unlike if you use something like function module VENDOR_INSERT, which does direct table updates without application validation.
Check if the standard vendor data transfer program (RFBIKR00) is in your system - it uses batch input so could be a very useful starting point for your BDC.

FM to Download ABAP report output to PC as text

Is there any function module aside from GUI_DOWNLOAD to download the ABAP report output?
When you say "ABAP report output", I am guessing you mean the list output.
You can use function module DOWNLOAD_LIST from within an ABAP report program to download the list, or any of the current lists in the stack.
Alternatively, use function module LIST_TO_ASCI to get the list into an internal table, then download it with CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD (GUI_DOWNLOAD will work, but it is recommended you use CL_GUI_FRONTEND_SERVICES instead). (Look at function group SLST for some other interesting list processing functions).
If you didn't mean the list output, then in general use CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD for downloading internal tables.
That is of course, if you are looking to download to the client PC. If you want to create a file on the application server, look at the keyword help for OPEN DATASET and related commands.

Is there any RFC or BAPI implementing the transaction rsscd001 for displaying change documents in SAP?

I would like to know whether there is any RFC or BAPI functions to display change documents (transaction RSSCD001) based on input query in SAP. The customer requirement is to implement a java monitor system on SAP without adding any ABAP functions on the SAP server.
I tried to make use of 'RFC_READ_TABLE' functions, which is deprecated according to the official documents, to read the CDPOS and CDHDR table and join them. But as vwegert said, to traverse the table CDPOS is really time-costing, as it contains billions of table entries.
My intention of this query is to find changes to all bank details of vendors.
Any other thoughts?
Many thanks in advance!
The least resource-consuming way to do this would be to use the workflow runtime system to actively notify the java application whenever a change document is written. You don't have to write any ABAP functions to do this, just setup the workflow engine (using the automatic customizing) and customize the event generation (documentation). Then, you write a java service that connects to the SAP system using JCo and registers as an RFC server using a destination of Type TCP/IP and a registered program ID. This java server program has to provide a function module handler that can be called using tRFC from the SAP system. Finally, add a linkage entry that will tell the workflow runtime system to call your java program each time a change document is written.
Of course, this will only record the changes that happen after installation, not the historical changes.
warning : I'm not very familliar with this field.
The RFC function BAPI_VENDOR_FIND (BAPI Vendor) seems to be used to find vendor based on values in table. You could use it to check gainst the modification date. This is not perfect, as there is no relationnal operator, only equals, and you'll have to check against several dates...
hopes this helps
Guillaume

File handling in ABAP

Can file operations, like creation of a file, be done in ABAP?
Yes it can be done.
You can code in ABAP by using 'open dataset' / 'transfer' / 'close dataset' statements to create files on the Application Server.
You can also create your file directly to a certain application for e.g. MS Excel like so.
Also there are several function modules and classes that can simplify certain tasks like gathering your report output, putting your file on the AS (such as 'GUI_UPLOAD' / 'GUI_DOWNLOAD' / 'WS_DOWNLOAD' / 'SAP_CONVERT_TO_CSV_FORMAT' / etc.) ...
Bear in mind that certain functions modules were built for foreground tasks so they won't work in background job scheduling ...
Yes, it's possible, as nict said before. You should start reading here - that's the official documentation, it covers pretty much everything, including working with files on both the application and the presentation server. It also explains how to use platform-independent filenames - always remember, someday you might encounter an application server running on OS/400 that will not let you write stuff to C:\Temp\MyExport.csv. One more hint: Be careful about the function modules nict mentioned, some of them are not safe to use when unicode content is involved. Always use the methods of class CL_GUI_FRONTEND_SERVICES to be on the safe side.
You can use CL_GUI_FRONTEND_SERVICES class or GUI_DOWNLOAD function. Here is a link
You may use CL_GUI_FRONTEND_SERVICES class. But this services only work on front end. Or you can use some function modules like GUI_DOWNLOAD, GUI_UPLOAD etc.
we can create a flat file with data entered into it, with tabs-separated.
Now, that dota corresponds to the sap tables-fields, where the tables are related to an application, like say, material master.
Now we can use the standard FMs to upload the data to the internal tables of the program and followed by updating the database.
So, uploading flat-file data can be done.