on 11-27-2022 12:17 PM
DO.
FETCH NEXT CURSOR gv_cursor
APPENDING TABLE lt_mseg PACKAGE SIZE 25000.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE CURSOR gv_cursor.
1) Theoretically, using FOR ALL ENTRIES means that ABAP behaves the same as if DISTINCT is used, so I guess that with a CURSOR all the lines will be extracted at the first FETCH so that to be aggregated by ABAP, so it would make the CURSOR useless.
I'm surprised to find nothing in the ABAP documentation about this very special case.
2) When using FOR ALL ENTRIES, you should always test that the internal table is not empty before using SELECT. If the internal table is empty, your OPEN CURSOR will be equivalent to not using FOR ALL ENTRIES, as shown below, and it's probably not what you want:
OPEN CURSOR WITH HOLD gv_cursor FOR
SELECT a~mblnr a~mjahr a~zeile a~bwart a~matnr a~werks a~lgort a~charg
a~lifnr a~kunnr a~shkzg a~dmbtr a~menge a~meins a~ebeln a~ebelp
a~aufnr a~kzbew
b~budat b~vgart
FROM mseg AS a INNER JOIN mkpf AS b ON b~mblnr = a~mblnr AND
b~mjahr = a~mjahr
WHERE a~shkzg EQ 'S'.
So you should do:IF it_temp1 IS NOT INITIAL. "<======= here
OPEN CURSOR WITH HOLD gv_cursor FOR
SELECT a~mblnr a~mjahr a~zeile a~bwart a~matnr a~werks a~lgort a~charg
a~lifnr a~kunnr a~shkzg a~dmbtr a~menge a~meins a~ebeln a~ebelp
a~aufnr a~kzbew
b~budat b~vgart
FROM mseg AS a INNER JOIN mkpf AS b ON b~mblnr = a~mblnr AND
b~mjahr = a~mjahr
FOR ALL ENTRIES IN it_temp1
WHERE a~matnr EQ it_temp1-matnr AND
a~werks EQ it_temp1-werks AND
a~charg EQ it_temp1-charg AND
a~shkzg EQ 'S'.
DO.
FETCH CURSOR ...
...
ENDDO.
CLOSE CURSOR ...
ENDIF.
3) You should avoid mixing JOIN and FOR ALL ENTRIES.
4) If it doesn't solve, you need to ask someone experienced in ABAP and SQL performance (traces, indexes and so on).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again, mubashirbennishirur,
I'm glad to see you got an answer to your question! If it helps you, please make sure to accept (you'll see the "accept" option beneath the question) -- so members with similar issues will be able to find a solution to their problems too.
If it doesn't help, you can always leave a comment providing more details that can guide members who wish to assist you.
I hope that this guidance is useful -- and we look forward to your next question for the community!
All the best,
DediYou should not go for another solution without trying to solve the current question. "Parallel cursor" is a lot misleading, it comprises lots of different possible solutions, better ask directly the person who proposed that. Please ask a new question if you need complements for this different question.
Hi, you can take a picture from this scenario running SAP performance tools (SQL).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Mohammed,
Using parallel cursor for the huge selection somehow work. but there is also a limitation for the internal table operation.
Please let me know if your issue is resolved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The "internal table operation" is usually better with "parallel cursor" (OPEN CURSOR/FETCH) than SELECT, because usually the internal table is limited to the size of a package (except that here the OP is possibly missing the advantage with using APPENDING TABLE, rather than using INTO TABLE, although maybe in the code the internal table is maybe later cleared at each loop).
CDS view is intrinsically not better than a cursor or SELECT, it's just possibly better on data modeling aspect.
Using parallel processing with parallel RFC will maybe not solve the OP issue.
Lots of assumptions about what can be the OP issue, as we don't have any information. The question about using DO is not answered. The OP issue is probably more related to how the OPEN CURSOR looks like and what the database contains.
User | Count |
---|---|
89 | |
9 | |
7 | |
5 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.