在ABAP的设计过程中经常会出现账务期输入,格式为年月。如果我们使用spmon元素为参考,但是系统无输入帮助,用户常常出错,为了避免输入错误。我们可以自定义输入帮助,步骤如下:
1、定义选择变量
代码语言:javascript复制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、定义搜索帮助
代码语言:javascript复制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_F4
3、定义搜索帮助事件
代码语言:javascript复制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.
方法二:
代码语言:javascript复制PARAMETERS: p_year TYPE mard-lfgja DEFAULT sy-datum 0(4),
p_month TYPE mard-lfmon.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_month.
DATA: actual_month LIKE isellist-month,
selected_month LIKE isellist-month,
return_code TYPE sy-subrc.
CONCATENATE p_year sy-datum 4(2) INTO actual_month.
CALL FUNCTION ‘POPUP_TO_SELECT_MONTH’
EXPORTING
actual_month = actual_month "传入年份
factory_calendar = ’ ’ "工厂日历 ID
holiday_calendar = ’ ’ "假日日历 ID
language = sy-langu "当前系统语言
start_column =10 "弹出框屏幕位置
start_row = 8 "弹出框屏幕位置
IMPORTING
selected_month = selected_month "返回用户输入月份
return_code = return_code "返回 sy-subrc
EXCEPTIONS
factory_calendar_not_found = 1
holiday_calendar_not_found = 2
month_not_found = 3
OTHERS = 4.
IF return_code = 0.
p_year = selected_month 0(4).
p_month = selected_month 4(2).
ENDIF.