Application Development 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: 

Correct usage of parallel cursors

former_member215563
Active Participant
0 Kudos
5,026

Hi All,

I want to use parallel cursor technique for the below code. I have read a lot of blogs on how to use it correctly.

But somehow I still have some uncertainty on how to use it.

Can you please help me.

LOOP AT gt_bkpf INTO gw_bkpf.

     LOOP AT gt_glpca_mara ASSIGNING <lw_glpca_mara> WHERE rbukrs = gw_bkpf-bukrs

                                                    AND   ryear = gw_bkpf-gjahr

                                                    AND   refdocnr_temp = gw_bkpf-awkey.

      IF sy-subrc = 0.

        <lw_glpca_mara>-belnr = gw_bkpf-belnr.

      ENDIF.

ENDLOOP.

ENDLOOP.

    

Thanks,

Faiz

5 REPLIES 5

sanjana_lingras
Active Participant
0 Kudos
903

Hi Faiz,

Please refer below sample code. Parallel cursor is mostly used when there is hige data in internal table and to avoid nested loops which may cause performance issue. For this you need to have atleast one field common in two internal tables: Refer below link for sample:

http://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor+-+Loop+Processing

Regards,

Sanjana

Former Member
0 Kudos
903

If you declared gt_glpca_mara as sorted table then:

LOOP AT gt_bkpf INTO gw_bkpf.

      LOOP AT gt_glpca_mara ASSIGNING <lw_glpca_mara> WHERE rbukrs = gw_bkpf-bukrs
                                                    AND   ryear = gw_bkpf-gjahr
                                                    AND   refdocnr_temp = gw_bkpf-awkey.
      IF sy-subrc = 0.
        <lw_glpca_mara>-belnr = gw_bkpf-belnr.
      ENDIF.

ENDLOOP.

ENDLOOP.

If gt_glpca_mara is not a sorted table then:

SORT gt_bkpf BY bukrs gjahr awkey.

SORT gt_glpca_mara BY rbukrs ryear refdocnr_temp.

LOOP AT gt_bkpf INTO gw_bkpf.

     READ TABLE gt_glpca_mara INTO gs_glpca_mara WITH KEY

                                                                                                       rbukrs = gw_bkpf-bukrs

                                                                                                      ryear = gw_bkpf-gjahr

                                                                                                      refdocnr_temp = gw_bkpf-awkey BINARY SEARCH.


      LOOP AT gt_glpca_mara ASSIGNING <lw_glpca_mara> FROM sy-tabix.
      IF <lw_glpca_mara>-rbukrs <> gw_bkpf-bukrs  OR

          <lw_glpca_mara>-ryear <> gw_bkpf-gjahr  OR

          <lw_glpca_mara>-refdocnr_temp <> gw_bkpf-awkey.
        EXIT.
      ENDIF.

       <lw_glpca_mara>-belnr = gw_bkpf-belnr.

ENDLOOP.

ENDLOOP.

The first way is better considering performance as you can see here:

Parallel Cursor - To speed up performance of Nested LOOP | ABAP Help Blog

former_member215563
Active Participant
0 Kudos
903

Im making an attempt.Please let me know if this is the correct way:-

SORT gt_glpca_mara by rbukrs.

LOOP AT gt_bkpf INTO gw_bkpf.

    

     READ gt_glpca_mara into gw_glpca_mara WITH KEY rbukrs = gw_bkpf-bukrs

                                                                            BINARY  SEARCH.

     if sy-subrc <> 0.

         

     else.

     v_index = sy-tabix.

     loop at gt_glpca_mara into gw_glpca_mara from v_index.

    

     if gw_glpca_mara-rbukrs <> gw_bkpf-bukrs. 

        exit.

     else.

             <lw_glpca_mara>-belnr = gw_bkpf-belnr

     endif.

    endlopp.

endloop.

0 Kudos
903

SORT gt_bkpf BY rbukrs.

SORT gt_glpca_mara by rbukrs.

LOOP AT gt_bkpf INTO gw_bkpf.

  

     READ gt_glpca_mara into gw_glpca_mara WITH KEY rbukrs = gw_bkpf-bukrs

                                                                            BINARY  SEARCH.

     v_index = sy-tabix.

     loop at gt_glpca_mara into gw_glpca_mara from v_index.

   

     if gw_glpca_mara-rbukrs <> gw_bkpf-bukrs.

        exit.

     else.

             <lw_glpca_mara>-belnr = gw_bkpf-belnr

     endif.

    endlopp.

endloop.

You can use this way, but take a look at the link in my previous post then you will get a clear idea about parallel cursor.

0 Kudos
903

Yes , this looks ok.

Also you can take trace of the program through SE30 transaction before use of parallel cursor and after adding code for parallel cursor.

And check by which method performance is improved , that would help you for analysis.

Regards,

Sanjana