SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assignment and Conversion Rules → Conversion Rules for Structures → Conversions Between Flat Structures →Conversion Rules for Structures
This example demonstrates how structures can be converted from one type to another.
Source Code
REPORT demo_data_conversion_structure.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: BEGIN OF fs1,
int TYPE i VALUE 5,
pack TYPE p DECIMALS 2 VALUE '2.26',
text TYPE c LENGTH 10 VALUE 'Fine Text',
float TYPE decfloat16 VALUE '1.234e+05',
date TYPE d VALUE '19950916',
END OF fs1.
DATA: BEGIN OF fs2,
int TYPE i VALUE 3,
pack TYPE p DECIMALS 2 VALUE '72.34',
text TYPE c LENGTH 5 VALUE 'Hello',
END OF fs2.
DATA(out) = cl_demo_output=>new(
)->begin_section( 'Source'
)->write( |{ fs1-int width = 10 } {
fs1-pack width = 10 } {
fs1-text width = 10 } {
fs1-float width = 10 } {
fs1-date width = 10 }| ).
out->next_section( 'Target'
)->write( |{ fs2-int width = 10 } {
fs2-pack width = 10 } {
fs2-text width = 10 }| ).
fs2 = fs1.
out->next_section( 'Result'
)->display( |{ fs2-int width = 10 } {
fs2-pack width = 10 } {
fs2-text width = 10 }| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Description
In this example two different structures are defined, fs1 and fs2. The requirements of the third conversion rule for flat structures apply to both structures and the corresponding rule is also used. After the assignment of fs1 to fs2, only the result for the first two components is as if they had been transferred component by component. fs2-text is filled with the first five positions from fs1-text. All the remaining elements of fs1 are not transferred.