Documente Academic
Documente Profesional
Documente Cultură
To subscribe to ERPtips, go to
www.ERPtips.com/Subscribe.asp.
How often do you find that your department is calling in a consultant in order to make business
process changes to a custom-built SAP application? We know it happens frequently, and it adds
up quickly. But before you shrug and say, “it`s unavoidable,” you need to read Rehan Zaidi`s latest articl
Open SQL. Due to the numerous We’ll also discuss the clauses or data is to be fetched. In such cases,
advantages that Dynamic Open SQL parts of SQL statements that may the known parameters are written
provides to customers, learning the be specified dynamically, as well as statically, whereas the unknown por-
basics of this technique is essential highlight the importance of addition- tion is specified using suitable ABAP
for developers and consultants. al code that should be used in con- variables. At the time of program
junction with Dynamic Open SQL. execution, the SAP system carries out
The goal of this article is to provide Finally, I will use an easy-for-all the parsing of the dynamic portion
a detailed description of Dynamic company scenario to illustrate how of the SQL statement and combines
Open SQL and the benefits it pro- this works, with, of course, any tips it with the static portion in order to
vides. These are some of the ques- learned from my experience. execute the entire SQL statement.
tions that this article will address.
This article is primarily intended As compared to statements speci-
• What is Dynamic Open SQL and for ABAP developers, but SAP users fied statically, we need to write extra
why is it necessary? who regularly work with developers coding prior to the SQL statements
to accommodate relevant flexibility whose components are to be deter-
features in their programs may also mined at runtime. This coding
a) first creates the additional ABAP determining the number of rows of a • In the first step a variable, MYREF,
variables to be used in the SQL table, the following static statement is defined as:
statement, may be used:
DATA: MYREF TYPE REF TO DATA.
b) then, creates the Dynamic Open SELECT COUNT(*) FROM SPFLI INTO MYNUM.
SQL code construct, This is used for storing the refer-
The above statement specifically ence to the data object.
c) and then stores this code in the counts the total records in the data-
defined ABAP variables. base table SPFLI. However, if you • Next, a working area corresponding
need to write a program for any data- to the dynamic table name stored
The art of Dynamic Open SQL base table that the user specifies, the in MYTABLE is created:
programming lies in combining these following Dynamic Open SQL state-
SQL statements with some elegant ments will be required: CREATE DATA MYREF TYPE (MYTABLE).
ABAP programming logic in order to
write powerful generic code. Dynam- DATA: MYTABLE(20). This statement lets you make
ic Open SQL provides a number of SELECT COUNT(*) FROM (MYTABLE) INTO MYREF refer to the work area.
advantages to SAP developers and MYNUM.
consultants: • You’ll then define a field symbol
Note: The variable that refers to the that should point to your work
• The code is more meaningful and dynamic part of the SQL statement is area. This assignment is made via
compact. specified in parenthesis, for example an ASSIGN statement:
• No additional resources are used (MYTABLE).
for generating the source code. FIELD-SYMBOLS : <ONERECORD> TYPE
At runtime, the variable MYTABLE ANY.
• All appropriate syntax checks are is populated with the name of the ASSIGN MYREF->* TO <ONERECORD> .
performed, and the program may table that you are interested in. The
be debugged very easily. SELECT statement is then used to • The SELECT statement is finally
read the number of rows in the table used to read data row by row from
Since SAP Release 4.6, the ABAP and store the value in the MYNUM the table in question, with the help
language provides a stable set of variable. of the work area pointed by field
features pertinent to Dynamic Open symbol ONERECORD:
SQL. In the SAP Web Application Dynamically Specifying
Server 6.10, the Dynamic Open SQL Parts of the SELECT state- SELECT * FROM (MYTABLE) UP TO 100 ROWS
capabilities of ABAP were further ment INTO <ONERECORD>.
improved. Some of the statements As already mentioned, a number ……
(and their clauses) that may be of clauses of the SELECT statement .......
specified dynamically are shown in may be specified dynamically. Let’s ENDSELECT.
SAPtipsJournal