码迷,mamicode.com
首页 > 其他好文 > 详细

BDC 调用中 金额格式转换

时间:2020-06-25 09:22:53      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:name   single   输入   type   HERE   span   with   格式   data-   

在BDC调用中,由于用户设置不同,导致金额、日期等字段的输入格式不正确。此处给出 自创 金额转换FM 并配有 调用方式。

function zgm_conver_cuur.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_STRIN)
*"     REFERENCE(I_DECIMALS) TYPE  I
*"  EXPORTING


 

*"     REFERENCE(E_STROUT)
*"----------------------------------------------------------------------
  data:l_dcpfm   like usr01-dcpfm,
       l_strin   type char20,
       l_reverse type char20,
       l_strout  type char20,
       l_str1    type string,
       l_str2    type string,

       l_mask    type string.
  data:l_lenth type i.
  data:l_lenth2 type i.
  clear l_mask.
  l_str2 = ___.
  case i_decimals.
    when 2.
      l_str1 = __.
    when 3.
      l_str1 = ___.
    when 4.
      l_str1 = ____.
    when others.
  endcase.

  l_strin = i_strin.
  "remove Punctuation by space
  replace . with ‘‘ into l_strin.
  condense l_strin no-gaps.
  l_lenth = strlen( l_strin ).
  l_lenth2 = l_lenth - i_decimals.

  case l_lenth2.
    when 1 or 2 or 3.
    when 4 or 5 or 6.
    when others.
  endcase.
  "reverse string
  call function STRING_REVERSE
    exporting
      string  = l_strin
      lang    = sy-langu
    importing
      rstring = l_reverse.


  select single dcpfm into l_dcpfm from usr01 where bname = sy-uname.

  case l_dcpfm.
    when ‘‘.
      case l_lenth2.
        when 1 or 2 or 3.
          concatenate l_str1 l_str2 into l_mask separated by ,.
        when 4 or 5 or 6.
          concatenate l_str2 l_str2 into l_mask separated by ..
          concatenate l_str1 l_mask into l_mask separated by ,.
        when 7 or 8 or 9.
          concatenate l_str2 l_str2 l_str2 into l_mask separated by ..
          concatenate l_str1 l_mask into l_mask separated by ,.
        when 10 or 11 or 12.
          concatenate l_str2 l_str2 l_str2 l_str2 into l_mask separated by ..
          concatenate l_str1 l_mask into l_mask separated by ,.
        when others.
      endcase.
    when X.
      case l_lenth2.
        when 1 or 2 or 3.
          concatenate l_str1 l_str2 into l_mask separated by ..
        when 4 or 5 or 6.
          concatenate l_str2 l_str2 into l_mask separated by ,.
          concatenate l_str1 l_mask into l_mask separated by ..
        when 7 or 8 or 9.
          concatenate l_str2 l_str2 l_str2 into l_mask separated by ,.
          concatenate l_str1 l_mask into l_mask separated by ..
        when 10 or 11 or 12.
          concatenate l_str2 l_str2 l_str2 l_str2 into l_mask separated by ,.
          concatenate l_str1 l_mask into l_mask separated by ..
        when others.
      endcase.
    when Y.
      case l_lenth2.
        when 1 or 2 or 3.
          concatenate l_str1 l_str2 into l_mask separated by ,.
        when 4 or 5 or 6.
          concatenate l_str2 l_str2 into l_mask separated by space.
          concatenate l_str1 l_mask into l_mask separated by ,.
        when 7 or 8 or 9.
          concatenate l_str2 l_str2 l_str2 into l_mask separated by space.
          concatenate l_str1 l_mask into l_mask separated by ,.
        when 10 or 11 or 12.
          concatenate l_str2 l_str2 l_str2 l_str2 into l_mask separated by space.
          concatenate l_str1 l_mask into l_mask separated by ,.
        when others.
      endcase.
  endcase.

  write  l_reverse using edit mask l_mask to l_strout.

  if sy-subrc = 0.
    "reverse string
    call function STRING_REVERSE
      exporting
        string  = l_strout
        lang    = sy-langu
      importing
        rstring = e_strout.
  endif.
endfunction.
  DATA:l_wrbtr LIKE bdcdata-fval.       "BDC Amount

    l_wrbtr = <lfs_post>-kwert.

    CONDENSE l_wrbtr NO-GAPS.

    CALL FUNCTION ZGM_CONVER_CUUR
      EXPORTING
        i_strin    = l_wrbtr
        i_decimals = 2"两位小数,也可三位  四位
      IMPORTING
        e_strout   = l_wrbtr.

 

BDC 调用中 金额格式转换

标签:name   single   输入   type   HERE   span   with   格式   data-   

原文地址:https://www.cnblogs.com/JackeyLove/p/13191062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!