01-28-2022 10:21 AM
I have the following 2 select statements to build my internal table.
This works perfectly but I am wondering if there is a better, more efficient, neater way of doing this? Maybe with just 1 select somehow.
SELECT * FROM trdir INTO TABLE @DATA(lt_trdir)
WHERE name LIKE 'Z%'
AND subc = '1'
AND cdat GT '20210101'.
SELECT * FROM trdir APPENDING TABLE lt_trdir
WHERE name LIKE 'Z%'
AND subc = 'I'
AND varcl = abap_true
AND cdat GT '20210101'.
01-28-2022 10:30 AM
I think this should do the same but in one select.
SELECT * FROM trdir INTO TABLE @DATA(lt_trdir)
WHERE name LIKE 'Z%'
AND ( subc = '1' OR ( subc = 'I' and varcl = @abap_true ) )
AND cdat GT '20210101'.
01-28-2022 10:30 AM
I think this should do the same but in one select.
SELECT * FROM trdir INTO TABLE @DATA(lt_trdir)
WHERE name LIKE 'Z%'
AND ( subc = '1' OR ( subc = 'I' and varcl = @abap_true ) )
AND cdat GT '20210101'.
01-28-2022 12:28 PM
01-28-2022 11:05 AM
Please use meaningful title like "how to merge these 2 select statements into 1"
01-28-2022 11:06 AM
Hello gemini.twin
Just join both selects with OR:
SELECT * FROM trdir INTO TABLE @DATA(lt_trdir)
WHERE
name LIKE 'Z%'
AND subc = '1'
AND cdat GT '20210101'
OR
name LIKE 'Z%'
AND subc = 'I'
AND varcl = @abap_true
AND cdat GT '20210101'.
You could of course streamline the WHERE condition. However to me it's the most clear as it is.
Best regards
01-28-2022 12:28 PM