Application Development and Automation 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: 
Read only

About FOR Operator

Former Member
0 Likes
1,702

Hi Everyone,

Can anyone tell me how can achieve parallel cursor method using FOR operator?

Regards,

Kumudwini.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,642

Kumudwini Bheemisetty wrote:

Can anyone tell me how can achieve parallel cursor method using FOR operator?

  1. If you want to try the FOR operator => you are already in ABAP Release 740
  2. Since you are working with ABAP 740 => LOOP...WHERE has already been optimized for SORTED and HASHED tables (read: also secondary keys)
  3. Since LOOP...WHERE is already optimized => You do not need parallel cursor

Anyway on a more serious note, do not use parallel cursor method for optimizing nested loops. Instead switch to SORTED, HASHED tables

BR,

Suhas

PS - If you are more savvy, you can use secondary keys with STANDARD tables too. Fyi, I prefer to work with SORTED/HASHED tables wherever possible.

Hi Everyone,

Can anyone tell me how can achieve parallel cursor method using FOR operator?

Regards,

Kumudwini.

10 REPLIES 10
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,643

Kumudwini Bheemisetty wrote:

Can anyone tell me how can achieve parallel cursor method using FOR operator?

  1. If you want to try the FOR operator => you are already in ABAP Release 740
  2. Since you are working with ABAP 740 => LOOP...WHERE has already been optimized for SORTED and HASHED tables (read: also secondary keys)
  3. Since LOOP...WHERE is already optimized => You do not need parallel cursor

Anyway on a more serious note, do not use parallel cursor method for optimizing nested loops. Instead switch to SORTED, HASHED tables

BR,

Suhas

PS - If you are more savvy, you can use secondary keys with STANDARD tables too. Fyi, I prefer to work with SORTED/HASHED tables wherever possible.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,642

If you mean parallel cursor for reading 2 or more internal tables a few records of every table is read alternatively based on given join fields, I doubt there is any variant of FOR for doing such a thing. You may only do nested loops with FOR (i.e. a inner join).

Read only

0 Likes
1,642

Hi Rossi,

Yes, we can use many nested loops. As FOR is also having indexing, I thought there must be a way to do it. But I guess, there is no way we do it

Regards,

Kumudwini.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,642

Sandra Rossi wrote:

If you mean parallel cursor for reading 2 or more internal tables a few records of every table is read alternatively based on given join fields, I doubt there is any variant of FOR for doing such a thing. You may only do nested loops with FOR (i.e. a inner join).

