SELECT SINGLE vs SELECT UP TO 1 ROWS
Man, this is one of those endless discussions that will never get anywhere. Ditto trying to decide if you deserve to go on living if you put pineapple on your pizza or Philadelphia cheese on your sushi.
Man, this is one of those endless discussions that will never get anywhere. Ditto trying to decide if you deserve to go on living if you put pineapple on your pizza or Philadelphia cheese on your sushi.
I was always told that, when selecting a single record, I should use UP TO 1 ROWS whenever the key was not fully provided. My elementary school teacher told me that I should always aks why: why? Nobody ever told me why.
When you’re going to modify existing records of a database table it is common to first SELECT them to see how they are and only then UPDATE them with what they will be.
I recently found a program which was generating an SQL statement by concatenating several variables with fixed SQL parts. But, either by not paying attention or simple ignorance, the person who did it, thought it would make sense to associate a text-symbol to each of these variables with. Something like this:
[Guest post by Artur Moreira]
From ABAP version 7.4, SAP introduced the code pushdown concept, which means using more database for calculations (data aggregation, sums and previous calculations).
Sometimes ABAP SQL doesn’t allow you to do something you’d be able to do using the database’s native SQL. It can still be done.
Toad is a very famous SQL tool which allows you to build and execute SQL queries in an easy and interactive way. And now, thanks to Mr. Sébastien HERMANN, SAP has a simplified version of this wonderful tool.
Thank you Sérgio Fraga for spotting this.
Greetings from Abapinho.
Someone asks you to select records based on a criteria for which you’ll have a small set of known values which you’re told will never change. Did you know you can do it directly in the SELECT?
Get ready because you’ll soon be running into a lot of surprises. ABAP is learning new tricks. Look at this one:
CONSTANTS:
lc_menina TYPE STRING VALUE ‘GIRL',
lc_menino TYPE STRING VALUE ‘BOY’,
lc_senhor TYPE STRING VALUE ’GENTLEMAN’,
lc_senhora TYPE STRING VALUE ‘LADY’.
SELECT nome,
CASE
WHEN sexo_id = ‘M' AND idade < 18 THEN @lc_menino
WHEN sexo_id = ‘F’ AND idade < 18 THEN @lc_menina
WHEN sexo_id = ‘M' AND idade >=18 THEN @lc_senhor
WHEN sexo_id = ‘F’ AND idade >=18 THEN @lc_senhora
END AS titulo
FROM zpessoa
WHERE pessoa_id = @pessoa_id
INTO CORRESPONDING FIELDS OF @lt_pessoas.You just have to wait for version 7.40.
Since data operations are much more optimized in the database server than in ABAP, it is always better to use the first as much as possible. FOR ALL ENTRIES should only be used when INNER JOIN doesn’t give us what we need or is not possible (like with BSEG for example). Artificial ranges are also a possible alternative to FOR ALL ENTRIES but be careful not to reach the SQL parser limit. It depends on the database server but as a rule of thumb avoid ranges with more than 1000 lines. When using FOR ALL ENTRIES always make sure the internal table is not empty or else all lines of the database table will be fetched.