Source of Information for Field in structures FPAYH-FPAYHX-FPAYP
12259,491
While fine-tuning payment file output generation with the particular bank, typically, during customization and processing, there is a problem to find the source of the information used with the output.
That is why a simple excel file was created to connect information on structure fields with the corresponding step of the payment process. This excel tool helps you to easily detect the right field and its detailed description.
Preview of the navigation page is shown here.
Each table represents one color and sheet
FPAYH – red
FPAYHX – blue
FPAYP – green
So far the sources of the fields are connected to three mentioned processes that are the most used.
Domestic Payment
Foreign Payment
Payment with cash discount
In each table, you can easily change the language entering language code in the cell C2. Available languages: AR, CS, DA, DE, EN, ES, FI, FR, HU, IT, JA, KO, MS, NL, NO, PL, PT, RO, RU, SV, TH, TR, ZF, ZH.
There are two ways how to use this excel tool
Option 1 Select the process you would like to find the field source
Each screenshot has a name e.g. (FB03) and fields numbers with different colors (the color defines a table e.g. green – FPAYP).
Option 2 Select a particular field from the table and check if the screenshot exists
If the screenshot exists you find it in the relevant sheet like the example above.
>> Download here SAP Note 2820775 <<
Second version (Dec, 2020) changes: On Tab FPAYHX Source field/logic information for FIELDNAME UBNKL_EXT was updated.
You are more than welcome to leave your comments or wishes for further source descriptions.
SAP Note 2820775 – Source of Information for Field in structures FPAYH-FPAYHX-FPAYP
Read about Payment Formats and tools associated with them here.
By Jagadheeswara Raju BJul 08, 2020
12 Comments
Christoph Dutz
October 29, 2019 at 9:12 am
Great source of information. Thank you very much for this effort
Like 1
Reply
Alert Moderator
Share
Ibrahim Haja Mohideen
December 16, 2019 at 7:38 am
Very useful information, can you please share the excel file?
Like 1
Reply
Alert Moderator
Share
Tereza Ctvrtnikova
Blog Post Author
January 10, 2020 at 9:56 am
Hello Ibrahim,
The instruction how to download the excel file are written in the blog post.
Kind regards,
Tereza
Like 0
Reply
Alert Moderator
Share
Attune Support
June 16, 2021 at 6:19 am
Unable to find the way to download the file. please help
Like 0
Reply
Alert Moderator
Share
Hubert Cahn
January 10, 2020 at 9:23 am
Very useful. Thanks a lot for this work.
Like 1
Reply
Alert Moderator
Share
Alberto Cancelado Gonzalez
July 10, 2020 at 2:21 pm
Congrats! Tereza very useful. However, when trying to use the link, this error message is displayed
"The SAP Note/KBA you were trying to reach is currently being updated. This is usually to enhance its content with new information."
Like 0
Reply
Alert Moderator
Share
Tereza Ctvrtnikova
Blog Post Author
July 14, 2020 at 6:29 am
Hello Alberto,
There were no changes made since the SAP Note was released. Please, try to reopen the link or contact support service.
Best regards,
Tereza
Like 1
Reply
Alert Moderator
Share
Takeshi Fukushima
January 14, 2021 at 3:21 am
Hi Tereza,
Good day.
Upon checking SAP Note 2820775 – Source of Information for Field in structures FPAYH-FPAYHX-FPAYP, there is an error on the opening of the Excel File.
Please see attached: Error.jpeg
Can you please help us with this?
Thank you.
Like 0
Reply
Alert Moderator
Share
Tereza Ctvrtnikova
Blog Post Author
January 14, 2021 at 8:58 am
Hi Takeshi,
please follow the downloading instruction described in the SAP Note. You need to download all three files to open the Excel.
Best regards,
Tereza
Like 0
Reply
Alert Moderator
Share
Matthew Tsang
May 20, 2021 at 7:38 am
Hello hi Tereza,
This is very very useful. Thanks a lot.
And we are trying to use the following instruction fields, but they are not available in FPAYHX
We are already running S/4 HANA... do you have any ideas how we can enable these fields in FPAYHX?
Thanks.
Regards,
Matthew.
Like 1
Reply
Alert Moderator
Share
LnT Infotech FICO Support
July 15, 2021 at 12:29 pm
Hi Tereza,
I am facing issue for XML file structure for field PMTMTD and INSTRPRTY.
Same structure is used in different co codes with same payment method but in one company code it is populating correctly but other its not populating
Please help
Regards,
Mandar
Like 0
Reply
Alert Moderator
Share
Lutz Maue
August 25, 2021 at 1:32 pm
Hi Tereza,
very well done, thanks for this helpful information.
Can you let me know how I get table/ field T012D-DTKID (SUN) into structure FPAYHX, I can't find it.
Thanks so much.
Lutz
Like 0
APPLICATION_AREA | Instruction Key Application Area (e.g. Country)
TEXT1 | Text for Instruction
CODE1 | Code Word for Instructions
ADD_INFO1 | Text, 40 Characters Long
TEXT2 | Text for Instruction
CODE2 | Code Word for Instructions
ADD_INFO2 | Text, 40 Characters Long
TEXT3 | Text for Instruction
CODE3 | Code Word for Instructions
ADD_INFO3 | Text, 40 Characters Long
TEXT4 | Text for Instruction
CODE4 | Code Word for Instructions
ADD_INFO4 | Text, 40 Characters Long
以下内容整理自 SAP 官方 ABAP 速查表(主题:Structures),作为本文的扩展补充资料。
Structures ...
with structured data types (which is a complex data type because it is composed of other data types).
"Creating structures based on globally available structured types
"Database table
DATA struc_from_dbtab TYPE zdemo_abap_fli.
"CDS view entity
DATA struc_from_cds_ve TYPE zdemo_abap_fli_ve.
"CDS abstract entity
DATA struc_from_cds_abs TYPE zdemo_abap_abstract_ent.
"CDS table function
DATA struc_from_cds_tab_func TYPE zdemo_abap_table_function.
"Globally available structured type in the public visibility section of
"classes/interfaces
DATA struc_from_struc_type_in_cl TYPE zcl_demo_abap_amdp=>fli_struc.
"Creating structured types based on globally available structured types
TYPES ty_struc_from_dbtab TYPE zdemo_abap_fli.
TYPES ty_struc_from_cds_ve TYPE zdemo_abap_fli.[!NOTE] - This cheat sheet focuses on locally defined structures and structured types. - Classic DDIC views are not available in ABAP Cloud. They can only be used as structured types in classic ABAP.
The typical language elements for creating structures and structured types locally in an ABAP program are BEGIN OF ... END OF .... They are used in combination with the TYPES keyword to create a structured type and the DATA keyword to create a structure.
TYPES. The type name is preceded by BEGIN OF (which marks the beginning of the structured type definition) and END OF (the end of the definition). TYPES is followed by a colon, and the components are separated by commas.TYPES: BEGIN OF struc_type,
comp1 TYPE ...,
comp2 TYPE ...,
comp3 TYPE ...,
...,
END OF struc_type.Alternatively, you can also use the following syntax. However, a chained statement may provide better readability.
TYPES BEGIN OF struc_type.
TYPES comp1 TYPE ... .
TYPES comp2 TYPE ... .
TYPES comp3 TYPE ... .
... .
TYPES END OF struc_type.components.
TYPEand LIKE additions for the types of the components. You can use the LINE OF addition to refer to a table type or an internal table.
TYPES: BEGIN OF struc_type,
comp1 TYPE i, "elementary type
comp2 TYPE c LENGTH 5, "elementary type
comp3 TYPE structured_type, "structured type
comp4 TYPE itab_type, "internal table type
comp5 TYPE ddic_type, "DDIC type
comp6 TYPE REF TO i, "data reference
comp7 LIKE data_object, "deriving type from a data object
comp8 TYPE LINE OF itab_type, "component has structured type, type derived from internal table type
comp9 LIKE LINE OF itab, "component has structured type, type derived from internal table
comp10 TYPE REF TO struc_type, "recursive structure refererence
...,
END OF struc_type.[!NOTE] - Outside of classes, you can also refer to DDIC types usingLIKE(... comp11 LIKE ddic_type, ...). If you actually want to refer to an existing data object, but due to typing errors you inadvertently specify a name that exists as DDIC type, errors may be unavoidable. - It is possible to create recursive structure references. These are components of a structured type that represent data references to the same structure in which they are defined (see thecomp10component in thestruc_typeexample).
DATA keyword. TYPES statement above. TYPES statement, you can use the VALUE addition to set default values. DATA: BEGIN OF struc,
comp1 TYPE ...,
comp2 TYPE ... VALUE ...,
comp3 TYPE i VALUE 99,
comp4 TYPE i VALUE IS INITIAL, "Without the addition VALUE, or if IS INITIAL is specified,
"the content is initial.
comp5 TYPE local_structured_type,
...,
END OF struc.Alternatively, you can use the following syntax. Similar to above, a chained statement may provide better readability.
DATA BEGIN OF struc.
DATA comp1 TYPE ... .
DATA comp2 TYPE ... VALUE ... .
... .
DATA END OF struc.[!NOTE] - The keywordsCLASS-DATAandCONSTANTScan also be used to create structures. In principle, they represent special cases of the general statement shown above. See the ABAP Keyword Documentation for more information. - Structures can also be created inline usingDATA(...)orFINAL(...), as shown below.
"Local structured type
TYPES: BEGIN OF struc_type,
comp1 TYPE i,
comp2 TYPE c LENGTH 5,
END OF struc_type.
"Creating a structure using a local structured type
DATA struc_1 TYPE struc_type.
"Creating structures based on globally available types from the DDIC
"Note: When referring to such types, you cannot provide start values for the individual components.
DATA: struc_2 TYPE some_ddic_structure,
struc_3 TYPE some_ddic_table,
struc_4 TYPE some_cds_view.
"Structure based on a structured type that is available in the public
"visibility section of a global class
DATA struc_5 TYPE cl_some_class=>struc_type.
"Creating structures by referring to local data objects and internal table types
DATA: struc_6 LIKE struc_1,
struc_7 LIKE LINE OF some_itab,
struc_8 TYPE LINE OF some_itab_type.DATA(...). The FINAL declaration operator is used to create immutable variables.VALUE operator (and also fill them as shown below). Without specifying component values in the parentheses, you create an initial structure. "Structures created inline instead of an extra declared variable
DATA struc_9 LIKE struc_1.
struc_9 = struc_1
"Type is derived from the right-hand structure; the content of struc is assigned, too.
DATA(struc_10) = struc_1.
FINAL(struc_11) = struc_9.
"Using the VALUE operator
"A structure declaration as follows (without providing component
"value assignments) ...
DATA(struc_a) = VALUE struc_type( ).
"... is similar to the following declaration.
DATA struc_b TYPE struc_type.
"Structures declared inline instead of an extra declared variable
"Example: SELECT statement
"Extra declaration
DATA struc_12 TYPE zdemo_abap_fli.
SELECT SINGLE *
FROM zdemo_abap_fli
WHERE carrid = 'LH'
INTO @struc_12.
"Inline declaration
SELECT SINGLE *
FROM zdemo_abap_fli
WHERE carrid = 'LH'
INTO @DATA(struc_13).
"Example: Loop over an internal table
DATA itab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
... "itab is filled
"Extra declaration
DATA wa_1 LIKE LINE OF itab.
LOOP AT itab INTO wa_1.
...
ENDLOOP.
"Inline declaration
LOOP AT itab INTO DATA(wa_2).
...
ENDLOOP.... BEGIN OF ... END OF ... additions. Their values cannot be changed.FINAL declaration operator is used to create immutable variables.CONSTANTS: BEGIN OF const_struct,
num TYPE i VALUE 123,
str TYPE string VALUE `ABAP`,
n3 TYPE n LENGTH 3 VALUE '000',
c5 TYPE c LENGTH 5 VALUE 'abcde',
END OF const_struct.
DATA(num) = const_struct-num.
"const_struct-num = 456.
TYPES struct_type LIKE const_struct.
FINAL(final_struct) = VALUE struct_type( num = 987 str = `hello` n3 = '123' c5 = 'xyz' ).
DATA(num_from_final) = final_struct-num.
"final_struct-num = 1.
SELECT * FROM zdemo_abap_carr INTO TABLE @DATA(itab).
"The work area is specified as immutable variable. The variable's content cannot be changed
"in the loop, however, the variable is exchanged with the next loop pass.
LOOP AT itab INTO FINAL(wa).
DATA(carrid) = wa-carrid.
"wa-carrid = 'XY'.
ENDLOOP.Find more information on enumerated types in the Data Types and Data Objects cheat sheet.
"When creating enumerated types, an enumerated structure can optionally be declared in
"the context of the type declaration.
"A component of an enumerated structure: An enumerated constant that exists as a component
"of a constant structure, not as a single data object.
TYPES basetype TYPE i.
TYPES: BEGIN OF ENUM t_enum_struc STRUCTURE en_struc BASE TYPE basetype,
a VALUE IS INITIAL,
b VALUE 1,
c VALUE 2,
d VALUE 3,
END OF ENUM t_enum_struc STRUCTURE en_struc.
DATA(enum_comp) = en_struc-b.
DATA(conv_enum_comp) = CONV basetype( en_struc-b ).
ASSERT conv_enum_comp = 1.Using the instance operator NEW and CREATE DATA statements, you can create anonymous data objects, such as anonymous structures. The NEW addition of the INTO clause of an ABAP SQL SELECT statement also creates an anonymous data object. As outlined below, you can access the components or the entire data objects by dereferencing. For more information, refer to the Dynamic Programming and Constructor Expressions cheat sheets.
"Without assigning component values in the parentheses, the anonymous
"structure is initial.
DATA(struc_ref_a) = NEW struc_type( ).
DATA struc_ref_b TYPE REF TO DATA.
struc_ref_b = NEW struc_type( ).
"Multiple syntax options are available for CREATE DATA
"statements. See the cheat sheets mentioned.
CREATE DATA struc_ref_b TYPE struc_type.
DATA struc_ref_c TYPE REF TO struc_type.
"Implicit data type definition
CREATE DATA struc_ref_c.
"NEW addition of the INTO clause of an ABAP SQL SELECT statement
SELECT SINGLE carrid, carrname
FROM zdemo_abap_carr
WHERE carrid = char`LH`
INTO NEW @DATA(struc_ref_d).Depending on the component type, the structure can be a flat structure, a nested structure, or a deep structure.
DATA: BEGIN OF struc,
comp1 TYPE i,
comp2 TYPE c LENGTH 15,
comp3 TYPE p LENGTH 8 DECIMALS 2,
...,
END OF struc.that is, it refers to another structure. The following example has multiple substructures.
DATA: BEGIN OF address_n,
BEGIN OF name,
title TYPE string VALUE `Mr.`,
prename TYPE string VALUE `Duncan`,
surname TYPE string VALUE `Pea`,
END OF name,
BEGIN OF street,
name TYPE string VALUE `Vegetable Lane`,
num TYPE string VALUE `11`,
END OF street,
BEGIN OF city,
zipcode TYPE string VALUE `349875`,
name TYPE string VALUE `Botanica`,
END OF city,
END OF address_n. DATA: BEGIN OF address_d,
name TYPE string VALUE `Mr. Duncan Pea`,
street TYPE string VALUE `Vegetable Lane 11`,
city TYPE string VALUE `349875 Botanica`,
details TYPE TABLE OF some_table WITH EMPTY KEY,
END OF address_d.Although the following structure looks quite simple, it is not a flat structure, but a deep structure, because it contains strings.
DATA: BEGIN OF address,
name TYPE string VALUE `Mr. Duncan Pea`,
street TYPE string VALUE `Vegetable Lane 11`,
city TYPE string VALUE `349875 Botanica`,
END OF address.[!NOTE] - The data types of DDIC types are all flat (not nested) structures. Exception: Components of type string can be contained. - Work areas of ABAP SQL statements cannot contain any deep components other than strings among others. - Especially for assignments and comparisons of deep structures, the compatibility of the source and target structure must be taken into account.
-.
-> can be used: ...dref->comp .... The following syntax also works, but is less convenient: ... dref->*-comp ...."Addressing components via the structure component selector
... struc-comp1 ...
... struc-comp2 ...
... struc-comp3 ...
"Examples for addressing the whole structure and individual components
IF struc IS INITIAL.
...
ENDIF.
IF struc-comp1 = 1.
...
ENDIF.
DATA(complete_struc) = struc.
DATA(comp_value) = struc-comp2.
"Type and data declarations
TYPES: type_1 TYPE structured_type-comp1,
type_2 LIKE struc-comp1.
DATA: var_1 TYPE structured_type-comp1,
var_2 LIKE struc-comp1.
"Variables with reference to a structured data object
DATA ref_struc_1 TYPE REF TO structured_type.
ref_struc_1 = NEW #( ).
"Excursion: Creating a reference variable using inline declaration
DATA(ref_struc_2) = NEW structured_type( ).
... ref_struc_1->comp1 ...
... ref_struc_1->*-comp1 ... "Using the dereferencing operator
... ref_struc_2->comp2 ...
... ref_struc_2->*-comp2 ... "Using the dereferencing operatorNested components can be addressed using chaining:
... struc-substructure-comp1 ...
... address_n-name-title ...[!NOTE] There are syntax options for dynamically accessing structure components. See the Dynamic Porgramming cheat sheet.
"A field symbol is set using an assignment of a memory area to the
"field symbol by ASSIGN statements.
"Particularly, field symbols and ASSIGN statements are supporting elements for
"dynamic programming. ASSIGN statements have multiple additions. Find more information
"and examples in the Dynamic Programming cheat sheet.
TYPES: BEGIN OF s,
comp1 TYPE i,
comp2 TYPE c LENGTH 3,
comp3 TYPE n LENGTH 5,
comp4 TYPE string,
END OF s.
DATA(demo_struc) = VALUE s( comp1 = 1 comp2 = 'abc' comp3 = '12345' comp4 = `ABAP` ).
"Defining a field symbol
FIELD-SYMBOLS <a> TYPE s.
"Assigning the entire structure to a field symbole
ASSIGN demo_struc TO <a>.
"Accessing a structure component via the field symbol
DATA(comp1) = <a>-comp1.
"Field symbol declared inline
"Note: The typing depends on the memory area specified. In this case,
"the field symbol <fd> has the structured type s. This is valid for static
"assignments. In case of dynamic assignments, the type is the generic type
"data.
ASSIGN demo_struc TO FIELD-SYMBOL(<b>).
comp1 = <b>-comp1.
"Accessing components of structures by assigning components to field symbols
"The field symbols is typed with the generic type data so that all components,
"which have random types, can be assigned.
FIELD-SYMBOLS <d> TYPE data.
ASSIGN demo_struc-comp1 TO <d>.
ASSIGN demo_struc-comp2 TO <d>.
ASSIGN demo_struc-comp3 TO <d>.
ASSIGN demo_struc-comp4 TO <d>.
"Accessing structures and components dynamically
"Note: In case of dynamic assignments, ...
"- sy-subrc is set.
"- the type of field symbols declared inline is the generic type data.
ASSIGN ('DEMO_STRUC') TO FIELD-SYMBOL(<c>).
ASSERT sy-subrc = 0.
"Using ASSIGN COMPONENT statements
"It is recommended to use the newer syntax, which specifies the component
"selector followed by a data object in a pair of parentheses.
"After COMPONENT (and in the parentheses in the newer syntax), a character-like
"or numeric data object is expected.
DATA(some_comp) = `COMP2`.
ASSIGN COMPONENT some_comp OF STRUCTURE demo_struc TO <d>.
ASSERT sy-subrc = 0.
some_comp = `COMP5`.
ASSIGN COMPONENT some_comp OF STRUCTURE demo_struc TO <d>.
ASSERT sy-subrc = 4.
"Numeric data objects
"The data object is implicitly converted to type i (if required) and
"interpreted as the position of the component in the structure.
ASSIGN COMPONENT 1 OF STRUCTURE demo_struc TO <d>.
ASSERT sy-subrc = 0.
ASSIGN COMPONENT 5 OF STRUCTURE demo_struc TO <d>.
ASSERT sy-subrc = 4.
"0 means that the entire structure is assigned
ASSIGN COMPONENT 0 OF STRUCTURE demo_struc TO <d>.
ASSERT sy-subrc = 0.
ASSERT <d> = demo_struc.
"Newer syntax using the component selector followed by content in
"a pair of parentheses.
ASSIGN demo_struc-('COMP4') TO <d>.
ASSIGN demo_struc-(some_comp) TO <d>.
ASSIGN demo_struc-(3) TO <d>.
ASSIGN demo_struc-(0) TO <d>.
"Iterating across all structure components
DO.
ASSIGN demo_struc-(sy-index) TO <d>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.You can copy the content of a structure to another using the assignment operator =. In the following example, it is assumed that the target and source structures are of compatible types. In general, note that special conversion and comparison rules apply to value assignments involving structures.
some_struc = another_struc.
"When creating a new structure by inline declaration, the type of
"the right-hand structure is derived and the content is assigned.
DATA(struc_inl) = some_struc.To assign values to individual structure components, use the component selector.
TYPES: BEGIN OF addr_struc,
name TYPE string,
street TYPE string,
city TYPE string,
END OF addr_struc.
DATA address TYPE addr_struc.
address-name = `Mr. Duncan Pea`.
address-street = `Vegetable Lane 11`.
address-city = `349875 Botanica`.VALUE operator can be used to construct the content of complex data objects such as structures or internal tables. # character can be used used before the parentheses. Otherwise, the type must be specified explicitly. VALUE operator and inline declarations can be used to create and populate structures in one go."# used: type of the operand can be implicitly derived
address = VALUE #( name = `Mr. Duncan Pea`
street = `Vegetable Lane 11`
city = `349875 Botanica` ).
"Declaring a structure inline
"Type used explicitly: type of the operand cannot be implicitly derived
DATA(addr) = VALUE addr_struc( name = `Mr. Duncan Pea`
street = `Vegetable Lane 11`
city = `349875 Botanica` ).
"Using the BASE addition to retain existing component values
addr = VALUE #( BASE addr street = `Some Street 1` ).
*NAME STREET CITY
*Mr. Duncan Pea Some Street 1 349875 Botanica
"Without the BASE addition, the components are initialized
addr = VALUE #( street = `Another Street 2` ).
*NAME STREET CITY
* Another Street 2
"Nesting value operators
TYPES: BEGIN OF struc_nested,
a TYPE i,
BEGIN OF nested_1,
b TYPE i,
c TYPE i,
END OF nested_1,
BEGIN OF nested_2,
d TYPE i,
e TYPE i,
END OF nested_2,
END OF struc_nested.
DATA str_1 TYPE struc_nested.
str_1 = VALUE #( a = 1
nested_1 = VALUE #( b = 2 c = 3 )
nested_2 = VALUE #( d = 4 e = 5 ) ).
"Inline declaration
"Component a is not specified here, i.e. its value remains initial.
DATA(str_2) = VALUE struc_nested( nested_1 = VALUE #( b = 2 c = 3 )
nested_2 = VALUE #( d = 4 e = 5 ) ).
"Apart from the VALUE operator, the NEW operator can be used to create
"a data reference variable (and populate the structure)
DATA(str_ref) = NEW struc_nested( a = 1
nested_1 = VALUE #( b = 2 c = 3 )
nested_2 = VALUE #( d = 4 e = 5 ) ).Using the instance operator NEW, you can create anonymous data objects, such as anonymous structures. You can access the components or the entire data objects by dereferencing. For more information, refer to the Dynamic Programming and Constructor Expressions cheat sheets.
"Creating a data reference variable
DATA addr_ref1 TYPE REF TO addr_struc.
"Populating the anonymous structure
addr_ref1 = NEW #( name = `Mr. Duncan Pea`
street = `Vegetable Lane 11`
city = `349875 Botanica` ).
addr_ref1->name = `Mrs. Jane Doe`.
"Declaring an anonymous structure/a data reference variable inline
DATA(addr_ref2) = NEW addr_struc( name = `Mr. Duncan Pea`
street = `Vegetable Lane 11`
city = `349875 Botanica` ).
addr_ref2->* = VALUE #( BASE addr_ref2->* name = `Mr. John Doe` ).MOVE-CORRESPONDINGand the CORRESPONDING operator to assign values to structure components, especially when assigning values from a source structure to a target structure which have incompatible types and/or differently named components.
[!NOTE] - TheCL_ABAP_CORRESPONDINGsystem class is available for making assignments. See the ABAP Keyword Documentation for the details. - TheINTOclause of ABAP SQL statements has theCORRESPONDINGaddition. There, the following basic rule applies, which affects the value assignment: Without theCORRESPONDING ...addition, column names do not matter, only the position. With theCORRESPONDING ...addition, the position of the columns does not matter, only the name. See examples in the ABAP SQL cheat sheet.
The following examples demonstrate the value assignment using MOVE-CORRESPONDING statements and the CORRESPONDING operator with various additions. The focus is on flat structures only.
"Moves identically named components; content in other components
"of the targets structure are kept.
MOVE-CORRESPONDING struc TO diff_struc.
"Initializes target structure; moves identically named components
diff_struc = CORRESPONDING #( struc ).
"Same effect as the first MOVE-CORRESPONDING statement;
"addition BASE keeps existing content
diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc ).
"MAPPING addition: Specifying components of a source structure that are
"assigned to the components of a target structure in mapping
"relationships.
diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc MAPPING comp1 = compa ).
"EXCEPT addition: Excluding components from the assignment.
diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc EXCEPT comp1 ).Value assignments in deep structures
MOVE-CORRESPONDING statements and the CORRESPONDING operator."Nonidentical elementary component types are kept in target
"structure which is true for the below MOVE-CORRESPONDING statements;
"existing internal table content is replaced by content of
"the source table irrespective of identically named components
MOVE-CORRESPONDING deep_struc TO diff_deep_struc.
"Existing internal table content is replaced but the value
"assignment happens for identically named components only.
MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES.
"Existing internal table content is kept; table content of the source
"structure are added but the value assignment happens like the first
"MOVE-CORRESPONDING statement without further syntax additions.
MOVE-CORRESPONDING deep_struc TO diff_deep_struc KEEPING TARGET LINES.
"Existing internal table content is kept; table content of the source
"structure are added; the value assignment happens like the statement
"MOVE-CORRESPONDING ... EXPANDING NESTED TABLES.
MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES KEEPING TARGET LINES.
"Target structure is initialized; the value assignment for an internal
"table happens irrespective of identically named components.
diff_deep_struc = CORRESPONDING #( deep_struc ).
"Target structure is initialized; the value assignment for an internal
"table happens for identically named components only.
diff_deep_struc = CORRESPONDING #( DEEP deep_struc ).
"Nonidentical elementary component types are kept in target structure;
"internal table content is replaced; there, the value assignment
"happens like using the CORRESPONDING operator without addition.
diff_deep_struc = CORRESPONDING #( BASE ( diff_struc ) deep_struc ).
"Nonidentical elementary component types are kept in target structure;
"internal table content is replaced; there, the value assignment
"happens like using the CORRESPONDING operator with the addition DEEP.
diff_deep_struc = CORRESPONDING #( DEEP BASE ( diff_struc ) deep_struc ).
"Nonidentical elementary component types are kept in target structure;
"internal table content is kept, too, and table content of the
"source structure are added; there, the value assignment
"happens like using the CORRESPONDING operator without addition.
diff_deep_struc = CORRESPONDING #( APPENDING BASE ( diff_struc ) deep_struc ).
"Nonidentical elementary component types are kept in target structure;
"internal table content is kept, too, and table content of the
"source structure are added; there, the value assignment
"happens like using the CORRESPONDING operator with the addition DEEP.
diff_deep_struc = CORRESPONDING #( DEEP APPENDING BASE ( diff_struc ) deep_struc ).You can reset individual components to their initial values and clear the entire structure using the CLEAR keyword. Note that FREE statements also deletes the content, but they also release the initially allocated memory. space.
CLEAR struc-component.
CLEAR struc.
"This statement additionally releases memory space.
FREE struc.
"Note: An assignment using the VALUE operator without entries in the parentheses clears the structure.
struc = VALUE #( ).
"The same applies to data reference variables pointing to structures.
struc_ref = NEW #( ).Structures are primarily used to process data from tables. In this context, structures often take on the role of a work area. The following code snippets cover only a selection. For more examples, see the cheat sheets about internal tables and ABAP SQL.
The following code snippets cover a selection. Find more information and code snippets in the ABAP SQL cheat sheet.
| Subject | Notes |
| Reading a row from a database table into a structure that has a compatible type |
Note that, since database tables are flat, the target structure must also be flat. In the example below, the |
| Reading a row from a database table into a structure that has an incompatible type |
Components in the structure with identical names are filled. |
|
Reading a line from an internal table into a structure using an ABAP SQL |
Note the specified alias name and that ABAP variables like internal tables must be escaped with |
| Sequentially passing rows of a read result into a structure |
A |
|
Inserting a single row into a database table from a structure using ABAP SQL statements with |
The following statements can be considered as alternatives. The third statement shows that instead of inserting a row from an existing structure, you can create and fill a structure directly. Note that you should avoid inserting a row with a particular key into the database table if a row with the same key already exists. Note that with this and the followig syntax, various options/expressions are possible. |
|
Updating a single row in a database table from a structure using ABAP SQL statements with |
Note that this syntax changes the entire row and all of its components. If you want to update a database table row from a structure by specifying components to be changed without overwriting other components, you can use the following method. First, read the desired row from the database table into a structure. Then, use the |
|
Updating or creating a single row in a database table from a structure using ABAP SQL statements with |
If a row with the same key as specified in the structure already exists in the database table, the row is updated. If no row with the keys specified in the structure exists, a new row is created in the database table. |
|
Deleting a single row in a database table from a structure using ABAP SQL statements with |
If a row with the same key as specified in the structure already exists in the database table, the row is updated. If no row with the keys specified in the structure exists, a new row is created in the database table. |
The following code snippets cover a selection. Find more information and code snippets in the Internal Tables cheat sheet.
| Subject | Notes |
|
Reading a line from an internal table into a structure using a |
The code snippet below shows the reading of a line into a work area, a field symbol, and a data reference variable, all of which represent structured data objects that are declared inline. In the following example, a line is read based on the line number by specifying |
|
Reading a line from an internal table into a structure using a table expression |
The code snippet shows how to read a line into a structure declared inline. The index is given in square brackets. You can also specify table keys and free keys. |
|
Sequentially reading a line from an internal table into a structure using a |
There are many ways to specify the condition on which the loop is based. The following example covers the option of reading all lines sequentially into a field symbol declared inline. When using a field symbol, you can, for example, directly modify components. |
|
Adding lines to and updating single lines in an internal table from a structure using |
internal table,
snippets, see the Internal Tables cheat sheet. |
and INCLUDE STRUCTURE statements are used in the context of local structures.
... 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. INCLUDE STRUCTURE to include a structure.[!NOTE] - They are not additions of... BEGIN OF ... END OF ...but individual ABAP statements. - If you use a chained statement with a colon to declare the structure, the inclusion of other structures with these statements interrupts the chained statement, that is, the components of the included structures are included as direct components of the superstructure. - By using the optionalASaddition and specifying a name, the included components can be addressed by this common name as if they were actually components of a substructure. - The optionalRENAMING WITH SUFFIXaddition, followed by a name, gives the included components a suffix name to avoid naming conflicts with other components.
The following example shows how structured types and data objects are included in another structure. First, three structured types and a structured data object based on one of these types are created. Then, the types and the structure are included in the structured type address_type. As an excursion, Runtime Type Identification is used to retrieve the component names of created structured type address_type. Refer to the Getting Structured Type Information and Creating Structures at Runtime section. The executable example demonstrates a structure that includes other structures in this way.
TYPES: BEGIN OF name_type,
title TYPE string,
prename TYPE string,
surname TYPE string,
END OF name_type,
BEGIN OF street_type,
name TYPE string,
num TYPE string,
END OF street_type,
BEGIN OF city_type,
zipcode TYPE string,
name TYPE string,
END OF city_type.
DATA city_struc TYPE city_type.
TYPES BEGIN OF address_type.
INCLUDE TYPE name_type AS name.
INCLUDE TYPE street_type AS street RENAMING WITH SUFFIX _street.
INCLUDE STRUCTURE city_struc AS city RENAMING WITH SUFFIX _city.
TYPES END OF address_type.
DATA(component_names) = VALUE string_table( FOR wa IN CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( 'ADDRESS_TYPE' ) )->components ( CONV #( wa-name ) ) ).
*Content of COMPONENT_NAMES:
*TITLE
*PRENAME
*SURNAME
*NAME_STREET
*NUM_STREET
*ZIPCODE_CITY
*NAME_CITY sy (or syst) structure is a built-in data object. sy-subrc: Return code of many ABAP statements; typically, the value 0 indicates successsy-tabix: Row index of internal tablessy-index: Loop pass indexThe following example demonstrates a selection of ABAP system fields. It uses artifacts from the ABAP cheat sheet repository. Note the comments in the code because a syntax warning will be displayed when inserting the code in a demo class that uses ABAP for Cloud Development. It is meant to emphasize that multiple system fields should not be used in ABAP for Cloud Development. To try the example out, create a demo class named zcl_demo_abap. If it already exists, reuse it. Otherwise, create a new class with a different name. Paste the code into it. If you choose a different class name, update the class name in the code snippet accordingly. After activation, choose F9 in ADT to execute the class. The example is set up to display output in the console.
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"In ABAP for Cloud Development, the following statement will show a syntax warning saying that
"sy should not be used. Here, it is used for demonstration purposes.
"In the example, RTTI is used to get all component names of the built-in data object sy. In the loop,
"ABAP statements are created (they represent simple assignments using the various sy components) and
"output to the console. You can copy all the output DATA(...) = ... statements from the console and
"paste them in the demo class's main method implementation. The purpose is to demonstrate that most of
"the sy components should not be used in ABAP for Cloud Development. Most of the statements will show
"a syntax warning in ABAP for Cloud Development. Check the ABAP Keyword Documentation (for Standard ABAP)
"and the F2 information for the purpose of the individual sy components.
LOOP AT CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( sy ) )->components INTO DATA(co).
DATA(sycomp) = to_lower( co-name ).
DATA(code) = |DATA(sy{ sycomp }) = sy-{ sycomp }.|.
out->write( code ).
ENDLOOP.
out->write( |\n| ).
out->write( |\n| ).
"Demonstrating prominent sy components that can be used in ABAP for Cloud Development
*&---------------------------------------------------------------------*
*& sy-subrc: Return code of ABAP statements
*&---------------------------------------------------------------------*
"Many ABAP statements set a sy-subrc value. Check the ABAP Keyword Documentation
"for individual statements. Usually, the value 0 indicates a successful execution.
DATA(some_string) = `ABAP`.
"FIND statements
"Found
FIND `P` IN some_string.
ASSERT sy-subrc = 0.
"Not found
FIND `p` IN some_string RESPECTING CASE.
ASSERT sy-subrc = 4.
DATA(some_itab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ).
"READ TABLE statements
"Entry available
READ TABLE some_itab INTO DATA(wa1) INDEX 3.
ASSERT sy-subrc = 0.
"Entry not available
READ TABLE some_itab INTO DATA(wa2) INDEX 7.
ASSERT sy-subrc = 4.
"ABAP SQL statements
DELETE FROM zdemo_abap_tab1.
IF sy-subrc = 0.
out->write( `DELETE: All rows were deleted.` ).
ELSE.
out->write( `DELETE: No row was deleted because it was already empty.` ).
ENDIF.
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
IF sy-subrc = 0.
out->write( `INSERT: All rows of the internal table were inserted.` ).
ENDIF.
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 4.
out->write( `INSERT ... ACCEPTING DUPLICATE KEYS: sy-subrc has the value 4 in this case. Not all rows of the ` &&
`internal table were inserted because a row with the key already exists.` ).
ENDIF.
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
IF sy-subrc = 0.
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
ELSE.
out->write( `DELETE: No match according to the WHERE condition.` ).
ENDIF.
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
IF sy-subrc = 0.
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
ELSE.
out->write( `DELETE: No match according to the WHERE condition.` ).
ENDIF.
*&---------------------------------------------------------------------*
*& sy-index: Loop indexes
*&---------------------------------------------------------------------*
CLEAR some_string.
"DO loops
DO 5 TIMES.
some_string = some_string && sy-index.
ENDDO.
ASSERT some_string = `12345`.
CLEAR some_string.
DO 10 TIMES.
some_string = some_string && sy-index.
IF sy-index = 7.
EXIT.
ENDIF.
ENDDO.
ASSERT some_string = `1234567`.
CLEAR some_string.
DATA number TYPE i.
"WHILE loop
WHILE number < 9.
number = sy-index.
some_string = some_string && number.
ENDWHILE.
ASSERT some_string = `123456789`.
*&---------------------------------------------------------------------*
*& sy-tabix: Row index of internal tables
*&---------------------------------------------------------------------*
"Demo standard internal table with 5 entries
DATA(std_itab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
"READ TABLE statement using a free key
READ TABLE std_itab INTO DATA(wa3) WITH KEY table_line = `b`.
ASSERT sy-tabix = 2.
"Demo hashed internal table with 5 entries
DATA(hashed_itab) = VALUE string_hashed_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
"READ TABLE statement using a free key
READ TABLE hashed_itab INTO DATA(wa4) WITH KEY table_line = `b`.
"Hashed tables do not have a primary table index.
ASSERT sy-tabix = 0.
CLEAR some_string.
"LOOP statements
LOOP AT std_itab INTO DATA(wa5).
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `12345`.
CLEAR some_string.
"Step addition
"In the example, the table is looped across backwards
"indicated by the negative value. The step size 1 indicates
"that each line is respected.
LOOP AT std_itab INTO DATA(wa6) STEP -1.
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `54321`.
CLEAR some_string.
"Forward loop, step size = 2
LOOP AT std_itab INTO DATA(wa7) STEP 2.
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `135`.
CLEAR some_string.
"FROM/TO additions
LOOP AT std_itab INTO DATA(wa8) FROM 2 TO 4.
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `234`.
CLEAR some_string.
"STEP/FROM additions
LOOP AT std_itab INTO DATA(wa9) STEP 2 FROM 2.
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `24`.
CLEAR some_string.
"Hashed table
LOOP AT hashed_itab INTO DATA(wa10).
some_string = some_string && sy-tabix.
ENDLOOP.
ASSERT some_string = `00000`.
*&---------------------------------------------------------------------*
*& sy-dbcnt: Edited table rows
*&---------------------------------------------------------------------*
DELETE FROM zdemo_abap_tab1.
DATA(dbcnt) = sy-dbcnt.
out->write( |Dbtab rows deleted: { dbcnt }| ).
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
ASSERT sy-dbcnt = 2.
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
ASSERT sy-dbcnt = 1.
MODIFY zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 char1 = 'aaa' ) ).
ASSERT sy-dbcnt = 1.
UPDATE zdemo_abap_tab1 SET char2 = 'bbb'.
ASSERT sy-dbcnt = 3.
DELETE FROM zdemo_abap_tab1 WHERE num1 IS INITIAL.
ASSERT sy-dbcnt = 3.
*&---------------------------------------------------------------------*
*& sy-fdpos: Occurrence in byte or character strings
*&---------------------------------------------------------------------*
"For example, relevant in comparison expressions such as CS (constains string).
"If the comparison is true, sy-fdpos contains the offset of the found value. If it
"is false, sy-fdpos contains the length of the searched string.
some_string = `###abap###`.
IF some_string CS `p`.
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
ELSE.
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
ASSERT sy-fdpos = strlen( some_string ).
ENDIF.
IF some_string CS `#`.
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
ELSE.
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
ASSERT sy-fdpos = strlen( some_string ).
ENDIF.
IF some_string CS `Y`.
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
ELSE.
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
ASSERT sy-fdpos = strlen( some_string ).
ENDIF.
ENDMETHOD.
ENDCLASS.Using Runtime Type Services (RTTS) you can ...
For more information, see the Dynamic Programming cheat sheet.
RTTI example:
TYPES: BEGIN OF demo_struc_type,
comp1 TYPE c LENGTH 3,
comp2 TYPE i,
comp3 TYPE string,
END OF demo_struc_type.
DATA demo_struc TYPE demo_struc_type.
DATA(tdo_c) = cl_abap_typedescr=>describe_by_data( demo_struc ).
"DATA(tdo_c) = cl_abap_typedescr=>describe_by_name( 'DEMO_STRUC_TYPE' ).
"Cast to get more specific information
DATA(tdo_struc) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( demo_struc ) ).
"DATA(tdo_struc) = CAST cl_abap_structdescr( tdo_c ).
DATA(type_category_struc) = tdo_struc->kind.
DATA(relative_name_struc) = tdo_struc->get_relative_name( ).
... "Explore more options by positioning the cursor behind -> and choosing CTRL + Space
DATA(type_of_struc) = tdo_struc->struct_kind.
DATA(struc_comps) = tdo_struc->components.
DATA(struc_comps_more_details) = tdo_struc->get_components( ).
DATA(struc_has_include) = tdo_struc->has_include.
DATA(struc_incl_view) = tdo_struc->get_included_view( ).
DATA(applies_to_data_struc) = tdo_struc->applies_to_data( `some string` ).
"Example: "Looping" across a structure
"For example, this may also be done using a DO loop and dynamic assignments.
"Demo structure, all components are convertible to type string
TYPES: BEGIN OF ty_struc,
comp1 TYPE c LENGTH 3,
comp2 TYPE string,
comp3 TYPE i,
comp4 TYPE n LENGTH 4,
END OF ty_struc.
DATA(struct) = VALUE ty_struc( comp1 = 'abc' comp2 = `ABAP` comp3 = 123 comp4 = '9876' ).
DATA looped_struc TYPE string.
"In the loop, a string is populated, component by component.
LOOP AT CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( struct ) )->components INTO DATA(comp).
looped_struc = |{ looped_struc }{ COND #( WHEN sy-tabix <> 1 THEN ` / ` ) }Name: "{ CONV string( comp-name ) }", Value: "{ struct-(comp-name) }"|.
ENDLOOP.
"Result:
"Name: "COMP1", Value: "abc" / Name: "COMP2", Value: "ABAP" / Name: "COMP3", Value: "123" / Name: "COMP4", Value: "9876"BOXED. Syntax example: TYPES: BEGIN OF struct,
text TYPE c LENGTH 20,
nested_struct TYPE zdemo_abap_carr BOXED,
END OF struct.Expand the following collapsible section for more information and example code.
🟢 Click to expand for more information and example code
The following example illustrates boxed components:
zcl_demo_abap. If it already exists, reuse it. Otherwise, create a new class with a different name. Paste the code into it. If you choose a different class name, update the class name in the code snippet accordingly. Activate the class.ASSERT statement.CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Creating two demo internal tables
"One with boxed components, the other with a nested, non-boxed components
TYPES:
BEGIN OF struc,
comp1 TYPE c LENGTH 1024,
comp2 TYPE c LENGTH 1024,
END OF struc,
BEGIN OF struc_w_boxed,
id TYPE i,
boxed_comp TYPE struc BOXED,
END OF struc_w_boxed,
BEGIN OF struc_no_boxed,
id TYPE i,
struc TYPE struc,
END OF struc_no_boxed,
tab_w_boxed TYPE TABLE OF struc_w_boxed WITH EMPTY KEY,
tab_no_boxed TYPE TABLE OF struc_no_boxed WITH EMPTY KEY.
DATA: itab_w_boxed TYPE tab_w_boxed,
itab_no_boxed TYPE tab_no_boxed.
"Populating internal tables
"When running the example, only have one code snippet commented in, i.e.
"the snippets between the sections
"---- Comment in/out START ----
"...
"---- Comment in/out END ----
DO 100000 TIMES.
*&---------------------------------------------------------------------*
*& Comparison 1
*&---------------------------------------------------------------------*
"1) Internal table with boxed components: All boxed components empty
"---- Comment in/out START ----
INSERT INITIAL LINE INTO TABLE itab_w_boxed REFERENCE INTO DATA(wa1).
wa1->id = sy-index.
"---- Comment in/out END ----
**************************************************************************************************
"2) Internal table with non-boxed components: All nested, non-boxed components empty
"---- Comment in/out START ----
* INSERT INITIAL LINE INTO TABLE itab_no_boxed REFERENCE INTO DATA(wa2).
* wa2->id = sy-index.
"---- Comment in/out END ----
**************************************************************************************************
*&---------------------------------------------------------------------*
*& Comparison 2
*&---------------------------------------------------------------------*
"3) Internal table with boxed components: All boxed components filled
"---- Comment in/out START ----
* INSERT INITIAL LINE INTO TABLE itab_w_boxed REFERENCE INTO DATA(wa3).
* wa3->id = sy-index.
* wa3->boxed_comp-comp1 = sy-index.
* wa3->boxed_comp-comp2 = sy-index.
"---- Comment in/out END ----
**************************************************************************************************
"4) Internal table with non-boxed components: All nested, non-boxed components filled
"---- Comment in/out START ----
* INSERT INITIAL LINE INTO TABLE itab_no_boxed REFERENCE INTO DATA(wa4).
* wa4->id = sy-index.
* wa4->struc-comp1 = sy-index.
* wa4->struc-comp2 = sy-index.
"---- Comment in/out END ----
**************************************************************************************************
*&---------------------------------------------------------------------*
*& Comparison 3
*&---------------------------------------------------------------------*
"5) Internal table with boxed components: Only few boxed components filled
"---- Comment in/out START ----
* INSERT INITIAL LINE INTO TABLE itab_w_boxed REFERENCE INTO DATA(wa5).
* wa5->id = sy-index.
* IF sy-index <= 50.
* wa5->boxed_comp-comp1 = sy-index.
* wa5->boxed_comp-comp2 = sy-index.
* ENDIF.
"---- Comment in/out END ----
**************************************************************************************************
"6) Internal table with non-boxed components: Only few nested, non-boxed components filled
"---- Comment in/out START ----
* INSERT INITIAL LINE INTO TABLE itab_no_boxed REFERENCE INTO DATA(wa6).
* wa6->id = sy-index.
* IF sy-index <= 50.
* wa6->struc-comp1 = sy-index.
* wa6->struc-comp2 = sy-index.
* ENDIF.
"---- Comment in/out END ----
ENDDO.
ASSERT 1 = 1.
ENDMETHOD.
ENDCLASS.TYPES: BEGIN OF struc_type,
num TYPE i,
text TYPE string,
sref TYPE REF TO struc_type,
END OF struc_type.Expand the following collapsible section for example code. To try it out, create a demo class named zcl_demo_abap, or reuse it if it already exists. Paste the code into it. If you choose a different class name, update the class name in the code snippet accordingly. After activation, choose F9 in ADT to execute the class. The example is set up to display output in the console.
🟢 Click to expand for more information and example code
REF TO data (demos 2a and 2b).struc_rec (demo 1): A recursive structure with an integer value and a reference to itself.struc_data (demos 2a and 2b): Similar to struc_rec, but includes a component of type REF TO data.prepend1 (for demo 1) and prepend2 (for demos 2a and 2b) methods add elements to linked lists.reverse1 (for demo 1) and reverse2 (for demos 2a and 2b) reverse those lists.main method shows how to add elements to the lists and reverse them:reverse1 method demonstrates type-safe access, while reverse2 (for demos 2a and 2b) uses a cast that may raise an exception when handling the other structure.CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun .
PRIVATE SECTION.
"Components for demo 1
TYPES:
BEGIN OF struc_rec,
value TYPE i,
next TYPE REF TO struc_rec,
END OF struc_rec.
DATA head1 TYPE REF TO struc_rec.
METHODS prepend1 IMPORTING value TYPE i.
METHODS reverse1.
"Components for demos 2a/b
TYPES:
BEGIN OF struc_data,
value TYPE i,
next TYPE REF TO data,
END OF struc_data.
DATA head2 TYPE REF TO struc_data.
METHODS prepend2 IMPORTING value TYPE i.
METHODS reverse2 RAISING cx_sy_move_cast_error.
ENDCLASS.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
out->write( `-------- Demo 1 (uses a recursive structure reference) --------` ).
DATA(list1) = NEW zcl_demo_abap( ).
list1->prepend1( 1 ).
list1->prepend1( 2 ).
list1->prepend1( 3 ).
out->write( list1->head1 ).
list1->reverse1( ).
out->write( list1->head1 ).
out->write( repeat( val = `*` occ = 100 ) ).
out->write( `-------- Demo 2a (does not use a recursive structure reference) --------` ).
DATA(list2a) = NEW zcl_demo_abap( ).
list2a->prepend2( 4 ).
list2a->prepend2( 5 ).
list2a->prepend2( 6 ).
out->write( list2a->head2 ).
TRY.
list2a->reverse2( ).
out->write( list2a->head2 ).
CATCH cx_sy_move_cast_error INTO DATA(err2a).
out->write( err2a->get_text( ) ).
ENDTRY.
out->write( repeat( val = `*` occ = 100 ) ).
out->write( `-------- Demo 2b (does not use a recursive structure reference and raises an exception) --------` ).
DATA(list2b) = NEW zcl_demo_abap( ).
list2b->prepend2( 7 ).
list2b->prepend2( 8 ).
list2b->prepend2( 9 ).
out->write( list2b->head2 ).
"Manipulation for provoking an error
DATA(error) = 'error'.
list2b->head2->next = REF #( error ).
TRY.
list2b->reverse2( ).
out->write( list2b->head2 ).
CATCH cx_sy_move_cast_error INTO DATA(err2b).
out->write( err2b->get_text( ) ).
ENDTRY.
ENDMETHOD.
METHOD prepend1.
head1 = NEW #( next = head1 value = value ).
ENDMETHOD.
METHOD reverse1.
DATA last1 TYPE REF TO struc_rec.
DATA(current1) = head1.
WHILE current1 IS NOT INITIAL.
DATA(next1) = current1->next.
current1->next = last1.
last1 = current1.
current1 = next1.
ENDWHILE.
head1 = last1.
ENDMETHOD.
METHOD prepend2.
head2 = NEW #( next = head2 value = value ).
ENDMETHOD.
METHOD reverse2.
DATA last2 TYPE REF TO struc_data.
DATA(current2) = head2.
WHILE current2 IS NOT INITIAL.
DATA next2 TYPE REF TO struc_data.
next2 = CAST #( current2->next ).
current2->next = last2.
last2 = current2.
current2 = next2.
ENDWHILE.
head2 = last2.
ENDMETHOD.
ENDCLASS.[!NOTE] - The executable example covers the following topics, among others: - Creating structures and structured types - Variants of structures - Accessing, populating, and clearing structures - Structures in the context of tables - Including structures - The steps to import and run the code are outlined here. - Disclaimer
02_Structures.md。版权归原作者所有。