ABAP--如何生成年月的输入帮助?
2016-08-29
浏览次
在abap的设计过程中经常会出现账务期输入,格式为年月。如果我们使用spmon元素为参考,但是系统无输入帮助,用户常常出错,为了避免输入错误。我们可以自定义输入帮助,步骤如下:1、定义选择变量
parameter p_spmon type spmon default sy-datum+0(6) obligatory.
select-options s_spmon for s031-spmon default sy-datum+0(6) obligatory.2、定义帮助子过程
form monat_f4.
data: begin of mf_dynpfields occurs 1.
include structure dynpread.
data: end of mf_dynpfields.
data: mf_returncode like sy-subrc,
mf_monat like isellist-month,
mf_hlp_repid like sy-repid.
field-symbols: <mf_feld>. get cursor field mf_dynpfields-fieldname.
append mf_dynpfields.
mf_hlp_repid = sy-repid.
do 2 times.
call function 'DYNP_VALUES_READ'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07.
if sy-subrc = 3.
mf_hlp_repid = 'SAPLALDB'.
else.
read table mf_dynpfields index 1.
translate mf_dynpfields-fieldvalue using '_ '.
exit.
endif.
enddo.
if sy-subrc = 0.
call function 'CONVERSION_EXIT_PERI_INPUT'
exporting
input = mf_dynpfields-fieldvalue
importing
output = mf_monat
exceptions
error_message = 1.
if mf_monat is initial.
mf_monat = sy-datlo(6).
endif.
call function 'POPUP_TO_SELECT_MONTH'
exporting
actual_month = mf_monat
importing
selected_month = mf_monat
return_code = mf_returncode
exceptions
factory_calendar_not_found = 01
holiday_calendar_not_found = 02
month_not_found = 03.
if sy-subrc = 0 and mf_returncode = 0.
call function 'CONVERSION_EXIT_PERI_OUTPUT'
exporting
input = mf_monat
importing
output = mf_dynpfields-fieldvalue.
collect mf_dynpfields.
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07.
endif.
endif.
endform. "MONAT_F43、定义输入帮助事件
at selection-screen on value-request for p_spmon.
perform monat_f4.
at selection-screen on value-request for s_spmon-low.
perform monat_f4.
at selection-screen on value-request for s_spmon-high.
perform monat_f4.
parameter p_spmon type spmon default sy-datum+0(6) obligatory.
select-options s_spmon for s031-spmon default sy-datum+0(6) obligatory.2、定义帮助子过程
form monat_f4.
data: begin of mf_dynpfields occurs 1.
include structure dynpread.
data: end of mf_dynpfields.
data: mf_returncode like sy-subrc,
mf_monat like isellist-month,
mf_hlp_repid like sy-repid.
field-symbols: <mf_feld>. get cursor field mf_dynpfields-fieldname.
append mf_dynpfields.
mf_hlp_repid = sy-repid.
do 2 times.
call function 'DYNP_VALUES_READ'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07.
if sy-subrc = 3.
mf_hlp_repid = 'SAPLALDB'.
else.
read table mf_dynpfields index 1.
translate mf_dynpfields-fieldvalue using '_ '.
exit.
endif.
enddo.
if sy-subrc = 0.
call function 'CONVERSION_EXIT_PERI_INPUT'
exporting
input = mf_dynpfields-fieldvalue
importing
output = mf_monat
exceptions
error_message = 1.
if mf_monat is initial.
mf_monat = sy-datlo(6).
endif.
call function 'POPUP_TO_SELECT_MONTH'
exporting
actual_month = mf_monat
importing
selected_month = mf_monat
return_code = mf_returncode
exceptions
factory_calendar_not_found = 01
holiday_calendar_not_found = 02
month_not_found = 03.
if sy-subrc = 0 and mf_returncode = 0.
call function 'CONVERSION_EXIT_PERI_OUTPUT'
exporting
input = mf_monat
importing
output = mf_dynpfields-fieldvalue.
collect mf_dynpfields.
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07.
endif.
endif.
endform. "MONAT_F43、定义输入帮助事件
at selection-screen on value-request for p_spmon.
perform monat_f4.
at selection-screen on value-request for s_spmon-low.
perform monat_f4.
at selection-screen on value-request for s_spmon-high.
perform monat_f4.