If you’re working with SAP Analytics Cloud (SAC), you’ve probably used script variables to manage global values in your stories or applications. But there’s a new object in town called TextPool, and it might just make your life easier in certain situations.
Let’s break down what TextPool is, how it’s different from script variables, and when you should consider using it.
What is TextPool in SAP Analytics Cloud?
TextPool is a relatively new scripting object in SAC that allows you to store and manage string values centrally in your stories or analytic applications. Think of it as a global string manager — you define it once and use it wherever you need it.
You might be thinking, “We already have script variables for that.” And yes, script variables can also store values globally. But TextPool is designed specifically for constant strings — meaning values that shouldn’t change once defined.
Why Should You Use TextPool Instead of Script Variables?
Here are a few reasons why TextPool can be a better choice in specific scenarios:
1. Constant String Protection
With script variables, even after setting a value, there’s always a risk of accidentally updating it somewhere in the story. TextPool avoids that because the values are not meant to be changed dynamically.
2. Cleaner Reusability Across Objects
Let’s say you’re working on an API-based project and you need to reuse your API key across multiple widgets — buttons, input fields, etc.
With script variables, you’d have to initialize the value during onInitialization, and the value could still potentially change.
But with TextPool, you define your string once and use it as-is anywhere in your story.
3. Faster Access and Less Overhead
TextPool values load faster compared to variables initialized at runtime. This is helpful especially in large-scale applications with many dependencies.
4. Grouping Values Like an Array
You can add multiple text entries in a single TextPool — sort of like storing key-value pairs. This helps keep things organized and avoids confusion when you’re managing many string constants.
Example Use Case
Imagine you’re building an app where you don’t want certain strings like “API_KEY” or “DEFAULT_ERROR_MESSAGE” to change accidentally. Using a script variable may lead to someone overwriting them later. But with TextPool, once you’ve defined them, they’re safe — no accidental updates.
How to Create a TextPool in SAC
Creating a TextPool is simple:
Open your Story in SAP Analytics Cloud.
Go to the Outline tab.
Under the Scripting section, click the plus (+) icon.
Select TextPool.
Give your TextPool a name.
Add text entries by clicking the plus (+) icon inside the TextPool panel.
You can add multiple key-value pairs like:
“api_key” = “1234-xyz”
“error_msg” = “Something went wrong!”
How to Use TextPool in Your Scripts
To retrieve a value from TextPool, use the getText() method like this:
This always returns a string.
If you need it in another format (like a number or boolean), you can cast it manually after retrieving it.
Final Thoughts
TextPool may seem like a small feature, but it’s incredibly handy in large applications or when you want to store static string values safely and efficiently. While script variables still have their place, using TextPool gives you that extra control and clarity in your code.
I personally use TextPool whenever I’m working on a big project and want my constants to be uneditable, consistent, and easily reusable.
If you’re working with SAP Analytics Cloud (SAC), you’ve probably used script variables to manage global values in your stories or applications. But there’s a new object in town called TextPool, and it might just make your life easier in certain situations.Let’s break down what TextPool is, how it’s different from script variables, and when you should consider using it.What is TextPool in SAP Analytics Cloud?TextPool is a relatively new scripting object in SAC that allows you to store and manage string values centrally in your stories or analytic applications. Think of it as a global string manager — you define it once and use it wherever you need it.You might be thinking, “We already have script variables for that.” And yes, script variables can also store values globally. But TextPool is designed specifically for constant strings — meaning values that shouldn’t change once defined.Why Should You Use TextPool Instead of Script Variables?Here are a few reasons why TextPool can be a better choice in specific scenarios:1. Constant String ProtectionWith script variables, even after setting a value, there’s always a risk of accidentally updating it somewhere in the story. TextPool avoids that because the values are not meant to be changed dynamically.
2. Cleaner Reusability Across ObjectsLet’s say you’re working on an API-based project and you need to reuse your API key across multiple widgets — buttons, input fields, etc.With script variables, you’d have to initialize the value during onInitialization, and the value could still potentially change.But with TextPool, you define your string once and use it as-is anywhere in your story.
3. Faster Access and Less OverheadTextPool values load faster compared to variables initialized at runtime. This is helpful especially in large-scale applications with many dependencies.
4. Grouping Values Like an ArrayYou can add multiple text entries in a single TextPool — sort of like storing key-value pairs. This helps keep things organized and avoids confusion when you’re managing many string constants.Example Use CaseImagine you’re building an app where you don’t want certain strings like “API_KEY” or “DEFAULT_ERROR_MESSAGE” to change accidentally. Using a script variable may lead to someone overwriting them later. But with TextPool, once you’ve defined them, they’re safe — no accidental updates.How to Create a TextPool in SACCreating a TextPool is simple:Open your Story in SAP Analytics Cloud.Go to the Outline tab.Under the Scripting section, click the plus (+) icon.Select TextPool.Give your TextPool a name.Add text entries by clicking the plus (+) icon inside the TextPool panel.You can add multiple key-value pairs like:”api_key” = “1234-xyz””error_msg” = “Something went wrong!”How to Use TextPool in Your ScriptsTo retrieve a value from TextPool, use the getText() method like this:This always returns a string.If you need it in another format (like a number or boolean), you can cast it manually after retrieving it.Final ThoughtsTextPool may seem like a small feature, but it’s incredibly handy in large applications or when you want to store static string values safely and efficiently. While script variables still have their place, using TextPool gives you that extra control and clarity in your code.I personally use TextPool whenever I’m working on a big project and want my constants to be uneditable, consistent, and easily reusable. Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog