SAP Build Apps Functions – “Utility” of all formulas available for Data Transformation

Estimated read time 15 min read

SAP Build Apps is a powerful low-code platform that enables users to create robust applications with minimal coding. One of the key features of SAP Build Apps is its ability to use functions and formulas to manipulate and transform data dynamically. In this blog, we’ll explore when to use these functions and how to get the desired output from formulas.

Understanding SAP Build Apps Functions

Functions in SAP Build Apps are predefined operations that can be used to perform specific tasks within your application. These functions can range from simple arithmetic operations to complex data manipulations. Here are some common scenarios where you might need to use functions:

Data Validation: Ensuring that user inputs meet certain criteria before processing.Data Transformation: Converting data from one format to another, such as changing date formats or calculating derived values.Conditional Logic: Implementing if-else conditions to control the flow of your application based on specific criteria.

Using the Formula Editor

The Formula Editor in SAP Build Apps is a powerful tool that allows you to create and apply formulas to your data. It combines spreadsheet-like formulas with built-in support for application context, making it easy to create complex algorithms. Here’s how to get started:

Function NameFormulaFormula DescriptionExamples with ResultUtilityBOOLEANConverts the given value to a true/false. This conversion is equivalent to JavaScript BOOLEAN(“123”)
=true

BOOLEAN(123)
=true

BOOLEAN(“”)
=falseUtilityDECODE_BASE64Converts a given Base64 encoded text to UTF-8 text.DECODE_BASE64(“Zm9vYmFy”)
=”foobar”

DECODE_BASE64(“w6TDpMOk”)
=”äää”UtilityDECODE_JSONParses the given text with JSON-formatted content to the value it represents (number, true/false, list or object).DECODE_JSON(‘”foobar”‘)
=”foobar”

DECODE_JSON(‘[1, 2, null, “123”, true]’)
=[1, 2, null, “123”, true]

DECODE_JSON(‘{“a”: 1, “b”: null, “c”: “123”, “d”: true}’)
={“a”: 1, “b”: null, “c”: “123”, “d”: true}UtilityDEFAULTIf the given value is non-empty (as per the definitions in the EMPTY  function), returns the given value, otherwise return the given default.DEFAULT(true, 1)
=true

DEFAULT(null, 1)
=1

DEFAULT({ a: 1 }, 1)
={ a: 1 }

DEFAULT([], 1)
=[]UtilityDEFAULT_FILE_EXTENSIONReturns the default file extension associated with the given MIME type.DEFAULT_FILE_EXTENSION(“application/json”)
=”json”

DEFAULT_FILE_EXTENSION(“application/javascript”)
=”js”

DEFAULT_FILE_EXTENSION(“text/plain”)
=”txt”

DEFAULT_FILE_EXTENSION(“video/mp4”)
=”mp4″

DEFAULT_FILE_EXTENSION(“application/octet-stream”)
=”bin”

UtilityENCODE_BASE64Converts a given UTF-8 text to Base64-encoded text.ENCODE_BASE64(“foobar”)
=Zm9vYmFy