Joining (read: associating) internal table is possible via Meshes. I think FOR variant with meshes might be the solution (See http://help.sap.com/abapdocu_740/en/abenmesh_for_abexa.htm )

Read only

0 Likes
1,642

I think parallel cursor corresponds to both left and right outer join. Meshes do inner join I think.

Read only

0 Likes
1,642

Hi Suhas,

Then how does index works in FOR?

Thanks!

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,642

Hi Kumudwini,

Two suggestions -

  1. Read the F1 documentation
  2. Post the code-snippet which you want to translate to FOR

Without (2) it is not clear what do you mean by 'parallel cursor'

BR,

Suhas

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,642

Sandra Rossi wrote:

I think parallel cursor corresponds to both left and right outer join. Meshes do inner join I think.

You're right, as always

Forward associations correspond to are LEFT INNER JOIN. What about 'Inverse associations'? What do you think?

IMHO, meshes are really powerful but the chances of sc***ing up are quite high (at least for me). However, I like to use them and slowly I'm getting used to them.

Read only

0 Likes
1,642

Forward associations correspond to are LEFT INNER JOIN. What about 'Inverse associations'? What do you think?

I presume it's the same thing, but in the opposite direction 😉

Maybe we should invoke the "abap master" Horst Keller? I think that the parallel cursor is something that should be included in the ABAP language one day. Maybe it already exists, I don't know.

Read only

0 Likes
1,642

Hi Suhas,

My requirement is something like this:

For each Purchase Document there will be an condition number maintained in ME33K against each item of the Purc.Doc right?

for ex: I have a doc 4600014331 with 2 line items 10 and 20. For line item 10 there are 2 conditions maintained and for line item 20 some 3 condition types. so while displaying, i want the condition types that are maintained for 10 in one single row and for 20 also in one row. Using below code, I am able to get it. So now I want to get the same result using FOR. So is it possible to get it? You have asked me to check MESH. I am working on it . But is there any chance of achieving it with Nested FOR and index?

TYPES: BEGIN OF ty_ekko,

         ebeln    TYPE ebeln,      " Agreement

         bukrs    TYPE bukrs,      " Company Code

         lifnr    TYPE elifn,      " Vendor

         bsart    TYPE esart,      " Agreement Type

         ekorg    TYPE ekorg,      " Purchase Organization

         ekgrp    TYPE bkgrp,      " Purchase Group

         kdatb    TYPE kdatb,      " Validity Start

         kdate    TYPE kdate,      " Validity End

         oiexgnum TYPE oia_exgnum, " Exchange Number

         knumv    TYPE knumv,      " Number of the document condition

       END OF ty_ekko.

TYPES:

  BEGIN OF ty_ekpo,

    ebeln TYPE  ebeln,        " Purchasing Document Number

    ebelp TYPE  ebelp,        " Item

    werks TYPE  ewerk,        " Plant

    lgort TYPE  lgort_d,      " Storage Location

    matnr TYPE  matnr,        " Material Number

    txz01 TYPE  txz01,        " Short Text

    ktmng TYPE  ktmng,        " Target Quantity

    meins TYPE  bstme,        " Purchase Order Unit of Measure

  END OF ty_ekpo .

TYPES:

  BEGIN OF ty_oianf,

    knumv TYPE knumv,         " Number of the document condition

    kposn TYPE kposn,

    kschl TYPE  kscha,        " Condition Type

    kbetr TYPE  kbetr,        " Rate

    waers TYPE  waers,        " Currency Key

    kpein TYPE  kpein,        " Condition Pricing Unit

    kmein TYPE  kvmei,        " Condition Unit in the document

  END OF ty_oianf .

TYPES:

  BEGIN OF x_excel,

    ebeln    TYPE char15,  " Agreement

    bukrs    TYPE char12, " Company Code

    lifnr    TYPE lifnr,  " Vendor

    bsart    TYPE char14, " Agreement Type

    ekorg    TYPE char18, " Puch. Organization

    ekgrp    TYPE char16, " Purchasing Group

    kdatb    TYPE char14, " Validity Start

    kdate    TYPE char12, " Validity End

    oiexgnum TYPE char15, " Exchange Number

    ebelp    TYPE char5,  " Item

    werks    TYPE char5,  " Plant

    lgort    TYPE char8,  " Stor.Loc

    matnr    TYPE char25, " Material

    txz01    TYPE txz01,  " Short Text

    ktmng    TYPE char10, " Targ.Quty

    meins    TYPE char5,  " Qun

    kschl    TYPE char5,  " Fees

    kbetr    TYPE char11, " Amount

    waers    TYPE char8,  " Currency

    kpein    TYPE char5,  " Per

    kmein    TYPE char4,  " Unit

    kschl1   TYPE char5,  " Fees

    kbetr1   TYPE char11, " Amount

    waers1   TYPE char8,  " Currency

    kpein1   TYPE char5,  " Per

    kmein1   TYPE char4,  " Unit

    kschl2   TYPE char5,  " Fees

    kbetr2   TYPE char11, " Amount

    waers2   TYPE char8,  " Currency

    kpein2   TYPE char5,  " Per

    kmein2   TYPE char4,  " Unit

    kschl3   TYPE char5,  " Fees

    kbetr3   TYPE char11, " Amount

    waers3   TYPE char8,  " Currency

    kpein3   TYPE char5,  " Per

    kmein3   TYPE char4,  " Unit

    kschl4   TYPE char5,  " Fees

    kbetr4   TYPE char11, " Amount

    waers4   TYPE char8,  " Currency

    kpein4   TYPE char5,  " Per

    kmein4   TYPE char4,  " Unit

  END OF x_excel .

DATA: t_ekko        TYPE STANDARD TABLE OF ty_ekko,

      t_ekpo        TYPE STANDARD TABLE OF ty_ekpo,

      t_oianf       TYPE STANDARD TABLE OF ty_oianf,

      t_excel       TYPE STANDARD TABLE OF x_excel.

FIELD-SYMBOLS: <lfs_ekko>  TYPE ty_ekko,

               <lfs_ekpo>  TYPE ty_ekpo,

               <lfs_oianf> TYPE ty_oianf,

               <lfs_excel> TYPE x_excel.

** EKKO Fetch

SELECT ebeln      " Purchase Docuemnt Number

       bukrs      " Company Code

       lifnr      " Vendor

       bsart      " Order Type

       ekorg      " Purc. Org

       ekgrp      " Purc. Grp

       kdatb      " Validity Start

       kdate      " Validity End

       oiexgnum   " Exchange Number

       knumv      " Number of Document Condition

  FROM ekko

  INTO TABLE t_ekko

  WHERE ebeln EQ '4600014331'.

IF sy-subrc EQ 0.

  SORT t_ekko BY ebeln.

* EKPO Fetch

  SELECT ebeln  " Purchasing Document

         ebelp  " Item

         werks  " Plant

         lgort  " Stor. Loc

         matnr  " Matnr

         txz01  " Short Text

         ktmng  " Target Quantity

         meins  " UOM

    FROM ekpo

    INTO TABLE t_ekpo

    FOR ALL ENTRIES IN t_ekko

    WHERE ebeln EQ t_ekko-ebeln.

  IF sy-subrc EQ 0.

    SORT t_ekpo BY ebeln ebelp.

  ENDIF.

* OIANF Fetch

  SELECT knumv  " Condition Number

         kposn

         kschl  " Condition Type

         kbetr  " Rate

         waers  " Currency Key

         kpein  " Condition Pricing Unit

         kmein  " Condition Unit in the document

    FROM oianf

    INTO TABLE t_oianf

    FOR ALL ENTRIES IN t_ekko

    WHERE knumv EQ t_ekko-knumv.

  IF sy-subrc EQ 0.

    SORT t_oianf BY knumv.

  ENDIF.

ENDIF.

* Build Final Table

* build final table

IF t_ekpo IS NOT INITIAL.

  LOOP AT t_ekpo ASSIGNING <lfs_ekpo>.

    APPEND INITIAL LINE TO t_excel ASSIGNING <lfs_excel>.

    <lfs_excel>-ebelp = <lfs_ekpo>-ebelp.

    <lfs_excel>-werks = <lfs_ekpo>-werks.

    <lfs_excel>-lgort = <lfs_ekpo>-lgort.

    <lfs_excel>-matnr = <lfs_ekpo>-matnr.

    <lfs_excel>-txz01 = <lfs_ekpo>-txz01.

    <lfs_excel>-ktmng = <lfs_ekpo>-ktmng.

    CONDENSE <lfs_excel>-ktmng.

    CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

      EXPORTING

        input    = <lfs_ekpo>-meins

        language = sy-langu

      IMPORTING

        output   = <lfs_excel>-meins.

    READ TABLE t_ekko ASSIGNING <lfs_ekko> WITH KEY ebeln = <lfs_ekpo>-ebeln

                                           BINARY SEARCH.

    IF sy-subrc EQ 0.

      <lfs_excel>-ebeln    = <lfs_ekpo>-ebeln.

      <lfs_excel>-bukrs    = <lfs_ekko>-bukrs.

      <lfs_excel>-lifnr    = <lfs_ekko>-lifnr.

      <lfs_excel>-bsart    = <lfs_ekko>-bsart.

      <lfs_excel>-ekorg    = <lfs_ekko>-ekorg.

      <lfs_excel>-ekgrp    = <lfs_ekko>-ekgrp.

      <lfs_excel>-kdatb    = <lfs_ekko>-kdatb.

      <lfs_excel>-kdate    = <lfs_ekko>-kdate.

      <lfs_excel>-oiexgnum = <lfs_ekko>-oiexgnum.

      READ TABLE t_oianf ASSIGNING <lfs_oianf> WITH KEY knumv = <lfs_ekko>-knumv

                                                        kposn = <lfs_ekpo>-ebelp

                                                        BINARY SEARCH.

      IF sy-subrc EQ 0.

        DATA(l_tabix) = sy-tabix.

        LOOP AT t_oianf ASSIGNING <lfs_oianf> FROM l_tabix.

          IF <lfs_oianf>-knumv EQ <lfs_ekko>-knumv

             AND <lfs_oianf>-kposn EQ <lfs_ekpo>-ebelp.

            IF <lfs_excel>-kschl IS INITIAL.

              <lfs_excel>-kschl = <lfs_oianf>-kschl.

              CONDENSE <lfs_excel>-kschl.

              <lfs_excel>-kbetr = <lfs_oianf>-kbetr.

              CONDENSE <lfs_excel>-kbetr.

              <lfs_excel>-waers = <lfs_oianf>-waers.

              <lfs_excel>-kpein = <lfs_oianf>-kpein.

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

                EXPORTING

                  input    = <lfs_oianf>-kmein

                  language = sy-langu

                IMPORTING

                  output   = <lfs_excel>-kmein.

            ELSEIF <lfs_excel>-kschl NE <lfs_oianf>-kschl

               AND <lfs_excel>-kschl1 IS INITIAL.

              <lfs_excel>-kschl1 = <lfs_oianf>-kschl.

              CONDENSE <lfs_excel>-kschl1.

              <lfs_excel>-kbetr1 = <lfs_oianf>-kbetr.

              CONDENSE <lfs_excel>-kbetr1.

              <lfs_excel>-waers1 = <lfs_oianf>-waers.

              <lfs_excel>-kpein1 = <lfs_oianf>-kpein.

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

                EXPORTING

                  input    = <lfs_oianf>-kmein

                  language = sy-langu

                IMPORTING

                  output   = <lfs_excel>-kmein1.

            ELSEIF <lfs_excel>-kschl NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl1 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl2 IS INITIAL.

              <lfs_excel>-kschl2 = <lfs_oianf>-kschl.

              CONDENSE <lfs_excel>-kschl2.

              <lfs_excel>-kbetr2 = <lfs_oianf>-kbetr.

              CONDENSE <lfs_excel>-kbetr2.

              <lfs_excel>-waers2 = <lfs_oianf>-waers.

              <lfs_excel>-kpein2 = <lfs_oianf>-kpein.

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

                EXPORTING

                  input    = <lfs_oianf>-kmein

                  language = sy-langu

                IMPORTING

                  output   = <lfs_excel>-kmein2.

            ELSEIF <lfs_excel>-kschl NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl1 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl2 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl3 IS INITIAL.

              <lfs_excel>-kschl3 = <lfs_oianf>-kschl.

              CONDENSE <lfs_excel>-kschl3.

              <lfs_excel>-kbetr3 = <lfs_oianf>-kbetr.

              CONDENSE <lfs_excel>-kbetr3.

              <lfs_excel>-waers3 = <lfs_oianf>-waers.

              <lfs_excel>-kpein3 = <lfs_oianf>-kpein.

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

                EXPORTING

                  input    = <lfs_oianf>-kmein

                  language = sy-langu

                IMPORTING

                  output   = <lfs_excel>-kmein3.

            ELSEIF <lfs_excel>-kschl NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl1 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl2 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl3 NE <lfs_oianf>-kschl

              AND <lfs_excel>-kschl4 IS INITIAL.

              <lfs_excel>-kschl4 = <lfs_oianf>-kschl.

              CONDENSE <lfs_excel>-kschl4.

              <lfs_excel>-kbetr4 = <lfs_oianf>-kbetr.

              CONDENSE <lfs_excel>-kbetr4.

              <lfs_excel>-waers4 = <lfs_oianf>-waers.

              <lfs_excel>-kpein4 = <lfs_oianf>-kpein.

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'

                EXPORTING

                  input    = <lfs_oianf>-kmein

                  language = sy-langu

                IMPORTING

                  output   = <lfs_excel>-kmein4.

            ENDIF.

          ELSE.

            EXIT.

          ENDIF.

        ENDLOOP.

      ENDIF.

    ENDIF.

  ENDLOOP.

ENDIF.