SAP Analytics Cloud – APIs that manage private versions
2023-11-13 18:15:44 Author: blogs.sap.com(查看原文) 阅读量:10 收藏

You are the administrator of an SAP Analytics Cloud tenant and you notice a growing number of PRIVATE VERSIONS of data in the system. You see the need for some housekeeping tasks to potentially purge old private versions which are no longer in use but you are faced with a few challenges:

  1. Although you have the technical ability to manage these versions you don’t necessarily have the business knowledge/data ownership to make the decision whether the version may be deleted or not
  2. A governance process will be required to ensure that approval is obtained first from an authorised user before deleting data
  3. The end user(s) themselves may not even be fully aware of the number of private versions that they have created, how large their data volumes are or how old the data is. Simply asking for permission to purge old data may first lead to a discussion about what data is under review.
  4. There is a risk that a private version that a user worked on should have been published and they have neglected to do so.

The following small Analytic Application demonstrates how using the version management API’s could assist end users in managing their own data.

The application could be extended to include the CREATION DATE of versions and by calculating the age of the version could trigger email- and other notifications to the end users. You can also make use of the collaboration tools for commentary and discussions to manage versions effectively.

With the correct authorisations you can navigate to “PRIVATE VERSIONS STATISTICS AND ANALYSIS” from the menu option “SYSTEM” –> “PERFORMANCE”.

One of the dashboard items on this page lists the versions found in the system together with various attributes of the version and a column named “VERSION STATUS”. An “ACTIVE” version exists when it is loaded into HANA memory (considered HOT data) and is being actively edited by users. An “INACTIVE” version is automatically unloaded from HANA memory and stored on disk during a daily end-of-day process.

Although these versions do not occupy HANA memory they do take up disk space and their size is indicated by the number of rows they contain.

This Analytics Application demonstrates:

  1. A method to show end users when they have unpublished public version data
  2. A method for end users to view a list of their private versions and the ability to perform a “mass deletion”

If you are unfamiliar with version management you can find SAP help documentation:

SAP Help documentation – Version management

and a couple of blogs to answer FAQ:

https://blogs.sap.com/2022/10/14/sap-analytics-cloud-private-versions-statistics-and-analysis/

https://blogs.sap.com/2022/07/06/faq-version-management-with-sap-analytics-cloud-part-i-basics/#10

Unsaved public version data

This application opens with a canvas which contains a tabstrip with two tabs (1), one for PLANNING and one for HOUSEKEEPING.

A USER EDITING icon (2) has been added which turns green when all data is published and amber if there is any unpublished data on the public version “ACTUAL”.

A very simple planning data model serves as a datasource to an input table which has been prepared with sample data captured against public version “ACTUAL” (3).

Opening%20canvas

As soon as data is manually edited in the table the USER EDITING icon (1) turns to amber indicating to the user that there is unpublished data and the normal system response displays an asterisk (*) character after the version header (2) and highlights on cells that have been recently modified.

Public%20version%20edited

Using “VERSION MANAGEMENT”, under the TOOLS menu option, we can see that the data from the “ACTUAL” version (1) has been copied to a PRIVATE VERSION indicated by “EDIT MODE” (2) and in the analytic application we call this a “dirty” version.

If the user continues to work on this version and never publishes it then their changes will NOT be reflected in the final results of the public version “ACTUAL” (in this example).

To enable this functionality we upload two icon images which are identical except for the background colour and we position them on top of each other in the canvas design. We then check the “dirty” status of the version using the “isDirty()” method, which returns a boolean result, and use this to toggle which icon should be visible.

You will notice that this is very simple code with the public version hardcoded to “ACTUAL” and this will need to be extended for it to apply to any public version.

// Check to see if the public version is dirty and if so select
// the appropriate icon to display to the user
if (Table_1.getPlanning().getPublicVersion("Actual").isDirty()) {
	IconEditDirty.setVisible(true);
	IconEditClear.setVisible(false);
} else
	{	IconEditClear.setVisible(true);
	    IconEditDirty.setVisible(false);
	}

Only the icon with the background colour of amber (“IconEditDirty”) has an “onClick” event with the publish API.

// Allow the user to click the icon for unpublished data in order to
// publish it. This is for convenience as opposed to selecting the menu option.

Table_1.getPlanning().getPublicVersion("Actual").publish();

Private version management

To extend this example we use VERSION MANAGEMENT and the “ACTUAL” version as a source version to copy the data to ten private versions. The table is designed to display the versions side-by-side. This will probably not be the way a live planning screen will be designed which is why the user may not be aware of private versions of data that are present in the model.

For this reason the screen is designed to show an icon in the top-right-hand corner of the tabstrip as a visual indicator to the user that private version(s) exist. The user can then navigate to a HOUSEKEEPING area where these versions can be managed.

