Questions tagged [opensql]

Open SQL is used for SAP database access in the ABAP programming language.

Presentation

ABAP SQL (named Open SQL before version 7.53), is a set of ABAP statements that performs operations like reads, modifies or deletes data in the SAP database. ABAP SQL is independent of the database system, so the syntax of the ABAP SQL is uniform for all the databases supported by SAP.

All ABAP SQL statements are passed to the database interface. The DB interface converts the ABAP SQL into native SQL and passes it on to the database.

ABAP SQL Description

  • SELECT : Reads data from database
  • INSERT : Inserts lines to database
  • UPDATE : Changes the contents of lines in database
  • MODIFY : Inserts lines into database or changes the contents of existing lines
  • DELETE : Deletes lines from database

Links

ABAP SQL (ABAP documentation)

A complete guide to OpenSQL statements (SAP Community Blog Post)

Related Tags

288 questions
11
votes
1 answer

Select all fields from table A but single field from B?

Is there a way in ABAP's OpenSQL to simplify the select columns in a JOIN when I want to grab all the fields of one table but only selected fields from the other table(s)? For instance, in mysql we can simply do: SELECT tb1.*, tb2.b, tb2.d FROM …
Lilienthal
  • 4,327
  • 13
  • 52
  • 88
9
votes
1 answer

Reading original (before change) DB values in the current LUW?

Is it possible to retrieve the old or original values for a table when it has been changed, but not yet committed, in the current LUW? I'm implementing a BAdI that's supposed to be used to raise messages based on changes performed to an object, but…
Lilienthal
  • 4,327
  • 13
  • 52
  • 88
6
votes
4 answers

Case-insensitive comparison in SELECT condition

In ABAP SQL can I ignore the case when comparing fields in the WHERE clause of a SELECT? SELECT * FROM some_table WHERE field1 = variable1. How can I compare field1 to variable1 ignoring different case?
Dustin Sun
  • 5,292
  • 9
  • 49
  • 87
6
votes
2 answers

Literals in ABAP OpenSQL?

in SQL it is usually possible to use literals in a select statement, e.g. like this SELECT 'I', 'EQ', table.alev_uuid FROM table Is there any chance to do this in an ABAP SQL query? what I tried so far is this: DATA lt_aldf TYPE RANGE OF…
Felix
  • 78
  • 4
  • 15
6
votes
1 answer

How do I retrieve all child nodes of a hierarchical structure in ABAP?

Suppose I have a database table representing a hierachical structure, with the following columns: id predecessor_id name Starting from a given ID, I have to be able to retrieve all child nodes (not only the direct children). Since Common Table…
Tudor Ciotlos
  • 1,805
  • 4
  • 29
  • 47
5
votes
2 answers

Select statement with offset?

I'm trying to use this SELECT statement in ABAP: SELECT DISTINCT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE field1+7(16) IN s_field1 AND field2 IN s_field2. but I can't use offset for a dbtab…
Darko
  • 1,448
  • 4
  • 27
  • 44
5
votes
3 answers

SUM totals by FOR ALL ENTRIES itab keys

I want to execute a SELECT query on a database table that has 6 key fields, let's assume they are keyA, keyB, ..., keyF. As input parameters to my ABAP function module I do receive an internal table with exactly that structure of the key fields,…
Emdee
  • 1,689
  • 5
  • 22
  • 35
5
votes
8 answers

ABAP select performance hints?

Are there general ABAP-specific tips related to performance of big SELECT queries? In particular, is it possible to close once and for all the question of FOR ALL ENTRIES IN vs JOIN?
ilya n.
  • 18,398
  • 15
  • 71
  • 89
5
votes
1 answer

Multiple conditions in a SELECT statement?

First off, I have no experience with ABAP, I'm operating on guesswork here. I want to add a condition to a SELECT in an existing report. The existing code looks like this: SELECT SINGLE * FROM EKPO WHERE EBELN = GT_MSEG-EBELN AND EBELP =…
Seyren
  • 340
  • 1
  • 3
  • 15
4
votes
3 answers

SELECT by column of type STRING

I'll try to explain as simple as possible. I have a Database table 'DB_JOURNAL' that has only 2 columns 'Date' and 'Journal' type String. example : 01.01.2020 | I played football. 02.02.2020 | I played basketball I want to write a Select…
HUJ
  • 47
  • 1
  • 6
4
votes
3 answers

Fetch a single field from DB table into itab

I want to fetch the a field say excep_point from a transparent table z_accounts for the combination of company_code and account_number. How can I do this in ABAP SQL? Assume that table structure is |company_code | account_number | excep_point |
Bunny Rabbit
  • 8,213
  • 16
  • 66
  • 106
4
votes
2 answers

Nested subquery in FOR ALL ENTRIES

Consultant sent me this code example, here is something he expects to get SELECT m1~vbeln_im m1~vbelp_im m1~mblnr smbln INTO CORRESPONDING FIELDS OF TABLE lt_mseg FROM mseg AS m1 INNER JOIN mseg AS m2 ON m1~mblnr = m2~smbln …
AlexanderK
  • 365
  • 7
  • 21
4
votes
2 answers

ABAP 7.40 SELECT .. ENDSELECT UP TO n ROWS syntax?

Update: The question should be withdrawn, the grammar is correct. Apparently, SAP defines ABAP via a grammar, which is then modified by additional rules in plain text. I missed this second part. I'm looking at the ABAP Keyword Documentation 7.40,…
Ulrich Scholz
  • 2,039
  • 4
  • 30
  • 51
4
votes
2 answers

How to recreate SAP queries in Oracle?

I need to recreate some SAP stored procedures in Oracle. I've been trying to find tutorials, similar questions, examples, etc about this but apparently no one had to do this before What Oracle SQL query can be similar to this SAP query ? SELECT *…
frankie015
  • 358
  • 2
  • 10
4
votes
4 answers

SUM the NUMC field in SELECT

I need to group a table by the sum of a NUMC-column, which unfortunately seems not to be possible with ABAP / OpenSQL. My code looks like that: SELECT z~anln1 FROM zzanla AS z INTO TABLE gt_ GROUP BY z~anln1 z~anln2 HAVING SUM(…
K B
  • 1,330
  • 1
  • 18
  • 30
1
2 3
19 20