This commit is contained in:
danrega
2023-12-22 16:32:38 +01:00
parent 3290f1fd47
commit 88eaaa6f31
6 changed files with 66 additions and 43 deletions

View File

@@ -316,14 +316,14 @@ Nested components can be addressed using chaining:
```
> **💡 Note**<br>
> The [`ASSIGN`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapassign_dynamic_components.htm) statement has special variants for dynamically accessing structure components.
> There are syntax options for dynamically accessing structure components. See the [Dynamic Porgramming](06_Dynamic_Programming.md) cheat sheet.
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Populating Structures
You can copy the content of a structure to another using the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`.
In the following example, it is assumed that the target and source structure are of compatible types. In general, note that special [conversion](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_struc.htm) and [comparison rules](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlogexp_rules_operands_struc.htm) apply to value assignments involving structures.
In the following example, it is assumed that the target and source structures are of compatible types. In general, note that special [conversion](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_struc.htm) and [comparison rules](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlogexp_rules_operands_struc.htm) apply to value assignments involving structures.
``` abap
some_struc = another_struc.
@@ -448,8 +448,8 @@ diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc EXCEPT comp1 ).
```
Value assignments in deep structures
- In the context of deep structures, there are additional syntax variants available for [`MOVE-CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove-corresponding.htm) statements and the [`CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm).
- The follwing examples focus on internal tables as structure components. For the effect, see the executable example.
- In the context of deep structures, there are additional syntax variants available for [`MOVE-CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove-corresponding.htm) statements and the [`CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) operator.
- The following examples focus on internal tables as structure components. Check out the syntax in action in the executable example.
``` abap
"Nonidentical elementary component types are kept in target

View File

@@ -118,27 +118,34 @@ Once the memory area is assigned, you can work with the content.
``` abap
"Some data object declarations to be used
DATA: num TYPE i,
struc TYPE zdemo_abap_fli, "Demo database table
tab TYPE string_table.
DATA: num TYPE i,
struc TYPE zdemo_abap_fli, "Demo database table
itab_str TYPE string_table,
itab_fli TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
APPEND INITIAL LINE TO itab_fli.
"Declaring field symbols with complete types
FIELD-SYMBOLS: <fs_i> TYPE i,
<fs_struc> TYPE zdemo_abap_fli,
<fs_tab> TYPE string_table.
<fs_struc> TYPE zdemo_abap_fli,
<fs_tab> TYPE string_table.
"Declaring field symbols with generic type
FIELD-SYMBOLS <fs_gen> TYPE data.
"Assigning data objects to field symbols
"Note: In this case, the field symbols have an appropriate type.
"Using field symbols with a static type
ASSIGN num TO <fs_i>.
ASSIGN struc TO <fs_struc>.
ASSIGN tab TO <fs_tab>.
ASSIGN num TO <fs_gen>. "Could be any of the data objects
ASSIGN itab_str TO <fs_tab>.
"Using field symbol with a generic type
ASSIGN num TO <fs_gen>.
ASSIGN itab_fli TO <fs_gen>.
ASSIGN itab_fli[ 1 ] TO <fs_gen>.
"Assigning components
ASSIGN struc-carrid TO <fs_gen>.
ASSIGN itab_fli[ 1 ]-connid TO <fs_gen>.
"Inline declaration is possible, too. The type
"is automatically derived.
"Inline declaration (the field symbol has the type data)
ASSIGN num TO FIELD-SYMBOL(<fs_inl>).
"CASTING addition for matching types of data object and field
@@ -167,6 +174,8 @@ ASSIGN chars TO <fs2> CASTING LIKE chars_l4.
> IF <fs> IS ASSIGNED.
>   ...
> ENDIF.
>
> DATA(check) = COND #( WHEN <fs> IS ASSIGNED THEN `assigned` ELSE `not assigned` ).
> ```
>- Using the statement `UNASSIGN`, you can explicitly remove the assignment of the field symbol. A `CLEAR` statement only initializes the value.
> ``` abap
@@ -485,6 +494,8 @@ IF ref_carr IS BOUND.
  ...
ENDIF.
DATA(ref_bound) = COND #( WHEN ref_carr IS BOUND THEN ref_carr->carrid ELSE `is not bound` ).
"Explicitly removing a reference
"However, the garbage collector takes care of removing the references
"automatically once the data is not used any more by a reference.
@@ -500,10 +511,8 @@ ref_int->* = 123.
"Generic type
DATA ref_generic TYPE REF TO data.
ref_generic = NEW i( ).
"In older ABAP releases, CREATE DATA statements were needed.
CREATE DATA ref_generic TYPE i.
ref_generic = NEW i( ). "Syntax in modern ABAP
CREATE DATA ref_generic TYPE i. "Syntax for older ABAP releases
"As mentioned above, the content of anonymous data objects can only be
"accessed using dereferenced data variables and field symbols.
@@ -542,7 +551,7 @@ dref = NEW i( 2 ).
``` abap
"This snippet shows that three data references are created
"with the same reference variable. Storing them in an internal table
"using the TYPE TABLE OF REF TO prevents the overwriting.
"using the type TYPE TABLE OF REF TO prevents the overwriting.
DATA: dref TYPE REF TO data,
itab TYPE TABLE OF REF TO data,
@@ -582,6 +591,10 @@ LOOP AT fli_tab REFERENCE INTO DATA(ref).
ref->carrid = ...
...
ENDLOOP.
"More statements are available that assign content to a data reference variable,
"for example, READ TABLE.
READ TABLE fli_tab INDEX 1 REFERENCE INTO DATA(rt_ref).
```
*Data reference variables as part of structures and internal tables*:
@@ -737,7 +750,7 @@ ASSIGN iref->('IN_STR') TO <fs>.
"Assigning static attributes
"All visible static attributes in classes and interfaces can be assigned
"In the following example, a class and an interface is specified statically,
"In the following example, a class and an interface are specified statically,
"and the attributes are specified dynamically.
ASSIGN zcl_demo_abap_objects=>('PUBLIC_STRING') TO <fs>.
ASSIGN zdemo_abap_objects_interface=>('CONST_INTF') TO <fs>.
@@ -752,8 +765,21 @@ ASSIGN ('ZDEMO_ABAP_OBJECTS_INTERFACE')=>('CONST_INTF') TO <fs>.
"Further dynamic syntax options are possible, for example,
"specifying the memory area after ASSIGN with a writable expressions
"because the operand position after ASSIGN is a result position
"because the operand position after ASSIGN is a result position.
ASSIGN NEW zcl_demo_abap_objects( )->('PUBLIC_STRING') TO <fs>.
"ELSE UNASSIGN addition
"If ELSE UNASSIGN is specified in the context of dynamic assignments/accesses,
"no memory area is assigned to the field symbol. It is unassigned after
"the ASSIGN statement.
"Note: For the static variant of the ASSIGN statement, i.e. if the memory area
"to be assigned following the ASSIGN keyword is statically specified, the addition
"ELSE UNASSIGN is implicitly set and cannot be used explicitly.
DATA(hallo) = `Hello world`.
ASSIGN ('HALLO') TO FIELD-SYMBOL(<eu>) ELSE UNASSIGN.
ASSERT sy-subrc = 0 AND <eu> IS ASSIGNED.
ASSIGN ('DOES_NOT_EXIST') TO <eu> ELSE UNASSIGN.
ASSERT sy-subrc = 4 AND <eu> IS NOT ASSIGNED.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -909,11 +935,12 @@ READ TABLE itab FROM wa_read USING KEY ('SK') REFERENCE INTO DATA(read_ref).
"Explicitly specifying the key and key values (TABLE KEY addition)
"The component names can also be specified dynamically (which is done in most of the
"following examples for demonstration purposes).
"following examples for demonstration purposes). Note that each component of the table
"key must be specified.
READ TABLE itab WITH TABLE KEY ('SK') COMPONENTS ('COL2') = `aaa` REFERENCE INTO read_ref.
"Specifying the predefined name primary_key explicitly and dynamically
READ TABLE itab WITH TABLE KEY ('PRIMARY_KEY') COMPONENTS ('COL1') = 1 REFERENCE INTO read_ref.
"If the addition COMPONENTS is not specified, the primary table key is used by default.
"If the addition COMPONENTS is not specified, the primary table key is implicitly used.
READ TABLE itab WITH TABLE KEY ('COL1') = 1 REFERENCE INTO read_ref.
"Reading using a free key (WITH KEY addition)
@@ -1181,20 +1208,20 @@ CALL METHOD class=>(meth) PARAMETER-TABLE ptab.
" is of type REF TO data
"The addition EXCEPTION-TABLE for exceptions is not dealt with here.
"Copyable snippet
"Example that uses the PARAMETER-TABLE addition
"Creating an instance by specifying the type statically
"An example class of the cheat sheet repository is used.
DATA(ob_ref) = NEW zcl_demo_abap_objects( ).
DATA(oref1) = NEW zcl_demo_abap_objects( ).
"Calling an instance method
"The method multiplies an integer by 3.
"The calculation result is returned.
DATA(result) = ob_ref->triple( i_op = 2 ). "6
DATA(result) = oref1->triple( i_op = 2 ). "6
"Dynamic equivalent
"Creating an instance of a class by specifying the type
"dynamically
DATA objref TYPE REF TO object.
CREATE OBJECT objref TYPE ('ZCL_DEMO_ABAP_OBJECTS').
DATA oref2 TYPE REF TO object.
CREATE OBJECT oref2 TYPE ('ZCL_DEMO_ABAP_OBJECTS').
"Creating parameter table
DATA(ptab) = VALUE abap_parmbind_tab( ( name = 'I_OP'
@@ -1205,7 +1232,7 @@ DATA(ptab) = VALUE abap_parmbind_tab( ( name = 'I_OP'
value = NEW i( ) ) ).
"Dynamic method call and specifying a parameter table
CALL METHOD objref->('TRIPLE') PARAMETER-TABLE ptab.
CALL METHOD oref2->('TRIPLE') PARAMETER-TABLE ptab.
result = ptab[ name = 'R_TRIPLE' ]-('VALUE')->*. "9
```
@@ -1677,8 +1704,7 @@ CREATE DATA dref_cr TYPE HANDLE tdo_ref.
## More Information
- It is recommended that you also consult section [Dynamic Programming Techniques (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynamic_prog_technique_gdl.htm) in the ABAP Keyword Documentation since it provides important aspects that should be considered when dealing with dynamic programming in general (e. g. security aspects or runtime error prevention).
- There are even further dynamic programming techniques in the unrestricted language scope such as the
generation or execution of programs at runtime. They are not part of this cheat sheet. Find more details on the related syntax (e. g. `GENERATE SUBROUTINE POOL`, `READ REPORT` and `INSERT REPORT` in the ABAP Keyword Documentation for Standard ABAP: [Dynamic Program Development (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_language_dynamic.htm)
- There are even further dynamic programming techniques in the unrestricted ABAP language scope [Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm) such as the generation or execution of programs at runtime. They are not part of this cheat sheet. Find more details on the related syntax (e. g. `GENERATE SUBROUTINE POOL`, `READ REPORT` and `INSERT REPORT` in the ABAP Keyword Documentation for Standard ABAP: [Dynamic Program Development (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_language_dynamic.htm)
## Executable Example

View File

@@ -222,7 +222,7 @@ Note:
that the database objects that are specified after `USING` are accessible.
- Generally, in the [unrestricted ABAP language
version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenunrestricted_version_glosry.htm "Glossary Entry")
scope, more syntax options are allowed for AMDP method declaration
scope ([ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_for_sap_cloud_glosry.htm)), more syntax options are allowed for AMDP method declaration
and implementation parts. Check the ABAP Keyword Documentation for
more details as covered further down.

View File

@@ -108,8 +108,8 @@ For an [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US
Using the above bank transfer as an example:
- At the end of the transaction, the new totals of both accounts are updated (money is debited from account A and credited to B).
- You cannot debit account A in one work process and then credit account B in a separate work process. When the work process changes, new totals would be available in one account, but not in the other. Consider the consequences if an error occurs and the new totals for account B cannot be updated, and so on. You would no longer be able to easily roll back the changes.
- Consider prematurely updating the database and notifying the users or processing the data while the logical unit has not been successfully completed.
- You cannot debit account A in one work process and then credit account B in a separate work process. When the work process changes, new totals would be available in one account, but not in the other.
- Consider the consequences if an error occurs and the new totals for account B cannot be updated, and so on. You would no longer be able to easily roll back the changes. Consider prematurely updating the database and notifying the users or processing the data while the logical unit has not been successfully completed.
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -197,7 +197,7 @@ The following bundling techniques are available for classic ABAP. This means tha
**Using [remote-enabled function modules](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenremote_enabled_fm_glosry.htm)**
- Also in this case, the bundling is done through function modules.
- They are also specially marked as remote-enabled function modules.
- For example, you can use register them for later asynchronous execution in the background and through the [RFC interface](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrfc_interface_glosry.htm) ([background Remote Function Call (bgRFC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbg_remote_function_glosry.htm)). With this technology, you can make calls in the same or different ABAP systems.
- For example, you can register them for later asynchronous execution in the background and through the [RFC interface](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrfc_interface_glosry.htm) ([background Remote Function Call (bgRFC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbg_remote_function_glosry.htm)). With this technology, you can make calls in the same or different ABAP systems.
- More information:
- [SAP Help Portal documentation about RFC](https://help.sap.com/docs/ABAP_PLATFORM_NEW/753088fc00704d0a80e7fbd6803c8adb/4888068AD9134076E10000000A42189D)
- [`CALL FUNCTION ... IN BACKGROUND UNIT`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcall_function_background_unit.htm)
@@ -316,7 +316,7 @@ After the import of the repository, proceed as follows:
> - does not claim to include meaningful dynpros with meaningful dynpro sequences and is not intended to be a role model for proper dynpro design.
> - is not intended to solve concrete programming tasks. You should always work out your own solution for each individual case.
> - is only intended to demonstrate a selection of keywords and visualize SAP LUW-related syntax in action on a high level.
> - is explained in more detail below in the expandable section below. Click to view the details.
> - is explained in more detail in the expandable section below. Click to view the details.
> - Dynpros cannot be created in ABAP Cloud. As mentioned earlier, RAP is the transactional programming model for ABAP Cloud. It comes with a well-defined transactional model and follows the rules of the SAP LUW. See the links in the [More Information](#more-information) section.
> - The steps to import and run the code are outlined [here](README.md#-getting-started-with-the-examples).
> - [Disclaimer](README.md#%EF%B8%8F-disclaimer)

View File

@@ -1020,9 +1020,6 @@ 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(<fs_sc>).
@@ -1216,7 +1213,7 @@ TRY.
"*********************************** 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
" contains generic and additional functions. For the additional functions, 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
@@ -1285,7 +1282,7 @@ TRY.
"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.
"is displayed. Double-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

View File

@@ -512,7 +512,7 @@ CALL TRANSFORMATION ... SOURCE ...
## Dealing with JSON
- 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.
- create and read JSON data in ABAP using the readers and writers in the sXML ibrary. 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 and handle JSON data using the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud).
@@ -679,7 +679,7 @@ DATA(conv_string_xco) = xco_cp=>xstring( conv_xstring_xco
<p align="right"><a href="#top">⬆️ back to top</a></p>
### 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.
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.`.