KWEEK
refers to a factory calendar week in the format YYYYMM. Sadly, there is no standard search help available.RSCALWEEK
and /BI0/OCALWEEK
."data type for value help entries
TYPES:
BEGIN OF week_calendar_value_help,
year TYPE ajahr,
week TYPE weekn,
calendar_week TYPE kweek,
END OF week_calendar_value_help,
t_week_calendar_value_help TYPE STANDARD TABLE OF week_calendar_value_help
WITH DEFAULT KEY.
FOR
expression, which we can use in a nested way to fill all week values (52 for the number of weeks in a year)* for every relevant year.CONSTANTS weeks_in_a_year TYPE i VALUE 52.
CONSTANTS value_help_years_in_past TYPE i VALUE 2.
CONSTANTS value_help_years_in_future TYPE i VALUE 2.
"prepare value help table containing calendar week numbers
"going x amount of years in the past and future
DATA(calendar_weeks) = VALUE t_week_calendar_value_help(
LET current_year = sy-datum(4) IN
FOR year = CONV int2( current_year - value_help_years_in_past )
UNTIL year > current_year + value_help_years_in_future
FOR weeknumber = 1 UNTIL weeknumber > weeks_in_a_year
LET week = |{ CONV char2( weeknumber ) ALPHA = IN }|
IN ( year = year
week = weeknumber
calendar_week = |{ year }{ week }| ) ).
year = CONV int2( current_year - value_help_years_in_past
) until two years in the future (UNTIL year > current_year + value_help_years_in_future
).KWEEK
), year (AJAHR
), and week (WEEKN
) as shown in the screenshot below.F4IF_SHLP_EXIT_EXAMPLE
. There is no need to change the interface.FUNCTION zca_kweek_sh_exit.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" SHLP_TAB TYPE SHLP_DESCR_TAB_T
*" RECORD_TAB STRUCTURE SEAHLPRES
*" CHANGING
*" VALUE(SHLP) TYPE SHLP_DESCR_T
*" VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE DDSHF4CTRL
*"----------------------------------------------------------------------
IF callcontrol-step = 'DISP'.
TYPES:
BEGIN OF week_calendar_value_help,
year TYPE ajahr,
week TYPE weekn,
calendar_week TYPE kweek,
END OF week_calendar_value_help,
t_week_calendar_value_help TYPE STANDARD TABLE OF
week_calendar_value_help WITH DEFAULT KEY.
"handle 'F4'/value help request for the week calendar parameter
CONSTANTS weeks_in_a_year TYPE i VALUE 52.
CONSTANTS value_help_years_in_past TYPE i VALUE 2.
CONSTANTS value_help_years_in_future TYPE i VALUE 2.
"prepare value help table containing calendar week numbers
"going x amount of years in the past and future
DATA(calendar_weeks) = VALUE t_week_calendar_value_help(
LET current_year = sy-datum(4) IN
FOR year = CONV int2( current_year - value_help_years_in_past )
UNTIL year > current_year + value_help_years_in_future
FOR weeknumber = 1 UNTIL weeknumber > weeks_in_a_year
LET week = |{ CONV char2( weeknumber ) ALPHA = IN }|
IN ( year = year
week = weeknumber
calendar_week = |{ year }{ week }| ) ).
LOOP AT calendar_weeks ASSIGNING FIELD-SYMBOL(<calender_week>).
LOOP AT shlp_tab[ 1 ]-fielddescr ASSIGNING FIELD-SYMBOL(<fielddescr>).
ASSIGN COMPONENT <fielddescr>-fieldname
OF STRUCTURE <calender_week> TO FIELD-SYMBOL(<value>).
CALL FUNCTION 'F4UT_PARAMETER_RESULTS_PUT'
EXPORTING
parameter = <fielddescr>-fieldname
value = <value>
fieldname = CONV dfies-lfieldname( <fielddescr>-fieldname )
TABLES
shlp_tab = shlp_tab
record_tab = record_tab
source_tab = calendar_weeks
CHANGING
shlp = shlp
callcontrol = callcontrol
EXCEPTIONS
parameter_unknown = 1
OTHERS = 2.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFUNCTION.
F4IF_INT_TABLE_VALUE_REQUEST
.This function module displays a value list that you created in an ABAP program. The self-programmed value list is passed to the function module as the table parameter VALUE_TAB. If you specify the import parameters DYNPPROG, DYNPNR, and DYNPROFIELD, the user's selection is returned to the corresponding field on the screen. If you specify the table parameter RETURN_TAB, the selection is returned into the table instead.
*&---------------------------------------------------------------------*
*& Report ZKWEEKDEMO
*&---------------------------------------------------------------------*
*& Demo program for custom value help for factory calendar week (KWEEK)
*&
*&---------------------------------------------------------------------*
REPORT zkweekdemo.
"data type for value help entries
TYPES:
BEGIN OF week_calendar_value_help,
year TYPE ajahr,
week TYPE weekn,
calendar_week TYPE kweek,
END OF week_calendar_value_help,
t_week_calendar_value_help TYPE STANDARD TABLE OF
week_calendar_value_help WITH DEFAULT KEY.
"Helper class for determining the number of weeks in a given year
CLASS lcl_week_number_helper DEFINITION.
PUBLIC SECTION.
CLASS-METHODS get_weeks_in_year
IMPORTING
iv_year TYPE ajahr
RETURNING
VALUE(rv_amount_of_weeks) TYPE i.
ENDCLASS.
CLASS lcl_week_number_helper IMPLEMENTATION.
METHOD get_weeks_in_year.
DATA lv_max_calendar_week TYPE kweek.
DATA(lv_last_day_of_year) = CONV dats( |{ iv_year }1231| ).
WHILE lv_max_calendar_week(4) NE iv_year AND sy-subrc = 0.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = lv_last_day_of_year
IMPORTING
week = lv_max_calendar_week.
"try again with an earlier date
"if the week returned is in the wrong/next year
lv_last_day_of_year -= 1.
ENDWHILE.
rv_amount_of_weeks = CONV #( lv_max_calendar_week+4 ).
ENDMETHOD.
ENDCLASS.
PARAMETERS pa_kweek TYPE kweek.
"handle 'F4'/value help request for the week calendar parameter
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_kweek.
"2026 is an example of a year with 53 ISO calendar weeks
CONSTANTS start_year TYPE i VALUE 2026.
CONSTANTS value_help_years_in_past TYPE i VALUE 2.
CONSTANTS value_help_years_in_future TYPE i VALUE 2.
"prepare value help table containing calendar week numbers
"going x amount of years in the past and future
DATA(calendar_weeks) = VALUE t_week_calendar_value_help(
FOR current_year = start_year - value_help_years_in_past
UNTIL current_year > start_year + value_help_years_in_future
"determine number of weeks in each year
"since some years have 53 weeks
FOR weeknumber = 1
UNTIL weeknumber > lcl_week_number_helper=>get_weeks_in_year( CONV #( current_year ) )
LET week = |{ CONV char2( weeknumber ) ALPHA = IN }|
IN ( year = current_year
week = weeknumber
calendar_week = |{ current_year }{ week }| ) ).
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CALENDAR_WEEK'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'PA_KWEEK'
value_org = 'S'
TABLES
value_tab = calendar_weeks
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |