Loop

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
anandramaiya
Posts: 13
Joined: Fri Sep 12, 2008 7:28 am

Loop

Post by anandramaiya » Thu Jul 30, 2009 4:26 am

Hi friends,

I have a query regarding loop.I am fetching data from table ekko,ekpo,ekes& ekbe and finally inserted into internal table potab.program is running extremly fine on prd server but from sometimes loop omited one or more entries of grr's of particular po.when i debug the code i found that due to condistion fail,grr not been inserted.I recently found one case i.e. po has two items each item is having one inbound delivery but both items has four grr's among which only two has been inserted in potab.

plz go through the below mention code.

---------------********************---------------------

*EKES
SELECT VBELN VBELP MENGE DABMG INTO TABLE IT_EKES FROM EKES
WHERE EBELN EQ IT_YPO_ME2M-EBELN AND EBELP EQ IT_YPO_ME2M-EBELP.

*EKBE
SELECT BELNR BUZEI BWART MENGE INTO TABLE IT_EKBE FROM EKBE
WHERE EBELN EQ IT_YPO_ME2M-EBELN AND EBELP EQ IT_YPO_ME2M-EBELP AND BEWTP EQ 'E' AND BWART IN ('101','102','122','922').


IF IT_EKES[] GE IT_EKES[].

LOOP AT IT_EKES.

MOVE: IT_EKES-VBELN TO POTAB-DELIVERY,
IT_EKES-VBELP TO POTAB-ITEM_DELIVERY,
IT_EKES-MENGE TO POTAB-ASNQTY,
IT_EKES-DABMG TO POTAB-QTY_REDUCE.

READ TABLE IT_EKBE INDEX SY-TABIX.

IF SY-SUBRC = 0.
MOVE: IT_EKBE-BELNR TO POTAB-GRR,
IT_EKBE-BUZEI TO POTAB-GRR_ITEM,
IT_EKBE-BWART TO POTAB-MOV_TYPE,
IT_EKBE-MENGE TO POTAB-GRRQTY.
ENDIF.

APPEND POTAB.
CLEAR : POTAB-DELIVERY,POTAB-ITEM_DELIVERY,POTAB-ASNQTY,POTAB-QTY_REDUCE,POTAB-GRR,POTAB-GRR_ITEM,POTAB-MOV_TYPE,POTAB-GRRQTY.
W_FLAG = 'X'.
ENDLOOP.

ELSE.

LOOP AT IT_EKBE.
MOVE : IT_EKBE-BELNR TO POTAB-GRR,
IT_EKBE-BUZEI TO POTAB-GRR_ITEM,
IT_EKBE-BWART TO POTAB-MOV_TYPE,
IT_EKBE-MENGE TO POTAB-GRRQTY.

READ TABLE IT_EKES INDEX SY-TABIX.

IF SY-SUBRC = 0.
MOVE : IT_EKES-VBELN TO POTAB-DELIVERY,
IT_EKES-VBELP TO POTAB-ITEM_DELIVERY,
IT_EKES-MENGE TO POTAB-ASNQTY,
IT_EKES-DABMG TO POTAB-QTY_REDUCE.
ENDIF.

APPEND POTAB.
CLEAR : POTAB-DELIVERY,POTAB-ITEM_DELIVERY,POTAB-ASNQTY,POTAB-QTY_REDUCE,POTAB-GRR,POTAB-GRR_ITEM,POTAB-MOV_TYPE,POTAB-GRRQTY.
W_FLAG = 'X'.

ENDLOOP.

ENDIF.

IF W_FLAG IS INITIAL.
APPEND POTAB.
ENDIF.

BOBA
Posts: 138
Joined: Tue Oct 29, 2002 3:26 pm
Location: Pennsylvania
Contact:

Re: Loop

Post by BOBA » Thu Jul 30, 2009 11:33 am

At a quick glance, I would think you would have more more problems that what you explained. What is the purpose of this If statement
IF IT_EKES[] GE IT_EKES[].

LOOP AT IT_EKES.
This will always be the case !! which means this will never happen
ELSE.

LOOP AT IT_EKBE.
Why would you do this read with sy-index instead of doing a loop at it_ekbe where EBELN = IT_EKES-EBELN and EBELP = IT_EKES-EBELP
READ TABLE IT_EKBE INDEX SY-TABIX.

IF SY-SUBRC = 0.
Bob

As you go through life keep this in mind Don't wait till it's too late
No one ever changed the past, but everyone can change the future

anandramaiya
Posts: 13
Joined: Fri Sep 12, 2008 7:28 am

Re: Loop

Post by anandramaiya » Thu Jul 30, 2009 11:16 pm

sir,

Actully my requirement is to fetched purchase order inbound delivery & grr's .For the same I am repetadly getting the duplicate entries so finally i tried this condistion with read statment using tabix.If i changed the stament i will get duplicate entries.I also tried with sort command and delete adjascent duplicate statment on table it_ekbe but that also not working.
I also removed the first if condistion and tried with direct insertion in potab but still the result same.

I would be thankful for your help.......
suggest something to sort the issue.

Grogan
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: Loop

Post by Grogan » Fri Jul 31, 2009 3:47 pm

Firstly, please put blocks of inserted code inside code tags. If you can't be bothered to do this, then why should we be bothered to read it ?

BOBA has already pointed out that the following condition is always going to be true. The code inside the IF clause is therefore always executed. The condition itself and the code inside the ELSE clause is redundant.

Code: Select all

IF IT_EKES[] GE IT_EKES[].
Inside the IF clause, the code produces one POTAB record for every Confirmation (EKES) record. It doesn't matter how many GR (EKBE) records you have, the program is looping over the Confirmation records.

