zoukankan      html  css  js  c++  java
  • abap 币别汇率查询

    1.说明

      查询sap 汇率

    2.使用function

      币别因子: CURRENCY_CONVERTING_FACTOR

      转换 CONVERT_TO_LOCAL_CURRENCY

    3.屏幕参数说明

    4.实现效果

    5.完整代码

      1 *&---------------------------------------------------------------------*
      2 *& Report ZMMRTEST2
      3 *&---------------------------------------------------------------------*
      4 *&
      5 *&---------------------------------------------------------------------*
      6 REPORT ZMMRTEST2 NO STANDARD PAGE HEADING
      7                  MESSAGE-ID 00 LINE-SIZE 177 LINE-COUNT 200.
      8 
      9 DATA:BEGIN OF alv_data occurs 0,
     10 datum LIKE eine-erdat ,"日期
     11 f_konwa LIKE konp-konwa," 来源货币
     12 f_netpr TYPE p DECIMALS 2,
     13 l_konwa LIKE konp-konwa ," 目标货币
     14 l_netpr TYPE p DECIMALS 2,
     15 EX_KURS TYPE p DECIMALS 5,"汇率
     16 END OF alv_data.
     17 
     18 DATA: gs_layout TYPE slis_layout_alv,
     19           gt_fieldcat TYPE slis_t_fieldcat_alv ,"with header line.
     20           wa_fieldcat TYPE slis_fieldcat_alv.
     21 ************************************************************************
     22 * Includes Module
     23 ************************************************************************
     24 
     25 ************************************************************************
     26 * Selection Screen
     27 ************************************************************************
     28 SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.
     29   PARAMETERS:p_datum LIKE eine-erdat OBLIGATORY,"日期
     30                       f_konwa LIKE konp-konwa OBLIGATORY," 来源货币
     31                       f_netpr TYPE p DECIMALS 2 OBLIGATORY,"来源金额
     32                       l_konwa LIKE konp-konwa OBLIGATORY." 目标货币
     33 SELECTION-SCREEN END OF BLOCK b1.
     34 
     35 ************************************************************************
     36 * Initialization
     37 ************************************************************************
     38 INITIALIZATION.
     39 
     40 ************************************************************************
     41 * At Selection Screen
     42 ************************************************************************
     43 AT SELECTION-SCREEN.
     44 
     45 ************************************************************************
     46 * At Selection Screen Output
     47 ************************************************************************
     48 AT SELECTION-SCREEN OUTPUT.
     49 
     50 ************************************************************************
     51 * Report Format
     52 ************************************************************************
     53 TOP-OF-PAGE.
     54 
     55 END-OF-PAGE.
     56 ************************************************************************
     57 * Main Process
     58 ************************************************************************
     59 START-OF-SELECTION.
     60      PERFORM get_data.
     61      PERFORM get_col.
     62      PERFORM alv_show.
     63 END-OF-SELECTION.
     64 
     65 FORM get_data.
     66 
     67 data:
     68       KURS       LIKE TCURR-UKURS,
     69       FIX_KURS    LIKE KURS,
     70       EX_KURS     LIKE KURS,
     71       FFACT       LIKE TCURR-FFACT,
     72       TFACT       LIKE TCURR-TFACT,
     73       z_btr like mbew-salk3,
     74       KURST      LIKE TCURR-KURST.
     75 
     76 DATA: f_factor TYPE isoc_factor.
     77 DATA: l_factor TYPE isoc_factor.
     78 
     79   IF f_netpr is INITIAL.
     80     f_netpr = 1.
     81   ENDIF.
     82 
     83     CLEAR:alv_data[].
     84 
     85     CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
     86           EXPORTING
     87             DATE              = p_datum
     88             FOREIGN_AMOUNT    = f_netpr
     89             FOREIGN_CURRENCY  = f_konwa
     90             LOCAL_CURRENCY    = l_konwa
     91 *           RATE              = 0
     92            TYPE_OF_RATE      = 'M'
     93          IMPORTING
     94             FOREIGN_FACTOR    = FFACT
     95             LOCAL_FACTOR      = TFACT
     96             EXCHANGE_RATE     = EX_KURS
     97             DERIVED_RATE_TYPE = KURST
     98             LOCAL_AMOUNT      = z_btr
     99             FIXED_RATE        = FIX_KURS
    100          EXCEPTIONS
    101             OTHERS            = 6.
    102 
    103      CLEAR:f_factor,l_factor.
    104      CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
    105           EXPORTING
    106             currency =  f_konwa
    107          IMPORTING
    108            factor = f_factor.
    109 
    110       CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
    111           EXPORTING
    112             currency =  l_konwa
    113          IMPORTING
    114            factor = l_factor.
    115 
    116           alv_data-datum = p_datum ."日期
    117           alv_data-f_konwa = f_konwa." 来源货币
    118           alv_data-f_netpr = f_netpr.
    119           alv_data-l_konwa = l_konwa ." 目标货币
    120           alv_data-l_netpr = z_btr / f_factor * l_factor.
    121           alv_data-EX_KURS = EX_KURS.
    122           APPEND alv_data.  CLEAR alv_data.
    123 
    124 ENDFORM.
    125 
    126   FORM GET_COL.
    127       DATA: L_REPID    TYPE SY-REPID,
    128           L_INCLNAME TYPE TRDIR-NAME,
    129           L_IDX      LIKE SY-TABIX.
    130     CLEAR: GT_FIELDCAT[], WA_FIELDCAT.
    131 
    132     L_REPID = L_INCLNAME = SY-CPROG.
    133 
    134     CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    135       EXPORTING
    136         I_PROGRAM_NAME         = L_REPID
    137         I_INTERNAL_TABNAME     = 'ALV_DATA'
    138         I_INCLNAME             = L_INCLNAME
    139       CHANGING
    140         CT_FIELDCAT            = GT_FIELDCAT
    141       EXCEPTIONS
    142         INCONSISTENT_INTERFACE = 1
    143         PROGRAM_ERROR          = 2
    144         OTHERS                 = 3.
    145 
    146    LOOP AT gt_fieldcat INTO wa_fieldcat.
    147       l_idx = sy-tabix.
    148         CASE wa_fieldcat-fieldname.
    149           WHEN 'DATUM'.
    150             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    151             wa_fieldcat-seltext_l = '转换日期'.
    152             wa_fieldcat-ddictxt = 'S'.
    153           WHEN 'F_KONWA'.
    154             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    155             wa_fieldcat-seltext_l = '来源货币'.
    156             wa_fieldcat-ddictxt = 'S'.
    157           WHEN 'F_NETPR'.
    158             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    159             wa_fieldcat-seltext_l = '转换金额'.
    160             wa_fieldcat-ddictxt = 'S'.
    161           WHEN 'L_KONWA'.
    162             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    163             wa_fieldcat-seltext_l = '本地货币(目标货币)'.
    164             wa_fieldcat-ddictxt = 'S'.
    165           WHEN 'L_NETPR'.
    166             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    167             wa_fieldcat-seltext_l = '金额'.
    168             wa_fieldcat-ddictxt = 'S'.
    169           WHEN 'EX_KURS'.
    170             wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    171             wa_fieldcat-seltext_l = '汇率'.
    172             wa_fieldcat-ddictxt = 'S'.
    173 *          WHEN 'WRBTR1'.
    174 *            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
    175 *            wa_fieldcat-seltext_l = '金额'.
    176 *            wa_fieldcat-ddictxt = 'S'.
    177         ENDCASE.
    178 *      CLEAR wa_fieldcat-key.
    179       MODIFY gt_fieldcat FROM wa_fieldcat INDEX l_idx.
    180     ENDLOOP.
    181 ENDFORM.
    182 
    183   FORM ALV_SHOW.
    184       DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
    185       CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    186             EXPORTING
    187                 I_CALLBACK_PROGRAM = SY-REPID
    188                 IS_LAYOUT                   = GS_LAYOUT
    189                 IT_FIELDCAT                  = GT_FIELDCAT[]
    190                  I_SAVE                         = 'A'
    191                TABLES
    192                    T_OUTTAB                   = ALV_DATA
    193                 EXCEPTIONS
    194                   PROGRAM_ERROR      = 1
    195                 OTHERS                     = 2.
    196 ENDFORM.
  • 相关阅读:
    设计模式复习-状态模式
    设计模式复习-观察者模式
    设计模式复习-建造者模式
    设计模式复习-外观模式
    推荐算法-协同过滤
    设计模式复习-模板方法模式
    设计模式复习-原型模式
    设计模式复习-代理模式
    神经网络与机器学习 笔记—泛化和交叉验证
    神经网络与机器学习 笔记—改善反向传播的性能试探法
  • 原文地址:https://www.cnblogs.com/Brokenshelltao/p/13509312.html
Copyright © 2011-2022 走看看