Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
30,670

Arrays in Design Studio 1.3

With the release of Design Studio 1.3, a host of new features were brought in by SAP. One of the most useful is the concept of Arrays. Though the versatility of this feature is quite limited in this release, SAP has nevertheless offered certain aspects of Arrays that developers can play around with.

Considering the rather concise information available in the designer guide, it seemed useful to provide a detailed overview of this feature. So, here goes !

There are 7 different types of arrays available – subtypes of the object “Array”. These include:

  • Dimension Array:

This subtype can contain a list of different dimensions belonging to a data source. A dimension array can be created by referencing the “getDimensions()” method of a data source – dimensions belonging to rows, columns, free characteristics or all dimensions available in the data source can be obtained with this method.

  • Hierarchy Array:

This subtype can contain a list of hierarchies. While there is no way for a user to create a hierarchy array manually, it can be created using the “getHierarchies()” method of a data source. This returns a list of different hierarchies available for the dimension that has been passed as parameter to the method.

  • Member Array:

This subtype can contain a list of members belonging to a dimension. It can be created using the “getMembers()” method of a data Source. The method returns a list of members of a dimension as an array. The dimension for which the members are required must be passed as a parameter to the method.

 

  • Bookmark Array:

This subtype can contain a list of all bookmarks for an application. Such a type of Array can be created using the “getAllBookmarks()” method of the “Bookmarks” object. When the method is used, it returns all the available bookmarks for that particular application.

 

  • Variable Array:

This subtype can contain a list of variables. It can be created using the “getVariables()” method of a data source. This method returns all the available variables of the data source for which the method is being called.

  • String Array:

This subtype can contain a list of strings. Unlike the previously mentioned types of arrays, a String array can be created manually as well. This is shown in the screenshot below:

Apart from user customizable string arrays, the “getSelectedValues()” and “getSelectedTexts()” methods of a Multi-Select enabled List Box can also return values in the form of a String Array. Using the “Split()” method will also return a String Array.

  • Integer Array:

This subtype can contain a list of integers. This type of an array can also be created manually by users.

 

  • Float Array:

This subtype can contain a list of decimal point numbers or floats. This type of an array can also be created manually by users.

 

Manipulating elements of an Array

Individual elements of an array can be accessed using the “forEach” loop. The basic syntax for this :

 

The “forEach” loop iterates over each element of an array and executes the statements contained within the body of the loop. In the above syntax:

  • element” refers to the individual elements contained in the array, one at a time.
  • index” refers to the index/position of that particular element within the array.

Each element object has its own set of methods to access attributes of that element, depending on the array type. For instance, when handling a MemberArray, the external keys and internal keys of the elements can be accessed through methods of the “element” object. A list of the different methods available for each type of array has been given below:

Array Type

Methods belonging to “element” object

DimensionArray

  1. name – Returns the technical name of the dimension
  2. text – Returns the text (description/display name) of the dimension

HierarchyArray

  1. name – Returns the technical name of the hierarchy
  2. text – Returns the text (description/display name) of the hierarchy

MemberArray

  1. externalKey – Returns the representation of the member as an external key
  2. externalNonCompoundedKey – Returns the representation of the member as an external non-compounded key
  3. internalKey – Returns the representations of the member as an internal key
  4. internalNonCompoundedKey – Returns the representation of the member as an internal non-compounded key
  5. text – Returns the representation of the member as a text (display name)

BookmarkArray

  1. name – Returns the name of the bookmark
  2. text – Returns the text (description/display name) of the bookmark.

VariableArray

  1. inputEnabled – Returns true of the variable is enabled, and false if otherwise
  2. name – Returns the representation of the variable as its technical name
  3. text – Returns the representation of the variable as its display name

StringArray

  1. indexOf – Returns the positions of occurrence of a string being searched for in the array.
  2. length – Number of characters in the array
  3. split – Splits the string according to a given separator
  4. substring – Returns a new string which is a substring of the given string

(It should be noted that the “element” object does not have any methods for an Integer or a Float Array)

Examples of Arrays in use

The program below takes a String array, eliminates the word “WORLD” and returns the remaining elements of the StringArray as one concatenated string, in an application alert window.

The result of this program is an alert window shown below.

Dimension Arrays in Use:

Given below is an example of dimension arrays in use. Consider the dimensions of the data source arranged in the manner shown in the screenshot below:

The script below exhibits the different ways in which the “getDimensions()” function can be used:

var Dim_Array_Rows = DS_1.getDimensions(Axis.ROWS);

var Dim_Array_Cols = DS_1.getDimensions(Axis.COLUMNS);

var Dim_Array_Free = DS_1.getDimensions(Axis.FREE);

var Dim_Array_All = DS_1.getDimensions();

var Rows = "";

var Cols = "";

var Free = "";

var Overall = "";

Dim_Array_Rows.forEach(function(element, index) {

Rows = Rows + element.name +" ("+element.text+");";

});

Dim_Array_Cols.forEach(function(element, index) {

Cols = Cols + element.name+" ("+element.text+");";

});

Dim_Array_Free.forEach(function(element, index) {

Free = Free + element.name+" ("+element.text+");";

});

Dim_Array_All.forEach(function(element, index) {

Overall = Overall + element.name+" ("+element.text+");";

});

  1. APPLICATION.alert("Dimensions in Row:\n"+Rows+"\n\nDimensions in Cols:\n"+Cols+"\n\nDimensions in Free Characteristics:\n"+Free+"\n\nOverall:\n"+Overall);

The script shown in the above window consolidates a list of all the dimensions belonging to the data source, and displays them on an alert window as shown in the output below:

Hierarchy Arrays in Use:

Given below is an example of hierarchy arrays in use. Observe the different hierarchies available for the dimension “ZREGION” in the structure of the query shown in the screenshot below:

The script below simulates a situation where in the hierarchies available in a particular dimension (“ZREGION” in this case) are obtained and displayed on an alert dialogue as soon as the user clicks a button present on the screen:

var Dim_Hierarchy = DS_1.getHierarchies("ZREGION");

var Hierarchy = "";

Dim_Hierarchy.forEach(function(element, index) {

Hierarchy = Hierarchy + element.name + " ("+element.text+");";

});

  1. APPLICATION.alert("Hierarchies Available:\n"+Hierarchy);

The output, if hierarchies are available on the given dimension (which is the case here), should resemble the screenshot shown below:

 

(Source: Learn about Arrays in Design Studio 1.3 - Visual BI)

3 Comments
Labels in this area