2019 May 29 7:54 PM
I have a view that I am using that contains fields on IFLOT, ILOA, and IFLOTX.
The view is called ZAPMFLOCS.
I want to be able to exclude functional locations with the deletion flag set.
I was able to figure out the SQL to exclude records.
This is my code without variables substituted.
SELECT (selectpart) FROM (lv_from) UP TO lv_rowcount ROWS INTO CORRESPONDING FIELDS OF TABLE <fs_result> WHERE (wherepart_modified).
This is what it would look like with the substitutions:
SELECT * FROM ZAPMFLOCS UP TO 50000 ROWS INTO CORRESPONDING FIELDS OF TABLE <fs_result> WHERE OBJNR not in ( select f.OBJNR from ZAPMFLOCS f left outer join JEST j on f.OBJNR = j.OBJNR where j.STAT = 'I0076' and j.INACT <> 'X' )
But this fails, I'm guessing my where clause is too complicated to use with open sql.
I'm wondering if there is a way to either alter the view or the code to be able to exclude functional locations with the deletion flag set?
I have a view that I am using that contains fields on IFLOT, ILOA, and IFLOTX.
The view is called ZAPMFLOCS.
I want to be able to exclude functional locations with the deletion flag set.
I was able to figure out the SQL to exclude records.
This is my code without variables substituted.
SELECT (selectpart) FROM (lv_from) UP TO lv_rowcount ROWS INTO CORRESPONDING FIELDS OF TABLE <fs_result> WHERE (wherepart_modified).
This is what it would look like with the substitutions:
SELECT * FROM ZAPMFLOCS UP TO 50000 ROWS INTO CORRESPONDING FIELDS OF TABLE <fs_result> WHERE OBJNR not in ( select f.OBJNR from ZAPMFLOCS f left outer join JEST j on f.OBJNR = j.OBJNR where j.STAT = 'I0076' and j.INACT <> 'X' )
But this fails, I'm guessing my where clause is too complicated to use with open sql.
I'm wondering if there is a way to either alter the view or the code to be able to exclude functional locations with the deletion flag set?
2019 May 30 7:22 AM
Depending on your ABAP version, there may be different restrictions.
So first, make sure the substituted SELECT is valid at compile time and at run time.
If it doesn't work, you may also try to switch to the strict mode syntax, because it may accept more complex SQL (adding @ and change order of blocks):
SELECT (selectpart) FROM (lv_from)
WHERE (wherepart_modified)
INTO CORRESPONDING FIELDS OF TABLE @<fs_result>
UP TO @lv_rowcount ROWS.
2019 May 30 12:35 PM
Thanks Sandra!
I'm getting:
@LV_ROWCOUNT may not be converted into a number. number.
It is declared as:
lv_rowcount TYPE i.
Am I missing something?
Looking at the up to documentation:
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapselect_up_to_offset.htm
The addition UP TO limits the number of rows in the results set of a SELECT statement to n. n expects a host variable prefixed by an escape character @, a host expression or literal of type i that can represent all non-negative numbers from the value range of i except its maximum value +2,147,483,647. In the strict mode from Release 7.51, n must have the types b, s, i, or int8. Furthermore, a literal or constant specified for n cannot have the value 0 in this strict mode. The content of n must match the data type i in accordance with the rules for a lossless assignment. A host variable should be prefixed by the escape character @.
Our system has "SAP_BASIS" = "740" maybe that means we don't have the required stuff for strict mode in ABAP?
2019 May 31 6:45 AM
As I said, first, make sure the substituted SELECT is valid at compile time and at run time. Unfortunately, you probably didn't do it, cf Quynh Doan Manh answer.
2019 May 31 7:00 AM
The strict mode is valid from 7.40 SP 2.
" The syntax of this program is valid in 7.52, and it works at runtime too.
DATA: selectpart TYPE string VALUE '*',
lv_from TYPE string VALUE 'SCARR',
lv_rowcount TYPE i,
wherepart_modified TYPE string,
fs_result TYPE TABLE OF scarr.
" if strict mode is NOT used, it's NOT possible to have a JOIN in the nested SELECT
SELECT * FROM scarr UP TO lv_rowcount ROWS
INTO CORRESPONDING FIELDS OF TABLE fs_result
WHERE carrid NOT IN ( SELECT carrid FROM scarr ).
" if strict mode is used, it's possible to have a JOIN in the nested SELECT
SELECT * FROM scarr UP TO @lv_rowcount ROWS
INTO CORRESPONDING FIELDS OF TABLE @fs_result
WHERE carrid NOT IN ( SELECT f~carrid FROM scarr AS f LEFT OUTER JOIN spfli
AS j ON f~carrid = j~carrid WHERE j~airpfrom = 'JFK' ).
" the dynamic variant works at runtime only if the strict mode is used
wherepart_modified = |carrid not in ( select f~carrid from scarr as f left outer |
&& |join spfli as j on f~carrid = j~carrid where j~airpfrom = 'JFK' )|.
SELECT (selectpart) FROM (lv_from)
UP TO @lv_rowcount ROWS
INTO CORRESPONDING FIELDS OF TABLE @fs_result
WHERE (wherepart_modified).
2019 May 31 12:54 PM
Great answer! I still have a compile problem. I didn't think changing the wherepart would affect the compile problem but I did it anyway. Still have the compile problem, but good to know how to fix the wherepart.
I decided to try to run your program as-is, since I couldn't figure out my compile problems.
With your program I get:
"@LV_ROWCOUNT" may not be converted into a number. number.
I tried changing to:
lv_rowcount TYPE i VALUE 50000,But I still got:
"@LV_ROWCOUNT" may not be converted into a number. number.
So I tried hardcoding:
SELECT * FROM scarr UP TO 50000 ROWSAnd then I got:
No fields from the right-hand table of a LEFT OUTER JOIN may appear in
the WHERE condition: "J~AIRPFROM".
On Installed Software Component Versions I see:
SAP_BASIS
Release 740
SP-Level 0004
Is that the correct place to be looking?
2019 May 31 1:05 PM
I guess it's just because J~AIRPFROM would be better in the ON because it's an outer join: "on f~carrid = j~carrid and j~airpfrom ='JFK'" (WHERE not used)
2019 May 31 1:34 PM
Did your code run for you?
I tried altering to use as you did with (WHERE not used)
SELECT * FROM scarr UP TO 50000 ROWS
INTO CORRESPONDING FIELDS OF TABLE @fs_result
WHERE carrid NOT IN ( SELECT f~carrid FROM scarr AS f LEFT OUTER JOIN spfli
AS j ON f~carrid = j~carrid AND j~airpfrom = 'JFK' ).
And got:
The field "@FS_RESULT" is unknown, but there is a field with the
similar name "FS_RESULT". "FS_RESULT".
2019 May 31 1:37 PM
Here is the complete code listing for the ABAP program with your code:
*&---------------------------------------------------------------------*
*& Report Z_FLOC_OPEN_SQL_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_FLOC_OPEN_SQL_TEST.
*DATA: T_TABLE TYPE TABLE OF ZAPM_TYP_ZSZAPMFLOCS.
*
*SELECT * FROM zapmflocs
*UP TO 50000 ROWS
*INTO CORRESPONDING FIELDS OF TABLE @T_TABLE
*WHERE objnr NOT IN ( SELECT f~objnr FROM zapmflocs AS f LEFT OUTER JOIN jest AS j ON f~objnr = j~objnr
* WHERE j~stat = 'I0076' AND j~inact <> 'X' ).
DATA: selectpart TYPE string VALUE '*',
lv_from TYPE string VALUE 'SCARR',
lv_rowcount TYPE i VALUE 50000,
wherepart_modified TYPE string,
fs_result TYPE TABLE OF scarr.
" if strict mode is NOT used, it's NOT possible to have a JOIN in the nested SELECT
SELECT * FROM scarr UP TO lv_rowcount ROWS
INTO CORRESPONDING FIELDS OF TABLE fs_result
WHERE carrid NOT IN ( SELECT carrid FROM scarr ).
" if strict mode is used, it's possible to have a JOIN in the nested SELECT
SELECT * FROM scarr UP TO 50000 ROWS
INTO CORRESPONDING FIELDS OF TABLE @fs_result
WHERE carrid NOT IN ( SELECT f~carrid FROM scarr AS f LEFT OUTER JOIN spfli
AS j ON f~carrid = j~carrid AND j~airpfrom = 'JFK' ).
" the dynamic variant works at runtime only if the strict mode is used
wherepart_modified = |carrid not in ( select f~carrid from scarr as f left outer |
&& |join spfli as j on f~carrid = j~carrid where j~airpfrom = 'JFK' )|.
SELECT (selectpart) FROM (lv_from)
UP TO @lv_rowcount ROWS
INTO CORRESPONDING FIELDS OF TABLE @fs_result
WHERE (wherepart_modified).
2019 May 31 1:53 PM
Yes it works for ABAP 7.52. But the order I used is a little bit incorrect. Maybe only the correct order is accepted in 7.40 (INTO and UP TO at the end):
SELECT (selectpart)
FROM (lv_from)
WHERE (wherepart_modified)
INTO CORRESPONDING FIELDS OF TABLE @fs_result
UP TO @lv_rowcount ROWS.
2019 May 31 2:16 PM
That one gives me:
Couldn't find Error Message: E SELECT 473 because the system is running
with the database objects from release 740. The system has not
completely upgraded to release 742.
p.s Thanks so much for all of your help!
2019 May 31 2:32 PM
Unfortunately, it seems impossible to work well with your version. It seems that you need to upgrade the kernel, at least. Or you have to find a workaround by yourself (try all possible ways until something works...)
2019 Jun 03 1:28 AM
for your information, my system is 7.4 SP 14 and your code work for me.
2019 May 31 1:33 AM
may I ask above sql is open sql or native sql? the syntax of open SQL shouldnt be:
table.fieldbut
table~fieldi dont think your sql run. it should be:
SELECT * FROM zapmflocs
UP TO 50000 ROWS
INTO CORRESPONDING FIELDS OF TABLE <fs_result>
WHERE objnr NOT IN ( SELECT f~objnr FROM zapmflocs AS f LEFT OUTER JOIN jest AS j ON f~objnr = j~objnr
WHERE j~stat = 'I0076' AND j~inact <> 'X' )
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |