Update
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
- [Aggregate Expressions](#aggregate-expressions)
|
||||
- [Arithmetic, Cast, String Expressions, and Case Distinctions](#arithmetic-cast-string-expressions-and-case-distinctions)
|
||||
- [Window Expressions](#window-expressions)
|
||||
- [coalesce Function](#coalesce-function)
|
||||
- [SQL Conditions](#sql-conditions)
|
||||
- [Selecting Data by Evaluating the Content of Other Tables](#selecting-data-by-evaluating-the-content-of-other-tables)
|
||||
- [Combining Data of Multiple Database Tables](#combining-data-of-multiple-database-tables)
|
||||
@@ -626,7 +627,7 @@ SELECT FROM zdemo_abap_flsch
|
||||
on SQL expressions
|
||||
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapsql_expr.htm)
|
||||
and the subtopics there.
|
||||
- Built-in functions are available in ABAP SQL. The result is a value with the associated dictionary type. The arguments of the functions can cover one or more SQL expressions. Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_builtin_functions.htm).
|
||||
- Built-in SQL functions can be specified as standalone functions in ABAP SQL or as operands of SQL expressions. The result is a value with the associated dictionary type. The arguments of the functions can cover one or more SQL expressions. Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_builtin_functions.htm).
|
||||
|
||||
##### Elementary Expressions
|
||||
|
||||
@@ -1078,6 +1079,60 @@ SELECT carrid, currency, fldate,
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
##### coalesce Function
|
||||
|
||||
Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_coalesce.htm).
|
||||
|
||||
|
||||
```abap
|
||||
"The null value is a special value that is returned by a database. It indicates an
|
||||
"undefined value or result. Note that, in ABAP, there are no special null values. Do
|
||||
"not confuse the null value with a type-dependent initial value. When using SELECT
|
||||
"statements to read data, null values can be produced by, for example, outer joins.
|
||||
"When the null values are passed to a data object, they are transformed to the
|
||||
"type-dependent initial values. For more information, refer to the ABAP Keyword Documentation.
|
||||
"The following example uses a left outer join to intentionally create null values. For
|
||||
"this purpose, two demo database tables of the ABAP cheat sheet repository are cleared and
|
||||
"populated with specific values to visualize null values.
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
DELETE FROM zdemo_abap_tab2.
|
||||
MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' char2 = 'y' )
|
||||
( key_field = 2 char1 = 'b' char2 = 'z' ) ) ).
|
||||
MODIFY zdemo_abap_tab2 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' )
|
||||
( key_field = 2 char1 = 'a' )
|
||||
( key_field = 3 char1 = 'b' )
|
||||
( key_field = 4 ) ) ).
|
||||
|
||||
"Note that for the entry 'key_field = 4' no char1 value was passed.
|
||||
"char1 is a shared column of the two database tables, and which is used in
|
||||
"the ON condition of the join. Since there is no entry in char1 for 'key_field = 4',
|
||||
"the joined values are null in that case.
|
||||
"The coalesce function is used to replace null values produced by an outer join with
|
||||
"a different value.
|
||||
SELECT tab2~key_field,
|
||||
coalesce( tab1~char1, '-' ) AS coalesced1,
|
||||
coalesce( tab1~char2, '#' ) AS coalesced2,
|
||||
"A coalesce function is a short form of a complex
|
||||
"case distinction such as the following:
|
||||
CASE WHEN tab1~char1 IS NOT NULL THEN tab1~char1
|
||||
ELSE '?'
|
||||
END as coalesced3
|
||||
|
||||
FROM zdemo_abap_tab2 AS tab2
|
||||
LEFT OUTER JOIN zdemo_abap_tab1 AS tab1 ON tab1~char1 = tab2~char1
|
||||
INTO TABLE @DATA(join_w_null).
|
||||
|
||||
*Example table content
|
||||
*KEY_FIELD COALESCED1 COALESCED2 COALESCED3
|
||||
*1 a y a
|
||||
*2 a y a
|
||||
*3 b z b
|
||||
*4 - # ?
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
### SQL Conditions
|
||||
|
||||
You can formulate conditions in ABAP SQL statements, i. e. [logical
|
||||
|
||||
Reference in New Issue
Block a user