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

Selecting literals instead of fields in Open SQL

afordham
Participant
1,786

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

3 REPLIES 3
Read only

varma_narayana
Active Contributor
0 Kudos
870

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>

Read only

Former Member
0 Kudos
870

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

Read only

MadhavSharma
Explorer
0 Kudos
801

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.