SAP 金额转中文大写自开发函数

简介: 关于凭证打印时需将金额转换成中文大写

function zfm_dx_je.

*"----------------------------------------------------------------------

*"*"本地接口:

*"  IMPORTING

*"     REFERENCE(I_MONEY) TYPE  BF_DMBTR

*"  EXPORTING

*"     REFERENCE(O_MONEY)

*"----------------------------------------------------------------------

 data:

   v_s00(2)     value '零',

   v_s01(2)     value '壹',

   v_s02(2)     value '贰',

   v_s03(2)     value '叁',

   v_s04(2)     value '肆',

   v_s05(2)     value '伍',

   v_s06(2)     value '陆',

   v_s07(2)     value '柒',

   v_s08(2)     value '捌',

   v_s09(2)     value '玖',

   v_w00(2)     value '',

   v_w01(2)     value '拾',

   v_w02(2)     value '佰',

   v_w03(2)     value '仟',

   v_w04(2)     value '万',

   v_w05(4)     value '拾',

   v_w06(4)     value '佰',

   v_w07(4)     value '仟',

   v_w08(2)     value '亿',

   v_w09(4)     value '拾',

   v_w10(4)     value '佰',

   v_w11(4)     value '仟',

   v_w12(4)     value '万',

   v_sy(2)      value '元',

   v_sj(2)      value '角',

   v_sf(2)      value '分',

   gv_fs(2)     value '负',

   v_amount(16),"将金额转换成字符型

   v_len        type i, "v_amount或out的长度

   v_var(5),"v_s0,v_s1,...,v_w0,v_w1,...

   v_num(2)     type n, "每一位的数值

   v_s_num(2),"v_s0,v_s1,...中的值

   v_weight(2)  type n, "权数

   v_w_num(4),"v_w0,v_w1,...中的值

   v_flag0      type i value 0, "是否输出'零',0不输出,1输出

   v_n          type i value 0,

   v_index      type sy-index,

   gv_flag      type char1. "正负标识

 if i_money < 0.

   gv_flag = 'X'. "负数标识

 endif.

 data(gv_money) = conv zjine( abs( i_money ) ) .

 v_amount =   gv_money.

 clear o_money.

 shift v_amount left deleting leading space.

 shift v_amount left deleting leading '0'.

*-计算分-----------------------------------------

 v_len = strlen( v_amount ).

 v_len = v_len - 1.

 v_num = v_amount+v_len(1).

 if v_num <> '0'.

   concatenate 'v_s' v_num into v_var.

   write (v_var) to v_s_num.

   concatenate v_s_num v_sf o_money into o_money.

 endif.

*-计算角-----------------------------------------

 v_len = strlen( v_amount ).

 v_len = v_len - 2.

 v_num = v_amount+v_len(1).

 if v_num <> '0'.

   concatenate 'v_s' v_num into v_var.

   write (v_var) to v_s_num.

   concatenate v_s_num v_sj o_money into o_money.

 endif.

*-输出‘整’字-------------------------------------

 if o_money = ' '.

   concatenate '整' o_money into o_money.

 endif.

*-计算整数---------------------------------------

 v_len = strlen( v_amount ).

 v_len = v_len - 3.

 if v_len = 0.

   exit.

 endif.

 v_amount = v_amount(v_len)." 整数部分

*-输出‘元’字-------------------------------------

 concatenate v_sy o_money into o_money.

 v_n = v_len - 1.

 v_weight = 0.

 do v_len times.

   v_index = sy-index.

*   从个位开始

   v_num = v_amount+v_n(1).

   if v_num <> '0'.

     concatenate 'v_s' v_num into v_var.

     write (v_var) to v_s_num.

     concatenate 'v_w' v_weight into v_var.

     write (v_var) to v_w_num.

     concatenate v_s_num v_w_num o_money into o_money.

     v_flag0 = 1.

   else.

     if v_flag0 = 1.

       concatenate 'v_s' v_num into v_var.

       write (v_var) to v_s_num.

       concatenate v_s_num o_money into o_money.

       v_flag0 = 0.

     endif.

     if v_index = 5  and v_len > 5 and v_len < 9 .

       concatenate '万' o_money into o_money.

     elseif v_index = 9 and v_len > 9.

       concatenate '亿' o_money into o_money.

     endif.

*      CASE SY-INDEX.

*        WHEN 5.CONCATENATE '万' OUT INTO OUT.

*        WHEN 9.CONCATENATE '亿' OUT INTO OUT.

*      ENDCASE.

   endif.

   v_weight = v_weight + 1.

   v_n = v_n - 1.

 enddo.

*-删除个位可能出现'零'的情况-----------------

 search o_money for '圆'.

 if sy-subrc = 0.

   v_n = sy-fdpos - 2.

   if v_n >= 0.

     if o_money+v_n(2) = v_s00.

       v_len = strlen( o_money ).

       concatenate o_money(v_n) o_money+sy-fdpos into o_money.

     endif.

   endif.

 endif.

 if gv_flag = 'X'.

   o_money = gv_fs && o_money.

 endif.

endfunction.

目录
相关文章
|
2月前
|
API
在阿里云RPA中,你可以使用"SetForegroundWindow"函数来将SAP控件置顶
【2月更文挑战第28天】 在阿里云RPA中,你可以使用"SetForegroundWindow"函数来将SAP控件置顶
47 1
|
2月前
|
Linux 开发工具 开发者
关于 SAP HANA 开发那些事
关于 SAP HANA 开发那些事
|
2月前
|
存储 前端开发
SAP UI5 federatedLogout 函数源代码分析
SAP UI5 federatedLogout 函数源代码分析
|
2月前
|
供应链 BI 项目管理
SAP 业务顾问和开发顾问的各自职责
SAP 业务顾问和开发顾问的各自职责
|
2月前
|
缓存 JavaScript 前端开发
如何理解 SAP UI5 的 sap.ui.define 函数?
如何理解 SAP UI5 的 sap.ui.define 函数?
|
9月前
|
数据处理 UED
SAP CDS view 里的 COALESCE 函数
SAP CDS view 里的 COALESCE 函数
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
|
2月前
|
数据库
SAP ABAP 更新函数(Update Function Module)执行出错的原因分析试读版
SAP ABAP 更新函数(Update Function Module)执行出错的原因分析试读版
|
2月前
|
数据库
130. SAP ABAP 更新函数(Update Function Module)执行出错的原因分析
130. SAP ABAP 更新函数(Update Function Module)执行出错的原因分析
|
2月前
|
UED
SAP UI5 开发项目 package.json 文件里的 @sap/ux-specification 依赖
SAP UI5 开发项目 package.json 文件里的 @sap/ux-specification 依赖