在BDC调用中,由于用户设置不同,导致金额、日期等字段的输入格式不正确。此处给出 自创 金额转换FM 并配有 调用方式。
代码语言:javascript复制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.
代码语言:javascript复制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.