Update
This commit is contained in:
470
03_ABAP_SQL.md
470
03_ABAP_SQL.md
@@ -30,7 +30,9 @@
|
||||
- [Numeric Functions](#numeric-functions)
|
||||
- [String Functions](#string-functions)
|
||||
- [coalesce Function](#coalesce-function)
|
||||
- [More Functions](#more-functions)
|
||||
- [Conversion Functions](#conversion-functions)
|
||||
- [Date and Time Functions](#date-and-time-functions)
|
||||
- [UUID Function](#uuid-function)
|
||||
- [Create, Update, and Delete Operations](#create-update-and-delete-operations)
|
||||
- [Using INSERT](#using-insert)
|
||||
- [Using UPDATE](#using-update)
|
||||
@@ -1884,64 +1886,440 @@ SELECT tab2~key_field,
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### More Functions
|
||||
### Conversion Functions
|
||||
|
||||
More information:
|
||||
- [Special functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_special_functions.htm)
|
||||
- [UUID function](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_uuid.htm)
|
||||
- [Date and time functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_uuid.htm)
|
||||
- It is also possible to call [SQL-based scalar functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_sql_scalar_glosry.htm). Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_cds_scalar_func.htm).
|
||||
[Type conversion functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENSQL_TYPE_CONV_FUNC.html):
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<td> Function </td> <td> Notes </td> <td> Code Snippet </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`bintohex( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
Converts byte strings (type `raw`; mapped to ABAP type `x`) to character strings (type `char`)
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet implements the following:
|
||||
- To have a self-contained example, a demo internal table with elementary line type (byte-like type `x length 10`) is created.
|
||||
- The table is filled with demo data.
|
||||
- An ABAP SQL `SELECT` statement that includes the `bintohex` function retrieves data from the internal table. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
- [Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm) (find more information in the Dynamic Programming cheat sheet) is used to demonstrate that the type of the `tline` (the alias name for `table_line`) is character-like.
|
||||
<br>
|
||||
|
||||
``` abap
|
||||
TYPES x10 TYPE x LENGTH 10.
|
||||
TYPES ty_raw_tab TYPE TABLE OF x10 WITH EMPTY KEY.
|
||||
|
||||
DATA(raw_tab) = VALUE ty_raw_tab( ( CONV x10( '68656C6C6F' ) )
|
||||
( CONV x10( '776F726C64' ) )
|
||||
( CONV x10( '41424150' ) ) ).
|
||||
|
||||
SELECT bintohex( table_line ) AS tline
|
||||
FROM @raw_tab AS tab
|
||||
INTO TABLE @DATA(conv_to_blob_tab) ##ITAB_DB_SELECT.
|
||||
|
||||
DATA(tdo_itab) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( conv_to_blob_tab ) ).
|
||||
DATA(table_components_itab) = CAST cl_abap_structdescr( tdo_itab->get_table_line_type( ) )->components.
|
||||
DATA(text_line_type_kind) = table_components_itab[ name = 'TLINE' ]-type_kind.
|
||||
ASSERT text_line_type_kind = cl_abap_typedescr=>typekind_char.
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`hextobin( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
Converts character strings (type `char` or `numc`) to byte strings (type `raw`; mapped to ABAP type `x`)
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet implements the following:
|
||||
- To have a self-contained example, a demo internal table with elementary line type (character-like type `c length 10`) is created.
|
||||
- The table is filled with demo data.
|
||||
- An ABAP SQL `SELECT` statement that includes the `hextobin` function retrieves data from the internal table. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
- RTTI is used to demonstrate that the type of the `tline` (the alias name for `table_line`) is `x`.
|
||||
|
||||
<br>
|
||||
|
||||
``` abap
|
||||
TYPES c10 TYPE c LENGTH 10.
|
||||
TYPES ty_c_tab TYPE TABLE OF c10 WITH EMPTY KEY.
|
||||
|
||||
DATA(c_tab) = VALUE ty_c_tab( ( '68656C6C6F' )
|
||||
( '776F726C64' )
|
||||
( '41424150' ) ).
|
||||
|
||||
SELECT hextobin( table_line ) AS tline
|
||||
FROM @c_tab AS tab
|
||||
INTO TABLE @DATA(hextobin_tab) ##ITAB_DB_SELECT.
|
||||
|
||||
DATA(tdo_itab) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( hextobin_tab ) ).
|
||||
DATA(table_components_itab) = CAST cl_abap_structdescr( tdo_itab->get_table_line_type( ) )->components.
|
||||
DATA(text_line_type_kind) = table_components_itab[ name = 'TLINE' ]-type_kind.
|
||||
ASSERT text_line_type_kind = cl_abap_typedescr=>typekind_hex.
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`to_blob( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
Converts from a byte field (type `raw`; mapped to ABAP type `x`) to a byte string (a blob, Binary Large Object; type `rawstring`; mapped to ABAP type `xstring`).
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet implements the following:
|
||||
- To have a self-contained example, a demo internal table with elementary line type (byte-like type, `x length 10`) is created.
|
||||
- The table is filled with demo data.
|
||||
- An ABAP SQL `SELECT` statement that includes the `to_blob` function retrieves data from the internal table. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
- RTTI is used to demonstrate that the type of the `tline` (the alias name for `table_line`) is `xstring`.
|
||||
|
||||
<br>
|
||||
|
||||
``` abap
|
||||
TYPES x10 TYPE x LENGTH 10.
|
||||
TYPES ty_raw_tab TYPE TABLE OF x10 WITH EMPTY KEY.
|
||||
|
||||
DATA(raw_tab) = VALUE ty_raw_tab( ( CONV x10( '68656C6C6F' ) )
|
||||
( CONV x10( '776F726C64' ) )
|
||||
( CONV x10( '41424150' ) ) ).
|
||||
|
||||
SELECT to_blob( table_line ) AS tline
|
||||
FROM @raw_tab AS tab
|
||||
INTO TABLE @DATA(conv_to_blob_tab) ##ITAB_DB_SELECT.
|
||||
|
||||
DATA(tdo_itab) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( conv_to_blob_tab ) ).
|
||||
DATA(table_components_itab) = CAST cl_abap_structdescr( tdo_itab->get_table_line_type( ) )->components.
|
||||
DATA(text_line_type_kind) = table_components_itab[ name = 'TLINE' ]-type_kind.
|
||||
ASSERT text_line_type_kind = cl_abap_typedescr=>typekind_xstring.
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`to_clob( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
- Converts a fixed-length character string (type `char` or `sstring`) to a clob (character large object; type `string`)
|
||||
- The argument specified in the parentheses can be a table column, literal, host variable/constant, or an SQL expression
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The example class, executable with F9 in ADT, implements the following:
|
||||
- To have a self-contained example, a demo internal table is created. Among others, it includes the `text` component that is of type `c` with length 255.
|
||||
- The table is filled with lots of data. `text` receives random strings of a random length (1 - 255) to have data to work with.
|
||||
- An ABAP SQL `SELECT` statement that includes the `to_clob` function retrieves data from the internal table. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
- The `to_clob` has an SQL expression as argument. In this case, it is an aggregate expression with `STRING_AGG`, which aggregates the value of multiple rows into a single value.
|
||||
- Using RTTI, it is demonstrated that the type of the `text_line` component (the alias name for `text`) is `string`. It is then evaluated how many characters the random strings contain. The example is set up to show that the aggregated string exceeds 1333 characters, which is the maximum length of fields of type `sstring`.
|
||||
|
||||
<br>
|
||||
|
||||
```abap
|
||||
CLASS zcl_demo_abap DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
METHODS get_random_string IMPORTING VALUE(length) TYPE i OPTIONAL
|
||||
RETURNING VALUE(str) TYPE string.
|
||||
TYPES: BEGIN OF demo_struct,
|
||||
num TYPE i,
|
||||
uuid TYPE sysuuid_x16,
|
||||
text TYPE c LENGTH 255,
|
||||
END OF demo_struct.
|
||||
TYPES ty_demo_tab TYPE SORTED TABLE OF demo_struct WITH UNIQUE KEY num uuid.
|
||||
|
||||
METHODS get_random_table_content IMPORTING VALUE(table_entry_count) TYPE i OPTIONAL
|
||||
RETURNING VALUE(demo_tab) TYPE ty_demo_tab.
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
DATA(random_table) = get_random_table_content( 500 ).
|
||||
|
||||
SELECT num, to_clob( STRING_AGG( text, ',' ) ) AS text_line
|
||||
FROM @random_table AS tab
|
||||
GROUP BY num
|
||||
ORDER BY num
|
||||
INTO TABLE @DATA(aggregated_data) ##ITAB_DB_SELECT.
|
||||
|
||||
"Checking the type of the text_line component using RTTI
|
||||
DATA(tdo_itab) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( aggregated_data ) ).
|
||||
DATA(table_components_itab) = CAST cl_abap_structdescr( tdo_itab->get_table_line_type( ) )->components.
|
||||
DATA(text_line_type_kind) = table_components_itab[ name = 'TEXT_LINE' ]-type_kind.
|
||||
IF text_line_type_kind = cl_abap_typedescr=>typekind_string.
|
||||
out->write( `The text_line component is of type string.` ).
|
||||
out->write( |\n| ).
|
||||
ENDIF.
|
||||
|
||||
DATA(lines_w_more_than_1333) = REDUCE i( INIT int = 0
|
||||
FOR line IN aggregated_data
|
||||
NEXT int = COND #( WHEN strlen( line-text_line ) > 1333 THEN int + 1 ELSE int ) ).
|
||||
|
||||
out->write( |{ lines_w_more_than_1333 } out of { lines( aggregated_data ) } lines of the internal table have a text_line value exceeding 1333 characters.| ).
|
||||
out->write( |\n| ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD get_random_string.
|
||||
IF length IS NOT SUPPLIED OR length > 255.
|
||||
length = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
|
||||
min = 1
|
||||
max = 255 )->get_next( ).
|
||||
ENDIF.
|
||||
|
||||
DATA(characters) = `aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890`.
|
||||
DATA(off) = strlen( characters ) - 1.
|
||||
|
||||
DO length TIMES.
|
||||
DATA(random_offset) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
|
||||
min = 0
|
||||
max = off )->get_next( ).
|
||||
|
||||
TRY.
|
||||
str &&= characters+random_offset(1).
|
||||
CATCH cx_sy_range_out_of_bounds.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD get_random_table_content.
|
||||
IF table_entry_count IS NOT SUPPLIED OR table_entry_count > 1000.
|
||||
table_entry_count = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
|
||||
min = 1
|
||||
max = 1000 )->get_next( ).
|
||||
ENDIF.
|
||||
|
||||
"Example implementation: For the string aggregation in the SELECT statement,
|
||||
"multiple lines should be created with the same key value in 'num'.
|
||||
DATA(value4num) = 1.
|
||||
DO table_entry_count TIMES.
|
||||
IF sy-index MOD 25 = 0.
|
||||
value4num += 1.
|
||||
ENDIF.
|
||||
|
||||
INSERT VALUE #( num = value4num
|
||||
uuid = xco_cp=>uuid( )->value
|
||||
text = get_random_string( ) ) INTO TABLE demo_tab.
|
||||
ENDDO.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`unit_conversion( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
Converts units for a value passed to the `quantity` parameter
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet implements the following:
|
||||
- To have a self-contained example, a demo internal table with elementary line type (packed number, `p length 16 decimals 14`) is created.
|
||||
- The table is filled with demo data.
|
||||
- Two ABAP SQL `SELECT` statements are included that specify the `unit_conversion` function. Data is retrieved from the internal table and converted. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
- The example covers the conversion of miles to kilometers and vice versa.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
```abap
|
||||
TYPES p_len16dec14 TYPE p LENGTH 16 DECIMALS 14.
|
||||
TYPES ty_plen16dec14_tab TYPE TABLE OF p_len16dec14 WITH EMPTY KEY.
|
||||
|
||||
DATA(p_tab) = VALUE ty_plen16dec14_tab( ( CONV p_len16dec14( '1' ) )
|
||||
( CONV p_len16dec14( '5.7' ) )
|
||||
( CONV p_len16dec14( '4.2' ) )
|
||||
( CONV p_len16dec14( '25.78' ) ) ).
|
||||
|
||||
SELECT unit_conversion( quantity = table_line,
|
||||
source_unit = unit`MI`,
|
||||
target_unit = unit`KM` ) AS miles_to_km
|
||||
FROM @p_tab AS tab
|
||||
INTO TABLE @DATA(unit_conv_mi2km_tab) ##ITAB_DB_SELECT.
|
||||
|
||||
SELECT unit_conversion( quantity = miles_to_km,
|
||||
source_unit = unit`KM`,
|
||||
target_unit = unit`MI` ) AS km_to_miles
|
||||
FROM @unit_conv_mi2km_tab AS tab
|
||||
INTO TABLE @DATA(unit_conv_km2mi_tab) ##ITAB_DB_SELECT.
|
||||
```
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`currency_conversion( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
- Converts currencies for a value passed to the `amount` parameter
|
||||
- Multiple optional parameters can be specified (excluding `client` in ABAP for Cloud Development)
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet implements the following:
|
||||
- To have a self-contained example, a demo internal table with elementary line type (packed number, `p length 16 decimals 2`) is created.
|
||||
- The table is filled with demo data.
|
||||
- An ABAP SQL `SELECT` statement that includes the `currency_conversion` function retrieves data from the internal table and converts currency values from Euro to US dollars. Note that a warning would be displayed that the `SELECT` command is executed on the database. The warning is suppressed with a pragma.
|
||||
|
||||
<br>
|
||||
|
||||
```abap
|
||||
TYPES p_len16dec2 TYPE p LENGTH 16 DECIMALS 2.
|
||||
TYPES ty_plen16dec2_tab TYPE TABLE OF p_len16dec2 WITH EMPTY KEY.
|
||||
|
||||
DATA(p_tab) = VALUE ty_plen16dec2_tab( ( CONV p_len16dec2( '1' ) )
|
||||
( CONV p_len16dec2( '5.7' ) )
|
||||
( CONV p_len16dec2( '4.2' ) )
|
||||
( CONV p_len16dec2( '25.78' ) ) ).
|
||||
|
||||
SELECT currency_conversion( amount = table_line,
|
||||
source_currency = char`EUR`,
|
||||
target_currency = char`USD`,
|
||||
exchange_rate_date = @( cl_abap_context_info=>get_system_date( ) ) ) AS eur2usd
|
||||
FROM @p_tab AS tab
|
||||
INTO TABLE @DATA(curr_unit_conv_eur2usd) ##ITAB_DB_SELECT.
|
||||
```
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`as_geo_json( ... )`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
Converts geometry input in the [Extended Well-Known Binary (EWKB) representation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENDDIC_GEO_DATA.html) to a geometry object in JSON format
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
|
||||
```abap
|
||||
SELECT as_geo_json( some_geo_field )
|
||||
FROM ...
|
||||
WHERE ...
|
||||
INTO ...
|
||||
```
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
### Date and Time Functions
|
||||
|
||||
Find more information in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_uuid.htm). The [Built-In Functions](24_Builtin_Functions.md) cheat sheet covers code examples.
|
||||
|
||||
The following example shows a selection. Other cheat sheets such as [Built-In Functions](24_Builtin_Functions.md) show more snippets about date and time functions.
|
||||
|
||||
``` abap
|
||||
SELECT SINGLE
|
||||
carrid,
|
||||
|
||||
"Conversion functions
|
||||
"When used: Special conversions that cannot be handled in a general
|
||||
"CAST expression
|
||||
|
||||
"Type conversion: string of fixed length (e.g. of type c) to variable
|
||||
"length string of type string
|
||||
to_clob( carrid ) AS clob,
|
||||
|
||||
"Byte string -> character string
|
||||
bintohex( raw`3599421128650F4EE00008000978B976` ) AS bintohex,
|
||||
|
||||
"Character string -> byte string
|
||||
hextobin( char`3599421128650F4EE00008000978B976` ) AS hextobin,
|
||||
|
||||
"Byte field of type RAW to a byte string (BLOB) of type RAWSTRING
|
||||
to_blob( raw`3599421128650F4EE00008000978B976` ) AS blob,
|
||||
|
||||
"Unit and currency conversion functions
|
||||
"More parameters are available.
|
||||
|
||||
"Converts miles to kilometers
|
||||
unit_conversion( quantity = d34n`1`,
|
||||
source_unit = unit`MI`,
|
||||
target_unit = unit`KM` ) AS miles_to_km,
|
||||
|
||||
"Converts Euro to US dollars using today's rate
|
||||
currency_conversion(
|
||||
amount = d34n`1`,
|
||||
source_currency = char`EUR`,
|
||||
target_currency = char`USD`,
|
||||
exchange_rate_date = @( cl_abap_context_info=>get_system_date( ) )
|
||||
) AS eur_to_usd,
|
||||
|
||||
"Date and time functions
|
||||
|
||||
"Selection of time and date-related functions
|
||||
add_days( @( cl_abap_context_info=>get_system_date( ) ), 4 ) AS add_days,
|
||||
add_months( @( cl_abap_context_info=>get_system_date( ) ), 2 ) AS add_months,
|
||||
is_valid( @( cl_abap_context_info=>get_system_date( ) ) ) AS date_is_valid,
|
||||
is_valid( @( cl_abap_context_info=>get_system_time( ) ) ) AS time_is_valid,
|
||||
is_valid( @( cl_abap_context_info=>get_system_time( ) ) ) AS time_is_valid
|
||||
"...
|
||||
|
||||
FROM zdemo_abap_carr
|
||||
INTO @DATA(tab_w_date_time_func).
|
||||
```
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### UUID Function
|
||||
|
||||
[UUID function](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_uuid.htm)
|
||||
|
||||
``` abap
|
||||
SELECT SINGLE
|
||||
carrid,
|
||||
|
||||
"UUID
|
||||
uuid( ) AS uuid
|
||||
|
||||
FROM zdemo_abap_carr
|
||||
INTO @DATA(special_functions).
|
||||
INTO @DATA(tab_w_uuid).
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
- [Selection Screens and Classic Lists](#selection-screens-and-classic-lists)
|
||||
- [Introduction](#introduction)
|
||||
- [Terms](#terms)
|
||||
- [Selection Screens](#selection-screens)
|
||||
- [Classic Lists](#classic-lists)
|
||||
- [ABAP Statements for Selection Screens](#abap-statements-for-selection-screens)
|
||||
- [Creating Selection Screens](#creating-selection-screens)
|
||||
- [PARAMETERS](#parameters)
|
||||
- [SELECT-OPTIONS](#select-options)
|
||||
- [SELECTION-SCREEN](#selection-screen)
|
||||
@@ -48,8 +46,6 @@ For more detailed information and syntax options, see the topics [Selection Scre
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Terms
|
||||
|
||||
### Selection Screens
|
||||
- Are special [dynpros](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_glosry.htm) in [executable programs](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexecutable_program_glosry.htm) (*"reports"*; they're also possible in [function groups](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfunction_group_glosry.htm) and [module pools](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenmodul_pool_glosry.htm), but the focus here is on executable programs).
|
||||
- Used for data entry in an executable program, i.e. they allow users to ...
|
||||
@@ -71,6 +67,7 @@ For more detailed information and syntax options, see the topics [Selection Scre
|
||||
- Each executable program (and only there) contains a standard selection screen with the dynpro number 1000. Note: If you create a standalone selection screen, you cannot use dynpro number 1000.
|
||||
- The screen elements on the standard selection screen are defined by all `PARAMETERS`, `SELECT-OPTIONS`, and `SELECTION-SCREEN` statements that are defined outside of the statements mentioned above for creating standalone selection screens.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Classic Lists
|
||||
- Used to output data in a structured and formatted way.
|
||||
@@ -91,8 +88,6 @@ For more detailed information and syntax options, see the topics [Selection Scre
|
||||
|
||||
## ABAP Statements for Selection Screens
|
||||
|
||||
### Creating Selection Screens
|
||||
|
||||
Selection screens can be created by using special ABAP statements in the global declaration part of executable programs:
|
||||
- [`PARAMETERS`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapparameters.htm)
|
||||
- [`SELECT-OPTIONS`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapselect-options.htm)
|
||||
@@ -121,7 +116,7 @@ The following table includes code snippets with a selection of available syntax
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Type specification options<br>
|
||||
Type specification options<br><br>
|
||||
Additions `TYPE` and `LIKE`
|
||||
|
||||
</td>
|
||||
@@ -254,7 +249,7 @@ START-OF-SELECTION.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Dynamically specifying the type<br>
|
||||
Dynamically specifying the type<br><br>
|
||||
Addition `LIKE (...)`
|
||||
|
||||
</td>
|
||||
@@ -313,8 +308,8 @@ START-OF-SELECTION.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Specifying value options<br>
|
||||
Additions `DEFAULT`, `LOWER CASE`, `MATCHOCODE OBJECT`, `MEMORY ID`, `VALUE CHECK`
|
||||
Specifying value options<br><br>
|
||||
Additions `DEFAULT`, `LOWER CASE`, `MATCHCODE OBJECT`, `MEMORY ID`, `VALUE CHECK`
|
||||
|
||||
</td>
|
||||
|
||||
@@ -322,7 +317,7 @@ Additions `DEFAULT`, `LOWER CASE`, `MATCHOCODE OBJECT`, `MEMORY ID`, `VALUE CHEC
|
||||
|
||||
- `DEFAULT`: Defines a start value (can also be a data object instead of a literal)
|
||||
- `LOWER CASE`: Prevents the effect of capitalizing the entry made when the content is transported to the data object
|
||||
- `MATCHOCODE OBJECT`: Links an input field with a DDIC search help
|
||||
- `MATCHCODE OBJECT`: Links an input field with a DDIC search help
|
||||
- `MEMORY ID`: Links an input field with an SPA/GPA parameter in the user memory, i.e. data objects in the user memory accessible by ABAP programs. When calling the selection screen, the input field receives the SPA/GPA parameter value if the `PARAMETERS`'s data object is initial after processing of the `AT SELECTION-SCREEN OUTPUT` event block. The SPA/GPA parameters are set using [`SET PARAMETER`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_parameter.htm) and read using [`GET PARAMETER`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapget_parameter.htm) statements. See the names of the parameters in the `TPARA` database table.
|
||||
- `VALUE CHECK`: Checks input against fixed values defined for the domain of a data type. It can only be used for DDIC data types. Checks are also available for data types being components of foreign key tables. It is recommended to specify the `VALUE CHECK` addition with the `OBLIGATORY` addition as the check is also applied in case of empty input fields.
|
||||
|
||||
@@ -408,7 +403,7 @@ START-OF-SELECTION.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Specifying screen options<br>
|
||||
Specifying screen options<br><br>
|
||||
Additions `OBLIGATORY`, `NO-DISPLAY`, `VISIBLE LENGTH`, `AS CHECKBOX`, `RADIOBUTTON GROUP`, `AS LISTBOX VISIBLE LENGTH`
|
||||
|
||||
</td>
|
||||
@@ -543,7 +538,7 @@ START-OF-SELECTION.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Assigning function codes to selection parameters<br>
|
||||
Assigning function codes to selection parameters<br><br>
|
||||
Addition `USER-COMMAND`
|
||||
|
||||
</td>
|
||||
@@ -625,14 +620,14 @@ START-OF-SELECTION.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Assigning a screen element of a selection screen to a modification group<br>
|
||||
Assigning a screen element of a selection screen to a modification group<br><br>
|
||||
Addition `MODIF ID`
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
- The `PARAMETERS` statement can be specified with the `MODIF ID` addition to assign a screen element of a selection screen to a modification group, which represents a group of multiple screen elements of a dynpro having a three-character ID. This ID is used to modify the display properties of all those elements specifying the ID before they are actually displayed. For that purpose, you can use the `MODIFY SCREEN` statement. The ID is assigned to the `screen-grouop1` component that can be evaluated.
|
||||
- The `PARAMETERS` statement can be specified with the `MODIF ID` addition to assign a screen element of a selection screen to a modification group, which represents a group of multiple screen elements of a dynpro having a three-character ID. This ID is used to modify the display properties of all those elements specifying the ID before they are actually displayed. For that purpose, you can use the `MODIFY SCREEN` statement. The ID is assigned to the `screen-group1` component that can be evaluated.
|
||||
- Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenmodification_group_glosry.htm).
|
||||
|
||||
</td>
|
||||
|
||||
@@ -49,7 +49,7 @@ ABAP cheat sheets[^1] ...
|
||||
- Check the [Known Issues](#-known-issues) and [Disclaimer](#%EF%B8%8F-disclaimer).
|
||||
- The cheat sheets provide links to glossary entries and topics in the ABAP Keyword Documentation. Note that unlike the classic ABAP-only cheat sheets, in most cases these links refer to ABAP for Cloud Development.
|
||||
- [Here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrestricted_abap_elements.htm) is an overview of the different ABAP language elements in the different ABAP versions, i.e. what is allowed in ABAP Cloud and what is not. See also the released APIs [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_apis.htm).
|
||||
- In order to have all ABAP cheat sheet documents in one place, the *main* branch (for examples to be imported into the SAP BTP ABAP environment) also contains the ABAP cheat sheet documents that are only relevant for classic ABAP.
|
||||
- In order to have all ABAP cheat sheet documents in one place, the *main* branch (for examples to be imported into the SAP BTP ABAP environment) also contains the ABAP cheat sheet documents that are only relevant for [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).
|
||||
- The example classes contained in the branches for classic ABAP mostly use syntax that is also available in ABAP for Cloud Development. Only the `TEST_ABAP_CHEAT_SHEETS_CLASSIC` subpackage contains syntax relevant to Standard ABAP and that is not available in ABAP for Cloud Development, such as dynpro-related ABAP keywords.
|
||||
- The code snippets in the ABAP cheat sheet documents and the executable examples include many comments. While it is generally not recommended to overuse comments in your code, they are used here to explain and provide context directly where it is needed. In many cases, they illustrate the results of ABAP statements.
|
||||
- As previously mentioned, the cheat sheet documents and examples primarily focus on syntax options. Most of the executable examples, code snippets, names of data objects, classes, methods, interfaces, etc., are nonsemantic.
|
||||
@@ -86,9 +86,9 @@ ABAP cheat sheets[^1] ...
|
||||
|[Program Flow Logic](13_Program_Flow_Logic.md)|Deals with control structures (`IF`, `CASE`), loops (`DO`, `WHILE`) and exception handling|[zcl_demo_abap_prog_flow_logic](./src/zcl_demo_abap_prog_flow_logic.clas.abap)|
|
||||
|[ABAP Unit Tests](14_ABAP_Unit_Tests.md)|Contains basic information about unit testing in ABAP|[zcl_demo_abap_unit_test](./src/zcl_demo_abap_unit_test.clas.abap)|
|
||||
|[CDS View Entities](15_CDS_View_Entities.md)|The cheat sheet provides references to information on ABAP CDS. Find a feature table for available language elements in ABAP CDS in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abencds_language_elements.html) with links to detailed topics. The focus here is on the example CDS artifacts and the [executable example class](./src/zcl_demo_abap_cds_ve.clas.abap), which include comments.|[zcl_demo_abap_cds_ve](./src/zcl_demo_abap_cds_ve.clas.abap)|
|
||||
|[SAP LUW](17_SAP_LUW.md)|Provides a high-level overview of the [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) concept that deals with data consistency with a focus on SAP LUW-related statements <br> 💡 Several statements covered in the cheat sheet and the executable example are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).|Program `ZDEMO_ABAP_SAP_LUW`|
|
||||
|[Dynpro](18_Dynpro.md)|Provides a high-level overview of dynpro topics with a focus on dynpro-related statements <br> 💡 The content of this cheat sheet and the executable example are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).|Program `ZDEMO_ABAP_DYNPRO`|
|
||||
|[Selection Screens and Classic Lists](20_Selection_Screens_Lists.md)|Provides a high-level overview of selection screens and classic lists with a focus on related statements. It includes an excursion into the SAP List Viewer (ALV). <br> 💡 The content of this cheat sheet and the executable examples are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).|Program `ZDEMO_ABAP_SELSCR_LISTS_INTRO` (the "intro" program, from which the other related example programs can be started)|
|
||||
|[SAP LUW](17_SAP_LUW.md)|Provides a high-level overview of the [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) concept that deals with data consistency with a focus on SAP LUW-related statements <br> 💡 Several statements covered in the cheat sheet and the executable example are only relevant to [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).|Program `ZDEMO_ABAP_SAP_LUW`|
|
||||
|[Dynpro](18_Dynpro.md)|Provides a high-level overview of dynpro topics with a focus on dynpro-related statements <br> 💡 The content of this cheat sheet and the executable example are only relevant to [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).|Program `ZDEMO_ABAP_DYNPRO`|
|
||||
|[Selection Screens and Classic Lists](20_Selection_Screens_Lists.md)|Provides a high-level overview of selection screens and classic lists with a focus on related statements. It includes an excursion into the SAP List Viewer (ALV). <br> 💡 The content of this cheat sheet and the executable examples are only relevant to [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).|Program `ZDEMO_ABAP_SELSCR_LISTS_INTRO` (the "intro" program, from which the other related example programs can be started)|
|
||||
|[Working with XML and JSON in ABAP](21_XML_JSON.md)|Covers processing XML using class libraries, XML transformations using XSLT and Simple Transformations (ST), serializations (ABAP to XML) and deserializations (XML to ABAP), dealing with JSON data|[zcl_demo_abap_xml_json](./src/zcl_demo_abap_xml_json.clas.abap)|
|
||||
|[Released ABAP Classes](22_Released_ABAP_Classes.md)|Contains a selection of ABAP classes, serving as a quick introduction, along with code snippets to explore the functionality in action|- (The cheat sheet includes copy and paste code snippets and example classes)|
|
||||
|[Date, Time, and Time Stamp](23_Date_and_Time.md)|Covers how to handle and process dates, times, and time stamps in ABAP|[zcl_demo_abap_date_time](./src/zcl_demo_abap_date_time.clas.abap)|
|
||||
|
||||
Reference in New Issue
Block a user