Get Example source ABAP code based on a different SAP table
• CASE TYPE OF ABAP Statement
CASE TYPE OF> Short Reference >
ABAP_SYNTAX CASE TYPE OF oref.> $[WHEN TYPE class$|intf $[INTO target1$].> $[statement_block1$]$]> $[WHEN TYPE class$|intf $[INTO target2$].> $[statement_block2$]$]> ...> $[WHEN OTHERS.> $[statement_blockn$]$]> ENDCASE.>
ABAP Addition ... INTO target>
What does it do? Special case distinction> for object reference variables>. This form of a control structure introduced using CASE >> checks the dynamic type> of a non-initial object reference variable and the static type> of an initial object reference variable oref>. oref> expects an object reference variable with the static type of a class or an interface. oref> is a general expression position>. A class class> or an interface intf> that can be used at this position must be specified after WHEN TYPE>. The first statement block statement_block> is executed for which the class class> or the interface intf> is more general than or equal to the following:
A dynamic type of a non-initial object reference variable oref>
A static type of an initial object reference variable oref> If this does not apply to any class class> or interface intf >, the statement block is executed after WHEN OTHERS>. No object type class> or intf> can be specified if it is known statically that it does not fulfill the condition.
Latest notes:
A case distinction using CASE TYPE OF> is another way of writing the following branch using IF>> and the predicate expression IS INSTANCE OF>> and the corresponding rules and notes apply: IF oref IS INSTANCE OF> class$|intf. $[statement_block1$] ELSEIF oref IS INSTANCE OF> class$|intf. $[statement_block2$] ... ELSE. $[statement_blockn$] ENDIF.>
In the control structure, more specific classes class> or interfaces intf> must be listed before more general classes or interfaces to enable the associated statement block to be executed. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Case distinction for the dynamic type of an object reference variable oref>, from more specific to more general classes. In the case shown, c2> is the first class that fulfills the condition. oref> can be assigned to ref2> with static type c2> without raising an exception. ABEXA 00088 ABAP_EXAMPLE_END
ABAP_EXAMPLE_ABEXA Case Distinction CASE TYPE OF > for Exceptions> ABAP_EXAMPLE_END • INTO CASE TYPE OF
ABAP Addition
What does it do? For every statement WHEN TYPE> of a case distinction introduced using CASE TYPE OF>, a target variable target> can be specified after the optional addition INTO> as follows:
An existing object reference variable> ref> whose static type> is more general than or equal to the class class> or interface intf> specified in the statement.
An inline declaration DATA(ref)>> or FINAL(ref)>>. In this case, an object reference variable with the static type of the class class> or the interface intf> is declared. If the addition INTO> is specified in the first WHEN> statement that fulfills the condition, the reference oref> is assigned to ref> before the statement block is executed, whereby both upcasts> and downcasts> can be performed.
Latest notes: The statement WHEN TYPE class$|intf INTO ref.> is a semantically identical short form of WHEN TYPE class$|intf. ref = oref.> The statement WHEN TYPE class$|intf INTO DATA(ref).> is a semantically identical short form of WHEN TYPE class$|intf. DATA(ref) = CAST class$|intf( oref ).> NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 The following case distinction shows the short form of the case distinction of the previous example. ABEXA 00089 ABAP_EXAMPLE_END
ABAP_EXAMPLE_ABEXA Case Distinction CASE TYPE OF> for RTTI> ABAP_EXAMPLE_END