Application Development and Automation 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: 
Read only

Neater coding technique?

former_member201275
Active Contributor
0 Likes
1,530
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
Read only

Jorge_Herrero_Blanco
Participant
1,435

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
Read only

Jorge_Herrero_Blanco
Participant
1,436

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

0 Likes
1,435

Thank you Jorge

Read only

Sandra_Rossi
Active Contributor
1,435

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

Read only

Dominik_Tylczynski
SAP Champion
SAP Champion
0 Likes
1,435

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

Read only

0 Likes
1,435

Thank you Dominik