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

Problem with read statement

Former Member
0 Likes
988

Hi Expert,

As per my rquirement I need to display all corresponding ebeln for a particular matnr also

if any matnr have no ebeln also I need to display in O/P.

I succeded in fetching the records but my problem is in displaying it as in my O/P there one excess line for every record ( which is unwanted or duplicate ) now I want to clear it please advice.

Please have look on my below code and advice me.

SELECT MARA~MATNR MARA~MTART MARD~WERKS MARD~LABST MARD~INSME MARD~SPEME FROM MARA INNER JOIN MARD ON MARA~MATNR EQ MARD~MATNR
INTO CORRESPONDING FIELDS OF TABLE IT_MARA  WHERE MARA~MATNR IN MATNR AND MARD~WERKS IN WERKS.

LOOP AT IT_MARA.
    MOVE IT_MARA-MATNR TO IT_TAB-MATNR.
    MOVE IT_MARA-WERKS TO IT_TAB-WERKS.
    MOVE IT_MARA-LABST TO IT_TAB-LABST.
    MOVE IT_MARA-INSME TO IT_TAB-INSME.
    MOVE IT_MARA-SPEME TO IT_TAB-SPEME.
    COLLECT IT_TAB.
  ENDLOOP.

LOOP AT IT_TAB.
    MOVE-CORRESPONDING IT_TAB TO IT_FIRST.
    APPEND IT_FIRST.
  ENDLOOP.

IF NOT IT_FIRST IS INITIAL.
    SELECT * FROM EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO
       FOR ALL ENTRIES IN IT_FIRST WHERE MATNR EQ IT_FIRST-MATNR
       AND WERKS EQ IT_FIRST-WERKS AND PSTYP EQ '0' AND BSTYP EQ 'F'
       AND ELIKZ EQ ' ' AND LOEKZ NE 'L'.
  ENDIF.

For the below code I am facing trouble.

SORT IT_FIRST BY MATNR EBELN.
    LOOP AT IT_EKPO.
    READ TABLE IT_FIRST WITH KEY MATNR = IT_EKPO-MATNR
                                 WERKS = IT_EKPO-WERKS.
    IF SY-SUBRC = 0.
      MOVE IT_EKPO-EBELN TO IT_FIRST-EBELN.
      MOVE IT_EKPO-EBELP TO IT_FIRST-EBELP.
    ENDIF.
    APPEND IT_FIRST.
  ENDLOOP.

Thanks

Karthik

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
958

Hi,

100% sure it will display....

That was the reason I wrote the delete statement inside the loop and giving the condition to delete only if the ebeln for the particular matnr is found... If the value for ebeln for the matnr is not found then the delete statement will not execute which means that those matnr values would remain undeleted....

Hence it will work ... if you want you can check by entering some dummy values in the database table or in the program just write a test code before the loop of delete, inserting the value in it_first and not entering any value in it ekpo.

then check if it displays those records which does not have any values in ebeln i.e. there are no entries in it_ekpo for those records.....

Regards,

Siddarth

11 REPLIES 11
Read only

Former Member
0 Likes
958

Hi,

declare another table to display the output..lets say it_final...move the entries to it_final and display it.

SORT IT_FIRST BY MATNR EBELN.

LOOP AT IT_EKPO.

READ TABLE IT_FIRST WITH KEY MATNR = IT_EKPO-MATNR

WERKS = IT_EKPO-WERKS.

IF SY-SUBRC = 0.

MOVE IT_EKPO-EBELN TO IT_FINAL-EBELN.

MOVE IT_EKPO-EBELP TO IT_FINAL-EBELP.

ENDIF.

APPEND IT_FINAL.

ENDLOOP.

Regards,

Pavan

Read only

Former Member
0 Likes
958

Hi Can you please check this code once :

SORT IT_FIRST BY MATNR EBELN.

LOOP AT IT_EKPO.

READ TABLE SORT IT_FIRST BY MATNR EBELN.

LOOP AT IT_EKPO.

READ TABLE IT_FIRST WITH KEY MATNR = IT_EKPO-MATNR

WERKS = IT_EKPO-WERKS.

IF SY-SUBRC = 0.

MOVE IT_EKPO-EBELN TO IT_FIRST-EBELN.

MOVE IT_EKPO-EBELP TO IT_FIRST-EBELP.

ENDIF.

APPEND IT_FIRST.

ENDLOOP.

Here you are reading from IT_FIRST and again you are appending IT_FIRST.

This logic you have written is not correct.

Check the logic once.

Read only

0 Likes
958

Hi Vinay,

Thank u !! But its not working 4 me ...actually my o/p is correct only thing is one duplicate line is displayed for every record.

for eg:

If a matnr have no Po number it is displayed correctly.

suppose if a matnr have Po...its displayed like..

