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

where contion in select statement

Former Member
0 Likes
12,183

Hi all

I wanted to select

SELECT VBELN KALSM KNUMV FROM VBRK INTO CORRESPONDING FIELDS OF ITAB

WHERE KALSM = 'ZDEPO2' OR KALSM = 'ZNETO1'.

but I am not getting value of vbeln kalsm and knumv for

KALSM = 'ZNETO1'

Regards

Shashi

Hi all

I wanted to select

SELECT VBELN KALSM KNUMV FROM VBRK INTO CORRESPONDING FIELDS OF ITAB

WHERE KALSM = 'ZDEPO2' OR KALSM = 'ZNETO1'.

but I am not getting value of vbeln kalsm and knumv for

KALSM = 'ZNETO1'

Regards

Shashi

6 REPLIES 6
Read only

Former Member
0 Likes
3,724

Hi,

SELECT

Reads data from the database.

Syntax

SELECT <result>

INTO <target>

FROM <source>

[WHERE <condition>]

[GROUP BY <fields>]

[HAVING <cond>]

[ORDER BY <fields>].

The SELECT statement consists of a series of clauses, each of which fulfils a certain task:

SELECT clause

Defines the structure of the selection.

Syntax

SELECT [SINGLE]|[DISTINCT]

  • | <si> [AS <a i>]... <agg>( [DISTINCT] <s j>) [AS <a j>]...

The selection can be one line, SINGLE, or several lines. You can eliminate duplicate lines using the DISTINCT addition. To select the entire line, use *, otherwise, you can specify individual columns <si>. For individual columns, you can use aggregate functions <agg>, and assign alternative column names <a i>.

INTO clause

Defines the target area into which the selection from the SELECT clause is written.

Syntax

... INTO [CORRESPONDING FIELDS OF] <wa>

| INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab>

[PACKAGE SIZE <n>]

| INTO (<f1>, <f 2>,...)

The target area can be a flat work area <wa>, an internal table <itab>, or a list of fields <fi>. If you use the CORRESPONDING FIELDS addition, data is only selected if there is an identically-named field in the target area. If you use APPENDING instead of INTO, the data is appended to an internal table instead of overwriting the existing contents. PACKAGE SIZE allows you to overwrite or extend the internal table in a series of packages.The data type of the target area must be appropriate for the selection in the SELECT clause.

FROM clause

The FROM clause determines the database tables from which the data specified in the SELECT clause is read.

Syntax

... FROM [<tab> [INNER]|LEFT [OUTER] JOIN] <dbtab> [AS <alias>]

[ON <cond>]

[CLIENT SPECIFIED]

[BYPASSING BUFFER]

[UP TO <n> ROWS]

You can read both single fields and groups of fields. You link several tables using inner and outer joins to link tables with conditions <cond>, where <tab> is a single table or itself a join condition. The names of database tables may be specified statically or dynamically, and you can use alias names. You can bypass automatic client handling with the CLIENT SPECIFIED addition, and SAP buffering with BYPASSING BUFFER. You can also restrict the number of lines read from the table using the UP TO <n> ROWS addition.

WHERE clause

Restricts the number of lines selected.

Syntax

... [FOR ALL ENTRIES IN <itab>] WHERE <cond>

The condition <cond> may contain one or more comparisons, tests for belonging to intervals, value list checks, subqueries, selection table queries or null value checks, all linked with AND, OR, and NOT. If you use the FOR ALL ENTRIES addition, the condition <cond> is checked for each line of the internal table <itab> as long as <cond> contains a field of the internal table as an operand. For each line of the internal table, the system selects the lines from the database table that satisfy the condition. The result set is the union of the individual selections resulting from each line.

GROUP BY clause

Groups lines in the selection.

Syntax

... GROUP BY <s1> <s 2>

Groups lines with the same contents in the specified columns. Uses aggregate functions for all other columns in each group. All columns of the SELECT clause that are not listed in the GROUP BY clause must be included in aggregate functions.

HAVING clause

Restricts the number of line groups selected.

Syntax

... HAVING <cond>

Like the WHERE clause, but can only be used in conjunction with a GROUP BY clause. The HAVING clause uses conditions to restrict the number of groups selected.

ORDER BY clause

Sorts the lines of the selection.

Syntax

... ORDER BY PRIMARY KEY |... <si> [ASCENDING|DESCENDING]...

Sorts the selection in ascending or descending order according to the primary key or the contents of the fields listed

Regards,

Priya.

Read only

Former Member
0 Likes
3,724

hi,

Does the table have data for that ..

Regards,

Arunsri

Read only

Former Member
0 Likes
3,724

Hi

See the bold

SELECT VBELN KALSM KNUMV FROM VBRK INTO CORRESPONDING FIELDS OF TABLE ITAB

WHERE KALSM = 'ZDEPO2' OR KALSM = 'ZNETO1'

Read only

vinod_vemuru2
Active Contributor
0 Likes
3,724

Hi,

First check whether VBRK table have the entries for the conditions in the where clause. Also see below the effective way of Select statement for ur requirement.

TYPES: BEGIN OF t_vbek,

vbeln TYPE vbrk-vbeln,

kalsm TYPE vbrk-kalsm,

knumv TYPE vbrk-knumv,

END OF t_vbrk.

DATA: i_vbrk TYPE STANDARD TABLE OF t_vbrk.

SELECT VBELN KALSM KNUMV

INTO TABLE I_vbrk

FROM VBRK

WHERE KALSM IN ('ZDEPO2' , 'ZNETO1').

Thanks,

Vinod.

Read only

Former Member
0 Likes
3,724

as posted by Vinod,

You can also define the Work Area for the ITAB.

data: itab type table of zstrcuture.

data: wa type zstructure.

Read only

Former Member
0 Likes
3,724

If you would liek to fill few columns in teh internal table INTO CORRESPONDING is fine.

Else u can use INTO TABLE.

Data: Begin of itab occurs 0,
         vbeln type vbrk-vbeln,
         kalsm type vbrk-kalsm,
         knumv type vbrk-knumv,
        End of itb.

SELECT VBELN KALSM KNUMV 
              FROM VBRK INTO TABLE ITAB
               WHERE KALSM IN ( 'ZDEPO2' ,  'ZNETO1').