ABAP SQL capture records of a date range of active employees

2k views Asked by At

Record in pa0000 / pa0001 has two records as follows:

Begda Endda

[03.07.2017 - 31.12.9999]

[03.01.2017 - 02.07.2017]

Selection screen has the date range: Low: 01/07/2017 and High: 31/07/2017

ABAP Code has written as follows:

 Select data from Pa0001 table
  SELECT PERNR
        ENDDA
         BEGDA
         PERSG
         PERSK
    FROM PA0001
    INTO TABLE T_PA0001
    WHERE PERNR IN S_PERNR[] AND
          BEGDA <= S_BUDAT-LOW AND
          ENDDA >= S_BUDAT-HIGH AND
          PERSG IN S_EMPGR[] AND
          PERSK IN S_EMPSG[] AND
          GSBER IN S_WERKS AND
         BTRTL = 'FURC' .

The aforesaid two records are not captured.

I would like to re-write the code by using the method "Exclude all wrong options" instead of present method "enlist all acceptable options", as follows.

WHERE NOT ( pa0001-begda > s_budat-high or pa0001-endda < s_budat-low)

Any help in this regard will be highly appreciated.

2

There are 2 answers

0
Jagger On

It probably does not work because S_BUDAT is a header of the internal table with header line S_BUDAT[] so in other words it is a structure. You should rather split select option S_BUDAT to two parameters eg. P_LOW and P_HIGH and rephrase your query.

The other option would be to write simply NOT IN S_BUDAT[].

0
Gert Beukema On

The selection you have now will only match employees that are active on all the days from S_BUDAT-LOW to S_BUDAT-HIGH. From your question it looks like you actually want to select all employees that have at least one day in that range. To get the last selection you can use:

BEGDA LE S_BUDAT-HIGH AND
ENDDA GE S_BUDAT-LOW