crm web ui 负号默认显示在后面,统一把负号改为左边显示,
代码增强方法 CL_BSP_UTILITY->MAKE_STRING
ENHANCEMENT 1 ZENH_CRM_CL_BSP_UTILITY. "active version
* sap 默认负号显示右边,这里默认把负号放左边显示
CALL METHOD zcl_crm_bsp_utility=>make_string
EXPORTING
value = VALUE
num_decimals = NUM_DECIMALS
reference_value = REFERENCE_VALUE
reference_type = REFERENCE_TYPE
receiving
output = output.
RETURN.
ENDENHANCEMENT.
*$*$-End: (1)---------------------------------------------------------------------------------$*$*
创建class ZCL_CRM_BSP_UTILITY
class ZCL_CRM_BSP_UTILITY definition
public
final
create public .
public section.
class-methods MOVE_SIGN_TO_LEFT
importing
!IV_VALUE type ANY optional
!IV_TYPE type C optional
changing
!CV_OUTPUT type STRING .
class-methods TEST_SIGN_VALUES .
class-methods MAKE_STRING
importing
!VALUE type ANY
!NUM_DECIMALS type I default -1
!REFERENCE_VALUE type C optional
!REFERENCE_TYPE type C optional
returning
value(OUTPUT) type STRING .
protected section.
private section.
ENDCLASS.
CLASS ZCL_CRM_BSP_UTILITY IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CRM_BSP_UTILITY=>MAKE_STRING
* +-------------------------------------------------------------------------------------------------+
* | [--->] VALUE TYPE ANY
* | [--->] NUM_DECIMALS TYPE I (default =-1)
* | [--->] REFERENCE_VALUE TYPE C(optional)
* | [--->] REFERENCE_TYPE TYPE C(optional)
* | [<-()] OUTPUT TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
method MAKE_STRING .
*
* 为了负号左边显示,代码增强方法 CL_BSP_UTILITY->MAKE_STRING
data: l_type type C. " type of value
DEFINE left_sign.
move_sign_to_left(
EXPORTING
iv_value = VALUE
iv_type = l_type
CHANGING
cv_output = &1 ).
END-OF-DEFINITION.
* check valid type
describe field value type l_type.
case l_type. "#EC CI_INT8_OK
when 'g' " string
or 'C'. " char
output = value.
return.
when 'a' " decfloat16
or 'e' " decfloat34
or 'F'. " float
output = value.
left_sign output . " 负号提前
return.
when 'b' " 1-byte integer
or 's' " 2-byte integer
or 'I' " integer
or '8' " int8
or 'D' " date
or 'T' " time
or 'N' " numerical text
or 'P'. " packed
" O.K.
when 'h' " internal table
or 'u' " structure
or 'v'. " structure
raise exception type cx_bsp_inv_format.
when others.
raise exception type cx_bsp_inv_format.
endcase.
* convert value
data: tempchar(40) type C.
case l_type. "#EC CI_INT8_OK
when 'b' " 1-byte integer
or 's' " 2-byte integer
or 'I'. " integer
data: intval type I.
move value to intval.
if intval < 0.
tempchar = '-'. "#EC NOTEXT
write intval to tempchar+1 no-sign left-justified.
else.
write intval to tempchar left-justified.
endif.
move tempchar to output.
condense output.
left_sign output . " 负号提前
when '8' "int8.
.
data: intval8 type int8.
move value to intval8.
if intval < 0.
tempchar = '-'. "#EC NOTEXT
write intval8 to tempchar+1 no-sign left-justified.
else.
write intval8 to tempchar left-justified.
endif.
move tempchar to output.
condense output.
left_sign output . " 负号提前
when 'g' " string
or 'C' " char
or 'N'. " numerical text
move value to output.
when 'D'. " date
data: datval type D.
move value to datval.
if datval is not initial.
write datval to tempchar DD/MM/YYYY.
move tempchar(10) to output.
else.
clear output.
endif.
when 'T'. " time
data: timval type T.
move value to timval.
* if timval+4(2) = '00'.
* write timval(4) to tempchar
* using edit mask '__:__'. "#EC NOTEXT
* move tempchar(5) to output.
* else.
write timval(6) to tempchar
using edit mask '__:__:__'. "#EC NOTEXT
move tempchar(8) to output.
* endif.
when 'P'. " packed
data: l_reference_type type c.
if reference_value is initial.
l_reference_type = ''.
else.
l_reference_type = reference_type.
endif.
if l_reference_type = 'C'.
write value to tempchar CURRENCY reference_value.
elseif l_reference_type = 'Q'.
write value to tempchar UNIT reference_value.
elseif num_decimals ne -1.
write value to tempchar decimals num_decimals.
else.
write value to tempchar.
endif.
move tempchar to output.
condense output.
left_sign output . " 负号提前
endcase.
endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CRM_BSP_UTILITY=>MOVE_SIGN_TO_LEFT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_VALUE TYPE ANY(optional)
* | [--->] IV_TYPE TYPE C(optional)
* | [<-->] CV_OUTPUT TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD move_sign_to_left.
CASE iv_type.
WHEN 'a' " decfloat16
OR 'e' " decfloat34
OR 'F' " float
OR 'b' " 1-byte integer
OR 's' " 2-byte integer
OR 'I' " integer
OR 'P'. " packed
.
IF iv_value >= 0.
RETURN.
ENDIF.
WHEN ''.
WHEN OTHERS.
RETURN.
ENDCASE.
DATA: lv_part_a TYPE string,
lv_part_b TYPE string,
lv_a_pos TYPE i,
lv_length TYPE i
.
CONDENSE cv_output NO-GAPS. " 去空格
lv_length = strlen( cv_output ).
lv_a_pos = lv_length - 1.
lv_part_b = cv_output+lv_a_pos(1).
IF lv_part_b EQ '-'.
lv_part_a = cv_output(lv_a_pos).
cv_output = lv_part_b && lv_part_a.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CRM_BSP_UTILITY=>TEST_SIGN_VALUES
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
method TEST_SIGN_VALUES.
data:lv_out TYPE string,
lv_test_script TYPE string,
lv_newline(1),
lv_cr_lf(2) TYPE c
.
data:
LV_ABPER_RF type ABPER_RF value '201901' , " 过账期间 YYYYMM
LV_char10 type char10 value '11-' , " 字符串
LV_MANDT type MANDT value '300' , " 集团
LV_WAERS type WAERS value 'CNY' , " 货币字段的货币键值
LV_WERT11V type WERT11V value '-1000' , " 采用 BCD 格式的货币字段
LV_decfloat16 type decfloat16 value -10000 , " 以 BCD 格式存储的十进制浮点数
LV_WDR_TEST_DECFLOAT3 type WDR_TEST_DECFLOAT3 value -10000 , " 以二进制数字形式存储的十进制浮点数
LV_TBA_PRICE type TBA_PRICE value -1230000 , " 以 BCD 格式存储的十进制浮点数
LV_CRM_FS_FDT_NUM_DECFLOAT type CRM_FS_FDT_NUM_DECFLOAT value -10000 , " 以二进制数字形式存储的十进制浮点数
LV_DATum type DATum value '20221124' , " 使用格式 YYYYMMDD 的日期
LV_CRM_MKTPL_DEF_PCTN type CRM_MKTPL_DEF_PCTN value -13455 , " DEC 采用 BCD 格式的压缩数字
LV_/SAPAPO/SCMB_TSVALUE type /SAPAPO/SCMB_TSVALUE value -8900 , " 浮点数
LV_INT1 type INT1 value 100 , " 1 字节整数,0 到 255
LV_INT2 type INT2 value -32000 , " 2 字节整数,-32.768 到 32.767
LV_INT4 type INT4 value -212000 , " 4 字节整数,-2.147.483.648 到 +2.147.483.647
LV_INT8 type INT8 value -9223372036854 , " 8 字节整数
LV_LANG type LANG value 1 , " 语言代码
LV_SHOPTEXT type SHOPTEXT value '20-' , " 长字节串
LV_RFCINT type RFCINT value '3033' , " 长字节字符串
LV_SCMS_PAIND type SCMS_PAIND value '10-' , " 数字文本
LV_ACT_NTGEW type ACT_NTGEW value -2000 , " 采用 BCD 格式的数量字段
LV_CRMT_STATUS_GUID type CRMT_STATUS_GUID value '005056817CDB1ED68A942A0730600B40' , " 字节序列
LV_CRM_IC_XSTRING type CRM_IC_XSTRING value '005056817CDB1ED68A942A0730600B40' , " 字节字符串 (BLOB)
LV_CHIP_NAME type CHIP_NAME value '005056817CDB1ED68FE5B21927C6D986' , " 字符串
LV_STRING type STRING value '005056817CDB1ED693FE6B4FBB7656E7' , " 字符串 (CLOB)
LV_TIMS type TIMS value '201133' , " 格式为 HHMMSS 的时间
LV_CRMUNIT type CRMUNIT value 'TO' , " 数量字段的单元码
lv_int TYPE INT1 VALUE 100
.
CLASS cl_abap_char_utilities DEFINITION LOAD.
lv_newline = cl_abap_char_utilities=>newline.
lv_cr_lf = cl_abap_char_utilities=>cr_lf.
DEFINE conv_out_sign.
CLEAR lv_out.
CALL METHOD make_string
EXPORTING
value = &2
receiving
output = lv_out.
lv_test_script = lv_test_script && '数据类型:' && &1 && lv_cr_lf && '结果:' && lv_out && lv_newline.
END-OF-DEFINITION.
* conv_out_sign: 'lv_int TYPE INT1 VALUE -100' lv_int.
conv_out_sign:
' LV_ABPER_RF type ABPER_RF value ''201901'' . ' LV_ABPER_RF
, ' LV_char10 type char10 value ''11-'' . ' LV_char10
, ' LV_MANDT type MANDT value ''300'' . ' LV_MANDT
, ' LV_WAERS type WAERS value ''CNY'' . ' LV_WAERS
, ' LV_WERT11V type WERT11V value ''-1000'' . ' LV_WERT11V
, ' LV_decfloat16 type decfloat16 value -10000 . ' LV_decfloat16
, ' LV_WDR_TEST_DECFLOAT3 type WDR_TEST_DECFLOAT3 value -10000 . ' LV_WDR_TEST_DECFLOAT3
, ' LV_TBA_PRICE type TBA_PRICE value -1230000 . ' LV_TBA_PRICE
, ' LV_CRM_FS_FDT_NUM_DECFLOAT type CRM_FS_FDT_NUM_DECFLOAT value -10000 . ' LV_CRM_FS_FDT_NUM_DECFLOAT
, ' LV_DATum type DATum value ''20221124'' . ' LV_DATum
, ' LV_CRM_MKTPL_DEF_PCTN type CRM_MKTPL_DEF_PCTN value -13455 . ' LV_CRM_MKTPL_DEF_PCTN
, ' LV_/SAPAPO/SCMB_TSVALUE type /SAPAPO/SCMB_TSVALUE value -8900 . ' LV_/SAPAPO/SCMB_TSVALUE
, ' LV_INT1 type INT1 value 100 . ' LV_INT1
, ' LV_INT2 type INT2 value -32000 . ' LV_INT2
, ' LV_INT4 type INT4 value -212000 . ' LV_INT4
, ' LV_INT8 type INT8 value -9223372036854 . ' LV_INT8
, ' LV_LANG type LANG value 1 . ' LV_LANG
, ' LV_SHOPTEXT type SHOPTEXT value ''20-'' . ' LV_SHOPTEXT
*, ' LV_RFCINT type RFCINT value ''3033'' . ' LV_RFCINT
, ' LV_SCMS_PAIND type SCMS_PAIND value ''10-'' . ' LV_SCMS_PAIND
, ' LV_ACT_NTGEW type ACT_NTGEW value -2000 . ' LV_ACT_NTGEW
, ' LV_CRMT_STATUS_GUID type CRMT_STATUS_GUID value ''005056817CDB1ED68A942A0730600B40'' . ' LV_CRMT_STATUS_GUID
, ' LV_CRM_IC_XSTRING type CRM_IC_XSTRING value ''005056817CDB1ED68A942A0730600B40'' . ' LV_CRM_IC_XSTRING
, ' LV_CHIP_NAME type CHIP_NAME value ''005056817CDB1ED68FE5B21927C6D986'' . ' LV_CHIP_NAME
, ' LV_STRING type STRING value ''005056817CDB1ED693FE6B4FBB7656E7'' . ' LV_STRING
, ' LV_TIMS type TIMS value ''201133'' . ' LV_TIMS
, ' LV_CRMUNIT type CRMUNIT value ''TO'' . ' LV_CRMUNIT
.
cl_demo_output=>display_text( lv_test_script ).
endmethod.
ENDCLASS.