Code: Alles auswählen.
REPORT knobelei_august_2021.
CLASS lcl DEFINITION FINAL.
PUBLIC SECTION.
METHODS:
main,
korresponding IMPORTING is_structure_1 TYPE any
CHANGING cs_structure_2 TYPE any.
ENDCLASS.
END-OF-SELECTION.
NEW lcl( )->main( ).
CLASS lcl IMPLEMENTATION.
METHOD korresponding.
**********************************************************************
*--------------------------------------------------------------------*
* Hier bitte euer Coding
*--------------------------------------------------------------------*
**********************************************************************
ENDMETHOD.
METHOD main.
DATA: struc1 TYPE bapiaddr3,
struc2 TYPE addr2_data,
correct_result LIKE struc2.
*--------------------------------------------------------------------*
* Testdaten erstellen
*--------------------------------------------------------------------*
CLEAR struc1 WITH 'X'.
*--------------------------------------------------------------------*
* Umgehen des SCI
*--------------------------------------------------------------------*
korresponding( EXPORTING is_structure_1 = struc1
CHANGING cs_structure_2 = struc2 ).
*--------------------------------------------------------------------*
* Prüfen ob das Ergebnis korrekt ist durch Verwendung des "bösen" Befehls
*--------------------------------------------------------------------*
MOVE-CORRESPONDING struc1 TO correct_result.
IF struc2 = correct_result.
WRITE:/ 'Grün' COLOR 5.
ELSE.
WRITE:/ 'Hat nicht funktioniert' COLOR 6.
ENDIF.
ENDMETHOD.
ENDCLASS.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
IHe
Code: Alles auswählen.
METHOD korresponding.
FIELD-SYMBOLS: <ls_source> TYPE bapiaddr3,
<ls_target> TYPE addr2_data.
ASSIGN is_structure_1 TO <ls_source>.
ASSIGN cs_structure_2 TO <ls_target>.
<ls_target> = VALUE #( home_city = <ls_source>-home_city
chckstatus = <ls_source>-chckstatus
regiogroup = <ls_source>-regiogroup
pcode1_ext = <ls_source>-pcode1_ext
pcode2_ext = <ls_source>-pcode2_ext
pcode3_ext = <ls_source>-pcode3_ext
po_box = <ls_source>-po_box
dont_use_p = <ls_source>-dont_use_p
po_box_reg = <ls_source>-po_box_reg
transpzone = <ls_source>-transpzone
street = <ls_source>-street
dont_use_s = <ls_source>-dont_use_s
str_suppl1 = <ls_source>-str_suppl1
str_suppl2 = <ls_source>-str_suppl2
str_suppl3 = <ls_source>-str_suppl3
location = <ls_source>-location
building = <ls_source>-building
floor = <ls_source>-floor
country = <ls_source>-country
langu = <ls_source>-langu
region = <ls_source>-region
sort1 = <ls_source>-sort1
sort2 = <ls_source>-sort2
time_zone = <ls_source>-time_zone
taxjurcode = <ls_source>-taxjurcode
po_box_lobby = <ls_source>-po_box_lobby
deli_serv_type = <ls_source>-deli_serv_type
deli_serv_number = <ls_source>-deli_serv_number
county_code = <ls_source>-county_code
county = <ls_source>-county
township_code = <ls_source>-township_code
township = <ls_source>-township
title_p = <ls_source>-title_p
title_aca1 = <ls_source>-title_aca1
title_aca2 = <ls_source>-title_aca2
prefix1 = <ls_source>-prefix1
prefix2 = <ls_source>-prefix2
title_sppl = <ls_source>-title_sppl
nickname = <ls_source>-nickname
initials = <ls_source>-initials
nameformat = <ls_source>-nameformat
namcountry = <ls_source>-namcountry
langu_p = <ls_source>-langu_p
sort1_p = <ls_source>-sort1_p
sort2_p = <ls_source>-sort2_p
langu_cr_p = <ls_source>-langu_cr_p
).
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
DATA: lt_data TYPE STANDARD TABLE OF bapiaddr3.
APPEND is_structure_1 TO lt_data.
SELECT SINGLE *
FROM @lt_data AS itab
INTO CORRESPONDING FIELDS OF @cs_structure_2.
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
DATA(lo_descr) = CAST cl_abap_structdescr( cl_abap_structdescr=>describe_by_data( is_structure_1 ) ).
LOOP AT lo_descr->components ASSIGNING FIELD-SYMBOL(<ls_component>).
ASSIGN COMPONENT <ls_component>-name OF STRUCTURE cs_structure_2 TO FIELD-SYMBOL(<ls_target>).
IF sy-subrc = 0.
ASSIGN COMPONENT <ls_component>-name OF STRUCTURE is_structure_1 TO FIELD-SYMBOL(<ls_source>).
<ls_target> = <ls_source>.
ENDIF.
ENDLOOP.
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
DATA(code) = VALUE string_table(
( |REPORT.| )
( |FORM MOVC USING IN TYPE ANY CHANGING OUT TYPE ANY.| )
( | MOVE-CO{ sy-abcde+17(1) WIDTH = 2 PAD = 'R' }ESPONDING IN TO OUT.| )
( |ENDFORM.| ) ).
DATA(repname) = CONV syrepid( |Z%{ sy-uname }_{ sy-uzeit }| ).
INSERT REPORT repname FROM code PROGRAM TYPE 'S'.
IF sy-subrc = 0.
PERFORM movc IN PROGRAM (repname) USING is_structure_1 CHANGING cs_structure_2 IF FOUND.
ENDIF.
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
CALL FUNCTION 'COPY_STRUCTURE_CORRESPONDING'
EXPORTING
im_structure = is_structure_1
IMPORTING
ex_structure = cs_structure_2.
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
cl_abap_corresponding=>create( source = is_structure_1
destination = cs_structure_2
mapping = VALUE #( ) )->execute( EXPORTING source = is_structure_1
CHANGING destination = cs_structure_2 ).
ENDMETHOD.
Code: Alles auswählen.
METHOD korresponding.
DATA: lv_xml TYPE string.
CALL TRANSFORMATION id
SOURCE data = is_structure_1
RESULT XML lv_xml.
CALL TRANSFORMATION id
OPTIONS value_handling = 'accept_data_loss'
SOURCE XML lv_xml
RESULT data = cs_structure_2.
ENDMETHOD.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag (Insgesamt 3):
IHe • ewx • Shortcut IT
Code: Alles auswählen.
REPORT.
CLASS lcl_get DEFINITION.
PUBLIC SECTION.
INTERFACES if_serializable_object.
METHODS constructor.
PRIVATE SECTION.
DATA: mv1 TYPE i,
mv2 TYPE i,
mv3 TYPE i.
ENDCLASS.
CLASS lcl_get IMPLEMENTATION.
METHOD constructor.
mv1 = 1.
mv2 = 2.
mv3 = 3.
ENDMETHOD.
ENDCLASS.
CLASS lcl_put DEFINITION.
PUBLIC SECTION.
INTERFACES if_serializable_object.
DATA: mv2 TYPE i.
ENDCLASS.
END-OF-SELECTION.
DATA: lv_xml TYPE string.
DATA(lo_get) = NEW lcl_get( ).
CALL TRANSFORMATION id
SOURCE oref = lo_get
RESULT XML lv_xml.
**********************************************************************
*** Schummeln ***
**********************************************************************
REPLACE ALL OCCURRENCES OF 'LCL_GET' IN lv_xml WITH 'LCL_PUT'.
**********************************************************************
DATA(lo_put) = NEW lcl_put( ).
WRITE:/ 'Vorher :',lo_put->mv2.
CALL TRANSFORMATION id
SOURCE XML lv_xml
RESULT oref = lo_put.
WRITE:/ 'Nachher:',lo_put->mv2.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
IHe