2014 Sep 01 11:26 AM
Hi SAP Experts,
I have a small question regarding simple selection screen.
Now I got following screen:
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_vstel FOR likp-vstel,
s_vkorg FOR likp-vkorg,
s_fkdat FOR vbrk-fkdat.
SELECTION-SCREEN END OF BLOCK bl1.
As you see the last fields including the dates and what I'd like to implement it's following:
- If user does call transaction and the selection screen is appearing during the week 'n'
- The fields should automatically be set for the filtering of information for the week 'n-1'
Example: Today is 01.09.2014. I call the transaction and I'd like that in s_fkdat the infromation:
- FROM: 25.08.2014 TO 31.08.2014 would appear.
Did someone have any idea how to implement it in the best way?
Thanks
Denis
2014 Sep 01 11:33 AM
Hi Denis,
It can be achieved by using simple date-time manipulation function modules.
You'll have to write code in INITIALIZATION to set the date range.
1. Get the current month number from date using string manipulation
2. subtract 1 to get previous month.
3. concate 01 and year to it to get the first date of month.
4. use standard FM to get the last date of month
Regards,
Sumit.
2014 Sep 01 11:37 AM
Hi,
You can utilize event INITIALIZATION and pre fill the parameters.
See program Y_R_EITAN_TEST_26_02 in
Sample:
SELECT-OPTIONS: s_as4dat FOR e070-as4date .
INITIALIZATION.
PERFORM at_initialization .
FORM at_initialization .
s_as4dat-sign = 'I' .
s_as4dat-option = 'BT' .
s_as4dat-high = sy-datum .
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = -2
olddate = s_as4dat-high
IMPORTING
newdate = s_as4dat-low.
APPEND s_as4dat .
ENDFORM .
Regards.
2014 Sep 01 12:21 PM
Hello Denis,
Please follow the following steps in the INITIALIZATION.
Step 1) . Use FM DATE_GET_WEEK
importing
Date = SY-datum
exporting
week = wv_week_data_in . (in wv_week , you will get your week number wiht year like 201436 )
Step 2). Decrement the week no by 1.
So get year wv_year = wv_week_data_in(4).
and wv_week = wv_week_data_in(2)+4.
Now decrement the week by WV_WEEK = WV_WEEK - 1.
Now again concatanate it with year.
concatanate wv_year wv_week into wv_week_data_out.
Step 3 : Use FM WEEK_GET_FIRST_DAY
importing
week = wv_week_data_out.
exporting
Date = wv_date_start (this is the starting date of your week).
Now simply add 7 days in the wv_date_start and then you will have both the starting dates and the end dates of the previous week.
Set these two values in the start option low and high.
s_fkdat-sign = 'I' .
s_fkdat-option = 'EQ' .
s_fkdat-high = wv_date_start .
s_fkdat-high = wv_date_end.
append s_fkdate.
Hope it is helpful...
Ask if need more clarification
2014 Sep 01 1:40 PM
Create a variant, and define variant variables. No programming required.
2014 Sep 01 2:13 PM
Hi Matthew,
thank you, but the variant will not work, because I need to perform my report as a Job, so I think the data information has to be coded.
Or can variant help also in this case?
2014 Sep 01 4:05 PM
Yes, a variant will do the job. You specify the variant and the dates are automatically filled in each time the job runs.
2014 Sep 01 1:59 PM
Thank you guys for the advises,
I just have tried this way:
INITIALIZATION.
s_fkdat-SIGN = 'I'.
s_fkdat-OPTION = 'BT'.
s_fkdat-HIGH = sy-datum - 7.
s_fkdat-LOW = sy-datum - 2.
APPEND s_fkdat.
Small question: how to declare such a variables like s_fkdat_SIGN in the best way?
2014 Sep 01 2:17 PM
Hi
Try This
initialization.
s_fkdat-low = sy-datum - 8.
s_fkdat-high = sy-datum - 1.
APPEND s_fkdat.
Regards
Parveen
2014 Sep 01 2:24 PM
Thanks Parveen,
but how should I declare s_fkdat-low in DATA?
2014 Sep 01 2:36 PM
Hi
Please clarify what exactly you want to do with s_fkdat?
want to pick data from database table or somthing else?
Regards
Parveen
2014 Sep 01 2:54 PM
Hi Parveen,
well this is my screen:
the single thing I do need is to have following predifined data in the selection screen:
1. SY-datum - 7
2. SY-datum -2
BR
Denis
2014 Sep 01 2:25 PM
Hi Denis,
The following code snippet works:
DATA: gv_date TYPE dats,
gv_start_date TYPE dats,
gv_end_date TYPE dats,
gv_current_day TYPE c.
SELECT-OPTIONS so_week FOR gv_date.
DATA: gs_selopt LIKE LINE OF so_week.
* Has to be declared after so_week using LIKE LINE OF
* in order to guarantee the correct type!
INITIALIZATION.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
date = sy-datum
IMPORTING
day = gv_current_day.
gv_start_date = sy-datum - 7 - gv_current_day + 1.
gv_end_date = gv_start_date + 6.
gs_selopt-sign = 'I'.
gs_selopt-option = 'BT'.
gs_selopt-low = gv_start_date.
gs_selopt-high = gv_end_date.
APPEND gs_selopt TO so_week.
2014 Sep 01 2:45 PM
Thanks for the answers, guys.
But could anyone give me a tipp, why this code doen't work, I mean I can't even compile it, because the variables in the INITIALIZATION part are not declared, but whe I try to declare them like for example:
s_fkdat-HIGH TYPE d.
the compiler tells me that this variable is already declared...
2014 Sep 01 2:57 PM
Hi Denis,
With the SELECT-OPTIONS statement the variable s_fkdat is already declared. The variable is an internal table. The columns of this table are SIGN, OPTION, LOW and HIGH.
What you need to do in the INITIALIZATION block is to insert a single entry into this table. Therefore you have to declare another variable which has the same line type as the internal table s_fkdat. Then you have to fill the variable and append it to the table s_fkdat.
That is exactly the approach I took in the code snippet above.
I hope that helps.
It may also be helpful to have a look at http://help.sap.com/abapdocu_702/en/abapselect-options.htm .
Kind regards,
Valentin
2014 Sep 01 3:31 PM
Hi Valentin, thank you vor the responce. But actually my problem can be solved in really simple way like this:
s_fkdat-SIGN = 'I'.
s_fkdat-OPTION = 'BT'.
s_fkdat-HIGH = sy-datum - 7.
s_fkdat-LOW = sy-datum - 2.
APPEND s_fkdat.
, but I really don't understand what I need to declare additionally in this case...
2014 Sep 01 4:27 PM
for this code to work, you just need to define :
Tables: VBRK.
Select-options : S_FKDAT FOR vbrk-fkdat.
but below code will not work according to your requirement.
So please make your solution general instead or substracting like this :
s_fkdat-HIGH = sy-datum - 7.
s_fkdat-LOW = sy-datum - 2.
2014 Sep 02 6:46 AM
Hi Denis,
I updated my sample code according to your comments and added comments of my own:
REPORT zvh_sel_week2.
* Each select-option has to refer to a declared data element.
* The system needs to be able to determine the correct type for
* the select-option's low and high columns.
* Therefore we declare a global structure variable with the type we
* need.
* Note that the TABLES statement could be used for this. But this
* is not recommended since the TABLES statement shall only be used
* for data transfer between the program and a classic dynpro screen.
DATA: gs_vbrk TYPE vbrk.
* Now we can declare the select-option with reference to the
* declared data element.
SELECT-OPTIONS so_fkdat FOR gs_vbrk-fkdat.
* The following variables are helper variables for the calculation of
* the start and end dates. These variables and the code under the
* INITIALIZATION block should be put into a FORM routine.
* For the sake of brevity this is omitted in this example.
DATA: gv_start_date TYPE dats,
gv_end_date TYPE dats,
gv_current_day TYPE c.
INITIALIZATION.
* Now we determine the current day of the week.
* Mondey = 1
* Tuesday = 2
* ...
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
date = sy-datum
IMPORTING
day = gv_current_day.
* The start of the current week is sy-datum - gv_current_day + 1.
* Example: On 01.09.2014 (it's a Monday) gv_current_day = 1.
* So the start of the current week is 01.09.2014 - 1 + 1 = 01.09.2014.
* Example 2: On 02.09.2014 (Tuesday) gv_current_day = 2.
* So the start of the current week is 02.09.2014 - 2 + 1 = 01.09.2014.
* But we need the start of the previous week, so have have to subtract 7:
gv_start_date = sy-datum - 7 - gv_current_day + 1.
* Once we have the start date of the last week, calculation the end dat is
* easy: Every week has 7 days 🙂
gv_end_date = gv_start_date + 6.
* Now we have the lower and upper bound for the select-option.
* In the following code we use the fact that a select-option has a header line.
* The next 4 statements fill the header line. The 5th statement puts the entry
* into the select-option "body table".
* (Using header lines is deprecated, that's why I suggest to put the helper code
* into a FORM routine and to declare a new structure variable).
so_fkdat-sign = 'I'.
so_fkdat-option = 'BT'.
so_fkdat-low = gv_start_date.
so_fkdat-high = gv_end_date.
APPEND so_fkdat.
Again I advise you to read the keyword documentation:
http://help.sap.com/abapdocu_702/en/abapselect-options.htm
http://help.sap.com/abapdocu_702/en/abapselect-options_for.htm
Kind regards,
Valentin