Update
This commit is contained in:
@@ -460,7 +460,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
|
|||||||
DO.
|
DO.
|
||||||
"sy-index represents the position of a structure component
|
"sy-index represents the position of a structure component
|
||||||
|
|
||||||
ASSIGN <struct>-(sy-index) to <comp>.
|
ASSIGN <struct>-(sy-index) TO <comp>.
|
||||||
|
|
||||||
"Old syntax
|
"Old syntax
|
||||||
"ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
|
"ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
|
||||||
@@ -1458,6 +1458,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
|
|||||||
|
|
||||||
"In the example, the SELECT list that is used in a SELECT statement is
|
"In the example, the SELECT list that is used in a SELECT statement is
|
||||||
"determined at runtime.
|
"determined at runtime.
|
||||||
|
"Note: Check out the CL_ABAP_DYN_PRG class, which supports dynamic programming by
|
||||||
|
"checking the validity of dynamic specifications. See an example below.
|
||||||
|
|
||||||
DATA(select_list) = lcl_det_at_runtime=>get_dyn_select_list( ).
|
DATA(select_list) = lcl_det_at_runtime=>get_dyn_select_list( ).
|
||||||
|
|
||||||
@@ -1512,8 +1514,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
output->next_section( `37) Excursion: Multiple Dynamically Specified ` &&
|
output->next_section( `37a) Excursion: Multiple Dynamically ` &&
|
||||||
`Clauses in an ABAP SQL SELECT Statement` ).
|
`Specified Clauses in an ABAP SQL SELECT Statement` ).
|
||||||
|
|
||||||
"In this example, multiple clauses in a SELECT statement are
|
"In this example, multiple clauses in a SELECT statement are
|
||||||
"determined at runtime to demonstrate the rich variety of possibilities.
|
"determined at runtime to demonstrate the rich variety of possibilities.
|
||||||
@@ -1548,6 +1550,46 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
|
|||||||
output->display( `There's an issue with syntax elements.` ).
|
output->display( `There's an issue with syntax elements.` ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
output->next_section( `37b) Excursion: Checking the validity of dynamic specifications` ).
|
||||||
|
"The following example uses the CL_ABAP_DYN_PRG class, which supports
|
||||||
|
"dynamic programming by checking the validity of dynamic specifications.
|
||||||
|
"Check out the class documentation for more information.
|
||||||
|
"In the example, several table names are provided in a string table that
|
||||||
|
"is looped over. Some wrong table names are intentionally included.
|
||||||
|
"You can provide the "packages" formal parameter with a table that contains
|
||||||
|
"the names of packages in which the tables should be included. The
|
||||||
|
"assumption is that you imported the repository into the package
|
||||||
|
"specified. If you imported it into a package with a different name,
|
||||||
|
"change the value accordingly. Otherwise, none of the tables is found.
|
||||||
|
|
||||||
|
DATA(table_names) = VALUE string_table( ( `ZDEMO_ABAP_CARR` )
|
||||||
|
( `ZDEMO_ABAP_FLI` )
|
||||||
|
( `NO_DBTAB` )
|
||||||
|
( `ZDEMO_ABAP_FLSCH` )
|
||||||
|
( `ZDEMO_ABAP_FLI2` )
|
||||||
|
( `WRONG_DBTAB` ) ).
|
||||||
|
|
||||||
|
DATA(check_packages) = VALUE string_hashed_table( ( `TEST_ABAP_CHEAT_SHEETS` ) ).
|
||||||
|
|
||||||
|
DATA dbtab TYPE string.
|
||||||
|
|
||||||
|
LOOP AT table_names INTO DATA(wa_tab).
|
||||||
|
TRY.
|
||||||
|
dbtab = cl_abap_dyn_prg=>check_table_name_tab( val = to_upper( wa_tab )
|
||||||
|
packages = check_packages ).
|
||||||
|
|
||||||
|
SELECT SINGLE * FROM (dbtab) INTO NEW @DATA(ref_wa).
|
||||||
|
|
||||||
|
output->display( |Result for { wa_tab }| ).
|
||||||
|
output->display( ref_wa->* ).
|
||||||
|
CATCH cx_abap_not_a_table cx_abap_not_in_package INTO DATA(err).
|
||||||
|
output->display( |Result for { wa_tab }| ).
|
||||||
|
output->display( err->get_text( ) ).
|
||||||
|
ENDTRY.
|
||||||
|
ENDLOOP.
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
output->next_section( `38) Dynamic Invoke` ).
|
output->next_section( `38) Dynamic Invoke` ).
|
||||||
@@ -2102,4 +2144,4 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
|
|||||||
output->display( input = ref_tab->* name = `ref_tab->*` ).
|
output->display( input = ref_tab->* name = `ref_tab->*` ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
Reference in New Issue
Block a user