Fixing the SAC Table2 export issue with SAC Scripting

Recent changes in SAC regarding Table2 handling have caused row/column formatting to be lost during exports (XLS, PPT, DOC, PDF). The issue arises due to lazy loading—only visible rows/columns are rendered. 

The biExport widget currently can not automatically resize or re-render Table2 tables anymore. A SAC scripting workaround is required to manually adjust the table before export.

1. Prerequisites

  • Disable the SAC report setting "Auto-Size and Page Table Vertically" in the configuration.
  • Required components:
    • biExport widget (e.g., biExport_1) required for communication with biExport backend.
    • Scripting Variable (e.g., export_triggered) a flag preventing the export being triggered with each table refresh.
    • Button (e.g., Button_doExport) triggers the export.
    • Table2 (e.g., SampleTable) the table thats to be exported.

2. Example Flow (Online Export)

  1. User clicks Button_doExport.
  2. SampleTable is resized based on calculated height/width.
  3. SampleTable's data is refreshed → onResultChanged is triggered.
  4. SampleTable.onResultChanged → initiates the export via biExport_1.
  5. User receives a success/error message.

3. SAC Component Setup

  • biExport widget: Configure the export. Link the onStart, onReturn, and onError events to the provided scripts.
  • Button: Add a button and link its onClick event to the script.
  • Table2: Ensure the table is connected to data. Link the onResultChanged event to the script.
  • Scripting Variable: Create a SAC Scripting Variable with Type= boolean, Default Value= false.

4. SAC Scripting Steps (Online Export)

4.1. Button (onClick Event)

{
  Application.showMessage(ApplicationMessageType.Info, "Step 1/3: preparing export.");
  
  // 1. Calculate and set table height  
  var avgRowHeight = 40; // Adjust to match your table's average row height  
  var approximatedTableHeight = SampleTable.getRowCount() * avgRowHeight;  
  SampleTable.getLayout().setHeight(approximatedTableHeight);  

  // 2. Calculate and set table width  
  var avgColumnWidth = 120; // Adjust to match your table's average column width  
  var approximatedTableWidth = SampleTable.getColumnCount() * avgColumnWidth;  
  SampleTable.getLayout().setWidth(approximatedTableWidth);  
  
  Application.showBusyIndicator("refreshing table data...");
    
  // 3. Refresh table data to trigger rendering  
  export_triggered = true; // Flag to trigger export  
  SampleTable.getDataSource().refreshData(); // Triggers `onResultChanged`  
}

4.2. SampleTable (onResultChanged Event)

{
  if (export_triggered) { // flag prevents export being executed if onResultChanged was triggered by something else then the button
    export_triggered = false; // Reset flag  
    
    Application.hideBusyIndicator();
    Application.showMessage(ApplicationMessageType.Info, "Step 2/3: initiating export");
    
    biExport_1.doExport("XLS"); // Start export  
  }
}

4.3. biExport Widget (Events)

  • onStart:

    {
      Application.showBusyIndicator("Step 3/3: waiting for export ...");  
    }
  • onReturn:

    {
      Application.hideBusyIndicator();  
      Application.showMessage(ApplicationMessageType.Success, "export successful");  
    }
  • onError:

    {
      Application.hideBusyIndicator();  
      Application.showMessage(ApplicationMessageType.Error, "error during export - please contact an administrator or check browser dev tools");  
    }

5. Troubleshooting

  • Missing Formatting in Export?
    • Adjust Values: Modify avgRowHeight and avgColumnWidth to match your table’s actual dimensions. Test and refine these values for optimal results.
    • Issue with getColumnCount(): If getColumnCount() returns 0, set the width manually (e.g., SampleTable.getLayout().setWidth(1200);)
  • Export Error?
    • Use browser dev tools to debug script errors.

 

Luis Eckert
Author: Luis Eckert
Creation date: 03/09/2026
Category: SAP Export
back to overview