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( ).

一个使用CDS VIEW 的 DEMO

一个使用CDS VIEW 的 DEMO

相关文章:

  • 2021-07-29
  • 2022-12-23
  • 2021-06-13
  • 2021-10-12
  • 2022-12-23
  • 2021-06-06
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2021-08-21
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案