一個使用CDS VIEW 的 DEMO


一個使用CDS VIEW 的demo

 1 REPORT demo_cds_currency_conversion.
 2 
 3 CLASS demo DEFINITION.
 4   PUBLIC SECTION.
 5     CLASS-METHODS main.
 6   PRIVATE SECTION.
 7     CLASS-METHODS setup.
 8 ENDCLASS.
 9 
10 CLASS demo IMPLEMENTATION.
11   METHOD main.
12     DATA(out) = cl_demo_output=>new( ).
13 
14     DATA currency TYPE c LENGTH 5 VALUE 'USD'.
15     cl_demo_input=>request( CHANGING field = currency ).
16     currency = to_upper( currency ).
17     setup( ).
18 
19     SELECT *
20            FROM demo_prices
21            ORDER BY id
22            INTO TABLE @DATA(original_prices).
23 
24     out->begin_section( `Original Prices`
25       )->write( original_prices
26       )->next_section( `Converted Prices` ).
27 
28     IF cl_abap_dbfeatures=>use_features(
29       EXPORTING
30         requested_features =
31           VALUE #( ( cl_abap_dbfeatures=>views_with_parameters ) ) ).
32       TRY.
33           SELECT *
34                  FROM demo_cds_currency_conversion(
35                         to_currency = @currency, exc_date = @sy-datlo )
36                  ORDER BY id
37                  INTO TABLE @DATA(converted_prices)
38                  ##db_feature_mode[views_with_parameters].
39           out->write( converted_prices ).
40         CATCH cx_sy_open_sql_db INTO DATA(exc).
41           out->write( exc->get_text( ) ).
42       ENDTRY.
43     ELSE.
44       out->write(
45             'Database system does not support views with parameters' ).
46     ENDIF.
47 
48     out->display( ).
49   ENDMETHOD.
50   METHOD setup.
51     DATA prices TYPE SORTED TABLE OF demo_prices
52                 WITH UNIQUE KEY id.
53     prices = VALUE #(
54       ( id = 1 amount = '1.00' currency = 'EUR' )
55       ( id = 2 amount = '1.00' currency = 'GBP' )
56       ( id = 3 amount = '1.00' currency = 'JPY' )
57       ( id = 4 amount = '1.00' currency = 'USD' ) ).
58 
59     DELETE FROM demo_prices.
60     INSERT demo_prices FROM TABLE prices.
61   ENDMETHOD.
62 ENDCLASS.
63 
64 START-OF-SELECTION.
65   demo=>main( ).

 

 

 

----------------湊字數-------------------------

勵志美文、《抉擇》
  
人的一生常處於抉擇之中,如:念哪一間大學?選哪一種職業?娶哪一種女子?……等等傷腦筋的事情。一個人抉擇力的有無,可以顯示其人格成熟與否。
  
倒是哪些胸無主見的人,不受抉擇之苦。因為逢到需要決定的時候,他總是求詢別人說:"嘿,你看怎么做?"
  
大凡能夠成大功業的人,都是抉擇力甚強的人。他知道事之成敗,全在乎已沒有人可以代勞,更沒有人能代你決定。
  
在抉擇的哪一刻,成敗實已露出端倪。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM