on ‎2020 Aug 27 10:56 AM
Request clarification before answering.
Hello jose.lopes2
Please use "Comment" when adding additional information to question. "Answer" is for solution proposal only.
You're probably reading the BSAK without using the primary key or any index, that's why it takes so long. But that's just a guess. You need to show your logic.
Kind regards,You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code is quite large. so exclude some parts...
IF bsik-budat IN so_budat.
t_bsik-bukrs = bsik-bukrs.
t_bsik-lifnr = bsik-lifnr.
t_bsik-fwaer = bsik-waers.
t_bsik-budat = bsik-budat.
t_bsik-blart = bsik-blart.
t_bsik-belnr = bsik-belnr.
t_bsik-xblnr = bsik-xblnr.
t_bsik-shkzg = bsik-shkzg.
t_bsik-hkont = bsik-hkont.
t_bsik-umskz = bsik-umskz.
t_bsik-wrbtr = bsik-wrbtr.
t_bsik-wrshb = bsega-wrshb.
t_bsik-dmbtr = bsik-dmbtr.
t_bsik-dmshb = bsega-dmshb.
t_bsik-gjahr = bsik-gjahr.
SELECT SINGLE augbl FROM bsakINTO t_bsik-augblWHERE bukrs EQ bsik-bukrsAND lifnr EQ bsik-lifnrAND gjahr EQ bsik-gjahrAND belnr EQ bsik-belnrand SHKZG EQ bsik-SHKZGAND WAERS EQ bsik-WAERS.
APPEND t_bsik.ENDIF..
.
-----
* Tratar primeiro os ABLOOP AT lt_bsik INTO ls_bsik WHERE blart EQ 'AB'.
SELECT *FROM bsak INTO TABLE lt_bsakWHERE augbl EQ ls_bsik-belnr " and ( blart eq 'ES' or blart eq 'RE').AND budat IN so_budat.
IF sy-subrc EQ 0.
CLEAR: lv_re, lv_es, total_re, total_es, lv_total, total_ab_deb, total_ab_cre, ls_bsak_tmp.
* Calcular os totais de todos os items para doc RE e doc ES
LOOP AT lt_bsak INTO ls_bsak_tmp.
IF ls_bsak_tmp-blart EQ 'RE' AND ls_bsak_tmp-shkzg EQ 'S'.
lv_re = ls_bsak_tmp-belnr.
total_re = total_re + ls_bsak_tmp-wrbtr.ELSEIF ls_bsak_tmp-blart EQ 'RE' AND ls_bsak_tmp-shkzg EQ 'H'.
lv_re = ls_bsak_tmp-belnr.
total_re = total_re + ls_bsak_tmp-wrbtr.
total_re = total_re * -1.ELSEIF ls_bsak_tmp-blart EQ 'ES' AND ls_bsak_tmp-shkzg EQ 'H'.
lv_es = ls_bsak_tmp-belnr.
total_es = total_es + ls_bsak_tmp-wrbtr.
total_es = total_es * -1.ELSEIF ls_bsak_tmp-blart EQ 'ES' AND ls_bsak_tmp-shkzg EQ 'S'.
lv_es = ls_bsak_tmp-belnr.
total_es = total_es + ls_bsak_tmp-wrbtr.ELSEIF ls_bsak_tmp-blart EQ 'AB' AND ls_bsak_tmp-shkzg EQ 'S'.
total_ab_deb = total_ab_deb + ls_bsak_tmp-wrbtr.ELSEIF ls_bsak_tmp-blart EQ 'AB' AND ls_bsak_tmp-shkzg EQ 'H'.
total_ab_cre = total_ab_cre + ls_bsak_tmp-wrbtr.
total_ab_cre = total_ab_cre * -1.ENDIF.ENDLOOP.
IF lv_re IS NOT INITIAL AND lv_es IS NOT INITIAL.
lv_total = total_es + total_re + total_ab_cre + total_ab_deb.
IF lv_total EQ 0.CLEAR ls_excluir.
ls_excluir-num_excluir = ls_bsik-belnr.APPEND ls_excluir TO lt_excluir.
CLEAR ls_excluir.
ls_excluir-num_excluir = lv_re.APPEND ls_excluir TO lt_excluir.
CLEAR ls_excluir.
ls_excluir-num_excluir = lv_es.APPEND ls_excluir TO lt_excluir.ENDIF.ENDIF.
ELSE.
CLEAR: lt_bsak[], ls_bsak_tmp, total_blart, total_ab_deb, total_ab_cre.
SELECT * FROM bsak INTO TABLE lt_bsakWHERE augbl EQ ls_bsik-augblAND bukrs EQ ls_bsik-bukrsAND lifnr EQ ls_bsik-lifnrAND gjahr EQ ls_bsik-gjahr.
IF sy-subrc EQ 0.LOOP AT lt_bsak INTO ls_bsak_tmp.IF ls_bsak_tmp-blart NE 'AB' AND ls_bsak_tmp-shkzg EQ 'H'.
lv_blart = ls_bsak_tmp-belnr.
total_blart = total_blart + ls_bsak_tmp-wrbtr.
total_blart = total_blart * -1.ELSEIF ls_bsak_tmp-blart NE 'AB' AND ls_bsak_tmp-shkzg EQ 'S'.
lv_blart = ls_bsak_tmp-belnr.
total_blart = total_blart + ls_bsak_tmp-wrbtr.ELSEIF ls_bsak_tmp-blart EQ 'AB' AND ls_bsak_tmp-shkzg EQ 'S'.
total_ab_deb = total_ab_deb + ls_bsak_tmp-wrbtr.ELSEIF ls_bsak_tmp-blart EQ 'AB' AND ls_bsak_tmp-shkzg EQ 'H'.
total_ab_cre = total_ab_cre + ls_bsak_tmp-wrbtr.
total_ab_cre = total_ab_cre * -1.ENDIF.ENDLOOP.IN so_budat.
IF sy-subrc EQ 0.
CLEAR: lv_re, lv_es, total_re, total_es, lv_total, total_ab_deb, total_ab_cre, ls_bsak_tmp.
I see you're reading from BSAK based on AUGBL field only.
SELECT * FROM bsak INTO TABLE lt_bsak WHERE augbl EQ ls_bsik-belnr " and ( blart eq 'ES' or blart eq 'RE').AND budat IN so_budat.
You should check in SE11 transaction in BSAK definition what is the primary key and what indices are available and try to modify you SELECT's WHERE clause to meet one of these indices. If that's not possible, your next best option is to create a new index which with the fields you're using in your SELECT, this should speed-up the DB read.
Also, please format your code with the "Code" button of the comment editor.
Kind regards,
Mateusz| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.