2007 Oct 04 12:19 PM
Is it possible to use a literal as opposed to a fieldname in the SELECT clause of a SELECT statement in order to populate all the columns in a table with the same value? For example (and I realise this doesn't syntax check), is there a way of doing the following without any looping statements?
* Build a range of Company Codes in a Controlling Area
data: r_bukrs type range of tka02-bukrs.
select 'I' as sign
'EQ' as option
bukrs as low
from table r_bukrs
from tka02
where kokrs eq '0001'.
Many thanks,
Andrew
2007 Oct 04 12:29 PM
Hi Andrew.
We cannot use Literals in place of field names in SELECT.
So this can be the Work around solution.
data: r_bukrs type range of tka02-bukrs.
data : t_bukrs type TABLE OF T001-BUKRS .
select
bukrs
INTO table T_bukrs
from tka02
where kokrs eq '0001'.
LOOP AT T_BUKRS into T_BUKRS-TABLE_LINE.
MOVE 'I' TO R_BUKRS-SIGN.
MOVE 'EQ' TO R_BUKRS-OPTION.
MOVE T_BUKRS-TABLE_LINE TO R_BUKRS-LOW.
APPEND R_BUKRS.
ENDLOOP.
<b>reward if helpful.</b>
2007 Oct 04 12:32 PM
Hi Andrew,
You can write the code in follwing way.
ranges:r_bukrs for tka02-bukrs.
select bukrs as low
into corresponding fields of table r_bukrs
from tka02
where kokrs eq '0001'.
r_bukrs-sign = 'I'.
r_bukrs-option = 'EQ'.
modify r_bukrs transporting sign option where sign is initial.
**Reward if useful
Regards,
Archana
2024 Apr 15 10:32 AM
Hi,
I am not sure about your specific requirement but if we have lots of entries in a table lets say, we have lots of entries in MARA table, I want specific entries where matnr starts with "SFDC". So inshort I am trying to create a range which stores this "SFDC" and selects only those fields.
This is the new syntax used for HANA.
DATA: lr_matnr type range of matnr,
ls_matnr like line of lr_matrn.
ls_matnr-sign = 'I'.
ls_matnr-option = 'CP'.
ls_matnr-low = 'SFDC*'.
Append ls_matnr to lr_matnr.
SELECT 'I' AS sign,
'EQ; AS option,
matnr AS low,
' ' AS high
from mara
into table @DATA(lt_matnr)
where ( matnr in @s_matnr AND matnr in @LR_matnr ).
// the s_matnr is a select option just to choose the matnr value from selection screen.
I hope I answered your query, The output table will have the 4 field i.e, sign, option, low, high
In the low field all the required matnr value will be stored.