2017 Jul 28 8:14 AM
Hi,
Please advise if this can be done in the single select clause?
Select vbeln , posnr , matnr ,
case
when matnr = 'M-01' then '50'
else 'FOC'
End as Amt ,
Concat(vbeln , posnr , matnr , Amt) as Status
from vbap into table @data(it_tab).
.........
The above mentioned code will give error as Amt is unknown until runtime,you cannot specify a fieldlist
How to use the variable created during runtime in the same select clause for initializing another variable in ABAP 7.4?
Hi,
Please advise if this can be done in the single select clause?
Select vbeln , posnr , matnr ,
case
when matnr = 'M-01' then '50'
else 'FOC'
End as Amt ,
Concat(vbeln , posnr , matnr , Amt) as Status
from vbap into table @data(it_tab).
.........
The above mentioned code will give error as Amt is unknown until runtime,you cannot specify a fieldlist
How to use the variable created during runtime in the same select clause for initializing another variable in ABAP 7.4?
2017 Jul 28 9:37 AM
An alias defined with AS can be used behind ORDER BY only. As far as I know that is common for SQL, not only for Open SQL.
As a workaround, use the expression twice (ugly, but this is SQL). From 7.51 on WITH might help.
SELECT carrid,
CASE WHEN connid = '0400' THEN 'X' ELSE 'Y' END AS expr,
concat( CASE WHEN connid = '0400' THEN 'X' ELSE 'Y' END , 'X' ) AS text
FROM spfli
INTO TABLE @DATA(itab).
2025 Apr 03 3:30 PM
Also here:
sql - Reference a created column in the same select statement - Stack Overflow
is written:
"You can only reference a calculated column in the order by clause.":
howerer, there is also written:
"For any other use either use a sub-query or repeat the logic."