Casting yn ABAP-programma

KLASSE a1 DEFINISJON.
 Iepenbiere SECTION.
 DATA: num1 TYPE i WAARDE 100.
 METODES: m1.
 ENDKLASSE.
 KLASSE a1 IMPLEMENTERING.
 METODE m1.
 SKRYF: 'a1:', num1.
 ENDMETHODE.
 ENDKLASSE.
 KLASSE b1 DEFINISJE ERVENDE FAN a1.
 Iepenbiere SECTION.
 METHODEN: m2, m1 REDEFINISJE.
 ENDKLASSE.
 KLASSE b1 IMPLEMENTERING.
 METODE m1.
 nûmer1 = nûmer1.
 SKRYF: 'b1:', nûmer1.
 ENDMETHODE.
 METODE m2.
 SKRYF: 'M2 yn klasse b1'.
 ENDMETHODE.
 ENDKLASSE.
 START-OF-SELEKJE.
 DATA: in TYPE REF NEI a1.
 DATA: b TYPE REF TO b1.
 *gegevens: c type REF TO c1.
 ************************************************** ************* OBJECT CREATE b.
 a = b.  "upcasting CALL METHOD a->m1( ).
 *oprop METHODE a->m2( ).  "wy kinne gjin tagong krije ta de eigen subklassemetoaden mei superklasse ref.
 NIJE RIGEL.
 b ?= a.  "down casting CALL METHODE b->m1( ).
 NIJE RIGEL.
 OPROEPMETODE b->m2( ).
 ************************************************** *************** " flater null ref oanmeitsje OBJECT a.
 b ?= a.  "down casting noch altyd syn jaan dump call METHODE b->m1().
 ************************************************** *************** CREATE OBJECT a.
 BESYKJE.
 b ?= a.  "ur besocht in 'NULL' objektreferinsjedump CATCH te brûken cx_sy_move_cast_error.
 OPROEPMETODE b->m1( ).
 ENDTRY.
 ************************************************** *************** CREATE OBJECT a.
 OBJECT CREATE b.
 BESYKJE.
 b ?= a.
 CATCH cx_sy_move_cast_error.
 OPROEPMETODE b->m1( ).
 oprop METHODE b->m2( ).
 ENDTRY.
 KLASSE lcl_shape DEFINISJE.
 Iepenbiere SECTION.
 METHODEN tekenje.
 ENDKLASSE.
 KLASSE lcl_sirkel DEFINISJE ERVERJE FAN lcl_shape.
 Iepenbiere SECTION.
 METHODEN: draw REDEFINITION, calc_area.
 ENDKLASSE.
 KLASSE lcl_shape IMPLEMENTATION.
 METODE tekenje.
 WRITE:/ 'Elke foarm tekenje'.
 ENDMETHODE.
 ENDKLASSE.
 KLASSE lcl_circle IMPLEMENTATION.
 METODE tekenje.
 WRITE:/ 'Speciale foarm tekenje: Circle'.
 ENDMETHODE.
 METHODE calc_area.
 WRITE:/ 'Area Of Crcle = 2iiR'.
 ENDMETHODE.
 ENDKLASSE.
 START-OF-SELEKJE.
 DATA: o_cir TYPE REF TO lcl_circle.
 OBJECT CREATE o_cir.
 CALL METHODE o_cir->draw().  " ropt subklasse Draw() metoade CALL METHOD o_cir->calc_area( ).
 ULINE.
 "--------- Narrow cast (Upcast) ---------------" DATA : o_shp TYPE REF TO lcl_shape.
 o_shp = o_cir.  "Smelle cast (Upcast) CALL METHODE o_shp-> draw ( ).  " ropt subklasse Draw () metoade "rop METHOD o_shp-> calc_area ( ) .  " kompilaasjeflater ULINE.
 "--------- Widening Cast (Downcast) -----------" DATA : o_cir1 TYPE REF TO lcl_circle.
 "o_cir1 = o_shp.  " kompilaasjeflater o_cir1 ?= o_shp.  "Widende Cast (Downcast) CALL METHOD o_cir1->draw( ).  " ropt subklasse Draw() metoade CALL METHOD o_cir1->calc_area( ).
 KLASSE a1 DEFINISJON.
 Iepenbiere SECTION.
 DATA: num1 TYPE i WAARDE 100.
 METODES: m1.
 ENDKLASSE.
 KLASSE a1 IMPLEMENTERING.
 METODE m1.
 SKRYF: 'a1:', num1.
 ENDMETHODE.
 ENDKLASSE.
 KLASSE b1 DEFINISJE ERVENDE FAN a1.
 Iepenbiere SECTION.
 METHODEN: m2, m1 REDEFINISJE.
 ENDKLASSE.
 KLASSE b1 IMPLEMENTERING.
 METODE m1.
 nûmer1 = nûmer1.
 SKRYF: 'b1:', nûmer1.
 ENDMETHODE.
 METODE m2.
 SKRYF: 'M2 yn klasse b1'.
 ENDMETHODE.
 ENDKLASSE.
 START-OF-SELEKJE.
 DATA: âlder TYPE REF TO a1.
 DATA: bern TYPE REF TO b1.
 *gegevens: c type REF TO c1.
 ************************************************** ************** CREATE OBJECT bern.
 âlder = bern.  "upcasting CALL METHOD parent->m1( ).
 CALL METHODE bern->m1( ).
 CALL METHODE bern->m2( ).
 *oprop METHODE a->m2( ).  "wy kinne gjin tagong krije ta de eigen subklassemetoaden mei superklasse ref.
 NIJE RIGEL.
 bern ?= âlder.  "down casting CALL METHOD bern-> m1 ( ).
 NIJE RIGEL.
 CALL METHODE bern->m2( ).
 ************************************************** **************** *" flater null ref *oanmeitsje OBJECT a.
 *b ?= a.  "down casting noch altyd syn jaan dump * call METHODE b-> m1 ( ).
 ************************************************** *************** * OBJECT CREATE a.
 BESYKJE.
 b ?= a.  "ur besocht in 'NULL' objektreferinsjedump CATCH te brûken cx_sy_move_cast_error.
 OPROEPMETODE b->m1( ).
 ENDTRY.
 ************************************************** *************** * OBJECT CREATE a.
 OBJECT CREATE b.
 BESYKJE.
 b ?= a.
 CATCH cx_sy_move_cast_error.
 OPROEPMETODE b->m1( ).
 oprop METHODE b->m2( ).
 ENDTRY.
 ******** Unike wearden****************** DATA : lv_string TYPE string, lv_string2 TYPE string, lv_string_final TYPE string.
 TYPES: BEGIN OF ty_data, auth TYPE c, END OF ty_data.
 DATA: ls_user TYPE ty_data, ls_user2 TYPE ty_data, lt_user2 TYPE TABEL FAN ty_data, lt_user TYPE TABEL FAN ty_data.
 lv_string = 'a,b,c,a'.
 lv_string2 = 'd,b,c,a'.
 SPLIT lv_string AT ',' INTO TABLE lt_user.
 SPLIT lv_string2 AT ',' YN TABEL lt_user2.
 LOOP AT lt_user2 FIELD-SYMBOOL ( ).
 YNFOEGJE INTO TABEL lt_user.
 ENDLOOP.
 SORT lt_user BY auth.
 DELETE ADJACENT DUPLIKATES FROM lt_user Fergelykje auth.
 IF sy-subrc = 0.
 LOOP AT lt_user FIELD-SYMBOOL ( ).
 IF lv_string_final IS INITIAL.
 lv_string_final = -auth.
 OARS.
 CONCATENATE lv_string_final -auth INTO lv_string_final SKEIDEN FAN ','.
 OPHALDE AS.
 ENDLOOP.
 OPHALDE AS.

 

Lit in reaksje efter

Dizze side brûkt Akismet om spam te ferleegjen. Learje hoe't jo kommentaargegevens ferwurke wurde.