From 74d741d698d992cf19b8fd42eb7a9fba67b6bc86 Mon Sep 17 00:00:00 2001 From: danrega <16720986+danrega@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:56:33 +0100 Subject: [PATCH] Update --- 02_Structures.md | 5 +- 06_Dynamic_Programming.md | 3 +- 08_EML_ABAP_for_RAP.md | 10 +- 18_Dynpro.md | 4 +- 19_ABAP_for_Cloud_Development.md | 2 +- 20_Selection_Screens_Lists.md | 381 ++++++++++++++++++++++++++++++- 21_XML_JSON.md | 51 ++++- README.md | 2 +- 8 files changed, 433 insertions(+), 25 deletions(-) diff --git a/02_Structures.md b/02_Structures.md index 3b6fd01..9d11f0e 100644 --- a/02_Structures.md +++ b/02_Structures.md @@ -664,10 +664,9 @@ MODIFY TABLE itab FROM struc. ## Excursion: Including Structures -- Although their use is not recommended in the ABAP programming -guidelines, you may come across [`INCLUDE TYPE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) +- [`INCLUDE TYPE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) and [`INCLUDE STRUCTURE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) statements -in the context of local structures. +are used in the context of local structures. - Structured data objects and types created with `... BEGIN OF... END OF ...` can use this syntax to include components of another structure, whether it is a locally defined or global structure, without creating substructures. - `INCLUDE TYPE` can be used to include a structured type. - You can use `INCLUDE STRUCTURE` to include a structure. diff --git a/06_Dynamic_Programming.md b/06_Dynamic_Programming.md index ba9d3e3..5878112 100644 --- a/06_Dynamic_Programming.md +++ b/06_Dynamic_Programming.md @@ -386,8 +386,7 @@ Excursion: Static vs. dynamic type, upcasts and downcasts - Upcast: If the static type of the target variables is **less specific or the same** as the static type of the source variable, an assignment is possible. This includes, for example, assignments with the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`. - Downcast: If the static type of the target variable is **more specific** than the static type of the source variable, a check must be made at runtime before the assignment is done. If you indeed want to trigger such a downcast, you must do it explicitly in your code. You can do this, for example, using the [constructor operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_operator_glosry.htm "Glossary Entry") -[`CAST`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_cast.htm). In older code, you may see the use of - [`?=`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove_cast.htm) operator. +[`CAST`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_cast.htm). In older code, you may see the use of the [`?=`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove_cast.htm) operator. - In contrast to a downcast, an upcast does not have to be done explicitly. However, you can - but need not - use the mentioned operators for upcasts, too. diff --git a/08_EML_ABAP_for_RAP.md b/08_EML_ABAP_for_RAP.md index 3add1eb..92a683d 100644 --- a/08_EML_ABAP_for_RAP.md +++ b/08_EML_ABAP_for_RAP.md @@ -261,10 +261,10 @@ CLASS lhc_root DEFINITION INHERITING FROM cl_abap_behavior_handler. ENDCLASS. ``` - Handler method definitions include the additions `... FOR ... FOR - ...` followed by the kind of operations. There are various + ...` followed by the kinds of operations. There are various options depending on the RAP BO operation. -- Depending on the definition in the BDEF, there might be more ABAP - words with dedicated method parameters. For example, an action might +- Depending on the definition in the BDEF, there might be more additions + with dedicated method parameters. For example, an action might be defined with a result parameter, hence, the method must be defined with the addition `RESULT` and a parameter. - The `FOR MODIFY` handler method can handle multiple entities @@ -292,7 +292,7 @@ METHODS some_action FOR MODIFY **Parameters of Handler Methods** -- The handler method definition contains RAP-specific additions like +- The handler method definitions contain RAP-specific additions like `FOR MODIFY`, `FOR CREATE` or `FOR READ` as well as mandatory or optional additions like `RESULT` that are followed by parameters. @@ -307,7 +307,7 @@ METHODS some_action FOR MODIFY of an instance are imported. - All handler methods have changing parameters that are usually not explicitly specified in the definition but implicitly used. The - addition `CHANGING` is not needed. In most cases, these are + explicit specification of the `CHANGING` addition is not needed. In most cases, these are [RAP response parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_response_param_glosry.htm "Glossary Entry"). The following image shows the F2 information in ADT for the create diff --git a/18_Dynpro.md b/18_Dynpro.md index 22d40cc..d39842f 100644 --- a/18_Dynpro.md +++ b/18_Dynpro.md @@ -635,7 +635,7 @@ ENDLOOP. > **💡 Note**
> - In a modern program, it is more comfortable to use an ALV Grid control. -> - More addiitions are available for the statement. +> - More additions are available for the statement. The ABAP statement [`REFRESH CONTROL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaprefresh_control.htm) initializes the properties of a table control. @@ -705,7 +705,7 @@ PROCESS AFTER INPUT. - Browser control (`CL_GUI_HTML_VIEWER`): A browser for HTML pages or XML documents on the dynpro. Special links in the document trigger the `SAPEVENT` event when the user clicks, which can then be evaluated in the ABAP program. - Edit control (`CL_GUI_TEXTEDIT`): A simple text editor with the basic functions such as select, find, and replace on the dynpro. These functions can also be called in a program-controlled way using methods such as `FIND_AND_REPLACE`. - Tree control: Are available in different versions (for example, `CL_GUI_SIMPLE_TREE`). They allow hierarchical relationships to be displayed in tree structures. - - ALV Grid control: Is the replacement for classic lists. It provides functions such as searching, sorting, and printing the content of the list. However, the associated class `CL_GUI_ALV_GRID` should no longer be used directly for new developments. Classes such as `CL_SALV_TABLE` encapsulate the use of the ALV Grid control and simplify the integration. + - ALV Grid control: Is the replacement for classic lists. It provides functions such as searching, sorting, and printing the content of the list. However, the associated class `CL_GUI_ALV_GRID` should no longer be used directly for new developments. Classes such as `CL_SALV_TABLE` encapsulate the use of the ALV Grid control and simplify the integration.

⬆️ back to top

diff --git a/19_ABAP_for_Cloud_Development.md b/19_ABAP_for_Cloud_Development.md index 8029cbc..a7d074f 100644 --- a/19_ABAP_for_Cloud_Development.md +++ b/19_ABAP_for_Cloud_Development.md @@ -127,7 +127,7 @@ It provides references to more detailed information on the topic. 2) If available to you, you have accessed an on-premise ABAP system using ADT. It is assumed that the latest ABAP release is available. - a) Checking API Status information + a) Checking API status information - Choose `CTRL + SHIFT + A` to open the search in ADT. Search the class `CL_ABAP_RANDOM_INT`. Once you have opened the class, check the *Properties* tab and find the API status information. b) Creating an example class diff --git a/20_Selection_Screens_Lists.md b/20_Selection_Screens_Lists.md index aa79bb8..e10bede 100644 --- a/20_Selection_Screens_Lists.md +++ b/20_Selection_Screens_Lists.md @@ -19,6 +19,9 @@ - [Creating Lists](#creating-lists) - [Reading and Modifying in Lists](#reading-and-modifying-in-lists) - [Event Blocks](#event-blocks) + - [Excursion: SAP List Viewer (ALV)](#excursion-sap-list-viewer-alv) + - [Getting Started](#getting-started) + - [Optional Layout Settings and Functionality](#optional-layout-settings-and-functionality) - [More Information](#more-information) - [Executable Examples](#executable-examples) @@ -29,7 +32,7 @@ [Selection screens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenselection_screen_glosry.htm) and [classic lists](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_list_glosry.htm) are among the classic ABAP user interfaces. They are integrated into the ABAP language itself, which means that special ABAP statements are available to create and handle them. -This cheat sheet provides a high-level overview of selection screens and classic lists, focusing on a selection of related statements, supported by executable examples to explore the syntax in action. +This cheat sheet provides a high-level overview of selection screens and classic lists, focusing on a selection of related statements, supported by executable examples to explore the syntax in action. It includes an excursion into the SAP List Viewer (ALV). For more detailed information and syntax options, see the topics [Selection Screens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenselection_screen.htm) and [Classic Lists](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dynpro_list.htm) in the ABAP Keyword Documentation. @@ -115,7 +118,7 @@ Note that various combinations of multiple additions are possible, and some are PARAMETERS pa TYPE string. "Referring to an existing data object with the LIKE addition -Data dobj type i. +DATA dobj TYPE i. PARAMETERS pb LIke dobj. "Reference to a data type from the ABAP Dictionary @@ -937,12 +940,379 @@ MODIFY CURRENT LINE FIELD FORMAT a COLOR 5 b COLOR 6 LINE FORMAT COLOR 7. - [`AT USER-COMMAND`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapat_user-command.htm)
Called when a function with a user-defined function code is selected when a screen list is displayed; the function codes can be evaluated using `sy-ucomm`; you can set a list event programmatically using [`SET USER-COMMAND`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_user-command.htm) +

⬆️ back to top

+ +## Excursion: SAP List Viewer (ALV) + +- Provides an object-oriented API for displaying and formatting lists +- Allows you to specify layout settings and functionality +- Classes such as `CL_SALV_TABLE` encapsulate the use of the ALV grid control and simplify the integration into ABAP programs. Note: The older class `CL_GUI_ALV_GRID` should no longer be used directly for new developments. +- Other classes are available to handle hierarchical lists and tree structures. The focus of the code snippets is on simple, non-nested tables and the use of the `CL_SALV_TABLE` class. + +### Getting Started +- To get started quickly, you only need to ... + - instantiate an ALV table object using the `factory` method. + - define the display type for the ALV output. By default, full-screen display is enabled. + - display the ALV output using the `display` method. + +> **💡 Note**
+> - When working with ALV, make sure that you implement appropriate error handling. +> - The `factory` method also has optional exporting parameters. You can use the optional `list_display` parameter to specify whether you want to display the ALV output as classic list. It is set to false by default. There are also exporting parameters to display the ALV output in containers (e.g. see the dynpro cheat sheet example). The exporting parameters are not relevant in this example. Here, the ALV output is displayed on the entire screen (however, it is also possible to display the ALV output in a dialog box). + +The following code snippet shows a simple example to get you started quickly with the necessary method calls. It includes a demo internal table with content. + +```abap +TYPES: BEGIN OF demo_struct, + col1 TYPE string, + col2 TYPE i, + col3 TYPE c LENGTH 1, + END OF demo_struct. + +DATA itab TYPE TABLE OF demo_struct WITH EMPTY KEY. +itab = VALUE #( ( col1 = `abc` col2 = 1 col3 = 'X' ) + ( col1 = `def` col2 = 2 col3 = 'Y' ) + ( col1 = `ghi` col2 = 3 col3 = 'Z' ) ). + +TRY. + cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv) + CHANGING t_table = itab ). + + alv->display( ). + CATCH cx_salv_msg INTO DATA(err). + MESSAGE err->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. +ENDTRY. +``` + +### Optional Layout Settings and Functionality + +- The following commented code snippet covers a selection of the many setting and functionality options. +- For simplicity of the snippet, the code only uses the root exception class. Make sure that you implement appropriate error handling and exception classes. +- You can copy and paste the code into your own test program to explore the ALV output and the effect of the method calls. + +> **💡 Note**
+> Check the comments for the custom functions. If there are errors in your test program, replace the relevant code section and enable the generic ALV functions. + +```abap +TYPES: BEGIN OF demo_struct, + col1 TYPE string, + col2 TYPE i, + col3 TYPE string, + col4 TYPE icon_d, + col5 TYPE string, + END OF demo_struct. +DATA itab TYPE TABLE OF demo_struct WITH EMPTY KEY. +DATA alv TYPE REF TO cl_salv_table. +DATA cnt4evt TYPE i VALUE 6. + +"Local class to handle events +CLASS lcl_events DEFINITION. + PUBLIC SECTION. + CLASS-METHODS single_click + FOR EVENT link_click OF cl_salv_events_table + IMPORTING row column. + CLASS-METHODS double_click + FOR EVENT double_click OF cl_salv_events_table + IMPORTING row column. + CLASS-METHODS func_click + FOR EVENT added_function OF cl_salv_events + IMPORTING e_salv_function. +ENDCLASS. +CLASS lcl_events IMPLEMENTATION. + METHOD single_click. + "Both single and double click events trigger messages. + "Note: To make the example work in lower ABAP releases, newer ABAP syntax is + "intentionally not used to dynamically access the internal table component. + "Refer to the internal table and dynamic programming cheat sheets. + READ TABLE itab INDEX row REFERENCE INTO DATA(sc_ref). + IF sy-subrc = 0. + ASSIGN sc_ref->(column) TO FIELD-SYMBOL(). + MESSAGE `Single click event. ` && + |Row: { row } { COND #( WHEN column IS NOT INITIAL THEN `Column: ` && column ) } | && + |{ COND #( WHEN IS ASSIGNED THEN `Value: ` && ) }| TYPE 'I'. + ELSE. + MESSAGE `Single click event` TYPE 'I'. + ENDIF. + ENDMETHOD. + METHOD double_click. + READ TABLE itab INDEX row REFERENCE INTO DATA(dc_ref). + IF sy-subrc = 0. + ASSIGN dc_ref->(column) TO FIELD-SYMBOL(). + MESSAGE `Double click event. ` && + |Row: { row } { COND #( WHEN column IS NOT INITIAL THEN `Column: ` && column ) } | && + |{ COND #( WHEN IS ASSIGNED THEN `Value: ` && ) }| TYPE 'I'. + ELSE. + MESSAGE `Double click event` TYPE 'I'. + ENDIF. + ENDMETHOD. + METHOD func_click. + "Handling custom functions + CASE e_salv_function. + WHEN 'DATA'. + MESSAGE `Custom function DATA. Do something ...` TYPE 'I'. + WHEN 'TEST'. + IF cnt4evt = 6. + MESSAGE `A table row will be added, demonstrating the 'refresh' ` && + `method that rebuilds the output table.` TYPE 'I'. + ENDIF. + cnt4evt += 1. + itab = VALUE #( BASE itab ( col1 = `fffff` col2 = cnt4evt + col3 = `ttttt` col4 = icon_green_light ) ). + "Rebuilding the output table + alv->refresh( ). + WHEN 'QUIT'. + MESSAGE `Custom function QUIT. Do something ...` TYPE 'I'. + WHEN OTHERS. + MESSAGE `Some other function` TYPE 'I'. + ENDCASE. + ENDMETHOD. +ENDCLASS. +START-OF-SELECTION. +"Populating internal table that is output +itab = VALUE #( ( col1 = `aaaaa` col2 = 1 col3 = `zzzzz` col4 = icon_green_light ) + ( col1 = `bbbbb` col2 = 2 col3 = 'yyyyy' col4 = icon_green_light ) + ( col1 = `ccccc` col2 = 3 col3 = 'xxxxx' col4 = icon_green_light ) ). +TRY. + "----------- Instantiating an ALV table object ----------- + cl_salv_table=>factory( IMPORTING r_salv_table = alv + CHANGING t_table = itab ). + "----------- Creating a new instance with new data ----------- + "Notes on the set_data method: + "- All objects that were referred to previously are removed. + "- Not to be used in event handlers. + "In the example, new lines are added to the existing internal table. + itab = VALUE #( BASE itab ( col1 = `ddddd` col2 = 4 + col3 = `wwwww` col4 = icon_green_light ) + ( col1 = `ddddd` col2 = 5 + col3 = `vvvvv` col4 = icon_green_light ) + ( col1 = `eeeee` col2 = 6 + col3 = `uuuuu` col4 = icon_green_light ) ). + alv->set_data( CHANGING t_table = itab ). + "----------- Layout-related settings ----------- + "Changing the list header title + CAST cl_salv_display_settings( + alv->get_display_settings( ) )->set_list_header( 'Demo Title' ). + "There are several methods to retrieve column-specific information. + "The following examples show a selection. You can check the variable + "content in the debugger. + DATA(col1obj) = alv->get_columns( )->get_column( 'COL1' ). + DATA(col1alignment) = col1obj->get_alignment( ). + DATA(col1type) = col1obj->get_ddic_inttype( ). + DATA(col1colname) = col1obj->get_columnname( ). + DATA(is_col1_visible) = col1obj->is_visible( ). + "Settings for the column header + "This example uses the get method, which returns all column objects of + "the output table. The table is processed in a loop. + "Settings covered: + "- Specifying the column header titles (long, medium, and short + " column header) + "- Specifying a tooltip for the column header + LOOP AT alv->get_columns( )->get( ) REFERENCE INTO DATA(colref). + "Specifying the column header titles + "The example sets the texts based on the columname value. + "Note: The column width is optimized further down. You may want to + "manually adjust the width in the ALV output to see the column header + "name change. + colref->r_column->set_long_text( |{ colref->columnname }| ). + colref->r_column->set_medium_text( |{ colref->columnname+2(3) }| ). + colref->r_column->set_short_text( |{ colref->columnname+3(3) }| ). + "Specifying a tooltip for the column headers + colref->r_column->set_tooltip( + |Demo tooltip { colref->columnname+3(3) }| ). + ENDLOOP. + "Displaying/Hiding the column headers + "In the example, the value is set to abap_true. Set it to abap_false + "to hide the column header. + "Note: In this and the following examples, the settings are + "intentionally done using separate casts for each example. You can also + "create object reference variables, such as for 'col1obj' to avoid having + "to specify the casts explicitly each time. + CAST cl_salv_columns_list( + alv->get_columns( ) )->set_headers_visible( abap_true ). + "Setting key columns + "Note: The key columns have a default color setting. There, you can only + "change the color in individual cells. + CAST cl_salv_column_table( + alv->get_columns( )->get_column( 'COL1' ) )->set_key( abap_true ). + + "Setting column color + "Note: The executable example includes examples of coloring entire rows and + "specific cells. + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL2' ) + )->set_color( VALUE lvc_s_colo( col = col_positive ) ). + + "Hiding columns + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL5' ) + )->set_visible( abap_false ). + + "Setting text alignment + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL2' ) + )->set_alignment( if_salv_c_alignment=>left ). + + "Optimizing column width, i.e. automatically adjusting the column width + "to display values completely (can also be done for individual columns) + alv->get_columns( )->set_optimize( abap_true ). + + "Setting output width explicitly (for an individual column) + "Note: Just to demonstrate the method call. This setting has no effect in + "the example due to the column width optimization above, and the column is + "hidden anyway. + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL5' ) + )->set_output_length( '100' ). + + "Setting table rows to a striped pattern + alv->get_display_settings( )->set_striped_pattern( abap_true ). + + "Displaying/hiding horizontal and vertical grid lines (here, they're hidden) + alv->get_display_settings( )->set_horizontal_lines( abap_false ). + alv->get_display_settings( )->set_vertical_lines( abap_false ). + + "With the following method call, the ALV output is displayed in a dialog box. + "Demo coordinates are provided. You can comment it in to see the effect. +* alv->set_screen_popup( start_column = 10 +* end_column = 100 +* start_line = 4 +* end_line = 15 ). + + "------ Adding functionality/user interaction options to the ALV output ------ + "Specifying the selection type + "The following specification allows you to select multiple rows/columns (a column + "is added on the left for selections). Check the other options in the + "if_salv_c_selection_mode interface. + alv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ). + + "Setting the sorting + "In the example, a particular column is sorted in descending order. + alv->get_sorts( )->add_sort( 'COL1' )->set_sequence( if_salv_c_sort=>sort_down ). + + "Applying a filter + "The example is implemented to exculed one entry from the demo table. + alv->get_filters( )->add_filter( 'COL2' )->add_selopt( sign = 'E' + option = 'EQ' + low = '6' ). + + "Making a calculation/aggregation + "In this example, an aggregation is added for a specific column. + "In this case, the average value is calculated. It is displayed in a row added + "at the bottom of the table. + alv->get_aggregations( )->add_aggregation( + columnname = 'COL2' + aggregation = if_salv_c_aggregation=>average ). + + "Generic and custom ALV functions + "Note: + "- By default, ALV functions (such as sorting or filtering) are not available + " to users. You must explicitly enable them. + "- Depending on whether the display is full-screen (as it is here) or in a + " container, restrictions apply. In the first case, you can use your own GUI status + " to integrate custom functions. + + "This (self-contained, ready-to-use) code snippet is intended so that you can simply + "copy & paste the code into a test program. For this purpose, and to be able to + "demonstrate custom functions in this full-screen ALV example using a GUI status, the + "example uses a demo GUI status that is included in another sample program (in a + "subpackage of SALV). For your own GUI status, you can check the SALV_TABLE_STANDARD + "status contained in the SALV_METADATA_STATUS function group, which you can copy and + "use as a template, for example. + "*********************************** NOTE *********************************** + "- The GUI status used here is just reused to have a copyable and self-contained example. + "- The GUI status of the sample program (specified for the report parameter below) + " contains generic and additional functions. For the additional fucntions, a simple + " implementation is included in this snippet. The GUI status should include the + " functions TEST, DATA, QUIT. + "- The implementations in the event handler class here do not match the implementations + " there, the button texts do not make sense for the implementations here, and so on. + "- So even though it (the button names, icons, implementations, etc.) does not make much + " sense for this snippet, you should get an idea about custom functions and be able to + " explore the event handling by clicking on the buttons. + "- The TEST function demonstrates adding new rows to the table and the 'refresh' method. + "- If this particular program, the GUI status and/or the custom functions are not available + " in your system, or if you insert the code into your own test program, run it, and + " encounter problems setting the status, remove the TRY control structure that contains + " the set_screen_status method call, and comment in the code below to use the standard + " ALV functions. In this case, the custom functions cannot be checked out with this + " snippet. + "- Check out the executable example of the cheat sheet that includes a GUI status. + TRY. + alv->set_screen_status( + pfstatus = 'SALV_TABLE_STANDARD' + report = 'SALV_TEST_REFRESH' + set_functions = alv->c_functions_all ). + + "In this GUI status, the custom functions TEST, DATA, and QUIT are specified. You can + "check the results of the following method calls in the debugger. + DATA(getfunc) = alv->get_functions( ). + "Checking the activation status + DATA(is_enabled) = getfunc->is_enabled( 'TEST' ). + "Checking the visibility + DATA(is_visible) = getfunc->is_visible( 'TEST' ). + + "Registering an event handler for the custom functions + "The added_function event is raised. In the implementation of the event handler method, + "you can then implement your code based on the value of the e_salv_function parameter + "(which contains the specified function name), for example, using a CASE statement. + "The implementation in this code snippet is different from the original program. + SET HANDLER lcl_events=>func_click FOR alv->get_event( ). + + CATCH cx_salv_object_not_found. + MESSAGE `GUI status error. Instead, use the set_default method, for example.` + TYPE 'I'. + ENDTRY. + + "If you remove the TRY control structure above, you can comment in the following + "code to use the generic ALV functions. Use the set_all method for all generic + "functions. You can also enable generic ALV functions individually. Check the + "set_* methods. + "alv->get_functions( )->set_default( abap_true ). + + "Hotspot/single click functionality + "You can define the content of a cell as a clickable area. You can do this by + "specifying the cell type hotspot. When a user clicks the cell content, + "the link_click event is raised. + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL1' ) + )->set_cell_type( if_salv_c_cell_type=>hotspot ). + + "You can set icon columns and make the icon cells clickable areas. To do this, + "use the set_icon method. As above, the cell type of the column is set to hotspot. + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL4' ) + )->set_icon( if_salv_c_bool_sap=>true ). + CAST cl_salv_column_table( alv->get_columns( )->get_column( 'COL4' ) + )->set_cell_type( if_salv_c_cell_type=>hotspot ). + + "An event handler is registered for the clickable areas (the link_click event + "is raised). The get_event method returns the required event object. In the + "example, a message is displayed. + SET HANDLER lcl_events=>single_click FOR alv->get_event( ). + + "Double click functionality + "Registering an event handler for the double click event. In the example, a message + "is displayed. Click cells in columns for which the cell type is not set to hotspot. + SET HANDLER lcl_events=>double_click FOR alv->get_event( ). + + "Adding tooltips to the icon column cells + alv->get_functional_settings( )->get_tooltips( )->add_tooltip( + type = cl_salv_tooltip=>c_type_icon + value = CONV lvc_value( icon_green_light ) + tooltip = `This is a tooltip for an icon` ). + + "----------- Displaying the ALV output ----------- + alv->display( ). + CATCH cx_root INTO DATA(error). + "For simplicity, this example uses the root exception class. + "Always make sure that you use appropriate exception classes. Check the F2 + "information for the methods in ADT. + MESSAGE error->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. +ENDTRY. +``` +

⬆️ back to top

## More Information -ABAP Keyword Documentation: -- [Selection Screens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenselection_screen.htm) -- [Classic Lists](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dynpro_list.htm) +- ABAP Keyword Documentation: + - [Selection Screens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenselection_screen.htm) + - [Classic Lists](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dynpro_list.htm) +- ALV: + - [SAP List Viewer (ALV)](https://help.sap.com/docs/SAP_NETWEAVER_731_BW_ABAP/b1c834a22d05483b8a75710743b5ff26/4ec38f8788d22b90e10000000a42189d.html?locale=en-US) on the SAP Help Portal + - Find more demonstration examples in package `SALV` and its subpackages. ## Executable Examples @@ -955,6 +1325,7 @@ After the import of the repository, proceed as follows: - `ZDEMO_ABAP_SELSCR_STMTS_VAR`: Demonstrates variants of the `SELECTION-SCREEN` statements that do not create selection screens - `ZDEMO_ABAP_LISTS`: Demonstrates various ABAP statements to create and handle classic lists - `ZDEMO_ABAP_EVENT_BLOCKS`: Demonstrates event blocks + - `ZDEMO_ABAP_ALV`: Demonstrates the SAP List Viewer (ALV) - Run the program by choosing `F8`. > **💡 Note**
diff --git a/21_XML_JSON.md b/21_XML_JSON.md index b100cf2..ea05e91 100644 --- a/21_XML_JSON.md +++ b/21_XML_JSON.md @@ -10,7 +10,9 @@ - [XML Transformations](#xml-transformations) - [CALL TRANSFORMATION Syntax](#call-transformation-syntax) - [Dealing with JSON](#dealing-with-json) - - [Excursion: Converting string \<-\> xstring](#excursion-converting-string---xstring) + - [Excursions](#excursions) + - [Converting string \<-\> xstring](#converting-string---xstring) + - [Compressing and Decompressing Binary Data](#compressing-and-decompressing-binary-data) - [More Information](#more-information) - [Executable Example](#executable-example) @@ -512,7 +514,7 @@ CALL TRANSFORMATION ... SOURCE ... - You can .. - create and read JSON data in ABAP using the readers and writers in the sXML Library. See the processing of XML data in the sXML section above. Parsing and rendering JSON data works in a similar way. However, instead of using XML readers/writers, you use JSON readers/writers. - transform ABAP to and from JSON data using transformations. You can directly transform ABAP <-> JSON using identity transformation (ID). In this context, note the intermediate format asJSON (see the notes on asXML above). - - create an handle JSON data using the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud). + - create and handle JSON data using the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud). The following code snippets show a selection of transformation options using the predefined identity transformation. Here, a JSON writer is specified as the target. @@ -565,7 +567,7 @@ DATA(json_formatted) = cl_abap_conv_codepage=>create_in( )->convert( json_wr->ge *} ``` -The following snippets demonstrate creating and handling JSON data using the XCO library. Note that unlike above, the snippets do not work with asJSON as an intermediate format. +The following snippets demonstrate creating and handling JSON data using the XCO library. ```abap "Creating and populating a demo structure and internal table @@ -576,7 +578,7 @@ DATA: BEGIN OF carrier_struc, city_to TYPE c length 20, END OF carrier_struc. -DATA carriers_tab like TABLE OF carrier_struc WITH EMPTY KEY. +DATA carriers_tab LIKE TABLE OF carrier_struc WITH EMPTY KEY. carrier_struc = VALUE #( carrier_id = 'AA' connection_id = '17' city_from = 'New York' city_to = 'San Francisco' ). carriers_tab = VALUE #( ( carrier_id = 'AZ' connection_id = '788' city_from = 'Rome' city_to = 'Tokyo' ) @@ -639,10 +641,11 @@ xco_cp_json=>data->from_string( json_created_xco )->apply( VALUE #(

⬆️ back to top

-## Excursion: Converting string <-> xstring +## Excursions +### Converting string <-> xstring In the code snippets above and in the executable example, many operations are performed using binary data. This excursion shows the conversion of string <-> xstring using a codepage. The examples use UTF-8. -For example, you can use the `cl_abap_conv_codepage` class and the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud). The executable example also covers an excursion regarding compressing and decompressing of binary data. +For example, you can use the `cl_abap_conv_codepage` class and the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud). ```abap DATA(xml_string) = `ABAP`. @@ -675,6 +678,42 @@ DATA(conv_string_xco) = xco_cp=>xstring( conv_xstring_xco

⬆️ back to top

+### Compressing and Decompressing Binary Data +You may want to process or store binary data. The data may be very large. You can compress the data in gzip format and decompress it for further processing using the cl_abap_gzip class. + +```abap +DATA(str) = `This is a data object of type string. It should be converted to xstring, compressed and decompressed.`. +DATA(xstr) = cl_abap_conv_codepage=>create_out( )->convert( str ). +DATA xstr_comp TYPE xstring. + +"Compressing binary data +TRY. + cl_abap_gzip=>compress_binary( EXPORTING raw_in = xstr + IMPORTING gzip_out = xstr_comp ). + CATCH cx_parameter_invalid_range cx_sy_buffer_overflow cx_sy_compression_error. +ENDTRY. + +"Comparing the length of the data objects +DATA(len_xstr) = xstrlen( xstr ). "101 +DATA(len_xstr_comp) = xstrlen( xstr_comp ). "81 + +"Decompressing binary data +DATA xstr_decomp TYPE xstring. +TRY. + cl_abap_gzip=>decompress_binary( EXPORTING gzip_in = xstr_comp + IMPORTING raw_out = xstr_decomp ). + CATCH cx_parameter_invalid_range cx_sy_buffer_overflow cx_sy_compression_error. +ENDTRY. + +DATA(len_xstr_decomp) = xstrlen( xstr_decomp ). "101 +DATA(conv_str) = cl_abap_conv_codepage=>create_in( )->convert( xstr_decomp ). + +DATA(is_equal) = COND #( WHEN len_xstr = len_xstr_decomp + AND str = conv_str + THEN 'X' + ELSE '' ). "Result: X +``` + ## More Information - [ABAP and XML (main topic in the ABAP Keyword Documentation)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_xml.htm) diff --git a/README.md b/README.md index d093cfe..cb6c6b9 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ ABAP cheat sheets[^1] ... |[CDS View Entities](15_CDS_View_Entities.md)|Note that cheat sheet content is available in [this blog](https://blogs.sap.com/2022/10/24/feature-matrix-data-modeling-with-abap-core-data-services/). 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
💡 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
💡 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
💡 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)| +|[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).
💡 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)| |[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)|