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

Adding columns in a open sql select query

Former Member
0 Likes
1,726

Hi Everyone,

I would like to add the values of n columns of a table and place them in one column, how can i achieve this in open sql.

In oracle native sql the query will look like this:

Select col1 + col2 + col3 AS col

from tab1;

On a similar grounds, i would like to concatenate the contents of n columns into one column. The oracle native sql will look like this:

select col1 || col2 || col3

from tab1;

How can I do this in Open SQL.

Thanks in advance.

Prabhu.

3 REPLIES 3
Read only

Former Member
0 Likes
777

Hi Prabhu,

I'm afraid what you're trying to do is not possible using the Open SQL. You will have to get the data from all the three columns into an internal table and then write your own logic to accomplish the same.

data : begin of itab occurs 0,
         col1 type i,
         col2 type i,
         col3 type i,
         col4 type i,
       end of itab.
field-symbols: <fs_itab> like line of itab.

SELECT COL1
       COL2
       COL3
  INTO TABLE ITAB.

LOOP AT ITAB assigning <fs_itab>.
  <fs_itab>-col4 = <fs_itab>-col1 + <fs_itab>-col2 + <fs_itab>-col3.
ENDLOOP.

Regards,

Anand Mandalika.

Read only

Former Member
0 Likes
777

I don't think it's possible in open sql..

you should use the ABAP processing to achieve this after selecting all the fileds in relevant varibles ( or itabs)..

Cheers,

Ram

Read only

0 Likes
777

Thanks you so much.