ABAP SQL Examples – Select Query
Requirement:
Select those MM tables which are language dependant (For example you want to translate the customizing in two languages)
Solution:
report zbctcb96.
tables: dd03l, tadir.
data: counter type i value 1.
select * from tadir where pgmid eq ‘R3TR’ and
object eq ‘TABL’ and
devclass like ‘M%’.
select * from dd03l where tabname eq tadir-obj_name and
( fieldname like ‘SPRA%’ or fieldname like ‘LANG%’ ).
write: / counter, dd03l-tabname, dd03l-fieldname.
add 1 to counter.
exit.
endselect.
endselect.
The TADIR contains the development objects. All the ‘table’ objects are selected which are in an MM development class (MM development classes begin with ‘M’).
The DD03L table contains the fields of the database tables. Just those tables are selected, which has a field beginning with either ‘SPRA’ or ‘LANG’. ( ‘language’ is ‘Sprache’ in german).
Performance considerations in this example:
How frequently runs the report?
This report was used only once . I have tried to run it in dialog and finished without ‘time out error’. Performance optimization is not necessary.
Is DD03L and TADIR buffered and how many records are in the tables?
You find it in /Development Workbench/ABAP 4 Dictionary, Table Display, /Goto/Technical settings
Table
Buffering
Expected size in records
DD03L
No buffering
310,000 – 24,000,000
TADIR
Buffering single records
92 000 – 370 000
Both are large tables with no or poor buffering. A good performance can be only expected when you use indexed fields of the tables.
Are the selection fields indexed?
The primary key fields are always indexed. Other fields are indexed through additional index files. From the Table Display, /Goto/Indexes.
Table
Index
Indexed fields
DD03L
DD03L_____5__X
TABNAME
AS4LOCAL
FIELDNAME
TADIR
TADIR__1
DEVCLASS
This means that both tadir-devclass and dd03l-fieldname are indexed. However it doesn’t help, because in the WHERE clause the selection fields does not fully match the index fields.
Are there nested SELECT statements?
An example of nested SELECT statements:
select * from tstc.
select * from tstct where sprsl eq ‘E’ and tcode eq tstc-tcode.
[..]
endselect
[..]
endselect.
No. In nested SELECTs every ABAP command is executed n*m times, where n and m are the numer of rows in the first table and second table. In this example, after the SELECT statement an EXIT is used which quits after processing one record.
Bence Toth
Related SAP Tutorials & References
- ABAP Program for Output Table Fields to a ListWhen you're looking at the structure of a table, SAP will let you print the...
- ABAP program for find the user-exits of a SAP transaction code*Sample ABAP program for Find the user-exits of a particular SAP transaction code (Tcode) *...
- SELECT ( SAP ABAP Keyword)SELECT is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax...
- SELECT clause ( SAP ABAP Keyword)SELECT clause is a keyword used in SAP ABAP programming.This tutorial covers its introduction &...
- ABAP program for Reading database tables using selectRequirement: Write the a report with a select statement. ABAP Source Code: report zselect1 no...
- ENDSELECT (ABAP Keyword)ENDSELECT (ABAP Keyword) introduction & syntax details ENDSELECTBasic formENDSELECT.EffectCloses a loop introduced by SELECT .NoteSELECT...
- SELECT-OPTIONS ( SAP ABAP Keyword)SELECT-OPTIONS is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax...
- ABAP Code Optimization Methods & TechniquesFor all entries Nested selects Select using JOINS Use the selection criteria Use the aggregated...
- CHECK ( ABAP Keyword)CHECK ( ABAP Keyword) introduction & DetailsCHECK - within loops Basic formCHECK logexp.EffectCHECK evaluates the...
- TABLES ( SAP ABAP Keyword)TABLES is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax...
