matinal:SAP ABAP 币别汇率查询

2024-05-26 18:22:39 浏览数 (2)

1.说明

  查询sap 汇率

2.使用function

  币别因子: CURRENCY_CONVERTING_FACTOR

  转换 CONVERT_TO_LOCAL_CURRENCY

3.屏幕参数说明

4.实现效果

5.完整代码

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZMMRTEST2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMMRTEST2 NO STANDARD PAGE HEADING
                 MESSAGE-ID 00 LINE-SIZE 177 LINE-COUNT 200.

DATA:BEGIN OF alv_data occurs 0,
datum LIKE eine-erdat ,"日期
f_konwa LIKE konp-konwa," 来源货币
f_netpr TYPE p DECIMALS 2,
l_konwa LIKE konp-konwa ," 目标货币
l_netpr TYPE p DECIMALS 2,
EX_KURS TYPE p DECIMALS 5,"汇率
END OF alv_data.

DATA: gs_layout TYPE slis_layout_alv,
          gt_fieldcat TYPE slis_t_fieldcat_alv ,"with header line.
          wa_fieldcat TYPE slis_fieldcat_alv.
************************************************************************
* Includes Module
************************************************************************

************************************************************************
* Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.
  PARAMETERS:p_datum LIKE eine-erdat OBLIGATORY,"日期
                      f_konwa LIKE konp-konwa OBLIGATORY," 来源货币
                      f_netpr TYPE p DECIMALS 2 OBLIGATORY,"来源金额
                      l_konwa LIKE konp-konwa OBLIGATORY." 目标货币
SELECTION-SCREEN END OF BLOCK b1.

************************************************************************
* Initialization
************************************************************************
INITIALIZATION.

************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN.

************************************************************************
* At Selection Screen Output
************************************************************************
AT SELECTION-SCREEN OUTPUT.

************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.

END-OF-PAGE.
************************************************************************
* Main Process
************************************************************************
START-OF-SELECTION.
     PERFORM get_data.
     PERFORM get_col.
     PERFORM alv_show.
END-OF-SELECTION.

FORM get_data.

data:
      KURS       LIKE TCURR-UKURS,
      FIX_KURS    LIKE KURS,
      EX_KURS     LIKE KURS,
      FFACT       LIKE TCURR-FFACT,
      TFACT       LIKE TCURR-TFACT,
      z_btr like mbew-salk3,
      KURST      LIKE TCURR-KURST.

DATA: f_factor TYPE isoc_factor.
DATA: l_factor TYPE isoc_factor.

  IF f_netpr is INITIAL.
    f_netpr = 1.
  ENDIF.

    CLEAR:alv_data[].

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
          EXPORTING
            DATE              = p_datum
            FOREIGN_AMOUNT    = f_netpr
            FOREIGN_CURRENCY  = f_konwa
            LOCAL_CURRENCY    = l_konwa
*           RATE              = 0
           TYPE_OF_RATE      = 'M'
         IMPORTING
            FOREIGN_FACTOR    = FFACT
            LOCAL_FACTOR      = TFACT
            EXCHANGE_RATE     = EX_KURS
            DERIVED_RATE_TYPE = KURST
            LOCAL_AMOUNT      = z_btr
            FIXED_RATE        = FIX_KURS
         EXCEPTIONS
            OTHERS            = 6.

     CLEAR:f_factor,l_factor.
     CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
          EXPORTING
            currency =  f_konwa
         IMPORTING
           factor = f_factor.

      CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
          EXPORTING
            currency =  l_konwa
         IMPORTING
           factor = l_factor.

          alv_data-datum = p_datum ."日期
          alv_data-f_konwa = f_konwa." 来源货币
          alv_data-f_netpr = f_netpr.
          alv_data-l_konwa = l_konwa ." 目标货币
          alv_data-l_netpr = z_btr / f_factor * l_factor.
          alv_data-EX_KURS = EX_KURS.
          APPEND alv_data.  CLEAR alv_data.

ENDFORM.

  FORM GET_COL.
      DATA: L_REPID    TYPE SY-REPID,
          L_INCLNAME TYPE TRDIR-NAME,
          L_IDX      LIKE SY-TABIX.
    CLEAR: GT_FIELDCAT[], WA_FIELDCAT.

    L_REPID = L_INCLNAME = SY-CPROG.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        I_PROGRAM_NAME         = L_REPID
        I_INTERNAL_TABNAME     = 'ALV_DATA'
        I_INCLNAME             = L_INCLNAME
      CHANGING
        CT_FIELDCAT            = GT_FIELDCAT
      EXCEPTIONS
        INCONSISTENT_INTERFACE = 1
        PROGRAM_ERROR          = 2
        OTHERS                 = 3.

   LOOP AT gt_fieldcat INTO wa_fieldcat.
      l_idx = sy-tabix.
        CASE wa_fieldcat-fieldname.
          WHEN 'DATUM'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '转换日期'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'F_KONWA'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '来源货币'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'F_NETPR'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '转换金额'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'L_KONWA'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '本地货币(目标货币)'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'L_NETPR'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '金额'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'EX_KURS'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '汇率'.
            wa_fieldcat-ddictxt = 'S'.
*          WHEN 'WRBTR1'.
*            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
*            wa_fieldcat-seltext_l = '金额'.
*            wa_fieldcat-ddictxt = 'S'.
        ENDCASE.
*      CLEAR wa_fieldcat-key.
      MODIFY gt_fieldcat FROM wa_fieldcat INDEX l_idx.
    ENDLOOP.
ENDFORM.

  FORM ALV_SHOW.
      DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
                I_CALLBACK_PROGRAM = SY-REPID
                IS_LAYOUT                   = GS_LAYOUT
                IT_FIELDCAT                  = GT_FIELDCAT[]
                 I_SAVE                         = 'A'
               TABLES
                   T_OUTTAB                   = ALV_DATA
                EXCEPTIONS
                  PROGRAM_ERROR      = 1
                OTHERS                     = 2.
ENDFORM.

怎么样,在了解此篇文章有何感想?

0 人点赞