Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in fetching data from bseg table

Former Member
0 Kudos
2,022

Hi all,

i have to fetch some fields values from bseg table, firstly i have selected some fields from bkpf table then after i passed belnr in bseg table along with other fields, but while fetching data from bseg table, it is giving "maximum run time exceeds" and not fetching any data during debugging too.

Here is my code, please tell me what to do next

SELECT XBLNR
BLDAT
WAERS
CPUDT
MONAT
BLART
BELNR
BUKRS
GJAHR
FROM BKPF
INTO TABLE IT_BKPF
WHERE BELNR IN P_BELNR
AND BLDAT IN P_BLDAT.


SELECT MENGE
MEINS
HKONT
WRBTR
MWSKZ
BUPLA
BELNR
VALUT
ZFBDT
ZUONR
BSCHL
AUFNR
SGTXT
BUKRS
GJAHR
FROM BSEG INTO TABLE IT_BSEG
FOR ALL ENTRIES IN IT_BKPF
WHERE BELNR = IT_BKPF-BELNR
AND BUKRS = IT_BKPF-BUKRS
AND GJAHR = IT_BKPF-GJAHR
AND  HKONT EQ  '12345'
OR HKONT EQ '54321' .

16 REPLIES 16
Read only

former_member192971
Participant
0 Kudos
1,014

Hi Swetha,

Firstly check with your database tables whether you have data for your search criteria by passing the same values in the execution of BKPF and BSEG Tables.

If you have records , put a condition after  BFKP select statement as  If IT_BKPF[] is not initial.

then pass the values of Bkpf as input to Bseg and fetch them too...

If your select condition having many number of records , then it takes too much time to process and it will return "maximum run time exceeds" at a certain point of time.

Thanks.

Read only

sivaprasad_paruchuri
Active Participant
0 Kudos
1,014

U can use BSIS,BSAS for  GL account Based Retrieval..

Regards,

Siva

Read only

harshsisodia31
Participant
0 Kudos
1,014

Hi ,

It is because there may be large set of records being fetched from bseg table and bkpf table.

Try running your report in background or refine your your selection a little.

Read only

praveenboss
Participant
0 Kudos
1,014

Hi Shweta ,

while fetching data from bseg table, it is giving "maximum run time exceeds" and not fetching any data .

So  Only 2 Condition   for this problem.


1.   Firstly you make indexer for BSEG  table.

      for these fields   

      BELNR,BUKRS,GJAHR

      and also add in your select query  fields.



2.  And Make sure That data you try to fetch from BSEG  with reference BKPF table

     that is  available on both table.


Please Tell Which Problem You Facing now.


Thanks









Read only

mayur_priyan
Active Participant
0 Kudos
1,014

Hi,

Maximum run time error on select statement occurs for the following reasons.

1. When the DDIC table has a large amount of data.

2. When the key fields of the DDIC table are not properly considered in the WHERE clause of the         SELECT statement.

3. When the FOR ALL ENTRIES table is empty ( in your case IT_BKPF ).  That's the reason it is a must to check wehether the itab is INITIAL or not before using it in FOR ALL ENTRIES clause.

Check if your scenario has any of the the above mentioned situations.

Read only

former_member129652
Active Participant
0 Kudos
1,014

Hi,

  The SQL statement is problematic.  It is asking the system to run a full scan of BSEG and return all records whose hkont is '54321'.

  Please add parentheses like the code below.

SELECT *

FROM BSEG INTO TABLE IT_BSEG

FOR ALL ENTRIES IN IT_BKPF

WHERE BELNR = IT_BKPF-BELNR

AND BUKRS = IT_BKPF-BUKRS

AND GJAHR = IT_BKPF-GJAHR

AND ( HKONT EQ  '12345' OR HKONT EQ '54321'  ).

Read only

Former Member
0 Kudos
1,014

Hi Shweta,

Note 25528 - Parameter rdisp/max_wprun_time   Check this note

the rule of thumb that we use at in our project is any job that runs longer than 10 min has to run in the background, or else if everyone does that it will fill up the DIA processes and then no one can logon or work until they free up or system restart.http://scn.sap.com/thread/278023

Read only

Former Member
0 Kudos
1,014

Hi shweta,

when you are using for all entries, you first check the header level data is there or not.