*werks* , *matnr* , *ebeln*.
 unit1    , ABCD  ,  --space--            "duplicate line 
 unit1    , ABCD  , 4500019328
 unit1    , ABCD  , 4500018621
 unit2    , EFGH  ,  --space--            "duplicate line 
 unit2    , EFGH  , 4500192310
 unit2    , EFGH  , 4500065312

but it should display as :

*werks* , *matnr* , *ebeln*.
 unit1    , ABCD  , 4500019328
 unit1    , ABCD  , 4500018621
 unit2    , EFGH  , 4500192310
 unit2    , EFGH  , 4500065312

Please advice

Karthik

Edited by: Karthik R on Apr 20, 2009 5:57 PM

Read only

0 Likes
958

HI,

LOOP AT IT_EKPO.
    READ TABLE IT_FIRST WITH KEY MATNR = IT_EKPO-MATNR
                                 WERKS = IT_EKPO-WERKS.
    IF SY-SUBRC = 0.
      MOVE IT_EKPO-EBELN TO IT_FIRST-EBELN.
      MOVE IT_EKPO-EBELP TO IT_FIRST-EBELP.

 "   If you don't want to display the  blank ebeln with Append inside the condition
     APPEND IT_FIRST.
     CLEAR IT_FIRST.
    ENDIF.

 "   If you  want to display the  blank ebeln with Append outside the if condition 
  ENDLOOP.

Read only

0 Likes
958

Hi Avinash,

Its not working ...please advice

Read only

Former Member
0 Likes
958

Try following code :


  SORT it_first BY matnr ebeln.
  LOOP AT it_ekpo.
    READ TABLE it_first WITH KEY matnr = it_ekpo-matnr
                                 werks = it_ekpo-werks.
    IF sy-subrc = 0.
      MOVE it_ekpo-ebeln TO it_first-ebeln.
      MOVE it_ekpo-ebelp TO it_first-ebelp.
      MODIFY it_first.
    ENDIF.
  ENDLOOP.

Also In your select query you should check the contents of internal table rather than it's header line only.

IF NOT IT_FIRST[] IS INITIAL.

Correct Code :


IF NOT IT_FIRST[]  IS INITIAL.
    SELECT * FROM EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO
       FOR ALL ENTRIES IN IT_FIRST WHERE MATNR EQ IT_FIRST-MATNR
       AND WERKS EQ IT_FIRST-WERKS AND PSTYP EQ '0' AND BSTYP EQ 'F'
       AND ELIKZ EQ ' ' AND LOEKZ NE 'L'.
  ENDIF.

Try using delete adjacent duplicate command if you are still getting duplicate records.

Hope it helps

Tx

Ashwa

Read only

Former Member
0 Likes
958

Hello,

The code you are writing is having some problem.

you are reading the table IT_FIRST, and appending to the same table.

Instead of that

Loop at IT_EKPO

Read IT_FIRST

Then istead of using APPEND IT_FIRST,

write

MODIFY IT_EKPO.

Still if the problem prevails then make use of the following statement

DELETE ADJACENT duplicates from (Internal table) COMPARING all fields.

Regards

Read only

Former Member
0 Likes
958

Hi,

after the loop delete the unwanted records.

SORT IT_FIRST BY MATNR EBELN.
    LOOP AT IT_EKPO.
    READ TABLE IT_FIRST WITH KEY MATNR = IT_EKPO-MATNR
                                 WERKS = IT_EKPO-WERKS.
    IF SY-SUBRC = 0.
      DELETE IT_FIRST WHERE MATNR = IT_EKPO-MATNR AND WERKS - IT_EKPO-WERKS AND 
                           EBELN = SPACE.
      MOVE IT_EKPO-EBELN TO IT_FIRST-EBELN.
      MOVE IT_EKPO-EBELP TO IT_FIRST-EBELP.
      APPEND IT_FIRST.
    ENDIF.

  ENDLOOP.

Regards,

Siddarth

Read only

0 Likes
958

Hi Sidharth ,

Thank u !! its working but I need to display matnr which have no corresponding ebeln in have developed the program in development and now my o/p is correct but I want to know will all the matnr with no ebeln will display in Production if use ur logic ..

Please advice

Karthik

Read only

Former Member
0 Likes
959

Hi,

100% sure it will display....

That was the reason I wrote the delete statement inside the loop and giving the condition to delete only if the ebeln for the particular matnr is found... If the value for ebeln for the matnr is not found then the delete statement will not execute which means that those matnr values would remain undeleted....

Hence it will work ... if you want you can check by entering some dummy values in the database table or in the program just write a test code before the loop of delete, inserting the value in it_first and not entering any value in it ekpo.

then check if it displays those records which does not have any values in ebeln i.e. there are no entries in it_ekpo for those records.....

Regards,

Siddarth

Read only

0 Likes
958

wow ..Sidharth u ROCK !!

Thanks a lot for ur kind help.....ur above not was very helpful 4 me ...