ABAP 7.4/7.5 in OOPS:
--------------------------------------------------------------------------------------
1 Upcasting/Downcasting with CAST
Before:
DATA lo_structure TYPE REF TO CL_ABAP_STRUCTDESCR. "Structure_description
DATA lo_components TYPE ABAP_COMPDESCR_TAB.
lo_structure ?= cl_abap_typedescr=>describe_by_name( 'ZSC_MONSTER_HEADER' ).
lo_components = structure_description->components.
After:
DATA(lo_components) = CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( 'ZSC_MONSTER_HEADER' ) )->components.
--------------------------------------------------------------------------------------
2 Finding the Subclass of an Object Instance
DATA: full_screen_adapter TYPE REF TO cl_salv_fullscreen_adapter,
container_adapter TYPE REF TO cl_salv_grid_adapter.
TRY.
"Presume full screen mode (No Container)
"Fullscreen Adapter (Down Casting)
"Target FULL_SCREEN_ADAPTER = CL_SALV_FULLSCREEN_ADAPTER
"CL_SALV_FULLSCREEN is a subclass of CL_SALV_ADAPTER
full_screen_adapter ?= io_salv_adapter.
"Get the Grid
ro_alv_grid = full_screen_adapter->get_grid( ).
CATCH cx_sy_move_cast_error.
"We must be in container mode
"CL_SALV_GRID_ADAPTER is a subclass of CL_SALV_ADAPTER
container_adapter ?= io_salv_adapter.
ro_alv_grid = container_adapter->get_grid( ).
ENDTRY.
After:
IF io_salv_adapter IS INSTANCE OF cl_salv_fullscreen_adapter.
full_screen_adapter ?= io_salv_adapter.
ro_alv_grid = full_screen_adapter->get_grid( ).
ELSEIF io_salv_adapter IS INSTANCE OF cl_salv_grid_adapter.
container_adapter ?= io_salv_adapter.
ro_alv_grid = container_adapter->get_grid( ).
ENDIF.
-------------------------------------------------------------
CASE TYPE OF io_salv_adapter.
WHEN TYPE cl_salv_fullscreen_adapter INTO DATA(full_screen_adapter2).
ro_alv_grid = full_screen_adapter2->get_grid( ).
WHEN TYPE cl_salv_grid_adapter INTO DATA(container_adapter2).
ro_alv_grid = container_adapter2->get_grid( ).
WHEN OTHERS.
RETURN.
ENDCASE.
--------------------------------------------------------------------------------------
3 CHANGING and EXPORTING Parameters
DATA: monster_number TYPE zde_monster_number VALUE '0000000001',
something_spurious TYPE string,
something_unrelated TYPE string.
DATA(monster_header_record) = lcl_monster=>get_details(
EXPORTING id_monster_number = monster_number
IMPORTING ed_something_spurious = something_spurious
CHANGING cd_something_unrelated = something_unrelated ).
--------------------------------------------------------------------------------------
4 Changes to Interfaces
INTERFACE scary_behavior.
METHODS: scare_small_children,
sells_mortgages DEFAULT FAIL,
hide_under_bed DEFAULT IGNORE,
is_fire_breather
DEFAULT IGNORE
RETURNING rf_yes_it_is TYPE abap_bool.
ENDINTERFACE. "Scary Behavior
--------------------------------------------------------------------------------------
0 comments:
Post a Comment