Casting am ABAP Programm

KLASS a1 DEFINITION.
 Ëffentlech Sektioun.
 DATA: num1 TYPE i VALUE 100.
 Methode: m1.
 ENDKLASS.
 KLASS a1 IMPLEMENTATIOUN.
 METHODE m1.
 OPSCHREIWEN: 'a1:', num1.
 ENDMETHODE.
 ENDKLASS.
 KLASS b1 DEFINITIOUN Ierf VUN a1.
 Ëffentlech Sektioun.
 METHODEN: m2, m1 REDEFINITION.
 ENDKLASS.
 KLASS b1 ËMSETZUNG.
 METHODE m1.
 num1 = num1.
 OPSCHREIWEN: 'b1:', num1.
 ENDMETHODE.
 METHODE m2.
 OPSCHREIWEN: 'M2 an der Klass b1'.
 ENDMETHODE.
 ENDKLASS.
 START-VUN SELECTION.
 DATA: A TYPE REF BIS a1.
 DATA: b TYPE REF B1.
 *Daten: c Typ REF TO c1.
 ********************************************* ************* CREATE OBJECT b.
 a = b.  "upcasting CALL METHOD a->m1( ).
 *ruff METHODE a->m2( ).  "Mir kënnen net Zougang zu den eegene Ënnerklassmethoden benotze mat Super Class ref.
 NEW-LINE.
 b? = a.  " down casting CALL METHOD b->m1( ).
 NEW-LINE.
 URUFFMETHODE b->m2( ).
 ********************************************* *************** " Feeler null ref erstellen OBJECT a.
 b? = a.  "Down casting nach ëmmer seng Gëff Dump Call METHOD b->m1().
 ********************************************* *************** CREATE OBJECT a.
 PROBEER.
 b? = a.  "ur huet versicht en 'NULL' Objektreferenz Dump CATCH ze benotzen cx_sy_move_cast_error.
 URUFFMETHODE b->m1( ).
 ENDTRY.
 ********************************************* *************** CREATE OBJECT a.
 CREATE OBJECT b.
 PROBEER.
 b? = a.
 CATCH cx_sy_move_cast_error.
 URUFFMETHODE b->m1( ).
 ruffen METHODE b->m2( ).
 ENDTRY.
 CLASS lcl_shape DEFINITION.
 Ëffentlech Sektioun.
 METHODEN zéien.
 ENDKLASS.
 KLASS lcl_circle DEFINITIOUN Ierf VUN lcl_shape.
 Ëffentlech Sektioun.
 METHODEN: Zeechnen REDEFINITION, calc_area.
 ENDKLASS.
 KLASS lcl_shape IMPLEMENTATIOUN.
 METHODE Zeechnen.
 OPSCHREIWEN:/ 'All Form zeechnen'.
 ENDMETHODE.
 ENDKLASS.
 CLASS lcl_circle IMPLEMENTATIOUN.
 METHODE Zeechnen.
 OPSCHREIWEN:/ 'Zeechnen spezifesch Form: Krees'.
 ENDMETHODE.
 METHOD calc_area.
 OPSCHREIWEN:/ 'Area Of Crcle = 2iiR'.
 ENDMETHODE.
 ENDKLASS.
 START-VUN SELECTION.
 DATA : o_cir TYPE REF BIS lcl_circle.
 CREATE OBJECT o_cir.
 CALL METHOD o_cir->draw( ).  " rifft d'Ënnerklass Draw() Method CALL METHOD o_cir->calc_area( ).
 ULINE.
 "--------- Schmuel Besetzung (Upcast) ---------------" DATA : o_shp TYPE REF BIS lcl_shape.
 o_shp = o_cir.  "Schmuel Cast(Upcast) CALL METHOD o_shp->draw( ).  " rifft d'Ënnerklass Draw() Method "ruff METHOD o_shp->calc_area() .  " Kompiléierungsfehler ULINE.
 "--------- Widening Cast (Downcast) -----------" DATA : o_cir1 TYPE REF BIS lcl_circle.
 "o_cir1 = o_shp.  " Kompiléierungsfehler o_cir1 ?= o_shp.  "Verlängeren Cast (Downcast) CALL METHOD o_cir1->draw().  " rifft d'Ënnerklass Draw() Method CALL METHOD o_cir1->calc_area( ).
 KLASS a1 DEFINITION.
 Ëffentlech Sektioun.
 DATA: num1 TYPE i VALUE 100.
 Methode: m1.
 ENDKLASS.
 KLASS a1 IMPLEMENTATIOUN.
 METHODE m1.
 OPSCHREIWEN: 'a1:', num1.
 ENDMETHODE.
 ENDKLASS.
 KLASS b1 DEFINITIOUN Ierf VUN a1.
 Ëffentlech Sektioun.
 METHODEN: m2, m1 REDEFINITION.
 ENDKLASS.
 KLASS b1 ËMSETZUNG.
 METHODE m1.
 num1 = num1.
 OPSCHREIWEN: 'b1:', num1.
 ENDMETHODE.
 METHODE m2.
 OPSCHREIWEN: 'M2 an der Klass b1'.
 ENDMETHODE.
 ENDKLASS.
 START-VUN SELECTION.
 DATA: Elterendeel TYPE REF BIS a1.
 DATA: Kand TYPE REF B1.
 *Daten: c Typ REF TO c1.
 ********************************************* ************** CREATE OBJECT Kand.
 Elterendeel = Kand.  "upcasting CALL METHOD parent->m1( ).
 URUFF METHODE Kand->m1( ).
 URUFF METHODE Kand->m2( ).
 *ruff METHODE a->m2( ).  "Mir kënnen net Zougang zu den eegene Ënnerklassmethoden benotze mat Super Class ref.
 NEW-LINE.
 Kand ?= Elterendeel.  " down casting CALL METHOD Kand-> m1( ).
 NEW-LINE.
 URUFF METHODE Kand->m2( ).
 ********************************************* **************** *" Feeler null ref * OBJECT erstellen a.
 *b ?= a.  "Down casting still its give dump *call METHOD b->m1( ).
 ********************************************* **************** * CREATE OBJECT a.
 PROBEER.
 b? = a.  "ur huet versicht en 'NULL' Objektreferenz Dump CATCH ze benotzen cx_sy_move_cast_error.
 URUFFMETHODE b->m1( ).
 ENDTRY.
 ********************************************* **************** * CREATE OBJECT a.
 CREATE OBJECT b.
 PROBEER.
 b? = a.
 CATCH cx_sy_move_cast_error.
 URUFFMETHODE b->m1( ).
 ruffen METHODE b->m2( ).
 ENDTRY.
 ******** Eenzegaarteg Wäerter****************** DATA : lv_string TYPE String, lv_string2 TYPE String, lv_string_final TYPE String.
 TYPEN: BEGIN VUN ty_data, auth TYPE c, END OF ty_data.
 DATA: ls_user TYPE ty_data, ls_user2 TYPE ty_data, lt_user2 TYPE TABEL VUN ty_data, lt_user TYPE TABEL VUN ty_data.
 lv_string = 'a,b,c,a'.
 lv_string2 = 'd,b,c,a'.
 SPLIT lv_string AT ',' AN TABEL lt_user.
 SPLIT lv_string2 AT ',' AN TABEL lt_user2.
 LOOP AT lt_user2 ASSIGNING FIELD-SYMBOL( ).
 INSERT AN TABEL lt_user.
 ENDLOOP.
 SORT lt_user BY auth.
 LËSCHT ADJACENT DUPLICATEN VUN lt_user VERGLECHTEN auth.
 IF sy-subrc = 0.
 LOOP AT lt_user ASSIGNING FIELD-SYMBOL( ).
 WANN lv_string_final IS INITIAL.
 lv_string_final = -auth.
 ANNER.
 CONCATENATE lv_string_final -auth INTO lv_string_final GESPARAT VUN ','.
 ENDIF.
 ENDLOOP.
 ENDIF.

 

Hannerlooss eng Bemierkung

Dëse Site benotzt Akismet fir Spam ze reduzéieren. Léiert wéi Är Kommentarfaten veraarbecht ginn.