The icon “IconPvtVer” is uploaded as an image and the method “.getPrivateVersions()” is used to return an array of the private versions in the model. The length of the array is then checked in order to determine if the icon should be displayed or not.

// Return a list of private versions and if the list is not empty
// display the private version icon to the user
PrivateVersions = Table_1.getPlanning().getPrivateVersions();
if (PrivateVersions.length > 0) {
	IconPvtVer.setVisible(true);
} else {
	IconPvtVer.setVisible(false);
}

// The variable "PrivateVersions" is of type PLANNINGPRIVATEVERSION
// and is set as an array

As soon as the user navigates to the HOUSEKEEPING tab (1) a script is executed which populates the first listbox (2) with all the private version ID’s which belong to the user and the total number of versions is displayed in the textbox below the listbox. It is this variable, when greater than zero, that triggers the icon to appear on the PLANNING screen.

The first listbox (2) is a multi-selection listbox so the user can simply select any combination of rows and whichever rows are selected are displayed in the second listbox (3) as a confirmation of the selection.

The user can then press the DELETE button (4) to “mass delete” all the versions that they have selected.

The following code refreshes the left listbox with the private versions present in the model and is attached to the tabstrips only event “onSelection”.

// Obtain a list of private versions in the system
PrivateVersions = Table_1.getPlanning().getPrivateVersions();

// Clear the listbox of any prior values
ListBox_1.removeAllItems();

// Populate the listbox with the private versions ID's
for (i = 0; i < PrivateVersions.length; i++) {
  ListBox_1.addItem(PrivateVersions[i].getDisplayId(), PrivateVersions[i].getDisplayId());
}

// Set the text at the bottom of the listbox to indicate the number of rows added
Text_2.applyText("Total number of version(s) = " + ConvertUtils.numberToString(i));

As the items in the first listbox are selected the second listbox is populated with the selection using the “onSelection” event of listbox1.

// When the user executes multi-selection in the first listbox
// remove the items in the second listbox and populate it with
// the new selection from the user

ListBox_2.removeAllItems();

strSelectedVersions = ListBox_1.getSelectedKeys();

for (i = 0; i < strSelectedVersions.length; i++) {
	ListBox_2.addItem(strSelectedVersions[i]);
}

The delete button on listbox2 simply activates the popup screen.

// This button allows the user to delete private versions but
// before they do open a popup window to ask for confirmation first

Popup_1.open();

To prevent accidental deletions of version data a popup confirmation screen is first displayed with the default button set to “CANCEL” but on confirmation all the selected versions are deleted and the listboxes and planning screen icon are reset.

Once confirmation is received a loop is executed around the selection list and at the heart of the code is the “.deleteVersion()” method. Then both listboxes are reset as well as the private version indicator on the planning screen tab.

// If the confirmation button in the popup is selected then
// show the "busy indicator" as the system loops through the users
// version selection and deletes each one

if (buttonId === "btOK") {
	
	if (strSelectedVersions.length > 0) {
	Popup_1.showBusyIndicator("Deleting...");
	
	for (i = 0; i < strSelectedVersions.length; i++) {
	   Table_1.getPlanning().getPrivateVersion(strSelectedVersions[i]).deleteVersion();
	}

    // Remove the string array items which are used to populate the selection listbox
    // It is not enough to set the array values to "" as the length of the array is used
	// to determine the deletion loop. The array itself must have each item removed.
    for (i = 0; i < strSelectedVersions.length; i++) {
	   strSelectedVersions.pop();
	}		
	
	Popup_1.hideBusyIndicator();
		
	}
}

// Before closing the popup window refresh the two housekeeping listboxes with the 
// version lists after the deletion has occurred

ListBox_2.removeAllItems();

PrivateVersions = Table_1.getPlanning().getPrivateVersions();

ListBox_1.removeAllItems();

for (i = 0; i < PrivateVersions.length; i++) {
  ListBox_1.addItem(PrivateVersions[i].getDisplayId(), PrivateVersions[i].getDisplayId());
}

Text_2.applyText("Total number of version(s) = " + ConvertUtils.numberToString(i));

Popup_1.close();

The effect of the mass deletion can be seen when the user selects the “PLANNING” tab once again. In the right-top corner of the screen we see the PRIVATE VERSION icon (1) indicating that there are still private versions in our model. The data block reflects both our public version ACTUAL and the remaining private versions (2) in the columns and the publish icon (3) is green because there are no “dirty” public version that require publishing.


文章来源: https://blogs.sap.com/2023/11/13/sap-analytics-cloud-apis-that-manage-private-versions/
如有侵权请联系:admin#unsafe.sh