Advertisement
Guest User

HANA currency conversion

a guest
Jul 30th, 2014
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. CLASS zbc_currency_conversion_hana DEFINITION
  2. PUBLIC
  3. FINAL
  4. CREATE PUBLIC .
  5.  
  6. PUBLIC SECTION.
  7. types: BEGIN OF ls_vbak,
  8. so_id type snwd_so-so_id,
  9. net_amount type snwd_so-net_amount,
  10. currency_code type snwd_so-currency_code,
  11. end of ls_vbak.
  12.  
  13. data: lt_vbak type STANDARD TABLE OF ls_vbak.
  14. data: wa_vbak like line of lt_vbak.
  15.  
  16. "Specify the interface that it is a HANA connection class
  17. INTERFACEs if_amdp_marker_hdb.
  18.  
  19. types: lt_amount type standard TABLE OF ZCURR_CONV_HANA.
  20.  
  21. METHODS convert_currency_snwd
  22. IMPORTING
  23. value(it_conv_prices) like lt_vbak
  24. value(iv_mandt) type mandt
  25. value(iv_target_unit) type waerk
  26. value(iv_ref_date) type char10
  27. EXPORTING
  28. value(et_amount) type lt_amount.
  29.  
  30. METHODS convert_currency
  31. IMPORTING
  32. value(it_conv_prices) type lt_amount
  33. value(iv_mandt) type mandt
  34. EXPORTING
  35. value(et_amount) type lt_amount.
  36. PROTECTED SECTION.
  37. PRIVATE SECTION.
  38.  
  39. ENDCLASS.
  40.  
  41.  
  42.  
  43. CLASS ZBC_CURRENCY_CONVERSION_HANA IMPLEMENTATION.
  44.  
  45.  
  46. METHOD convert_currency BY DATABASE PROCEDURE FOR HDB
  47. LANGUAGE SQLSCRIPT.
  48.  
  49. *BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT needs to be typed in to specify that we are using AMDP procedures
  50.  
  51. *Start creating the input table for the procedure CE_CONVERSION
  52. PRICES = select id as id, in_amount as in_amount, source_unit as source_unit, target_unit as target_unit, ref_date as ref_date from :it_conv_prices;
  53.  
  54.  
  55. *Here we call the CE_CONVERSION method and specifying that the result should be stored in the variable lt_uom_std_conv
  56. lt_uom_std_conv = CE_CONVERSION(:PRICES, [family = 'currency',
  57. method = 'ERP',
  58. client = :iv_mandt,
  59. conversion_type = 'M',
  60. steps = 'shift,convert,shift_back',
  61. target_unit_column = target_unit,
  62. source_unit_column = source_unit,
  63. reference_date_column = ref_date],
  64. [ in_amount AS out_amount ] );
  65.  
  66. *The select statement for the output table is an inner join using id.
  67. et_amount =
  68. select
  69. lt.id as id,
  70. dm.in_amount as in_amount,
  71. lt.out_amount as out_amount,
  72. dm.source_unit as source_unit,
  73. dm.target_unit as target_unit,
  74. dm.ref_date as ref_date
  75. from :lt_uom_std_conv as lt
  76. inner join :prices as dm on dm.id=lt.id;
  77. ENDMETHOD.
  78.  
  79.  
  80. METHOD convert_currency_snwd BY DATABASE PROCEDURE FOR HDB
  81. LANGUAGE SQLSCRIPT using snwd_so.
  82. *BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT needs to be typed in to specify that we are using AMDP procedures
  83.  
  84. *Start creating the input table for the procedure CE_CONVERSION
  85. PRICES = select so_id as so_id, net_amount as in_amount, currency_code as source_unit from snwd_so;
  86.  
  87.  
  88. *Here we call the CE_CONVERSION method and specifying that the result should be stored in the variable lt_uom_std_conv
  89. lt_uom_std_conv = CE_CONVERSION(:PRICES, [family = 'currency',
  90. method = 'ERP',
  91. client = :iv_mandt,
  92. conversion_type = 'M',
  93. steps = 'shift,convert,shift_back',
  94. target_unit = :iv_target_unit,
  95. source_unit_column = source_unit,
  96. reference_date = :iv_ref_date],
  97. [ in_amount AS out_amount ] );
  98.  
  99. *The select statement for the output table is an inner join using id.
  100. et_amount =
  101. select
  102. lt.so_id as id,
  103. dm.in_amount as in_amount,
  104. lt.out_amount as out_amount,
  105. dm.source_unit as source_unit,
  106. :iv_target_unit as target_unit,
  107. :iv_ref_date as ref_date
  108. from :lt_uom_std_conv as lt
  109. inner join :prices as dm on dm.so_id=lt.so_id;
  110.  
  111. ENDMETHOD.
  112. ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement