偶然发现abap中的write语句还有个可以指定数字输出格式的style选项。
F1中的英文帮助截图如下:
可以通过style指定7种格式,这些格式在class CL_ABAP_FORMAT中的属性界面中找到,如下:
1, O_SIMPLE: 输出和su3中用户设定相同数字显示格式,结尾的0不显示
2, O_SIGN_AS_POSTFIX:与O_SIMPLE类似只不过,符号放在右边,正数符号为空
3, O_SCALE_PRESERVING:与O_SIMPLE类似,数字结尾无效的0也显示
4, O_SCIENTIFIC:科学计数法
5, O_SCIENTIFIC_WITH_LEADING_ZERO:带前导零的科学计数法,也就是小数点前是0
6, O_SCALE_PRESERVING_SCIENTIFIC:与O_SCIENTIFIC类似,数字结尾的0也显示
7, O_ENGINEERING:与O_SCIENTIFIC类似,只不过小数点前固定显示3位。
详细参照下面例子程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
REPORT ztest_unit_string_convert LINE-SIZE 255. DATA: l_conv(132) TYPE c. "Convert to local format DATA: l_number TYPE decfloat34 VALUE '-123456789.10'. WRITE l_number TO l_conv STYLE cl_abap_format=>o_simple LEFT-JUSTIFIED. WRITE:`O_SIMPLE: `, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_sign_as_postfix LEFT-JUSTIFIED. WRITE:/ `O_SIGN_AS_POSTFIX: `, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_scale_preserving LEFT-JUSTIFIED. WRITE:/ `O_SCALE_PRESERVING: `, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_scientific LEFT-JUSTIFIED. WRITE:/ `O_SCIENTIFIC: `, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_scientific_with_leading_zero LEFT-JUSTIFIED. WRITE:/ `O_SCIENTIFIC_WITH_LEADING_ZERO:`, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_scale_preserving_scientific LEFT-JUSTIFIED. WRITE:/ `O_SCALE_PRESERVING_SCIENTIFIC: `, l_conv. WRITE l_number TO l_conv STYLE cl_abap_format=>o_engineering LEFT-JUSTIFIED. WRITE:/ `O_ENGINEERING: `, l_conv. |
显示结果:
以上。
发表评论