BDC 录屏后金额和日期 转换

Posted 追寻无限

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BDC 录屏后金额和日期 转换相关的知识,希望对你有一定的参考价值。

转载自 ttp://blog.sina.com.cn/s/blog_9ae2f2940102v0qq.html

FUNCTION Z_F_CURRENY.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(ZNUM) TYPE  BSEG-WRBTR
*"  EXPORTING
*"     VALUE(ZSTR) TYPE  CHAR100
*"----------------------------------------------------------------------
  DATA : ZCLEN TYPE I,

  N TYPE I,

  ZCSTR(20) TYPE C,

  ZCSTR2(20) TYPE C,

  ZCTEMP(3) TYPE C,

  ZFLAG(1) TYPE C VALUE ‘.‘,

  ZFLAG2 TYPE I VALUE 0,

  ZCDEC(20) TYPE C. "记录小数部分.
  data:l_dcpfm LIKE usr01-dcpfm.
  SELECT SINGLE dcpfm INTO l_dcpfm
        FROM usr01
        WHERE bname = sy-uname.
  CHECK ZNUM <> 0.

  IF ZNUM <= -1000.

    ZFLAG2 = 1.

    ZNUM = ABS( ZNUM ).

  ENDIF.

  IF ZNUM >= 1000.

    ZCSTR = ZNUM.

* 压缩字符串,去除前面的空格。

    CONDENSE ZCSTR NO-GAPS.

* 分离整数与小数,好单独处理整数。

    SPLIT ZCSTR AT ZFLAG INTO ZCSTR ZCDEC.

    ZCLEN = STRLEN( ZCSTR ).

* 在循环中从右面在每三位的前面加上一个逗号。

    WHILE ZCLEN > 3.

      N = ZCLEN - 3.

      ZCTEMP = ZCSTR+N(3).

      IF NOT ZCSTR2 IS INITIAL.
        if l_dcpfm = ‘‘.
          CONCATENATE ZCTEMP ZCSTR2 INTO ZCSTR2 SEPARATED BY ‘.‘.
        ELSEIF l_dcpfm = ‘X‘.
          CONCATENATE ZCTEMP ZCSTR2 INTO ZCSTR2 SEPARATED BY ‘,‘.
        elseif l_dcpfm = ‘Y‘.
          CONCATENATE ZCTEMP ZCSTR2 INTO ZCSTR2 SEPARATED BY space.
        endif.
      ELSE.

        ZCSTR2 = ZCTEMP.

      ENDIF.

      ZCLEN = ZCLEN - 3.

    ENDWHILE.

* 将不剩下的不足三位数加到前面
    if l_dcpfm = ‘‘.
      CONCATENATE ZCSTR+0(ZCLEN) ZCSTR2 INTO ZCSTR2 SEPARATED BY ‘.‘.
    ELSEIF l_dcpfm = ‘X‘.
      CONCATENATE ZCSTR+0(ZCLEN) ZCSTR2 INTO ZCSTR2 SEPARATED BY ‘,‘.
    elseif  l_dcpfm = ‘Y‘.
      CONCATENATE ZCSTR+0(ZCLEN) ZCSTR2 INTO ZCSTR2 SEPARATED BY SPACE.
    endif.
    IF ZFLAG2 = 1.

      CONCATENATE ‘-‘ ZCSTR2 INTO ZCSTR2.

    ENDIF.

    CLEAR ZCSTR.

* 将处理过的整数与小数连接起来。

*CONCATENATE ZCSTR2 ZCDEC INTO ZCSTR SEPARATED BY ZFLAG.
    if l_dcpfm = ‘‘.
      CONCATENATE ZCSTR2 ZCDEC INTO ZCSTR SEPARATED BY ‘,‘.
    ELSEIF l_dcpfm = ‘X‘.
      CONCATENATE ZCSTR2 ZCDEC INTO ZCSTR SEPARATED BY ‘.‘.
    ELSEIF l_dcpfm = ‘Y‘.
      CONCATENATE ZCSTR2 ZCDEC INTO ZCSTR SEPARATED BY ‘,‘.
   ENDIF

* 将值返回

    ZSTR = ZCSTR.

  ELSE.

    ZSTR = ZNUM.
    CONDENSE ZSTR NO-GAPS.
    IF l_dcpfm = ‘‘.
      REPLACE ‘.‘ IN ZSTR WITH ‘,‘.
    ELSEIF l_dcpfm = ‘Y‘.
      REPLACE ‘.‘ IN ZSTR WITH ‘,‘.

    ENDIF.

  ENDIF.

 


ENDFUNCTION.

以上是关于BDC 录屏后金额和日期 转换的主要内容,如果未能解决你的问题,请参考以下文章

BDC中日期和数量格式的转换处理

sap bdc录屏的时候会遇到哪些问题

将日期范围转换为月份范围,除以金额[不是啥程序]

如何用sql的日期函数,分别查出1月~12月每个月的销售金额?

找到两个日期之间的金额总和

根据开始日期和结束日期每月分配金额