2013 Jul 01 6:50 PM
Hi,
We have query which is inner join of two tables with for all entries, The query takes long time to run and its almost stuck nothing really happens. This has been running in past successfully. Below is the query:
SELECT a~opsl_gl_sys_no INTO CORRESPONDING FIELDS OF TABLE it_sysno
FROM oiuh_rv_opsl AS a
INNER JOIN oiuh_rv_gl AS b
ON a~opsl_gl_sys_no = b~gl_gl_sys_no
FOR ALL ENTRIES IN it_selection_fields
WHERE a~opsl_own_no = it_selection_fields-owner_no
AND a~opsl_own_seq_no = it_selection_fields-owner_seq_no
AND b~gl_pd_cd = it_selection_fields-product_code
AND b~gl_or_lvl_1_no = ls_company_org1-org_level1_no
AND b~gl_sa_dt >= d_min_time
AND b~gl_sa_dt < d_max_time.
If we query the View with same conditions in se16, we get the desired results. But the ABAP code takes lot of time.
Best Regards,
Pinto
2013 Jul 02 7:04 AM
How is it_selection_fields filled? If it's by a selection before this bit of code, then including that in your inner join may well improve things. (Inner joins are usually better than FAE).
What are the fields of the available indexes on oiuh_rv_opsl and oiuh_rv_gl?
Run this program with an SQL trace on it (ST05). Then trace SE16 on the view. Compare the execution paths (or post them here, if you have difficult understanding them).
2013 Jul 02 1:21 PM
Matthew Billingham wrote:
(Inner joins are usually better than FAE).
But many people say and teach othewise.
2013 Jul 02 1:55 PM
Yes they do. And they are wrong. This has been discussed many times on this site, and if I see someone saying that FAE is better than INNER JOIN, their post will be rejected. "FAE better than INNER JOIN" is a myth. It isn't true.
2013 Jul 02 7:12 AM
Hi Pinto,
Before the FAE put initial check on it_selection_fields. More over put the query in ST04 and analyse whether you can leverage any index or not as sugg. by Matthew.
BR.
2013 Jul 02 7:54 AM
Try to run the query by removing INTO CORRESPONDING FIELDS OF TABLE it_sysno instead use 'INTO TABLE it_sysno'
2013 Jul 02 1:56 PM
Neha Sinha wrote:
Try to run the query by removing INTO CORRESPONDING FIELDS OF TABLE it_sysno instead use 'INTO TABLE it_sysno'
There is no essential difference in performance. This is another myth, discussed many times on this site.
Evidence here: https://scn.sap.com/thread/1714070 and especially here http://scn.sap.com/docs/DOC-33976.
2013 Jul 02 8:18 AM
Hi,
As per the suggestion from Matthew, try to check if the index is available in the table.
Use “SELECT INTO TABLE” rather than “SELECT INTO CORRESPONDING FIELDS OF TABLE”.
CHECK that the internal table used in FOR ALL ENTRIES is NOT empty as this will retrieve all entries from the table.
Regards,
Thanga Prakash T
2013 Jul 02 1:58 PM
Thanga Prakash wrote:
Use “SELECT INTO TABLE” rather than “SELECT INTO CORRESPONDING FIELDS OF TABLE”.
Regards,
Thanga Prakash T
No, don't. It makes no essential difference to the performance and is more error prone.
Evidence here: https://scn.sap.com/thread/1714070 and especially here: http://scn.sap.com/docs/DOC-33976
2013 Jul 02 8:33 AM
If the query was running successfully in the past and failing now ...may be it_selection_fields has huge number of entries, why don't you use the same join statements on some limited number of entries to check the query basic functioning.
2013 Jul 02 9:40 AM
1) While using FOR ALL ENTRIES you need to ensure that there exists atleast one row in internal table.
It may be possible that in the past , the same internal table might get filled with rows and for now due to some exceptions, it remains empty.
2) Compute statistcs of the database tables and indexes involved in the query. If your optimization mode is cost-based, then it may well depend on your statistical data of tables and indexes.
Regards,
Vishram
2013 Jul 02 4:03 PM
Hello All,
There is only record in the it_selection_fields internal table, If you directly query the corresponding view there are only 391 records in the database. But still in the code when it encounters this block it gets stuck for long time.
SAP did some analysis and came back to us saying that OIUH_RV_OPSL statistics has been locked, Can anyone elaborate on this. Can this could be reason for the delay.
Best Regards,
Pinto
2013 Jul 03 5:46 AM
That's something to ask your Basis team. Or over in one of the Netweaver spaces.
2013 Jul 03 6:15 AM
Hi Pinto,
your SELECT can be done with database view V_OIUCWOPSL_GL. But you should notice that view field names differ from database table field names (OIUH_RV_GL-GL_SA_DT = V_OIUCWOPSL_GL-SA_DT, ...).
You should change your code to view access. But I don't think this will fasten your program. Maybe you have a missing index on database or something like that.
Make a SQL trace of a program run to see the indexes used and post this trace.
Regards,
Klaus
2013 Jul 03 8:42 AM
Hello Klaus,
This code has been running successfully from past so many years, This query is trying to fetch only for for only owner which has just 391 records. We are just not bale to find the reason, Same query runs successfully in the test env. Are there any basis parameters that i need specifically look for.
Best Regards,
Pinto
2013 Jul 04 6:14 AM
Hi Pinto,
with the growth of database tables all queries without matching database indexes will slow down, if the query causes a full table scan for fetching the chosen data. In test env you will have less data in both database tables.
Please make a sql trace and show it to us. I think you will find a full table scan on database table oiuh_rv_gl then. This might show us a missing index for the fields
Regards,
Klaus
2013 Jul 04 6:52 AM
Hello Klaus.
Find the trace :
|
| |
_fix_control (7168184) add with value "7168184:OFF" |
2013 Jul 04 11:46 AM
Hi Pinto,
first it seems you have a "bad" secondary index Z01 on table OIUH_RV_OPSL which contains the primary unique key field OPSL_GL_SYS_NO and additionally the fields OPSL_OWN_NO and OPSL_OWN_SEQ_NO, which are the leading fields of stadard secondary index I02.
For OPSL_GL_SYS_NO is an unique identifier for the primary index and, if it is empty, both other fields are handled with secondary index I02, this additional index Z01 is needless and may slow down your system.
Also make sure that the internal table it_selection_fields isn't empty when processing the SELECT:
IF NOT it_selection_fields[] IS INITIAL.
SELECT ...
ENDIF.
Also you have to to the more restricting selection 1st.
Maybe it's more selective to switch table access to:
SELECT a~opsl_gl_sys_no INTO CORRESPONDING FIELDS OF TABLE it_sysno
FROM oiuh_rv_gl AS b
INNER JOIN oiuh_rv_opsl AS a
ON a~opsl_gl_sys_no = b~gl_gl_sys_no
FOR ALL ENTRIES IN it_selection_fields
WHERE b~gl_or_lvl_1_no = ls_company_org1-org_level1_no
AND b~gl_pd_cd = it_selection_fields-product_code
AND b~gl_sa_dt >= d_min_time
AND b~gl_sa_dt < d_max_time.
AND a~opsl_own_no = it_selection_fields-owner_no
AND a~opsl_own_seq_no = it_selection_fields-owner_seq_no.
This should effect data access from OIUH_RV_GL with index I09 and from OIUH_RV_OPSL with primary key.
Please check this with a sql trace.
Regards,
Klaus