diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md index 2e35532..6d0f84a 100644 --- a/01_Internal_Tables.md +++ b/01_Internal_Tables.md @@ -665,26 +665,34 @@ FINAL(it_c) = it_a. "As shown below and in other cheat sheets, constructor operators "are handy when creating internal tables in place. The following -"examples uses the VALUE operator and an internal table type. +"examples uses the VALUE operator and an internal table type. You +"may also use the NEW operator to create anonymous data objects. DATA(it_d) = VALUE string_table( ( `aaa` ) ( `bbb` ) ). +TYPES it_type TYPE TABLE OF zdemo_abap_carr with empty key. +DATA(it_e) = VALUE it_type( ( carrid = 'XY' carrname = 'XY Airlines' ) + ( carrid = 'YZ' carrname = 'Air YZ' ) ). + "Not providing any table lines means the table is initial "and has the same effect as the declaration of it_f. -DATA(it_e) = VALUE string_table( ). -DATA it_f TYPE string_table. +DATA(it_f) = VALUE string_table( ). +DATA it_g TYPE string_table. + +DATA(it_h) = VALUE it_type( ). +DATA it_i TYPE it_type. "Excursion "Table declared inline in the context of a SELECT statement; "a prior extra declaration of an internal table is not needed. -SELECT * FROM zdemo_abap_fli INTO TABLE @DATA(it_g). +SELECT * FROM zdemo_abap_fli INTO TABLE @DATA(it_j). "Instead of -DATA it_h TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY. -SELECT * FROM zdemo_abap_fli INTO TABLE @it_h. +DATA it_k TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY. +SELECT * FROM zdemo_abap_fli INTO TABLE @it_k. "Using FINAL -SELECT * FROM zdemo_abap_fli INTO TABLE @FINAL(it_i). +SELECT * FROM zdemo_abap_fli INTO TABLE @FINAL(it_l). ```
@@ -1233,7 +1241,7 @@ INSERT VALUE s( a = 'yyy' b = 3 ) INTO TABLE dref_tab->*. ### Example: Exploring Populating Internal Tables -Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. +Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console, but only for few data objects. You may want to set a break point at the earliest possible position and walk through the example in the debugger. This will allow you to double-click on data objects and observe how the different statements affect their contents.| Target Area | Notes | +
|
-- Assigning a line to a [field
- symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"),
- for example, using an inline declaration (`... ASSIGNING FIELD-SYMBOL( |
- READ TABLE itab ASSIGNING FIELD-SYMBOL(
-- Reading a line into a [data reference
- variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry")
- using `REFERENCE INTO`. In this case, no copying takes place. If you want to address the line, you must first [dereference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm) the data reference. You cannot use the addition `TRANSPORTING`.
+- Used to copy a line to a data object using the addition `INTO`.
+- After the copying, the line found exists separately in the internal table and in the data object.
+- If you change the data object or the table line, the change does not affect the other.
+- However, you can modify the copied table line and use a `MODIFY` statement to modify the table based on the modified table line (see below).
+- The `TRANSPORTING` addition specifies which components to copy. If it is not specified, all components are respected.
+
+ - ``` abap - READ TABLE itab REFERENCE INTO dref ... +``` abap +"dobj must have the table's structure type +READ TABLE itab INTO dobj ... - READ TABLE itab REFERENCE INTO DATA(dref_inl) ... - ``` +READ TABLE itab INTO DATA(dobj_inl) ... + +READ TABLE itab INTO ... TRANSPORTING comp1 [comp2 ... ]. +``` + + |
+
| + +Field symbol + + | + +
+
+- Assigning a line to a [field symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"),
+ for example, using an inline declaration (`... ASSIGNING FIELD-SYMBOL( + +``` abap +"The field symbol must have an appropriate type. +READ TABLE itab ASSIGNING |
+
| + +Data reference variable + + | + +
+
+- Reading a line into a [data reference variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry") using `REFERENCE INTO`.
+- In this case, no copying takes place.
+- If you want to address the line, you must first [dereference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm) the data reference.
+- You cannot use the addition `TRANSPORTING`.
+
+ + +``` abap +"The data reference variable must have an appropriate type. +READ TABLE itab REFERENCE INTO dref ... + +"Inline declaration +READ TABLE itab REFERENCE INTO DATA(dref_inl) ... +``` + + |
+
oref->some_static_method( ).| Class include | Code | +
| + +Global class + + | + +
+
+- Create a new global class (the example uses the name `zcl_demo_abap`) and copy and paste the following code in the *Global Class* tab in ADT.
- The class has a type and method declaration in the private section. They are used in the local class.
- Once activated (and the code of the other includes has been inserted), you can choose *F9* in ADT to run the class.
- When running the class, a method of the local class that is declared in the private section there is called. As a result of this method call, a string is assigned to an attribute that is also declared in the private section of the local class. This attribute is accessed by the global class, and finally displayed in the ADT console.
+ + ```abap -CLASS zcl_some_class DEFINITION +CLASS zcl_demo_abap DEFINITION PUBLIC FINAL CREATE PUBLIC . @@ -4243,7 +4264,7 @@ ENDCLASS. -CLASS zcl_some_class IMPLEMENTATION. +CLASS zcl_demo_abap IMPLEMENTATION. METHOD if_oo_adt_classrun~main. local_class=>say_hello( ). DATA(hello) = local_class=>hello. @@ -4255,44 +4276,73 @@ CLASS zcl_some_class IMPLEMENTATION. ENDCLASS. ``` -**CCDEF include (*Class-relevant Local Types* tab in ADT)** + |
+
| + +CCDEF include (Class-relevant Local Types tab in ADT) + + | + +
+
- Regarding the includes, see the information in section [Excursion: Class Pool and Include Programs](#excursion-class-pool-and-include-programs)
- The `LOCAL FRIENDS` addition makes the local class a friend of the global class. The private components of the global class can then be accessed by the local class.
+ + ```abap CLASS local_class DEFINITION DEFERRED. -CLASS zcl_some_class DEFINITION LOCAL FRIENDS local_class. +CLASS zcl_demo_abap DEFINITION LOCAL FRIENDS local_class. ``` -**CCIMP include (*Local Types* tab in ADT)** + + |
+
| + +CCIMP include (Local Types tab in ADT) + + | + +
+
- The `FRIENDS` addition makes the global class a friend of the local class. The private components of the local class can then be accessed by the global class.
- A type declared in the private section of the global class is used to type an attribute.
- The method, which is also declared in the private section, includes a method call in the implementation. It is a method declared in the private section of the global class.
+ ```abap -CLASS local_class DEFINITION FRIENDS zcl_some_class. +CLASS local_class DEFINITION FRIENDS zcl_demo_abap. PUBLIC SECTION. PROTECTED SECTION. PRIVATE SECTION. - CLASS-DATA hello TYPE zcl_some_class=>str. + CLASS-DATA hello TYPE zcl_demo_abap=>str. CLASS-METHODS say_hello. ENDCLASS. CLASS local_class IMPLEMENTATION. METHOD say_hello. - hello = |{ zcl_some_class=>get_hello( ) } { sy-uname }.|. + hello = |{ zcl_demo_abap=>get_hello( ) } { sy-uname }.|. ENDMETHOD. ENDCLASS. ``` + |
+
This class serves as an example to illustrate comments for ABAP Doc.
"! The comments begin with the string "!, a special form of regular comments introduced by ".
-"! The {@link zcl_some_class.METH:calculate} method of the example class performs a calculation.
CL_DEMO_CLASSRUN class. A st
CL_ABAP_CONTEXT_INFO XCO_CP