Problem solve Get help with specific problems with your technologies, process and projects.

Which SQL command is better?

Which of the following SQL commands is better to use SELECT SINGLE * or SELECT SINGLE INTO?
Specifying the fields you are using is usually better programming practice. The simplest reason is that the fewer fields retrieved, the better the performance.

On a more philosophical level, some developers say the former is better, because then if you, or a later developer needs a field, it is available. I disagree. In my view, the developer should always know what data he is dealing with, and should only specify that which he is actually using. To do otherwise, can lead to unexpected results. For example, a table with two fields whose names are very similar. E.g. txtln and txtnl. Perhaps you are only interested in txtln, and you define only that in your DATA statements, and specify the field in your SELECT. If you accidentally type txtnl, you will get a syntax error. However, if you use SELECT SINGLE *, you won't know, until your program starts behaving oddly. Many SAP field names are abbreviations of German words. Many are very similar to each other. This kind of error does happen!

The only times I would use SELECT SINGLE * are:

1. If I really do need all the fields
2. I need many fields from the table, and the danger of un-clear coding is greater than that of specifying unused fields.
3. You need the structure to work with SAP defined structures -- e.g. when using SAP function modules.

Dig Deeper on SAP Basis

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.