It also appears that you are reading a random, probably unrelated GR record with this statement:

Code: Select all

READ TABLE IT_EKBE INDEX SY-TABIX.
In theory a PO may have any number of Confirmations, and any number (more or less) of GRs. You need to consider what you want the program to do in each case.

You should also consider how to match GRs with Confirmation, as that is what the program seems to be trying to do. At the very least sort both Confirmations and GRs by date, so that you are merging the data in chronological order. Also look at field EKBE-ETENS - on the surface it looks as though this can be used to link back to a Confirmation, but I don't know.

I am also assuming field W_FLAG is initialised each time.
Grogan

Award cash if useful.

anandramaiya
Posts: 13
Joined: Fri Sep 12, 2008 7:28 am

Re: Loop

Post by anandramaiya » Sat Aug 01, 2009 1:26 am

sir,

I regret for the same and assure you next time i always follow the same.

Back to the code point,As per requirement i am feching the po delivery and grr data with there respective qty now point is in case if confirmation is more than grr than code is running smoother i.e match the condistion if it_ekes[] ge it_ekes[] but when grr's are more than delivery numbers than code omitte the remaning grr's.
I just need to know in case of grr more than delivery numbers how i can alter the above code/codistion sothat in both cases prg delivers smoother.

Thanking you....

Anand.

bucka
Posts: 291
Joined: Sat Jun 18, 2005 2:09 am
Location: Ballarat, Victoria, Australia

Re: Loop

Post by bucka » Sat Aug 01, 2009 4:02 am

Hi as a side note,

You should not use Tables with Header lines anymore...
Kind Regards,

Ron Johns.

The older I get the better I was.

MattG
Posts: 809
Joined: Wed Oct 23, 2002 2:06 pm
Location: England

Re: Loop

Post by MattG » Sat Aug 01, 2009 9:54 am

Back to the code.

Code: Select all

IF IT_EKES[] GE IT_EKES[].
As both both sides of the equasion are the same, the condition is always TRUE. x always equals x and therefore is greater or EQUAL TO x!

If we assume that your code has a typo, and should be:

Code: Select all

IF IT_EKES[] GE LT_EKES[].
We now have the more important question, which is, what do you expect this IF to be telling you? If you want to find out which table has the greater numer of entries (lines). Then this IF may or may not give the correct answer. It is NOT testing this.

It is testing the contents of the two tables! If row 1 of both tables is 'abc' it will check row 2, etc, until there is a pair of rows with a difference. So if row x of the tables are 'def' and 'deg', then the second table is greater than the first. However if the contents of row x were 'def' and 'dec' then the first table would be greater than the second.
MattG.
Image Search SAPfans

anandramaiya
Posts: 13
Joined: Fri Sep 12, 2008 7:28 am

Re: Loop

Post by anandramaiya » Wed Aug 05, 2009 12:14 am

sir,

I am trying to pull and insert all deliveries with respective Grr's into potab and to avoid duplication i ued the condistion it_ekes[] ge it_ekes.
My issue is as you said the condistion is always true ,that's why code is compatible with those purchase order who has more deliveries than the grr's but if in case total number of grr's are more than delivery number of a respective po item than condistion gets fail to insert more grr's, alse it will not go into else one.

I reqoest you to guide hoe can i alter the above code sothat both condistion wil work smoother.

Thanking you....

BOBA
Posts: 138
Joined: Tue Oct 29, 2002 3:26 pm
Location: Pennsylvania
Contact:

Re: Loop

Post by BOBA » Wed Aug 05, 2009 9:38 am

Try this code and see if it is what you are trying to accomplish. It should get you all Vendor Confirmations with goods receipts if any.

Code: Select all

Tables: EKES, EKBE.

Data: Begin Of IT_POTAB OCCURS 0,
       doc_num type ebeln,
       doc_item_num type ebelp,
       seq_num type etens,
       create_date type bberd,
       create_time type bbeze,
       confirm_qty type bbmng,
       ref_doc type xblnr_long,
       delivery_num type vbeln_vl,
       delivery_item type posnr_vl,
       trans_type type vgabe,
       category type bewtp,
       movement_type type bwart,
       posting_date type budat,
       posting_qty type menge_d,
      END OF   IT_POTAB.

SELECT-OPTIONS: S_EBELN FOR EKES-EBELN.

start-of-selection.

Code: Select all

SELECT
  C~EBELN
  C~EBELP
  C~ETENS
  C~ERDAT
  C~EZEIT
  C~MENGE
  C~XBLNR
  C~VBELN
  C~VBELP
  H~VGABE
  H~BEWTP
  H~BWART
  H~BUDAT
  H~MENGE
   INTO TABLE IT_POTAB
  FROM EKES as C
     LEFT OUTER JOIN EKBE as H
      ON C~EBELN = H~EBELN
      and C~EBELP = H~EBELP
      and C~MENGE = H~MENGE
    WHERE C~EBELN in S_EBELN.

** now delete unwanted records
  Delete IT_POTAB
   where category <> 'E'
     OR ( movement_type <> '101' and movement_type <> '102'
        and movement_type <> '122' and movement_type <> '922' ).
Bob

As you go through life keep this in mind Don't wait till it's too late
No one ever changed the past, but everyone can change the future

anandramaiya
Posts: 13
Joined: Fri Sep 12, 2008 7:28 am

Re: Loop

Post by anandramaiya » Mon Aug 10, 2009 1:48 am

Ok sir problem is sorted out...

I replace the if condistion with if ekes_cnt Le ekbe_cnt and it's working smoothly.

Thanks for your quick responce.

Anand Ramaiya.

Post Reply