Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

CREATE VIEW in ABAP (Open SQL or Native SQL)

Hi all you experts!

I want to create a VIEW in ABAP. I have created Table Views using ABAP Dictionary (in transaction SE11), I don't have any problem with them.

But, what I need is to create a dynamic view, I mean, a view that can be created/replaced (or modified) at runtime. Is this possible with SAP Open SQL, I don't think so... that is why I tried to created using native SQL but it is not working.

Here is the code:

  EXEC SQL.
    CREATE VIEW [ZMXRFIV_GLPCA]
      AS SELECT
         T1.GL_SIRID,
         T1.POPER,
         T1.RBUKRS,
         T1.RPRCTR,
         T1.RACCT,
         T1.HSL
      FROM
         GLPCA T1
      INNER JOIN
         SKA1 T2
      ON
         T1.RACCT = T2.SAKNR
      WHERE
        T1.RVERS      =  '000'
        AND T1.RYEAR  =  '2008'
        AND T1.KOKRS  =  'PI01'
        AND T2.KTOPL  =  'PI00'
        AND T2.XBILK  <> 'X'.
  ENDEXEC.

I have tried using quotes (") for the view name, parenthesis and even using only the name but this make no difference.

Do any of you experts have any idea?

PS: After creating the view I need to do a SELECT INTO TABLE to that view and finally delete this view and continue working with the data on the internal table.

Tags:
Former Member
Former Member replied

A database view is not really a database object; rather it is a join defined by a SQL statement that has been created and stored in the database when you define the view. At runtime, this bit of SQL is appended to your SQL. This being the case, I shouldn't think that there would be much difference in performance between using a join in the SQL statement in your program or using a database view - though since the database view has been predefined and the database optimiser knows about it, I guess using one would be slightly quicker since there would be less time spent on parsing the statement.

By creating the view at runtime, I think you would lose even this advantage. Is there really such a great difference between using a database view and not? What does explain plan in ST05 say?

Oh, and did you try removing the final full stop from your real SQL statement?

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question