SAC Analytical Designer : Splice Method – An attempt to explain
2023-10-27 01:51:20 Author: blogs.sap.com(查看原文) 阅读量:9 收藏

I was recently using the Analytics Designer API Reference Guide, though the guide explains the Syntax of a mentod well, I found it lacking in examples to better understand the working of an API or related method, below is my attempt to explain the methos with example, to bring in clarity on its usage.

The Splice method of an array in SAC Analytical Designer API Reference document, Is used to add, remove or replace an existing member of an existing array.

Note that, this does not create a new array for you, but modifies the existing array.

The Syntax for Splice method is as below, (from Analytical Designer API Reference Guide)

splice(pos: integer, amount?: integer, item?: <this array’s element type>)

Pos, is the starting position

Integer, is the count of members

Below are some of the examples of the features of this method,

Let us consider an Array of Countries.

Scenario 1: Remove all the Array members, except the first one.

Below we define two arrays, an array (ArrCntry) containing names of Countries, and another one (deletedmembers) to capture the deleted items.

the definition splice(1) will delete all array members starting from position 1, remember counting of array starts from 0

Below is the Output and both the Array’s Contents…

Scenario 2: Remove two members of  the Array members, starting from 1 position, as mentioned earlier remember counting of array elements starts from 0,

Below is the Output for above Code snippet,

Scenario 3: Removing 2 members, and adding 1 member to an existing Array, i.e. replacing two existing members with a new member

Below is the output for above scenario,

Scenario 4: Without removing any members, adding a new member to an existing Array,

Below is the output with new country added, and without any deletion. Observe that ‘Deleted members’ text box below is empty.

As I move forward, I will continue to add explainations for other methods to this or a separate blog. Meanwhile, if you find anything lacking in the above, do let me know. thanks.


文章来源: https://blogs.sap.com/2023/10/26/sac-analytical-designer-splice-method-an-attempt-to-explain/
如有侵权请联系:admin#unsafe.sh