As always, I hope this article can save someones time as I wasted time by googling and debugging. Here I want to describe two different approaches how to work with calendar week input field on dynpro, especially two search help options.
Simple dynpro field with given search help
Calendar week itself has NUMC(6) data format. When you are working with dynpro field you need type input as CHAR(7), remember standard search help returns separating dot in between. I found suitable in my case to use standard search help /BI0/OCALWEEK. You have to add just conversion exit, here it is PERI6. Now we have nice working stuff.
Dynpro settings:
Dynpro result:
Everything is simple enough and works just as you would expected, but.... There is one big but for me. The search helps starts somewhere in the deep past. Today I have year 2017, the default value is 6 year ago. The user is forced to scroll down too much to reach current year.
Search help with prefilled input parameters
So we have nice character (7) input field, conversion routines works Ok. So what is painkiller of above example? The answer is search help input parameters, by these you can influence given range of values. I decided to work with DATEFROM, because sy-datum is easily reachable.
Search help input parameters:
How to provide the input parameters? In my case I used ABAP and own F4 screen module. I wanted to have a list of weeks starting just few weeks ago, but not years.
So the result now looks like:
This is what I was exactly looking for. Search help starts from week I wanted.
Here is the solution:
On the screen "Flow logic" tab define module event trigger for F4 as e.g. below.
PROCESS ON VALUE-REQUEST. "F4
FIELD gs_task_schd-cw MODULE f4_cw.
Screen settings:
Just conversion exit is still present within field properties - see below, but no search help any more. It is replaced by F4 module. Conversion exit works to convert data from screen to program (from CHAR7 to NUMC6), but not from F4 module to screen, that is why I have added manual call of conversion routine to the F4 module to display data in a correct way on the screen.
The module can looks like:
*&---------------------------------------------------------------------*
*& Module F4_CW INPUT
*&---------------------------------------------------------------------*
* Calendar week search help with preset (change week list)
*----------------------------------------------------------------------*
MODULE f4_cw INPUT.
lcl_main=>self->o_ctrl_screen->screen_300_f4_cw(
iv_screen_field = 'GS_TASK_SCHD-CW'
).
ENDMODULE. " F4_CW INPUT
So the miracle here is the method screen_300_f4_cw.
Method definition:
screen_300_f4_cw
IMPORTING
iv_screen_field
TYPE dynfnam.
Method implementation:
METHOD screen_300_f4_cw
.
DATA: lt_dynpfields
TYPE STANDARD TABLE OF dynpread
,
ls_dynpfields
LIKE LINE OF lt_dynpfields
,
ls_shlp_descr
TYPE shlp_descr
,
lt_shlp_return_values
TYPE STANDARD TABLE OF ddshretval
,
lt_shlp_selopt
TYPE STANDARD TABLE OF ddshselopt
,
ls_shlp_selopt
LIKE LINE OF lt_shlp_selopt
,
lv_date
TYPE sydatum
.
" Get search help description
CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
EXPORTING
shlpname
= '/BI0/OCALWEEK' " Standard search help name
shlptype
= 'SH'
IMPORTING
shlp
= ls_shlp_descr
.
" Ask FM F4IF_START_VALUE_REQUEST for return values - set the sign
FIELD-SYMBOLS: <fs_interface>
LIKE LINE OF ls_shlp_descr
-interface.
LOOP AT ls_shlp_descr
-interface ASSIGNING <fs_interface>
.
<fs_interface>
-valfield
= 'X'.
ENDLOOP.
" Note: There is internaly used build in function DATE_CONV_EXT_TO_INT that is later used, it accepts DDMMYYYY,
" not other e.g. YYYYMMDD - it causes dumps. So sy-datum can not be used directly
lv_date
= sy
-datum
- 21. " start some weeks ago
CONCATENATE lv_date+6
(2) lv_date+4
(2) lv_date+0
(4) INTO ls_shlp_selopt
-low
.
" Preset default week interval of initial search help screen (not to start in stone age)
ls_shlp_selopt
-shlpname
= '/BI0/OCALWEEK'.
ls_shlp_selopt
-shlpfield
= 'DATEFROM'.
ls_shlp_selopt
-sign = 'I'.
ls_shlp_selopt
-option
= 'GT'.
" ls_shlp_selopt-high = ''.
APPEND ls_shlp_selopt
TO lt_shlp_selopt
.
ls_shlp_descr
-selopt
= lt_shlp_selopt
.
" Trigger search help popup screen
CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
EXPORTING
shlp
= ls_shlp_descr
TABLES
return_values
= lt_shlp_return_values
.
FIELD-SYMBOLS: <fs_return_value>
LIKE LINE OF lt_shlp_return_values
.
LOOP AT lt_shlp_return_values
ASSIGNING <fs_return_value>
.
" Run manually value conversion exit
CALL FUNCTION 'CONVERSION_EXIT_PERI6_OUTPUT'
EXPORTING
input = <fs_return_value>
-fieldval
IMPORTING
output = <fs_return_value>
-fieldval
.
" Fill screen field
ls_dynpfields
-fieldname
= iv_screen_field
.
ls_dynpfields
-fieldvalue
= <fs_return_value>
-fieldval
.
APPEND ls_dynpfields
TO lt_dynpfields
.
EXIT. " process just one item
ENDLOOP.
" Update screen
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname
= '/FDSEU/HCPC' "Program name
dynumb
= '0220' "Screen number
TABLES
dynpfields
= lt_dynpfields
EXCEPTIONS
OTHERS = 0.
ENDMETHOD. "screen_300_f4_cw
An addition - database data type
the data type storing calendar week within database could be e.g. KWEEK or /BI0/OICALWEEK, all have type NUMC(6).
Internally the stored value looks like:
May be there are easier ways, I found this. I hope it helps someone ;-)