什么都不说,先上2张图。SAP 5.0随便用BDC找了一个屏幕,录入日期和金额的时候出现坑爹的一幕
SAP 5.0 BDC前台录入必须按照你系统设置的日期或者金额格式录入,否则都会报非法日期或者金额。老特么坑爹了。
日期可以用一个function CONVERSION_EXIT_PDATE_OUTPUT 可以实现前台的转换。但是金额一直没找到能将金额转换成字符串的function。找了一下function 找到 BAPI_CURRENCY_CONV_TO_EXTERNAL以为可以,结果发现这个BAPI的export最终也是一个金额的数据元素,debug的时候还是显示成P类型的(100.12这种)
这个BAPI对应的内部转换bapi为BAPI_CURRENCY_CONV_TO_INTERNAL。但是都不能用。没招了,找function找了几个小时没有一个有用的。擦。SAP 5.0坑爹
最后想想不要浪费时间再找了 就自己写了一下。
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.