2025 May 06 12:38 PM - edited 2025 May 06 4:06 PM
Hello,
I'm experiencing some performance issues using OLE2 objects.
I'm aware of the ABAP2XLSX project — I use it in other developments and it works very well and is quite fast. However, in this case, I can't use it because we have an XLSM file stored on the server as a template. This file contains macros and validations written in Visual Basic. What we do is download this "template" and fill it with data using OLE2. As far as I know, ABAP2XLSX can't handle this scenario.
To improve performance in the program that uses OLE2, I avoid filling cells one by one. Instead, I use copy/paste from the clipboard and try to group operations by cell ranges to perform them all at once.
However, I'm still facing performance problems because some OLE2 method calls internally trigger the function AC_FLUSH_CALL_INTERNAL. In the latest ST12 trace, I see that this function is called around 2,600 times, consuming the vast majority of the program's runtime.
I'd like to be able to select multiple ranges at once to perform the same operation on several cells simultaneously, but this doesn't seem to work correctly. In Visual Basic, a simple instruction like:
Range("I11,N12,P8:P11,U12,U8").Select |
works just fine, but when I try to "translate" it to OLE2, it doesn't seem to function.
For example, this works:
Range("P8:P11").Select |
In other words, it seems that selecting multiple ranges at once is not supported (or maybe I'm doing it incorrectly).
I'll include a sample code that you can run to verify what I'm describing.
Do you know if it's possible to select multiple ranges at once using OLE2 objects?
REPORT zric_ole2. * First option, its working, selecting ranges one by one, but bad performance in I need to do it may times * Second option, trying to select several ranges at once, is not working... * If I use a single cell or range its working: |
Thanks in advance.
PS: I'm using a table for the code in the post because the button "insert code sample" is not working for me.
Request clarification before answering.
Have you indeed tried with abap2xlsx? AFAIK the template functionality should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you considered saving the VBA commands into a VBscript file, and then executing the script on the application server?
As you lay out this issue, you are executing this VBA code on a copy of Excel resident on your SAPGUI host PC. This copy of Excel has the XLSX template installed. Using OLE to call the instance of Excel is low performance, but it gives you great flexibility in the content of the commands, ranges in this case.
I have had great success in writing VBscript commands into a text file, saving it in the working directory defined by SAPGUI, and then executing it on the PC.
Inside the VBscript you can read any number of command line parameters in the WScript.Arguments object. Pass these parameters to the VBscript using the PARAMETER string in cl_gui_frontend_services=>execute.
This is a workaround, but the performance is vastly superior to OLE.
DATA: strcommand TYPE string.
strcommand = |"{ w_path }{ 'Z_SCRIPT.vbs'(vbs) }"|
&& | "{ p_file }"|
&& | "{ p_tab }"|
&& | "{ w_path }"|.
* Run script on Win32 WorkStation
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
application = 'WScript'
parameter = strcommand
synchronous = 'X'
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestion, although I think what you're proposing won't work in our scenario.
We need the file to be generated with code inside—it’s a file that will be dynamically filled out for each RFQ and sent to suppliers who have to complete it with their offers. Inside the Excel file, we have certain data validations, modules to display information, etc., so we need to use these downloaded XLSM files and then edit them to add the information in each case.
Using cell ranges and copy/pasting data via the clipboard is really helpful to improve OLE performance.
But I do not see you using this approach in your example code. Why?
Example code (adjusting needed):
"Export itab data to clipboard
cl_gui_frontend_services=>clipboard_export( ... ).
"Cell 1
CALL METHOD OF lo_excel 'Cells' = lo_cell1
EXPORTING
#1 = 1 "Row
#2 = 1. "Column
"Cell 2
CALL METHOD OF lo_excel 'Cells' = lo_cell2
EXPORTING
#1 = 1 "Row
#2 = 1. "Column
"Create a range from two cells
CALL METHOD OF lo_excel 'Range' = lo_range
EXPORTING
#1 = lo_cell1
#2 = lo_cell2.
"Paste data from clipboard to a Range
CALL METHOD OF lo_range 'Select'.
CALL METHOD OF lo_worksheet 'Paste'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
30 | |
21 | |
16 | |
8 | |
7 | |
7 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.