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.

posted @ 2018-05-02 17:09  追寻无限  阅读(223)  评论(0编辑  收藏  举报