Setting SELECT-OPTIONS manually?

20.4k views Asked by At

I have a program that, among other things, retrieves data from table RESB based on the bdter field, a DATS type. On the selection screen the user either specifies a range or a standard range (start of month - today) is used.

However, if I try to re-use the select-option I created for date in those cases where it isn't filled (the user entered no date range), my changes to this work area don't seem to be recognized when I use it in my select statement.

Relevant code segments follow. After some testing I've concluded that:

  • if s_bdter is not modified by the user and subsequently set in code, no records are filtered

  • if s_bdter is modified by the user, records are correctly filtered

  • if s_bdter is modified by the user and subsequently modified in code, records are correctly filtered

     SELECT-OPTIONS: s_bdter FOR ls_itab-bdter MODIF ID sbd.
    
     START-OF-SELECTION.
     " Set the interval.
     s_bdter-sign = 'I'.
     s_bdter-option = 'BT'.
     s_bdter-low = lc_bdter_start.
     s_bdter-high = sy-datum + 30.
    
     " This select doesn't filter on bdter unless the selection parameter was set by the user.
     SELECT r~aufnr p~psphi
         FROM resb AS r
         INNER JOIN afpo AS o ON o~aufnr = r~aufnr
         INNER JOIN prps AS p ON p~pspnr = o~projn
         INTO TABLE lt_resb_ss
         WHERE r~bdter IN s_bdter.
    

Is this known and documented behaviour? I resolved it by creating my own RANGE table, is this what you're always supposed to do? Is there then no way to re-use unset select-options to prevent code duplication?

1

There are 1 answers

4
knut On BEST ANSWER

You only fill the header line of s_bdter. You must also append it:

" Set the interval.
s_bdter-sign = 'I'.
s_bdter-option = 'BT'.
s_bdter-low = lc_bdter_start.
s_bdter-high = sy-datum + 30.
append s_bdter. "<- this was missing

With this, you don't check, if it isn't filled. This check must be done explicit:

" describe table s_bdter.
if sy-tfill = 0.
  " Set the interval.
  s_bdter-sign = 'I'.
  s_bdter-option = 'BT'.
  s_bdter-low = lc_bdter_start.
  s_bdter-high = sy-datum + 30.
  append s_bdter. "<- this was missing
endif. " sy-tfill = 0.

I hope my code has the correct syntax and sy-tfill is the correct value. I can't check it actual. But the principle should be clear.