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

regarding select single

Former Member
0 Likes
2,483

hi experts,

cud u plz tell me how to use select single statement can i use it to populat the internal table with header and body or only header,plz explain with the eg...thnx in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,948

Tables: mara. " here mara is only work area. You can take it as ONLY HEADER.

SELECT SINGLE *

FROM MARA

where matnr in s_matnr.

data:

t_mara like table of mara with header line.

SELECT SINGLE *

FROM MARA

into t_mara

where matnr in s_matnr.

In both the cases only the result will be populated into HEADER.

Not the table BODY.

So finally we have to use work area to get the select single output.

In general we will use this in VALIDATION cases. I mean to check the data is there in table for the specified ranges of values.

11 REPLIES 11
Read only

Former Member
0 Likes
1,948

select single will fetch only one record , in your terms it will fill only the header of internal table

select single matnr from mara into it_mara-matnr where matnr eq 'XXXXX'.

Read only

Former Member
0 Likes
1,948

Hi,

When you do the select single, Header and the Body will filled up with a single record, the header record and the Body record will be same

Regards

Sudheer

Read only

Former Member
0 Likes
1,949

Tables: mara. " here mara is only work area. You can take it as ONLY HEADER.

SELECT SINGLE *

FROM MARA

where matnr in s_matnr.

data:

t_mara like table of mara with header line.

SELECT SINGLE *

FROM MARA

into t_mara

where matnr in s_matnr.

In both the cases only the result will be populated into HEADER.

Not the table BODY.

So finally we have to use work area to get the select single output.

In general we will use this in VALIDATION cases. I mean to check the data is there in table for the specified ranges of values.

Read only

Former Member
0 Likes
1,948

Hi,

SELECT SINGLE:

1. Select single is based on PRIMARY KEY

2. It will take the first record directly without searching of all relevant records.(Though you have lot of records for given condition)

Regards,

Kumar.

Read only

Former Member
0 Likes
1,948

Hi Ravi,

Select single is used for fetching only one value.

If any single value found .sy-subrc becomes zero.

<b>with out header.</b>

Select single matnr into w_area from mara where matnr in s_matnr.

append w_area to itab.

with header.

Select single matnr into table itab from mara where matnr in s_matnr.

Regards,

Hemant

Read only

Former Member
0 Likes
1,948

Hi Ravi,

As it selects only one record at a time its not possible to directly insert into internal table's body. First select record into work area(headerline) then append it to internal table

DATA wa TYPE spfli.

SELECT SINGLE carrid connid cityfrom cityto

INTO CORRESPONDING FIELDS OF wa

FROM spfli

WHERE carrid EQ 'LH' AND connid EQ '0400'.

Regds,

Younus

<b>Reward Helpful Answers!!!</b>

Read only

Former Member
0 Likes
1,948

Hai,

SELECT SINGLE is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

The best way to find out is through sql trace or runtime analysis.

The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

Regards,

Padmam.

Read only

Former Member
0 Likes
1,948

Hi,

SELECT Single for only feching the data base tables then u can transfer to internal table. then u have to use

READ table tablename with key Primary key where value = internable value

in ur case only it will header value.

If it is solve ur problem give me points.

Read only

former_member196299
Active Contributor
0 Likes
1,948

hi Ravi,

Select single is the syntax you use when you want to select a single record from the database . you can use it to populat the internal table with header and body or without header line .

here you go with a sample prog ...

REPORT ZTEST03.

tables: mara.

data: begin of itab occurs 0,

matnr like mara-matnr ,

end of itab.

select single * from mara

into CORRESPONDING FIELDS OF itab .

write: itab-matnr.

hope this helps !

Reward if helpful !

Regards,

Ranjita

Read only

Former Member
0 Likes
1,948

Hi

You cant put table statement in select single, u can fetch the data to itab header or explicit work area

select single * into itab from mara where <condition>.

or

select single * into wa from mara where <condition>.

Thanks

Sandeep

Reward if helpful

Read only

Former Member
0 Likes
1,948

hi,

internal table without headerline.

select single * from table itab_mara into wa_mara where matnr in s_matnr.

internal table with headerline.

select single * from table itab_mara where matnr in s_matnr.

Reward with points if helpful.