cancel
Showing results for 
Search instead for 
Did you mean: 

Getting timeout error when using for loop.

RAJU_ABAP
Explorer
0 Kudos

Dear All,
I am using for loop to improve the performance of the report but still getting error like timeout error(dump).
So, How to solve?
Thanks in Advance.
My implemented code: 

it_final = value #( for lsmatdoc in it_matdoc
                     let zval = reduce labst( init lv_x type labst for lsmatdoc2 in it_matdoc2
                          WHERE ( matbf = lsmatdoc-matbf and charg_sid = lsmatdoc-charg_sid )
                         next lv_x = lv_x + lsmatdoc2-dmbtr_stock )
                         zqun = reduce labst( init lv_Y type labst for lsmat2 in it_matdoc2
                            WHERE ( matbf = lsmatdoc-matbf and charg_sid = lsmatdoc-charg_sid )
                         next lv_y = lv_y + lsmat2-stock_qty )
                         zday = lcl_cal=>cal_days( exporting dt1 = value #( it_mcha[ matnr = lsmatdoc-matbf charg = lsmatdoc-charg_sid werks = lsmatdoc-werks ]-ersda
                                                                                    default lsmatdoc-bldat  ) )
                     in
                   (
                    matnr = lsmatdoc-matbf
                    stloc = lsmatdoc-lgort_sid
                    plant = lsmatdoc-werks
                    batch = lsmatdoc-charg_sid
                    maktx = value #( it_makt[ matnr = lsmatdoc-matbf ]-maktx default space )
                    zvalu = zval
                    zquan = zqun
                    ztotv = cond labst( when RB1 EQ 'X' THEN ZQUN
                                        WHEN RB2 EQ 'X' THEN zval )
                    grndt = value #( it_mcha[ matnr = lsmatdoc-matbf charg = lsmatdoc-charg_sid werks = lsmatdoc-werks ]-ersda default lsmatdoc-bldat  )
                    zdayy = zday
                    zthit = cond i( when zday le 30 and RB1 eq 'X' then zqun
                                    when zday le 30 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zsixt = cond i( when zday le 60 and zday ge 31 AND RB1 EQ 'X' then zqun
                                    when zday le 60 and zday ge 31 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    znint = cond i( when zday le 90 and zday ge 61 AND RB1 EQ 'X' then zqun
                                    when zday le 90 and zday ge 61 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zotwt = cond i( when zday le 120 and zday ge 91 AND RB1 EQ 'X'  then zqun
                                    when zday le 120 and zday ge 91 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zofif = cond i( when zday le 150 and zday ge 121 AND RB1 EQ 'X' then zqun
                                    when zday le 150 and zday ge 121 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zoeit = cond i( when zday le 180 and zday ge 151 AND RB1 EQ 'X'  then zqun
                                    when zday le 180 and zday ge 151 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    ztwtn = cond i( when zday le 210 and zday ge 181 AND RB1 EQ 'X'  then zqun
                                    when zday le 210 and zday ge 181 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    ztfor = cond i( when zday le 240 and zday ge 211 AND RB1 EQ 'X'  then zqun
                                    when zday le 240 and zday ge 211 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    ztsev = cond i( when zday le 270 and zday ge 241 AND RB1 EQ 'X'  then zqun
                                    when zday le 270 and zday ge 241 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    ztthr = cond i( when zday le 300 and zday ge 271 AND RB1 EQ 'X'  then zqun
                                    when zday le 300 and zday ge 271 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zttht = cond i( when zday le 330 and zday ge 301 AND RB1 EQ 'X'  then zqun
                                    when zday le 330 and zday ge 301 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    ztsix = cond i( when zday le 360 and zday ge 331 AND RB1 EQ 'X'  then zqun
                                    when zday le 360 and zday ge 331 AND RB2 EQ 'X' then zval
                                    else ' ' )
                    zmsix = cond string( when zday ge 365 AND RB1 EQ 'X'  then zqun
                                         when zday ge 365 and RB2 EQ 'X' then zval
                                         else ' ' )

                    remarks = cond string( when zday le 180 then 'Moving'
                                           when zday le 366 and zday gt 180 then 'Slow moving item'
                                           else 'Non Moving Item' )   ) ).

 

Sandra_Rossi
Active Contributor
You are wrong, "for loop" never improved performance, it improves the legibility of code ("functional" writing). Performance is improved only if you use TYPE SORTED or HASHED internal tables.
Sandra_Rossi
Active Contributor

Please use the buttons "..." and "</>" to display your code nicely. See how to do it here: https://community.sap.com/t5/questions-about-sap-websites/how-to-post-code-in-sap-community-gt-2024/...

Accepted Solutions (1)

Accepted Solutions (1)

RAJU_ABAP
Explorer
0 Kudos

Thank you @Sandra_Rossi, for guiding me in posting code questions.

Answers (1)

Answers (1)

RAJU_ABAP
Explorer
0 Kudos

Thank you for your response, I will try.