2

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Lilienthal
  • 4,327
  • 13
  • 52
  • 88

1 Answers1

5

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.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
knut
  • 27,320
  • 6
  • 84
  • 112
  • Ah of course. I hadn't considered that select-options would still use the deprecated table objects with header lines. – Lilienthal Dec 27 '13 at 14:37
  • 1
    One alternative: You could fill the range during initialization and make the select option obligatory. The filling during initialization makes the default visible to the user, obligatory guarantees that the values are not deleted. But get attention if you use it in batch - initialization is not executed. – knut Dec 27 '13 at 14:44
  • Is that because a batch specifies a variant which overwrites the selection screen parameters after the initialization step completes? – Lilienthal Dec 27 '13 at 15:08
  • I memorize `INITIALIZATION` is not executed in batch. But perhaps this is a false opinion, perhaps the values are overwritten from the variant. Similar problems may occur with submit. – knut Dec 27 '13 at 15:51