Skip to Content
avatar image
Former Member

Basic select does not work

Hello Expert,

I'm trying to write the following select to fetch list of records based on the various filters. There are two fields in Standard SAP VBAK table (VDATU and BSTDK) where I'm keep getting error. On the first AND ( vdatu EQ bstdk ) I'm keep getting error that (Field "BSTDK" is unknown). However, when I look at VBAP both the fields are part of this table. Can anybody please point out my mistake and how to rectify it.

SELECT vbeln erdat vdatu bstdk
FROM vbak
INTO TABLE git_vbak
WHERE erdat IN so_date
"AND ( vdatu EQ bstdk )
AND ( vbtyp EQ lc_vbtyp )
AND ( auart EQ lc_zshp OR auart EQ lc_zlcy )
AND ( augru EQ lc_sh OR augru EQ lc_lc )
AND ( bsark EQ lc_zonl OR bsark EQ lc_zpws OR bsark EQ lc_zoff OR bsark EQ lc_zedi OR bsark EQ lc_zotb ).
sort git_vbak by vbeln.

Many thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 10, 2012 at 08:46 PM

    If you're trying to get a record where VBAK-BSTDK = VBAK-VDATU then it can't be done like this. You either need a subquery (see ABAP Help) or select into an internal table (like you're already doing) and then run through that internal table comparing the fields.

    The error message is because after 'VDATU EQ...' some local variable is expected and obviously there is no variable with the name BSTDK.

    Just a note - instead of the multiple OR conditions you might want to have those values in a range (or even as a selection criteria). Also you don't need parenthesis if there is just one statement. The whole thing is barely readable...

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 10, 2012 at 08:34 PM

    Hi Zero,

    You are trying to compare two fields within the database record itself...

    AND ( vdatu EQ bstdk )

    rather than comparing a database field with a local value. The compiler is expecting bstdk to exist within your local program, just as the range so_date exists locally and the constants lc_vbtyp, lc_zshp, lc_zlcy, etc exist locally.

    By the way, you can substitute the parenthetical OR expressions...

    AND ( augru EQ lc_sh OR  augru EQ lc_lc )

    with a range...

    AND augru IN (lc_sh, lc_lc)

    Also, instead of sorting your table after the select, you can sort the table as part of the select for better performance...

    SELECT ...               FROM ...               WHERE ...               ORDER BY vbeln



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Amy King

      Many thanks Amy for suck a big help. I wrote the following INNER JOIN

      I'm having it transported to Staging but still my fear is volume. There are more then 76 million records so let see how the above JOIN works.