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

Problem with SQL Statement

Former Member
0 Likes
625

I currently have the following code which returns no data:

TYPES: BEGIN OF i_test,
          vbeln LIKE vbak-vbeln,
       END OF i_test.

DATA: test TYPE STANDARD TABLE OF i_test
                WITH HEADER LINE
                WITH NON-UNIQUE KEY vbeln.

SELECT DISTINCT vbeln
  INTO CORRESPONDING FIELDS OF test
  FROM vbak
  WHERE bstnk LIKE '05.06.2007%'.
ENDSELECT.

But when I create an SQVI query with the same criteria I get 12 sale documents (I enter 05.06.2007* into the bstnk field).

Does anyone know what I am doing wrong?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
594

HI,

To read a several entries from the database, use the following:

SELECT [DISTINCT] <cols> ... WHERE ...

If you do not use DISTINCT (<lines> is then empty), the system reads all of the lines that satisfy the WHERE condition. If you use DISTINCT, the system excludes duplicate entries.

The result of the selection is a table. The target area of the INTO clause can be an internal table with a line type appropriate for <cols>. If the target area is not an internal table, but a flat structure, you must include an ENDSELECT statement after the SELECT statement:

SELECT DISTINCT (vbeln)

INTO CORRESPONDING FIELDS OF test

FROM vbak

WHERE bstnk LIKE '05.06.2007%'.

ENDSELECT.

4 REPLIES 4
Read only

Former Member
0 Likes
595

HI,

To read a several entries from the database, use the following:

SELECT [DISTINCT] <cols> ... WHERE ...

If you do not use DISTINCT (<lines> is then empty), the system reads all of the lines that satisfy the WHERE condition. If you use DISTINCT, the system excludes duplicate entries.

The result of the selection is a table. The target area of the INTO clause can be an internal table with a line type appropriate for <cols>. If the target area is not an internal table, but a flat structure, you must include an ENDSELECT statement after the SELECT statement:

SELECT DISTINCT (vbeln)

INTO CORRESPONDING FIELDS OF test

FROM vbak

WHERE bstnk LIKE '05.06.2007%'.

ENDSELECT.

Read only

Former Member
0 Likes
594

I am confused by what you have told me as I am already using SELECT DISTINCT...ENDSELECT.

Read only

Former Member
0 Likes
594

Hi,

Try

SELECT DISTINCT vbeln

INTO <i>TABLE</i> test

FROM vbak

WHERE bstnk LIKE '05.06.2007%'.

As written your code is filling the internal table header, but not moving the data to the table body.

Read only

Former Member
0 Likes
594

HI,

In the where condition you specied '05.06.2007%'. in the selects % means it will take all the charecters after the 05.06.2007.

lets say, if there is any entry with 05.06.2007A, then it will consider as a entry in the select statment,

and also use the () with the DESTICT statment

Regards

Sudheer