Application Development 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: 

Select double * from database table?

naveen_inuganti2
Active Contributor
0 Kudos

Hi,

See the entries in the following database table.

TABLE1

F1 -- F2 -- F3 -- F4 -- F5 etc..,

AB 12 de effd 32e

CD 34 fr wref 45fr

EF 34 rfr wfrf wfwrf

Here I need to get the two values of F1 field. Those are AB and CD into two separate variables.

How can get these two values in to two variables with out DECLARING INTERNAL TABLE and with ONE SELECT QUERY?

--Naveen Inuganti.

8 REPLIES 8

Former Member
0 Kudos

Hi ,

Check the code , it will resolve the issue --

DATA : w_variable2 TYPE scarr-carrid,
       w_variable1 TYPE scarr-carrid .

SELECT carrid UP TO 2 ROWS FROM scarr
INTO w_variable2 .
  MOVE w_variable2 TO w_variable1.
ENDSELECT.
WRITE : w_variable1, w_variable2.

From your reference I created single silect query without internel table - -

DATA : w_variable2 TYPE dbtable-f1,
       w_variable1 TYPE dbtable-f1 .

SELECT F1 UP TO 2 ROWS FROM dbtable
INTO w_variable2 .
  MOVE w_variable2 TO w_variable1.
ENDSELECT.
WRITE : w_variable1, w_variable2.

Regards

Pinaki

Former Member
0 Kudos

Hi Naveen Inuganti,

You mean we need to select two rows from DB table or any other issue.

data : begin of t_f1,
         f1 type table-f1,
        end of t_f1.

data: wa_f1 like t_f1,
         tbl_f1 like table of t_f1.

select F1 from DBtable
                  into table tbl_f1
                  where " any condition need
                 up to 2 rows.

Regards,

Suneel G

Former Member
0 Kudos

Hi,

You cannot do this without internal table but you can do this using UPTO 2 ROWS addition with SELECT.

Anyway i fear you cannot get it done using your new technique Select double * from database table?

Regards

Karthik D

Former Member
0 Kudos

See the entries in the following database table.

TABLE1

F1 -- F2 -- F3 -- F4 -- F5 etc..,

AB 12 de effd 32e

CD 34 fr wref 45fr

EF 34 rfr wfrf wfwrf.

i think its not possible without internal table in one select statement but it is possible in two select statements.

former_member242255
Active Contributor
0 Kudos

this is working....

DATA : w_variable2 TYPE scarr-carrid,

w_variable1 TYPE scarr-carrid,

flag TYPE c.

SELECT carrid UP TO 2 ROWS FROM scarr

INTO w_variable2 .

IF flag IS INITIAL.

MOVE w_variable2 TO w_variable1.

flag = 'X'.

ENDIF.

ENDSELECT.

WRITE : w_variable1, w_variable2.

faisal_altaf2
Active Contributor
0 Kudos

Hi, Naveen.

Please Test the following Sample Code Hope it will solve out your problem,

DATA: ename TYPE emnam,
      ename1 TYPE emnam,
      ename2 TYPE emnam,
      count TYPE i VALUE 1.

SELECT ename FROM pa0001
  INTO ename
  WHERE pernr IN ('00000001', '00000002')
    AND endda = '99991231'.
  IF sy-subrc EQ 0.
    IF count EQ 1.
      ename1 = ename.
      ADD: 1 TO count.
    ELSEIF count EQ 2.
      ename2 = ename.
      ADD: 1 TO count.
    ENDIF.
    CLEAR: ename.
  ENDIF.
ENDSELECT.

WRITE: ename1, / ename2.

Please Reply if any Issue,

Best Regards,

Faisal

former_member222860
Active Contributor
0 Kudos

Hi,

Check this too.

TABLES: MARA.

DATA: var type string.
DATA: var1 type string.
data: var2 type string.

SELECT MATNR FROM MARA UP TO 2 ROWS INTO var.
  IF sy-dbcnt = 1.
    MOVE var to var1.
  elseif sy-dbcnt = 2.
    move var to var2.
  endif.
ENDSELECT.

WRITE:/ VAR1, VAR2.

Mahesh

0 Kudos

Hi Friends,

Thanks for your inputs,

Anyway select ...end select also hits database table two times in this case.

So declaring internal table to handle these two entries is better solution for this in terms of performance wise.

So hopefully no solution to meet what I asked.

Here one more thing want to conform you that here f1, f2 are key fields.

We are having values of field f2, so we just need to include them in where condition to get AB,CD of field f1, no need of upto 2 rows here.

__Naveen Inuaganti.