ENCODE_BASE64(“äää”)
=w6TDpMOkUtilityENCODE_FOR_URLURL encodes the given text, escaping any special characters. Returns the encoded text.
ENCODE_FOR_URL(“https://example.com/example.html?color=red&width=120“)
=”https%3A%2F%2Fexample.com%2Fexample.html%3Fcolor%3Dred%26width%3D120″

ENCODE_FOR_URL(“https://test.net/test?animal=cat&color=black“)
=”https%3A%2F%2Ftest.net%2Ftest%3Fanimal%3Dcat%26color%3Dblack”UtilityENCODE_JSONConverts a given JSON-format input (number, true/false, list, object) into a text.ENCODE_JSON(“foobar”)
=””foobar””

ENCODE_JSON([1, 2, null, “123”, true])
=”[1,2,null,”123″,true]”

ENCODE_JSON({a: 1, b: null, c: “123”, d: true})
=”{“a”:1,”b”:null,”c”:”123″,”d”:true}”

ENCODE_JSON([1, 2, null, “123”, true], 2)
=”[n  1,n  2,n  null,n  “123”,n  truen]”

ENCODE_JSON({a: 1, b: null, c: “123”, d: true}, 2)
=”{n  “a”: 1,n  “b”: null,n  “c”: “123”,n  “d”: truen}”UtilityENCODE_OBJECT_FOR_URLEncodes an object as key=value pairs joined by an ampersand (&) character. The keys and values are percent encoded. Only keys with string, number or boolean values are included. This format is typically used in URLs to specify query parameters (after the 

ENCODE_OBJECT_FOR_URL({key: “value”})
=”key=value”

ENCODE_OBJECT_FOR_URL({sum: 23, currency: “€”})
=”sum=23&currency=%E2%82%AC”

ENCODE_OBJECT_FOR_URL({redirect_uri: “https://my-domain.tld/oauth?nonce=abc“})
=”redirect_uri=https%3A%2F%2Fmy-domain.tld%2Foauth%3Fnonce%3Dabc”UtilityFILENAME_IS_IMAGE Return TRUE if the given text is or has a file extension that belongs to a web-compatible image MIME type.FILENAME_IS_IMAGE(“a.png”)
=true

FILENAME_IS_IMAGE(“test.jpg”)
=true

FILENAME_IS_IMAGE(“/folder/test.best.svg”)
=true

FILENAME_IS_IMAGE(“video.mp4”)
=trueUtilityIFIf the first parameter evaluates to TRUE , returns the second parameter. Otherwise, returns the third parameter.IF(true, “yes”, “no”)
=”yes”

IF(false, “yes”, “no”)
=”no”UtilityINTEGERConverts the given input value to an integer number. Texts are parsed, and numbers are rounded down. If the input is already an integer, it is returned as-is. Any other values, and invalid texts, result in null ValueINTEGER(“123”)
=123

INTEGER(“123.567”)
=123

INTEGER(“-0896”)
=-896

INTEGER(5.67)
=5

INTEGER(“6e-7”)
=0UtilityIS_EMAILReturns TRUE  if the given text is a valid email address, otherwise returns IS_EMAIL(“test@mail.com”)
=true

IS_EMAIL(“@mail.com”)
=falseUtilityIS_EMPTYReturns TRUE or FALSE based on if the given value is empty.
Returns TRUE  if the parameter is one of the following values:
an empty text
an empty listIS_EMPTY(“”)
=true

IS_EMPTY(“a”)
=false

IS_EMPTY([])
=true

IS_EMPTY({})
=true

IS_EMPTY(0)
=falseUtilityIS_EQUALReturns TRUE if the both parameter values are equal, otherwise false. . Same than using the ==  operator in formulas.
The values are considered equal if they are of the same type and represent the same value. If the values are objects or arrays, a deep comparison is performed. Objects are considered equal if they have the same properties. Arrays are considered equal if they have equal items in the same order.IS_EQUAL(“cat”, “cat”)
=true

IS_EQUAL({name: “John”}, {name: “John”})
=true

IS_EQUAL([“cat”], [“cat”])
=trueUtilityIS_NULLReturns TRUE value.  if the given parameter is null value. For any other value, including undefined, returns FALSEIS_NULL(null)
=true

IS_NULL(undefined)
=false

IS_NULL(false)
=false

IS_NULL(0)
=false

IS_NULL(“”)
=falseUtilityIS_NULLYReturns True  if the given value is either null or undefined.
For any other value, returns falseIS_NULLY(null)
=false

IS_NULLY(undefined)
=true

IS_NULLY(false)
=false

IS_NULLY(0)
=false

IS_NULL(“”)
=falseUtilityIS_NUMBERReturns whether or not the given value is number.
 This returns TRUE if the parameter type is number.. For any other value this returns FALSE. . Note that this returns false  for numeric texts.IS_NUMBER(undefined)
=false

IS_NUMBER(null)
=false

IS_NUMBER(false)
=false

IS_NUMBER(0)
=true

IS_NUMBER(1)
=true

IS_NUMBER(“3”)
=false

IS_NUMBER(“”)
=falseUtilityIS_SAMEReturn TRUE if the both parameter values are exactly the same, otherwise FALSE . Same than using the === operator in formulas.IS_SAME(“cat”, “cat”)
=true

IS_SAME(2, 2)
=true

IS_SAME({name: “John”}, {name: “John”})
=false

IS_SAME([“cat”], [“cat”])
=falseUtilityIS_UNDEFINEDReturn TRUE if the parameter is undefined value. For all other values, including null this returns
Similar to IS_EQUAL except that it does not perform deep comparison for objects and lists. Instead objects are considered “same” only if they refer to the instance in the memory. In most cases, you might want to use IS_EQUAL  instead of this function.The functionality of this function is equal to JavaScript’s IS_UNDEFINED(undefined)
=true

IS_UNDEFINED(null)
=false

IS_UNDEFINED(false)
=false

IS_UNDEFINED(0)
=false

IS_UNDEFINED(“”)
=falseUtilityMIME_TYPEReturns the MIME type of the given file extension, or null  if it cannot be determined. Also works with full paths and filenames, where it’s assumed the text ends in an extension.MIME_TYPE(“json”)
=”application/json”

MIME_TYPE(“.json”)
=”application/json”

MIME_TYPE(“/cachedImages/test.png”)
=”image/png”

MIME_TYPE(“README.md”)
=”text/markdown”UtilityMIME_TYPE_IS_IMAGEReturn TRUE  if the given MIME type belongs to a web-safe image format, and FALSE otherwiseMIME_TYPE_IS_IMAGE(“image/apng”)
=true

MIME_TYPE_IS_IMAGE(“image/png”)
=true

MIME_TYPE_IS_IMAGE(“image/svg+xml”)
=true

MIME_TYPE_IS_IMAGE(“video/mp4”)
=false

MIME_TYPE_IS_IMAGE(“wrong MIME type”)
=falseUtilityNOTReturn TRUE if the given parameter is false , otherwise returns FALSE . Equivalent to the  ! OperatorNOT(false)
=true

NOT(true)
=falseUtilityNUMBERConverts the value to a number, if it is not already a number. Numeric texts are parsed. Any other values, and invalid texts, result in null valueNUMBER(“123”)
=123

NUMBER(“-0896”)
=-0896

NUMBER(-4.8)
=-4.8UtilityNUMERIC_BASEConverts the given number into a text representation in another base.
NUMERIC_BASE(123, 2)
=”111101″

NUMERIC_BASE(123, 4)
=”1323″

NUMERIC_BASE(123, 😎
=”173″

NUMERIC_BASE(123, 10)
=”123″

NUMERIC_BASE(123, 16)
=”7b”

NUMERIC_BASE(123, 2.5)
=”111101″

NUMERIC_BASE(123.625, 2)
=”111101.101″

NUMERIC_BASE(-123.625, 2)
=”-111101.101″UtilitySTRINGConverts the given value to a text. If the value is a number, returns its text representation, possibly including decimals. True/false values are converted to either TRUE or FALSE. A null  value is converted to an empty text.STRING(123.456)
=”123.456″

STRING(true)
=”true”

STRING(“hello”)
=”hello”Utility

URL

Converts the given text to an URL-type text. Returns null  if the text cannot be converted to an URL.URL(“http://foo.com/blah_blah“)
=”http://foo.com/blah_blah

URL(“https://www.example.com/foo/?bar=baz&inga=42&quux“)
=”https://www.example.com/foo/?bar=baz&inga=42&quux

URL(“http://userid@www.example.com/“)
=”http://userid@www.example.com/

URL(“http://142.42.1.1:8080/“)
= “http://142.42.1.1:8080/

I will continue to write a next blog with New function and New formulas, Keep watching the blog…

Conclusion

Using functions and formulas in SAP Build Apps can significantly enhance the functionality and user experience of your applications. By understanding when and how to use these tools, you can efficiently transform data and implement complex logic without extensive coding. Experiment with different functions and formulas to see how they can best serve your application needs.

 

 

​ SAP Build Apps is a powerful low-code platform that enables users to create robust applications with minimal coding. One of the key features of SAP Build Apps is its ability to use functions and formulas to manipulate and transform data dynamically. In this blog, we’ll explore when to use these functions and how to get the desired output from formulas.Understanding SAP Build Apps FunctionsFunctions in SAP Build Apps are predefined operations that can be used to perform specific tasks within your application. These functions can range from simple arithmetic operations to complex data manipulations. Here are some common scenarios where you might need to use functions:Data Validation: Ensuring that user inputs meet certain criteria before processing.Data Transformation: Converting data from one format to another, such as changing date formats or calculating derived values.Conditional Logic: Implementing if-else conditions to control the flow of your application based on specific criteria.Using the Formula EditorThe Formula Editor in SAP Build Apps is a powerful tool that allows you to create and apply formulas to your data. It combines spreadsheet-like formulas with built-in support for application context, making it easy to create complex algorithms. Here’s how to get started:Function NameFormulaFormula DescriptionExamples with ResultUtilityBOOLEANConverts the given value to a true/false. This conversion is equivalent to JavaScript BOOLEAN(“123”)=trueBOOLEAN(123)=trueBOOLEAN(“”)=falseUtilityDECODE_BASE64Converts a given Base64 encoded text to UTF-8 text.DECODE_BASE64(“Zm9vYmFy”)=”foobar”DECODE_BASE64(“w6TDpMOk”)=”äää”UtilityDECODE_JSONParses the given text with JSON-formatted content to the value it represents (number, true/false, list or object).DECODE_JSON(‘”foobar”‘)=”foobar”DECODE_JSON(‘[1, 2, null, “123”, true]’)=[1, 2, null, “123”, true]DECODE_JSON(‘{“a”: 1, “b”: null, “c”: “123”, “d”: true}’)={“a”: 1, “b”: null, “c”: “123”, “d”: true}UtilityDEFAULTIf the given value is non-empty (as per the definitions in the EMPTY  function), returns the given value, otherwise return the given default.DEFAULT(true, 1)=trueDEFAULT(null, 1)=1DEFAULT({ a: 1 }, 1)={ a: 1 }DEFAULT([], 1)=[]UtilityDEFAULT_FILE_EXTENSIONReturns the default file extension associated with the given MIME type.DEFAULT_FILE_EXTENSION(“application/json”)=”json”DEFAULT_FILE_EXTENSION(“application/javascript”)=”js”DEFAULT_FILE_EXTENSION(“text/plain”)=”txt”DEFAULT_FILE_EXTENSION(“video/mp4”)=”mp4″DEFAULT_FILE_EXTENSION(“application/octet-stream”)=”bin”UtilityENCODE_BASE64Converts a given UTF-8 text to Base64-encoded text.ENCODE_BASE64(“foobar”)=Zm9vYmFyENCODE_BASE64(“äää”)=w6TDpMOkUtilityENCODE_FOR_URLURL encodes the given text, escaping any special characters. Returns the encoded text.ENCODE_FOR_URL(“https://example.com/example.html?color=red&width=120”)=”https%3A%2F%2Fexample.com%2Fexample.html%3Fcolor%3Dred%26width%3D120″ENCODE_FOR_URL(“https://test.net/test?animal=cat&color=black”)=”https%3A%2F%2Ftest.net%2Ftest%3Fanimal%3Dcat%26color%3Dblack”UtilityENCODE_JSONConverts a given JSON-format input (number, true/false, list, object) into a text.ENCODE_JSON(“foobar”)=””foobar””ENCODE_JSON([1, 2, null, “123”, true])=”[1,2,null,”123″,true]”ENCODE_JSON({a: 1, b: null, c: “123”, d: true})=”{“a”:1,”b”:null,”c”:”123″,”d”:true}”ENCODE_JSON([1, 2, null, “123”, true], 2)=”[n  1,n  2,n  null,n  “123”,n  truen]”ENCODE_JSON({a: 1, b: null, c: “123”, d: true}, 2)=”{n  “a”: 1,n  “b”: null,n  “c”: “123”,n  “d”: truen}”UtilityENCODE_OBJECT_FOR_URLEncodes an object as key=value pairs joined by an ampersand (&) character. The keys and values are percent encoded. Only keys with string, number or boolean values are included. This format is typically used in URLs to specify query parameters (after the ENCODE_OBJECT_FOR_URL({key: “value”})=”key=value”ENCODE_OBJECT_FOR_URL({sum: 23, currency: “€”})=”sum=23&currency=%E2%82%AC”ENCODE_OBJECT_FOR_URL({redirect_uri: “https://my-domain.tld/oauth?nonce=abc”})=”redirect_uri=https%3A%2F%2Fmy-domain.tld%2Foauth%3Fnonce%3Dabc”UtilityFILENAME_IS_IMAGE Return TRUE if the given text is or has a file extension that belongs to a web-compatible image MIME type.FILENAME_IS_IMAGE(“a.png”)=trueFILENAME_IS_IMAGE(“test.jpg”)=trueFILENAME_IS_IMAGE(“/folder/test.best.svg”)=trueFILENAME_IS_IMAGE(“video.mp4”)=trueUtilityIFIf the first parameter evaluates to TRUE , returns the second parameter. Otherwise, returns the third parameter.IF(true, “yes”, “no”)=”yes”IF(false, “yes”, “no”)=”no”UtilityINTEGERConverts the given input value to an integer number. Texts are parsed, and numbers are rounded down. If the input is already an integer, it is returned as-is. Any other values, and invalid texts, result in null ValueINTEGER(“123”)=123INTEGER(“123.567”)=123INTEGER(“-0896”)=-896INTEGER(5.67)=5INTEGER(“6e-7”)=0UtilityIS_EMAILReturns TRUE  if the given text is a valid email address, otherwise returns IS_EMAIL(“test@mail.com”)=trueIS_EMAIL(“@mail.com”)=falseUtilityIS_EMPTYReturns TRUE or FALSE based on if the given value is empty.Returns TRUE  if the parameter is one of the following values:an empty textan empty listIS_EMPTY(“”)=trueIS_EMPTY(“a”)=falseIS_EMPTY([])=trueIS_EMPTY({})=trueIS_EMPTY(0)=falseUtilityIS_EQUALReturns TRUE if the both parameter values are equal, otherwise false. . Same than using the ==  operator in formulas.The values are considered equal if they are of the same type and represent the same value. If the values are objects or arrays, a deep comparison is performed. Objects are considered equal if they have the same properties. Arrays are considered equal if they have equal items in the same order.IS_EQUAL(“cat”, “cat”)=trueIS_EQUAL({name: “John”}, {name: “John”})=trueIS_EQUAL([“cat”], [“cat”])=trueUtilityIS_NULLReturns TRUE value.  if the given parameter is null value. For any other value, including undefined, returns FALSEIS_NULL(null)=trueIS_NULL(undefined)=falseIS_NULL(false)=falseIS_NULL(0)=falseIS_NULL(“”)=falseUtilityIS_NULLYReturns True  if the given value is either null or undefined.For any other value, returns falseIS_NULLY(null)=falseIS_NULLY(undefined)=trueIS_NULLY(false)=falseIS_NULLY(0)=falseIS_NULL(“”)=falseUtilityIS_NUMBERReturns whether or not the given value is number. This returns TRUE if the parameter type is number.. For any other value this returns FALSE. . Note that this returns false  for numeric texts.IS_NUMBER(undefined)=falseIS_NUMBER(null)=falseIS_NUMBER(false)=falseIS_NUMBER(0)=trueIS_NUMBER(1)=trueIS_NUMBER(“3”)=falseIS_NUMBER(“”)=falseUtilityIS_SAMEReturn TRUE if the both parameter values are exactly the same, otherwise FALSE . Same than using the === operator in formulas.IS_SAME(“cat”, “cat”)=trueIS_SAME(2, 2)=trueIS_SAME({name: “John”}, {name: “John”})=falseIS_SAME([“cat”], [“cat”])=falseUtilityIS_UNDEFINEDReturn TRUE if the parameter is undefined value. For all other values, including null this returnsSimilar to IS_EQUAL except that it does not perform deep comparison for objects and lists. Instead objects are considered “same” only if they refer to the instance in the memory. In most cases, you might want to use IS_EQUAL  instead of this function.The functionality of this function is equal to JavaScript’s IS_UNDEFINED(undefined)=trueIS_UNDEFINED(null)=falseIS_UNDEFINED(false)=falseIS_UNDEFINED(0)=falseIS_UNDEFINED(“”)=falseUtilityMIME_TYPEReturns the MIME type of the given file extension, or null  if it cannot be determined. Also works with full paths and filenames, where it’s assumed the text ends in an extension.MIME_TYPE(“json”)=”application/json”MIME_TYPE(“.json”)=”application/json”MIME_TYPE(“/cachedImages/test.png”)=”image/png”MIME_TYPE(“README.md”)=”text/markdown”UtilityMIME_TYPE_IS_IMAGEReturn TRUE  if the given MIME type belongs to a web-safe image format, and FALSE otherwiseMIME_TYPE_IS_IMAGE(“image/apng”)=trueMIME_TYPE_IS_IMAGE(“image/png”)=trueMIME_TYPE_IS_IMAGE(“image/svg+xml”)=trueMIME_TYPE_IS_IMAGE(“video/mp4”)=falseMIME_TYPE_IS_IMAGE(“wrong MIME type”)=falseUtilityNOTReturn TRUE if the given parameter is false , otherwise returns FALSE . Equivalent to the  ! OperatorNOT(false)=trueNOT(true)=falseUtilityNUMBERConverts the value to a number, if it is not already a number. Numeric texts are parsed. Any other values, and invalid texts, result in null valueNUMBER(“123”)=123NUMBER(“-0896″)=-0896NUMBER(-4.8)=-4.8UtilityNUMERIC_BASEConverts the given number into a text representation in another base.NUMERIC_BASE(123, 2)=”111101″NUMERIC_BASE(123, 4)=”1323″NUMERIC_BASE(123, 😎=”173″NUMERIC_BASE(123, 10)=”123″NUMERIC_BASE(123, 16)=”7b”NUMERIC_BASE(123, 2.5)=”111101″NUMERIC_BASE(123.625, 2)=”111101.101″NUMERIC_BASE(-123.625, 2)=”-111101.101″UtilitySTRINGConverts the given value to a text. If the value is a number, returns its text representation, possibly including decimals. True/false values are converted to either TRUE or FALSE. A null  value is converted to an empty text.STRING(123.456)=”123.456″STRING(true)=”true”STRING(“hello”)=”hello”UtilityURLConverts the given text to an URL-type text. Returns null  if the text cannot be converted to an URL.URL(“http://foo.com/blah_blah”)=”http://foo.com/blah_blah”URL(“https://www.example.com/foo/?bar=baz&inga=42&quux”)=”https://www.example.com/foo/?bar=baz&inga=42&quux”URL(“http://userid@www.example.com/”)=”http://userid@www.example.com/”URL(“http://142.42.1.1:8080/”)= “http://142.42.1.1:8080/”I will continue to write a next blog with New function and New formulas, Keep watching the blog…ConclusionUsing functions and formulas in SAP Build Apps can significantly enhance the functionality and user experience of your applications. By understanding when and how to use these tools, you can efficiently transform data and implement complex logic without extensive coding. Experiment with different functions and formulas to see how they can best serve your application needs.    Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author