2024 Jul 22 3:09 PM - edited 2024 Jul 22 3:15 PM
Hi Master,
I want to give a "range" condition to the where condition of the select query.
If you define range as follows and IV_WERKS is given an empty value, the SELECT query does not return data. Even if IV_WERKS is empty, shouldn't the select query return data because I defined Range?
***********************************************************************
DATA: LR_WERKS TYPE RANGE OF EKPO-WERKS,
lS_WERKS LIKE LINE OF LR_WERKS.
LS_WERKS-SIGN = 'I'.
LS_WERKS-OPTION = 'EQ'.
LS_WERKS-LOW = IV_WERKS. "IV_WERKS value is taken from the user on the screen.
APPEND LS_WERKS TO LR_WERKS.
SELECT
EKK~BUKRS,
EKK~LIFNR,
FROM EKKO AS EKK
LEFT JOIN EKPO AS EKP ON EKK~EBELN EQ EKP~EBELN
AND EKP~LOEKZ EQ ' '
AND EKK~BSTYP EQ 'F'
WHERE EKK~BUKRS EQ @iv_BUKRS
AND EKP~WERKS IN @LR_WERKS
AND EKK~LIFNR EQ @iv_LIFNR
INTO CORRESPONDING FIELDS OF TABLE @ET_RESULT.
*************************************************************************************
If I define my RANGE as follows, the select query returns the data correctly, even if IV_RANGE is empty.
********************************************************************
ranges lr_werks for ekpo-werks.
refresh lr_werks.
IF iv_werks is not INITIAL.
move 'I' to lr_werks-sign.
move 'EQ' to lr_werks-option.
move iv_werks to lr_werks-low.
append lr_werks.
ENDIF.
SELECT
EKK~BUKRS,
EKK~LIFNR,
FROM EKKO AS EKK
LEFT JOIN EKPO AS EKP ON EKK~EBELN EQ EKP~EBELN
AND EKP~LOEKZ EQ ' '
AND EKK~BSTYP EQ 'F'
WHERE EKK~BUKRS EQ @iv_BUKRS
AND EKP~WERKS IN @LR_WERKS
AND EKK~LIFNR EQ @iv_LIFNR
INTO CORRESPONDING FIELDS OF TABLE @ET_RESULT.
**********************************************************************************
If the IV_WERKS-LOW value is full, both selects return data. If the IV_WERKS-LOW value is empty, the 2nd code example works and the 1st code example works. But I think I made the correct range definitions in both.
How should the correct definition of "Range" be made? I have seen the 1st code example (not working) too many times on the internet.
Thanks
The IF-Condition from the second example is missing in the first one, so when IV_WERKS is empty your range will contain one row with I EQ and an initial value.
Add that IF-Condition there and it should work, too.
The "ranges"-keyword from the second example is deprecated and you should go for the first one with "type range of"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
58 | |
10 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.