Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Neater coding technique?

former_member201275
Active Contributor
0 Kudos
Hi All,

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'.
1 ACCEPTED SOLUTION

S0010925360
Participant

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'.
5 REPLIES 5

S0010925360
Participant

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'.

0 Kudos

Thank you Jorge

Sandra_Rossi
Active Contributor

Please use meaningful title like "how to merge these 2 select statements into 1"

DominikTylczyn
Active Contributor
0 Kudos

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

0 Kudos

Thank you Dominik