1

My expression in OpenSQL is:

SELECT * FROM  J_1BNFLIN  AS B
  WHERE SUBSTRING(REFKEY , 1 , 10 )

The substring portion of the where clause is not working. What am I doing wrong?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Glauco Oliveira
  • 21
  • 1
  • 1
  • 6
  • 1
    As fas as I know, there is no SUBSTRING in OpenSQL. What do you want exactly? You want the first ten characters of field REFKEY from table J_1BNFLIN? – József Szikszai Dec 19 '17 at 11:19
  • Yes @JozsefSzikszai – Glauco Oliveira Dec 19 '17 at 11:55
  • Sorry, I might misunderstood the problem, so I ask again: You want to use the first 10 characters of field REFKEY as a selection criteria? – József Szikszai Dec 19 '17 at 12:08
  • Yes, with possibilty of SUBSTRING(REFKEY , 1 , 10 ) = SUBSTRING(REFKEY , 4 , 4 ) – Glauco Oliveira Dec 19 '17 at 12:15
  • No, there is no such possibility. There is no `SUBSTRING` in OpenSQL and [substring access](https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/abenoffset_length.htm) also doesn't work for the left side operands (but works for right). Jozsef is right, your only solution is LIKE. – Suncatcher Dec 19 '17 at 14:15
  • 2
    SUBSTRING is accepted from ABAP 7.50, on the left side of a condition. References: [release changes 7.50 - new SQL functions](https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/abennews-750-open_sql.htm#!ABAP_MODIFICATION_5@5@) – Sandra Rossi Feb 24 '18 at 14:19
  • Yep, you are right! My info is outdated :) – Suncatcher Mar 24 '18 at 15:18

1 Answers1

3

You can use LIKE in the WHERE condition. For example:

DATA: gv_refkey TYPE j_1bnflin-refkey.
gv_refkey = '123%'.
SELECT *
       INTO TABLE ...
       FROM j_1bnflin
       WHERE refkey LIKE gv_refkey.

This will select all entries where the field refkey starts with '123' (pls. note a % is used as wildcard)

József Szikszai
  • 4,791
  • 3
  • 14
  • 24