分享

一个使用CDS VIEW 的 DEMO

 一骑当千_30 2018-07-06
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( ).



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多