REPORT demo_cds_currency_conversion. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. PRIVATE SECTION. CLASS-METHODS setup. ENDCLASS. CLASS demo IMPLEMENTATION. METHOD main. DATA(out) = cl_demo_output=>new( ). DATA currency TYPE c LENGTH 5 VALUE 'USD'. cl_demo_input=>request( CHANGING field = currency ). currency = to_upper( currency ). setup( ). SELECT * FROM demo_prices ORDER BY id INTO TABLE @DATA(original_prices). out->begin_section( `Original Prices` )->write( original_prices )->next_section( `Converted Prices` ). IF cl_abap_dbfeatures=>use_features( EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>views_with_parameters ) ) ). TRY. SELECT * FROM demo_cds_currency_conversion( to_currency = @currency, exc_date = @sy-datlo ) ORDER BY id INTO TABLE @DATA(converted_prices) ##db_feature_mode[views_with_parameters]. out->write( converted_prices ). CATCH cx_sy_open_sql_db INTO DATA(exc). out->write( exc->get_text( ) ). ENDTRY. ELSE. out->write( 'Database system does not support views with parameters' ). ENDIF. out->display( ). ENDMETHOD. METHOD setup. DATA prices TYPE SORTED TABLE OF demo_prices WITH UNIQUE KEY id. prices = VALUE #( ( id = 1 amount = '1.00' currency = 'EUR' ) ( id = 2 amount = '1.00' currency = 'GBP' ) ( id = 3 amount = '1.00' currency = 'JPY' ) ( id = 4 amount = '1.00' currency = 'USD' ) ). DELETE FROM demo_prices. INSERT demo_prices FROM TABLE prices. ENDMETHOD. ENDCLASS. START-OF-SELECTION. demo=>main( ). |
|