you should not check the header data it fetch the total item level data.  then it takes too much time to process and it will return "maximum run time exceeds" .

before writing the for all entries you check that internal table having data or not

regards,

lakshman.

Read only

Former Member
0 Kudos
1,014

Try this code

DATA:IT_BSEG1 TYPE STANDARD TABLE OF (IT_BSEG TYPE)

eg:SELECT XBLNR
BLDAT
WAERS
CPUDT
MONAT
BLART
BELNR
BUKRS
GJAHR
FROM BKPF
INTO TABLE IT_BKPF
WHERE BELNR IN P_BELNR
AND BLDAT IN P_BLDAT.
IF IT_BKPF[] IS NOT INITIAL.
SELECT MENGE
MEINS
HKONT
WRBTR
MWSKZ
BUPLA
BELNR
VALUT
ZFBDT
ZUONR
BSCHL
AUFNR
SGTXT
BUKRS
GJAHR
FROM BSEG INTO TABLE IT_BSEG1
FOR ALL ENTRIES IN IT_BKPF
WHERE BELNR = IT_BKPF-BELNR
AND BUKRS = IT_BKPF-BUKRS
AND GJAHR = IT_BKPF-GJAHR
AND  HKONT EQ  '12345'
OR HKONT EQ '54321' .

APPEND LINES OF IT_BSEG1 TO IT_BSEG.

    REFRESH IT_BSEG1.

    CLEAR IT_BSEG1.

ENDIF.

This query will increase the performance of the report,it wannot go for dump.

Read only

0 Kudos
1,014

Hi, Shweta ,

You can use the Range of Belnr in stead of the For all entries and try.

SELECT XBLNR

BLDAT

WAERS

CPUDT

MONAT

BLART

BELNR

BUKRS

GJAHR

FROM BKPF

INTO TABLE IT_BKPF

WHERE BELNR IN P_BELNR

AND BLDAT IN P_BLDAT.

data: r_belnr type range of bkpf-BELNR .

data: wa_bkpf like line of it_bkpf .

loop at it_bkpf into wa_bkpf .

 

   r_belnr-sign = 'I' .

   r_belnr-option = 'EQ'.

   r_belnr-low = wa_bkpf-belnr .

   append r_belnr .

endloop .

SELECT MENGE

MEINS

HKONT

WRBTR

MWSKZ

BUPLA

BELNR

VALUT

ZFBDT

ZUONR

BSCHL

AUFNR

SGTXT

BUKRS

GJAHR

FROM BSEG INTO TABLE IT_BSEG

WHERE

   belnr IN r_belnr

    BELNR = IT_BKPF-BELNR

AND BUKRS = IT_BKPF-BUKRS

AND GJAHR = IT_BKPF-GJAHR

AND  HKONT EQ  '12345'

OR HKONT EQ '54321' .

Regards,

Joyjit

Read only

ThangaPrakash
Active Contributor
0 Kudos
1,014

Hello Shweta,

My question is why don't you try with INNER JOINS, as INNER JOINS has always the better performance than FOR ALL ENTRIES.

You won't get the runtime error if you use INNER JOINS.

Refer to the below links which explains why INNER JOINS is better than For all entries.

Inner Joins vs For All Entries - performance query | SCN

ABAP Performance tips - Contributor Corner - SCN Wiki

Regards,

TP

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,014

My question is why don't you try with INNER JOINS, as INNER JOINS has always the better performance than FOR ALL ENTRIES.

How would you use join on BSEG? What was your rationale behind posting this incorrect info (using JOINs on BSEG)?

- Suhas

Read only

0 Kudos
1,014

Hello Suhas,

Yes you are right, we can't use for all entries with BSEG.

Sorry I didn't analyse it before posting.

Please remove the comments from the discussion.

Regards,

Thanga

Read only

0 Kudos
1,014

Hi Shweta,

Reading data from BSEG Table is always time consuming sometimes also resulting in the dump that you got. Solution for this would be to optimize the select statment by better data fetching techniques like Open Cursor method or reading less number of records at a time.

Regards

Read only

former_member391265
Participant
0 Kudos
1,014

This message was moderated.

Read only

Former Member
0 Kudos
1,014

First of all check if table IT_BKPF is not initial if not initial then only write second query.

Avoid using OR condition where .

Instead filter those records from your internal table this will improve performance

hope it helps/

Thanks

Rahul