From 2e33bbcdfbc45999132b2e98b7f017afd89e5158 Mon Sep 17 00:00:00 2001 From: danrega <16720986+danrega@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:01:58 +0100 Subject: [PATCH] Update --- 17_SAP_LUW.md | 2 +- 22_Misc_ABAP_Classes.md | 227 ++++++++++++++++++++++++++++++++++++++-- README.md | 2 +- 3 files changed, 218 insertions(+), 13 deletions(-) diff --git a/17_SAP_LUW.md b/17_SAP_LUW.md index 0512575..8fa4f03 100644 --- a/17_SAP_LUW.md +++ b/17_SAP_LUW.md @@ -136,7 +136,7 @@ The following bundling techniques are available for classic ABAP. This means tha - Depending on your use case, you can run the update work process in several ways: - [Synchronous update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensynchronous_update_glosry.htm): The calling program waits until the update work process has finished. The `COMMIT WORK` statement with the `AND WAIT` addition triggers a synchronous update in a separate update work process. - [Asynchronous update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenasynchronous_update_glosry.htm): The calling program does not wait for the update work process to finish. The `COMMIT WORK` statement triggers an asynchronous update in a separate update work process. - - [Local update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlocal_update_glosry.htm): The update is performed immediately in the current work process in a separate internal session and not in a separate update work process, so that a synchronous update is always performed (regardless of whether `COMMIT WORK` is used with `AND WAIT` or not). By default, the local update is deactivated at the start of each SAP LUW. If required, you can activate local update for an SAP LUW using the [`SET UPDATE TASK LOCAL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_update_task_local.htm) statement before registering the update function modules. + - [Local update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlocal_update_glosry.htm): The update is performed immediately in the current work process in a separate internal session and not in a separate update work process. This is true regardless of whether `COMMIT WORK` is used with `AND WAIT` or not. By default, the local update is deactivated at the start of each SAP LUW. If required, you can activate local update for an SAP LUW using the [`SET UPDATE TASK LOCAL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_update_task_local.htm) statement before registering the update function modules. ```abap diff --git a/22_Misc_ABAP_Classes.md b/22_Misc_ABAP_Classes.md index 1248495..0d1d6d1 100644 --- a/22_Misc_ABAP_Classes.md +++ b/22_Misc_ABAP_Classes.md @@ -5,6 +5,7 @@ - [Misc ABAP Classes](#misc-abap-classes) - [Excursion: Available Classes in ABAP Cloud](#excursion-available-classes-in-abap-cloud) - [Creating UUIDs](#creating-uuids) + - [Displaying Output in the ADT Console](#displaying-output-in-the-adt-console) - [RAP](#rap) - [Transactional Consistency](#transactional-consistency) - [Numbers and Calculations](#numbers-and-calculations) @@ -12,6 +13,7 @@ - [Time and Date](#time-and-date) - [Runtime Type Services (RTTS)](#runtime-type-services-rtts) - [Assignments](#assignments) + - [Information about Non-Initial Structure Components](#information-about-non-initial-structure-components) - [Dynamic Programming](#dynamic-programming) - [Context Information](#context-information) - [XML/JSON](#xmljson) @@ -22,7 +24,8 @@ - [Exception Classes](#exception-classes) - [Parallel Processing](#parallel-processing) - [Application Log](#application-log) - - [Executing Code in Background](#executing-code-in-background) + - [Running Code in the Background](#running-code-in-the-background) + - [Locking](#locking) This ABAP cheat sheet contains a selection of available ABAP classes, serving as a quick introduction, along with code snippets to explore the functionality in action. @@ -78,6 +81,71 @@ ENDTRY.
+## Displaying Output in the ADT Console + +| Class | Details/Code Snippet | +
CL_DEMO_CLASSRUN |
+
+As an alternative to using the IF_OO_ADT_CLASSRUN interface for displaying output in the console, you can also use the CL_DEMO_CLASSRUN class, which offers more methods.
+For more information, refer to this blog.
+The following example makes use of CL_DEMO_CLASSRUN class for output purposes. A structure and an internal table are displayed in the console. Note the automatic dereferencing of the component. Plus, the write_xml method is shown, which displays XML data.
++ +``` abap +CLASS zcl_some_class DEFINITION + INHERITING FROM cl_demo_classrun + PUBLIC + CREATE PUBLIC. + + PUBLIC SECTION. + METHODS main REDEFINITION. + PROTECTED SECTION. + PRIVATE SECTION. +ENDCLASS. + +CLASS zcl_some_class IMPLEMENTATION. + METHOD main. + TYPES: BEGIN OF s, + comp1 TYPE string, + comp2 TYPE i, + comp3 TYPE string_table, + comp4 TYPE REF TO string, + END OF s, + it_type TYPE TABLE OF s WITH EMPTY KEY. + + DATA(struct) = VALUE s( comp1 = `Hello` + comp2 = 1 + comp3 = VALUE #( ( `a` ) ( `b` ) ( `a` ) ( `p` ) ) + comp4 = NEW #( `world` ) ). + + DATA(itab) = VALUE it_type( ( struct ) + ( comp1 = `Hi` + comp2 = 2 + comp3 = VALUE #( ( `x` ) ( `y` ) ( `z` ) ) + comp4 = NEW #( `ABAP` ) ) ). + + out->write( struct ). + out->write( itab ). + + DATA(some_xml) = cl_abap_conv_codepage=>create_out( )->convert( + ` ` ).
+
+ out->write( some_xml ).
+ out->write_xml( some_xml ).
+ ENDMETHOD.
+ENDCLASS.
+```
+
+ |
+
| Class | Details/Code Snippet | +
CL_ABAP_STRUCT_UTILITIES |
+
+Provides methods to get information about filled components in structures allowing an efficient processing of non-initial components of a structure.
+ + +``` abap +CLASS zcl_some_class DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_oo_adt_classrun. + PRIVATE SECTION. +ENDCLASS. + +CLASS zcl_some_class IMPLEMENTATION. + METHOD if_oo_adt_classrun~main. + out->write( `---------- filled_components method ----------` ). + "It returns an internal table containing the names of the non-initial + "components of the structure and their index. + DATA: BEGIN OF struct, + a TYPE c LENGTH 1, + b TYPE i, + c TYPE zdemo_abap_carr, + d TYPE REF TO string, + END OF struct. + + struct = VALUE #( a = 'X' + b = 123 + c = VALUE #( carrid = 'LH' ) + d = NEW #( `ABAP` ) ). + + "Getting component information using RTTI + DATA(all_comps) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( struct ) )->components. + out->write( all_comps ). + + "Getting an internal table containing the names of non-initial components + "and their index + DATA(filled_comps) = cl_abap_struct_utilities=>filled_components( struct ). + out->write( filled_comps ). + + "In a loop, structure components are cleared. The filled_components method + "is called in each loop pass, visualizing the filled components in the + "structure. + DO lines( all_comps ) TIMES. + CLEAR struct-(sy-index). + filled_comps = cl_abap_struct_utilities=>filled_components( struct ). + out->write( filled_comps ). + ENDDO. + + out->write( `---------- filled_components_c method ----------` ). + "Same as above. All structure components must be typed with c LENGTH 1. + DATA: BEGIN OF struct_c1, + a TYPE c LENGTH 1 VALUE 'X', + b TYPE c LENGTH 1, + c TYPE c LENGTH 1 VALUE 'X', + END OF struct_c1. + + filled_comps = cl_abap_struct_utilities=>filled_components_c( struct_c1 ). + out->write( filled_comps ). + + out->write( `---------- filled_components_x method ----------` ). + "Same as above. All structure components must be typed with x LENGTH 1. + "It is especially useful for checking filled components of BDEF derived types, + "for example, %control. + DATA struc_der_type TYPE STRUCTURE FOR READ IMPORT zdemo_abap_rap_ro_m. + struc_der_type = VALUE #( %control = VALUE #( key_field = if_abap_behv=>mk-on + field1 = if_abap_behv=>mk-on + field2 = if_abap_behv=>mk-off + field3 = if_abap_behv=>mk-off + field4 = if_abap_behv=>mk-on ) ). + + filled_comps = cl_abap_struct_utilities=>filled_components_x( struc_der_type-%control ). + out->write( filled_comps ). + ENDMETHOD. +ENDCLASS. +``` + + |
+
XCO_XP_JSON |
+ XCO_CP_JSON |
Handling JSON data using the XCO library
@@ -1382,13 +1544,13 @@ DATA(host) = ui_url->get_host( ). DATA(port) = ui_url->get_port( ). "Global account ID -DATA(ui_urdld) = ten->get_global_account_id( )->as_string( ). +DATA(global_acc_id) = ten->get_global_account_id( )->as_string( ). "Guid -DATA(udld) = ten->get_guid( )->value. +DATA(guid) = ten->get_guid( )->value. "Id -DATA(uddld) = ten->get_id( ). +DATA(id) = ten->get_id( ). "Subaccount ID -DATA(uddsdld) = ten->get_subaccount_id( )->as_string( ). +DATA(sub_acc_id) = ten->get_subaccount_id( )->as_string( ). ``` |
@@ -1689,7 +1851,7 @@ ENDTRY.
-## Executing Code in Background
+## Running Code in the Background
CL_BGMC_PROCESS_FACTORY |
|
| Class | Details/Code Snippet | +
CL_ABAP_LOCK_OBJECT_FACTORY |
+
+For activating lock objects. Note that you can also use the DEQUEUE_ALL method to remove all locks in the current SAP LUW.
+The following example code snippet uses artifacts from the ABAP cheat sheet repository.
++ +``` abap +"Deleting demo database table +DELETE FROM zdemo_abap_rapt1. +"Creating a database table entry and reading it into a data reference variable +MODIFY zdemo_abap_rapt1 FROM @( VALUE #( key_field = 1 field1 = 'aaa' field2 = 'bbb' field3 = 2 field4 = 3 ) ). +SELECT SINGLE * FROM zdemo_abap_rapt1 WHERE key_field = 1 INTO NEW @DATA(key). + +TRY. + "Instantiating a lock object + DATA(lock) = cl_abap_lock_object_factory=>get_instance( iv_name = 'EZDEMO_ABAP_LOCK' ). + + "Enqueuing a lock object + "Note that there are various parameters. The parameter used in the example contains + "a list of lock fields including a reference to the parameter value. + lock->enqueue( it_parameter = VALUE #( ( name = 'KEY_FIELD' value = REF #( key->key_field ) ) ) ). + CATCH cx_abap_lock_failure cx_abap_foreign_lock INTO DATA(enq_error). +ENDTRY. + +TRY. + "Dequeuing a lock object + lock->dequeue( it_parameter = VALUE #( ( name = 'KEY_FIELD' value = REF #( key->key_field ) ) ) ). + CATCH cx_abap_lock_failure INTO DATA(deq_error). +ENDTRY. +``` + + |
+