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
2
votes
2 answers

SELECT does not return rows when queried by VBELN

I'm trying to display table in alv from an internal table where rows are added form a table stored in the database. Without a where condition I see rows displayed in alv but with a where condition in the select statement no rows are returned. Here…
mj1261829
  • 1,200
  • 3
  • 26
  • 53
2
votes
3 answers

Conditional aggregation of VBAK/VBAP fields into single row in infoset

I encounter the following problem. What I want to do I want to create an infoset that would regroup, for a given Purchase Order, data from the VBAK table with several lines from the VBPA table that should be dispatched to different fields. Example…
Frederi ROSE
  • 297
  • 2
  • 9
2
votes
1 answer

max_blocking_factor and index hint in for all entry select

I have select looking like this: SELECT ztab1~field11 ztab1~field12 ztab2~field21 FROM ztab1 JOIN ztab2 ON ztab1~field10 = ztab2~field10 INTO CORRESPONDING FIELDS OF TABLE lt_data_tab FOR ALL ENTRIES IN lt_records[] WHERE ztab1~field13 =…
Skalozub
  • 539
  • 7
  • 26
2
votes
1 answer

SELECT FROM @itab causes syntax error. Why?

I try to use SELECT FROM @itab like explained here in SAP docs. I have never used this feature, but think this is great. You can query a internal data structure which just exists in the RAM of the interpreter like it would be a real table in the…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
2 answers

List of BUKRS which the current user is allowed to see

Is there a way to get a list of all BUKRS which the current user is allowed to see? I want to use this list as a filter in open sql. Imagine the result of the method I search stored the result in bk_list. Then I could use bk_list like this: SELECT *…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
1 answer

Meaningful error message for SAPSQL_PARSE_ERROR exception

I wrote a function in ABAP which gets called via SAP pyrfc. If there is a SAPSQL_PARSE_ERROR the RFC caller (the client written in Python) gets a meaningless error message: ABAPRuntimeError: RFC_ABAP_RUNTIME_FAILURE (rc=3): key=SAPSQL_PARSE_ERROR,…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
2 answers

Selecting multiple fields in subquery

This ABAP code works: select * into table from ADRC WHERE ADDRNUMBER in ( select ADRNRA from AUFK where (cond_string) ). But this does not: select * into table from ADRC WHERE (ADDRNUMBER, MANDT) in (…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
0 answers

Why does 'FETCH NEXT CURSOR' select no data?

I have the following code: OPEN CURSOR WITH HOLD dbcur FOR SELECT (it_attr) FROM (it_from) FOR ALL ENTRIES IN lt_filter_key WHERE (it_where). ... FETCH NEXT CURSOR dbcur INTO CORRESPONDING FIELDS OF TABLE…
Ovidiu Pocnet
  • 579
  • 12
  • 32
2
votes
3 answers

Quoting arguments in dynamic WHERE in OpenSQL

I found this example how to create a dynamic WHERE: REPORT ZII_RKP_TEST1. DATA: cond(72) TYPE c, itab LIKE TABLE OF cond. PARAMETERS: source(10) TYPE c, dest(10) TYPE c. DATA wa TYPE spfli-cityfrom. CONCATENATE 'CITYFROM = ''' source ''''…
guettli
  • 25,042
  • 81
  • 346
  • 663
2
votes
1 answer

SELECT SINGLE vs SELECT UP TO 1 ROW

I want to understand that why do we use select up to one row when we have select single and which one is faster, what happened at database level when we write those queries and is there any difference when we use HANA database.
2
votes
3 answers

COUNT returns ambiguous result for LEFT JOIN query with NULLs

Is possible to count the left join'ed records? I would like to see count return the actual records joined (including 0 if nothing is left joined). A join like the following worked in other forms of SQL I worked with, but OpenSQL does not seem to…
Zero
  • 1,562
  • 1
  • 13
  • 29
2
votes
2 answers

Select where multiple fields are not in subquery (excluding join)

I have a requirement to pull records, that do not have history in an archive table. 2 Fields of 1 record need to be checked for in the archive. In technical sense my requirement is a left join where right side is 'null' (a.k.a. an excluding join),…
Zero
  • 1,562
  • 1
  • 13
  • 29
2
votes
1 answer

ABAP Select fields with count > 1

Is there any way to select some fields from BSID where the combination of BUKRS-KUNNR-DMBTR is greater than 1. I thought that the below select will work, but it doesn't. SELECT bukrs kunnr dmbtr COUNT(*) INTO TABLE git_double FROM bsid …
ekekakos
  • 563
  • 3
  • 20
  • 39
2
votes
3 answers

SELECT with substring in ON clause?

I have the following select statement in ABAP: SELECT munic~mandt VREFER BIS AB ZZELECDATE ZZCERTDATE CONSYEAR ZDIMO ZZONE_M ZZONE_T USAGE_M USAGE_T M2MC M2MT M2RET EXEMPTMCMT EXEMPRET CHARGEMCMT INTO corresponding fields of table…
onlyf
  • 767
  • 3
  • 19
  • 39
2
votes
1 answer

Select only one row from a DB Table depending on a column value in ABAP Open SQL

I am looking for a solution where I want to select only one row from a DB Table depending on a column which like a flag. A sample DB table looks like this: C1 | C2 | C3 ----------------- A1 | N1 | A1 | N2 | X A1 | N3 | A2 | N21 | X A2 | N22…
qwerty
  • 163
  • 3
  • 12