‎2015 Apr 27 4:42 AM
Good day master's!
I'm having a so slow query with this code:
SELECT EBELN BELNR AUGBL GJAHR KOSTL INTO TABLE IT_BSEG FROM BSEG WHERE EBELN EQ LS_EKKO-EBELN AND BUKRS EQ S_BUKRS.
I use ABAP debugger and found out the cause why my program are so slow. Reading the BSEG table take a while to read. Is there alternate way to use.
Thanks, Sorry for my bad english.
‎2015 Apr 27 4:50 AM
Hi Kenneth,
BSEG being a cluster table make use of OPEN CURSOR method to get bulk of data at a time. Below is a sample code.
OPEN CURSOR l_cursor FOR
SELECT EBELN BELNR AUGBL GJAHR KOSTL FROM BESG
WHERE EBELN = LS_EKKO-EBELN AND BUKRS = S_BUKRS.
FETCH NEXT CURSOR l_cursor INTO TABLE IT_BSEG.
CLOSE CURSOR l_cursor.
Hope this helps,
~Athreya
‎2015 Apr 27 5:18 AM
HI,
Please can you explain ,what will happened internal when we are using open cursor
to improve performance.
‎2015 Apr 27 5:58 AM
Hi Mohan,
A SELECT statement internally uses cursor for fetching the data. The main difference is that a SELECT statement directly writes the data into the target memory. Where as a cursor selects the data first and write to the memory as a chunk of data.
Cursors are mainly used when there is chunk of data to be retrieved.
Regards,
~Athreya
‎2015 Apr 27 6:47 AM
It didn't changed at all sir.
ABAP debugger take a while to execute "FETCH NEXT CURSOR L_CUR INTO TABLE IT_BSEG."
Anyway is their any other method to get the Accounting Document no of Purchase order w/o using BSEG?
‎2015 Apr 27 5:28 AM
Hi Kenneth,
1- Partial solution: Add GJAHR to complete most of the table keys, you should never make a select to BSEG without BUKRS, BELNR and GJAHR.
2- Total Solution: don't use BSEG. BSEG is a Cluster table you have the same info in BSIS, BSID, BSIK, BSAS, BSAD, BSAK.
BSID, BSAD = KUNNR
BSIK, BSAK = LIFNR
BSIS, BSAS = HKONT
for example If you need vendor data just use BSID (partially) BSAD (totally)
Regards
‎2015 Apr 27 6:58 AM
Sir I didn't use GJAHR because table EKKO/EKPO don't have that, And their is a high chance that the payment of purchase order might delay or P.O. from December will be pay next year.
What I really need is to get the Accounting Document no. of Purchase order. Uncle google say use BSEG. But BSEG are to slow to use.
‎2015 Apr 27 10:21 AM
Then, in your selection criteria you are selecting data by PO number only ?
‎2015 Apr 27 10:38 AM
Hi Kenneth ,
Try to select from BKPF ( Accounting Document Header ) as following :
BKPF-XBLNR = EKKO-EBELN
then you will get BELNR ( Document Number )
‎2015 Apr 27 10:54 AM
It didn't work sir.
I try to use XBLNR but in Accounting document column doesn't show anything.
I try to do it manually, atleast 10 line by searching P.O. no. to BKPF-XBLNR using SE16 and still no entries found.
- Thanks for the effort sir.
‎2015 Apr 27 11:03 AM
Hi Kenneth,
try to take the first 2 digits of PO then put them in XBLNR field like this : 45*
You should find data.
‎2015 Apr 27 10:37 AM
Hi Kenneth,
Please try this
TYPES: BEGIN OF TY_RSEG,
BELNR TYPE RSEG-BELNR,
GJAHR TYPE RSEG-GJAHR,
EBELN TYPE RSEG-EBELN,
EBELP TYPE RSEG-EBELP,
AWKEY TYPE BKPF-AWKEY,
END OF TY_RSEG.
TYPES: BEGIN OF TY_BKPF,
BUKRS TYPE BKPF-BUKRS,
BELNR TYPE BKPF-BELNR,
GJAHR TYPE BKPF-GJAHR,
AWKEY TYPE BKPF-AWKEY,
END OF TY_BKPF.
DATA: IT_RSEG TYPE TABLE OF TY_RSEG,
IT_BKPF TYPE TABLE OF TY_BKPF.
FIELD-SYMBOLS : <FS_RSEG> TYPE TY_RSEG.
SELECT BELNR GJAHR EBELN EBELP FROM RSEG INTO CORRESPONDING FIELDS OF TABLE IT_RSEG
WHERE EBELN IN S_EBELN.
LOOP AT IT_RSEG ASSIGNING <FS_RSEG>.
<FS_RSEG>-AWKEY+0(10) = <FS_RSEG>-BELNR.
<FS_RSEG>-AWKEY+10(4) = <FS_RSEG>-GJAHR.
ENDLOOP.
IF IT_RSEG[] IS NOT INITIAL.
SELECT BUKRS BELNR GJAHR AWKEY FROM BKPF INTO TABLE IT_BKPF FOR ALL ENTRIES IN IT_RSEG
WHERE AWKEY = IT_RSEG-AWKEY.
ENDIF.
IF IT_BKPF[] IS NOT INITIAL.
SELECT * FROM BSEG INTO TABLE IT_BSEG FOR ALL ENTRIES IN IT_BKPF
WHERE BUKRS = IT_BKPF-BUKRS
AND BELNR = IT_BKPF-BELNR
AND GJAHR = IT_BKPF-GJAHR.
ENDIF.
I Think , it is helpful.
Regards,
Nilesh Patel
‎2015 Apr 27 11:05 AM
Wow this is almost perfect sir, But not all P.O. No. exist in RSEG.
I guest BSEG has everything, But that everything makes it slow.
My problem is how to get the Accounting document no (BELNR) of Purchase order no. (EBELN) and use the BELNR to get the Payments of P.O. (PAYR-CHECT,PAYR-RWBTR).
BSEG has AUGBL and BELNR (in case AUGBL fail).
‎2015 Apr 27 11:17 AM
Hi Kenneth,
All PO no exist in RSEG after invoice against PO no .
You please try table EKBE . Pass PO no and get BELNR and GJAHR . And then pass in BKPF-AWKEY.
After that Result of BKPF pass in BSEG. Get All result.
Regards,
Nilesh Patel
‎2015 Apr 28 2:38 AM
WOW!!!
It works like magic.
Thank you so much Sir Nilesh Patel
‎2015 Apr 28 2:40 AM
‎2015 Apr 28 4:33 AM
Kenneth,
Read this blog: http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why
BR,
Raphael.
‎2015 Apr 28 6:20 AM
This can't be closed as it is not posted as a question. The tick from the question box was removed.
This sentence is missing in the original post: This question is Not Answered.(Mark as assumed answered)
The speech bubble in the left corner of the question in your communication stream is white and not blue like it is for a question.
‎2015 Apr 28 6:20 AM
‎2015 Apr 28 6:27 AM
There is no "Correct Answer" and "Helpful Answer" button for me .
But anayway thread close
‎2015 Apr 28 6:41 AM
I see
Can I change it to Question?
If my memory serves me right this thread is question and there is "Correct asnwer"/"Helpful answer" button at first. But I don't know why it's gone.
‎2015 Apr 28 6:52 AM
No you can't change it yourself to a question, this is only possible within 15 minutes after posting. A space moderator can do it (they can even remove the tick if they think this question has been discussed x-times before and the participants should not get any points for answering recurring questions)
‎2015 Apr 28 7:00 AM
aw..
I'm really sorry Master's and thank you for your effort.
‎2015 Apr 28 11:03 AM
Ups, my mistake !
I did not see it was not a question, I answered on my phone and did not realize such detail ...
‎2015 Apr 28 5:26 AM
Hi ,
Simply use the key field in select query.
BUKRS
BELNR
GJAHR
BUZEI.