FLOAT 转日期
CTCV_CONVERT_FLOAT_TO_DATE
日期转换为内部格式
call function 'CONVERT_DATE_TO_INTERNAL'
exporting
date_external = ls_xlstemp-value
* ACCEPT_INITIAL_DATE =
importing
date_internal = ls_xlstemp-value
exceptions
date_external_is_invalid = 1
others = 2.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
数值内外部转换
自己建函数
conversion_exit_znumb_input
conversion_exit_znumb_output
FUNCTION conversion_exit_znumb_output.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(INPUT) TYPE NUMERIC
*" EXPORTING
*" REFERENCE(OUTPUT) TYPE ANY
*"----------------------------------------------------------------------
WRITE: input TO output.
ENDFUNCTION.
740
data(lv_number) = |{ gs_200-hu alpha = out }|.
SMARTFORMS中转换例程是起作用的,所以在传入接口参考的时候需要注意有没有转换例程,比如ALPHA会自动去前导零的
转换例程:前导零
- 增加前导零 CONVERSION_EXIT_ALPHA_INPUT
unpack A TO A(这种方法最简便)
- 去除前导零 CONVERSION_EXIT_ALPHA_OUTPUT
- 日期 CONVERT_DATE_TO_EXTERNAL(根据SAP用户日期格式转换,而不是windows日期格式,excel的日期格式和windows日期格式一样的)
- 单位 CUNIT
- 转换日期格式 CONVERT_DATE_TO_EXTERNAL
- 物料CONVERSION_EXIT_MATN1_INPUT。注:不要把物料的和前导零的弄混,比如物料号长度位40位是,用物料号的转换例程只会补零至18位,用前导零会补至40位
WBS
perform frm_conversion_pspnr_in using lt_upload_string-ps_psp_pnr2 changing lt_upload_string-ps_psp_pnr2 .
form frm_conversion_pspnr_in using uv_pspel changing cv_pspid.
call function 'CONVERSION_EXIT_ABPSP_INPUT'
exporting
input = uv_pspel
importing
output = cv_pspid
exceptions
error_message = 1.
endform.
perform frm_pspnr_out using gt_alv-pspel changing lv_pspid .
form frm_pspnr_out using uv_pspel changing cv_pspid.
call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
exporting
input = uv_pspel
importing
output = cv_pspid.
endform.
ALPHA
perform frm_alpha_in changing field.
form frm_alpha_in changing field.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = field
importing
output = field.
endform. "FRM_ALPHA_INPUT
perform frm_alpha_out changing et_customer-kunnr.
form frm_alpha_out changing field.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = field
importing
output = field.
endform.
MATN1
perform frm_matn1_input changing gt_alv-matnr.
form frm_matn1_in changing matnr.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = matnr
importing
output = matnr
exceptions
length_error = 1
others = 2.
endform. "FRM_ALPHA_INPUT
perform frm_matn1_output changing gs_screen_0100-matnr2.
form frm_matn1_output changing matnr.
call function 'CONVERSION_EXIT_MATN1_OUTPUT'
exporting
input = matnr
importing
output = matnr
exceptions
length_error = 1
others = 2.
endform.
单位
perform frm_cunit_in changing gt_alv-bstme.
form frm_cunit_in changing cv_meins.
data lv_meins like mara-meins.
lv_meins = cv_meins.
call function 'CONVERSION_EXIT_CUNIT_INPUT'
exporting
input = lv_meins
importing
output = lv_meins.
cv_meins = lv_meins.
endform.
perform frm_cunit_out changing ls_item-meins.
form frm_cunit_out changing cv_meins.
data lv_meins like mara-meins.
lv_meins = cv_meins.
call function 'CONVERSION_EXIT_CUNIT_OUTPUT'
exporting
input = lv_meins
importing
output = lv_meins.
cv_meins = lv_meins.
endform.
金额(日元 韩元等)
转出 CURRENCY_AMOUNT_SAP_TO_DISPLAY(注意不能write,这样就会有千分位符了)
perform frm_amount_trans using gt_alv-rtcur changing gt_alv-sr.
form frm_amount_trans using p_gt_alv_rtcur
changing p_gt_alv_sr.
data currency type tcurc-waers.
data amount_display type wmto_s-amount.
data amount_internal type wmto_s-amount.
amount_display = p_gt_alv_sr.
call function 'CURRENCY_AMOUNT_DISPLAY_TO_SAP'
exporting
currency = p_gt_alv_rtcur
amount_display = amount_display
importing
amount_internal = amount_internal
exceptions
internal_error = 1.
p_gt_alv_sr = amount_internal.
endform.
perform frm_amount_sap_to_display using gt_alv-waerk changing ls_so_list-cus_price.
form frm_amount_sap_to_display using p_gt_alv_rtcur
changing p_gt_alv_sr.
data currency type tcurc-waers.
data amount_display type wmto_s-amount.
data amount_internal type wmto_s-amount.
amount_internal = p_gt_alv_sr.
call function 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
exporting
currency = p_gt_alv_rtcur
amount_internal = amount_internal
importing
amount_display = amount_display
exceptions
internal_error = 1.
p_gt_alv_sr = amount_display.
endform.