Вы находитесь на странице: 1из 8

HOW TO EXECUTE SQL STATEMENTS

DIRECTLY VIA SQL COMMAND


EDITOR IN SAP ST04
GALLERY AUGUST 26, 2013 ERIC LEAVE A COMMENT

Sometimes, you might want to execute a SQL command/script directly


without using ABAP program in SAP system. You cannot write an ABAP code
in non-development box directly or you do not want to write a full ABAP
program just for executing a SQL etc. This post would show you on how to
enter SQL code and execute them directly without any ABAP program via
SQL command editor function provided by SAP DBA cockpit or SAP ST04
transaction. You got to have SQL knowledge to do this That is a precondition. My environment is based on Oracle 11.0 and SAP ECC 6.0.
Contents of the post:
1.
What is SAP utilities for executing SQL command directly
2.
General steps to execute SQL command in SAP system
3.
A few examples
4.
Other features of SQL command editor

1 What is SAP utilities for executing SQL


command
SAP DBA Cockpit provides a SQL command editor for you to enter a SQL
statement/script, parse it, execute it and review the result directly without
any ABAP knowledge. You can access SAP DBA Cockpit via SAP transaction
code DBACOCKPIT, or SAP transaction ST04, DB02 etc. After you are in SAP
DBA cockpit, you can use following path to access SQL command editor
functions in the cockpit navigation panel: Performance ->Additional functions
-> SQL Command Editor. Double click SQL Command Editor to launch the
SQL command editor screen refer to figure 1.

Figure 1 SAP SQL Command Editor Screen

2 General steps to execute SQL command


in SAP system
Now steps to run SQL statement in SQL command editor:
1. Enter SQL command in the ENTER SQL Statement tab ( refer to
Figure 1 )
2. Parse SQL command via drop-down menu SQL Command -> Parse
(F7 key)
3. Execute SQL command via drop-down menu SQL Command ->
Execute
4. Review the result SQL result is showed in Result tab of SQL
command editor
You can bypass Parse step and directly go to Execute. If you do that, SAP
would combine Parse and execute in one step. If SQL syntax is not
correct, you need to fix the syntax error. You can refer to other online
document to understand SQL syntax and how to fix SQL syntax error.
Please take note some SAP ABAP SQL KEY words is not supported in SQL
command editor like Single etc. and some Operators like EQ cannot be
used as well.
Need to know more? check book Expert Oracle Database Architecture

3 A few examples to execute SQL


statement using SQL command editor
Here I would show cases to query data from SAP configuration table, SAP
transaction table, SAP SIS table and Oracle system table. I would show
example on select on single table, multiple table and oracle hints technically.
Hope to give you some basic concept on executing SQL statement via SQL
command editor.

3.1 Retrieve SAP Configuration data one


table
In this example, we need to get company description for a list of company
code from SAP table T001 table. The SQL is
SELECT mandt, bukrs, butxt
FROM t001
WHERE mandt = 430 AND
bukrs IN (0001, AU01)
ORDER BY bukrs

Enter above SQL statement into Enter SQL Statement, Do parsing(F7), then
execute (F8), Data is returned in Result tab. Please refer to Figure 2.

Figure 2 retrieve company description via SQL command editor

A great book on SAP performance SAP Performance Optimization Guide:


Analyzing and Tuning SAP Systems, SAP Basis, SAP Administration

3.2 Retrieve SAP transactional data two


tables
This SQL is to get order information from order header VBAK and order item
table VBAP.
SELECT h.vbeln, l.posnr, l.matnr, l.kwmeng
FROM vbak h, vbap l
WHERE h.vbeln = l.vbeln
h.vbeln = 0010033682

Please refer to Figure 3 for the SQL and result.

Figure 3 Retrieve order info via SQL command editor

3.3 Retrieve data from Oracle system review


and table
This is to retrieve information related to an existing SQL based on SQL-ID.
Please refer to Figure 4 for detail

Figure 4 Retrieve SQL text via SQL command editor

Please take note that figure 5 show the SQL ID based on Oracle database
views

Figure 5 Part of SQLStats

3.4 Using Oracle hints in SQL command editor


Oracle hints can be used to influence SQL access path. Please refer to Figure
6( Full table access hints) and Figure 7(index hints)

Figure 6 Using Oracle Full table Hints in SQL Command Editor

Figure 7 Using Oracle Index hints in SQL command editor

4 Other features of SQL command editor


You can save the SQL you entered for sharing or late reference by clicking
Save of pull-down menu SQL command ( see figure 1). You need to give
an SQL statement ID. The SQL statement ID can be used for loading the
saved SQL statement into SQL command editor for execution/modification.
You can load a pre-saved SQL via statement id by clicking Load in SQL
Command pull-down menu.
You also execute the SQL in background job by clicking Execute
Background in Figure 1. In this case, you can check result via SAP SM37
transaction, result of SQL execution is output to spool file (Figure 8). For a
long query, you might wish to execute it in background instead of online
since duration of an online process is normally limited by system setting for a
dialog process.

Figure 8 Execute SQL in Command Editor via background job

5 Further Information
If you are interested in learning SQL commands, you can refer to Oracle
online document: http://docs.oracle.com/html/A95915_01/sqcmd.htm.
So far, you can see that you can get information from SAP tables and Oracle
tables by executing SQL command directly from SQL command editor. You
might wonder so what and how that would help on SAP application
performance analysis and trouble-shooting. You can use SQL command editor
to verify which execution plan is better for performance. You also can verify
whether performance is a cause of unexpected index change I would cover
this via example in my future post.

Reference: http://www.sap-perf.ca/execute-sql-statement-directly-in-sap/

Вам также может понравиться