Skip to Content
avatar image
Former Member

ST05 - Explain SQL

Hi,

I want to try out different kinds of sql-statements inside ST05.

Now:

This doesn't work:

SELECT VBAK~VBELN FROM VBAK

This works:

SELECT VBELN FROM VBAK

I need to get the first option to work as well. Mainly because I want to make some inner join stuff...

Any pointers ?

//Martin

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Sep 15, 2005 at 07:56 AM

    Hi Martin!

    In ST05-Explain you have to use (something like) native SQL. I copied statement from an explain of a trace:

    SELECT  * FROM   "USR21" 
    WHERE "MANDT" = :A0 AND "BNAME" = :A1

    and replaced the variables with some values (shown in the list below):

    SELECT  * FROM   "USR21" WHERE "MANDT" = "200" AND "BNAME" = "MY_USER"

    Now I'm also able to make new statements 'from scratch':

    SELECT * FROM "VBAK"
    WHERE   "MANDT" = '200' AND "VBELN" = '000000616'

    Just write your statement in a test report (local) in development system, make a trace, copy this in your production (or test) system and replace the variables accordingly.

    I guess, the syntax might be DB dependent, but by this way that's not a problem.

    Regards,

    Christian

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      so a join as example brings this result:

      SELECT
        T_00 . "VBELN"
      FROM
        "VBAK" T_00 , "VBAP" T_01
      WHERE
        ( T_01 . "MANDT" = :A0 AND T_00 . "VBELN" = T_01 . "VBELN" ) AND T_00 . "MANDT" = :A1 AND T_00 .
        "VBELN" > :A2

      - and without join no explicit definition is possible (or would make sense).

      Regards,

      Christian

  • avatar image
    Former Member
    Sep 15, 2005 at 05:44 AM

    Martin,

    That's right, you only use the '~' when you do joins.

    select vbak~vbeln from vbak

    is not a join

    try

    data: begin of tbl_vbak occurs 0,
            vbeln  like vbak-vbeln,
            posnr  like vbap-posnr,
          end of tbl_vbak.
    
    select vbak~vbeln
           vbap~posnr
           into table tbl_vbak
           from vbak
           inner join vbap
           on vbak~vbeln = vbap~vbeln.
    

    Cheers,

    Pat.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Martin,

      If you put this sample code in a ABAP program:

      data: begin of tbl_vbak occurs 0,
              vbeln  like vbak-vbeln,
              posnr  like vbap-posnr,
            end of tbl_vbak.
       
      select vbak~vbeln
             vbap~posnr
             into table tbl_vbak
             from vbak
             inner join vbap
             on vbak~vbeln = vbap~vbeln.

      then run ST05 to activate the trace, run your program, deactivate the trace, then view the trace.

      Look for the VBAK PREPARE line and click onit and hit Explain.

      You will see at the bottom a little tree structure. It will identify the index hit here (in this case VBAK0 and VBAP0).

      You will also see the parsed SQL statement on the top half of the screen.

      Hope this answers your question.

      Cheers,

      Pat.