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

Internal Table Help Req??

Former Member
0 Likes
950

Hi

I had 2 internal table : it_cdpos(4 Records) & it_cdhdr(6 Records)

it_cdpos :PO No. Doc_No2 it_cdhdr : PO No. Doc_No1

42 101 42 101

42 102 42 102

42 103 42 103

42 104 42 104

42 105

42 106

I want to delete the records of it_cdhdr,where Doc No is different.

I had written the below code:

LOOP AT it_cdhdr.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

IF it_cdhdr-doc_no1 EQ it_cdpos-doc_no2.

IF sy-subrc <> 0.

DELETE it_cdhdr.

ENDIF.

DELETE TABLE it_cdpos.

ENDIF.

CLEAR : it_cdhdr,it_cdpos.

ENDLOOP.

I don't have any data to check,plz tell me that is the logic correct or there has to be change,coz I am not sure,when there will be records in it_cdpos,will the case :if sy-subrc <> 0.

delete it_cdhdr.

endif.

will work or not,if it will be working than,its fine otheriwse how to code???plz tell me???

Regards

Vipin

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
932

hi

As per my knowledge, it will work fine.. go ahead

sorry, i have one observation

LOOP AT it_cdhdr.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

<b>loop at it_cdpos.</b>

IF it_cdhdr-doc_no1 EQ it_cdpos-doc_no2.

IF sy-subrc <> 0.

DELETE it_cdhdr.

ENDIF.

DELETE TABLE it_cdpos.

ENDIF.

CLEAR : it_cdhdr,it_cdpos.

<b>Endloop</b>

ENDLOOP.

now it will work fine.

reward points if useful.

regards,

pavan

Message was edited by:

pavan kumar pisipati

9 REPLIES 9
Read only

Former Member
0 Likes
933

hi

As per my knowledge, it will work fine.. go ahead

sorry, i have one observation

LOOP AT it_cdhdr.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

<b>loop at it_cdpos.</b>

IF it_cdhdr-doc_no1 EQ it_cdpos-doc_no2.

IF sy-subrc <> 0.

DELETE it_cdhdr.

ENDIF.

DELETE TABLE it_cdpos.

ENDIF.

CLEAR : it_cdhdr,it_cdpos.

<b>Endloop</b>

ENDLOOP.

now it will work fine.

reward points if useful.

regards,

pavan

Message was edited by:

pavan kumar pisipati

Read only

0 Likes
932

Do you think that,loop at it_cdpos after read statement, has to be there,as when loop will be at index 1,on it_cdhdr,if it is going to chk for entire it_cdpos,it will completely my it_cdhdr except record at index 1 & it_cdpos table.

than again for loop on it_cdhdr at index 2,there will be no data in it_cdhdr & it_cdpos.than......the output will be just the record at index 1.???

i thnk it will be wrong.??????

Read only

0 Likes
932

Please try this code....

First sort the two internal tables with the two fields....

data: wa type it_cdpos.

LOOP AT it_cdhdr.

READ TABLE it_cdpos into wa WITH KEY objectid = it_cdhdr-ebeln.

IF wa-doc_no2 is initial.

DELETE it_cdhdr.

else.

clear wa.

ENDIF.

endloop.

ENDLOOP.

Read only

0 Likes
932

Hi

i think is is better than previous query:

LOOP AT it_cdhdr.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

IF sy-subrc <> 0.

DELETE TABLE it_cdhdr.

ELSEIF it_cdhdr-changenr1 EQ it_cdpos-changenr2.

DELETE TABLE it_cdpos.

ELSEIF sy-subrc <> 0.

DELETE TABLE it_cdhdr.

ENDIF.

CLEAR : it_cdhdr,it_cdpos.

ENDLOOP.

Plz tell me ????

Regards

Vipin

Read only

0 Likes
932

Try like this:

LOOP AT it_cdhdr.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.
if sy-subrc = 0.
  l_index = sy-index.
  IF it_cdhdr-changenr1 EQ it_cdpos-changenr2
    DELETE TABLE it_cdpos index l_index.
  endif.
else
   DELETE TABLE it_cdhdr.
  continue.
ENDIF.

CLEAR : it_cdhdr,it_cdpos.

ENDLOOP.

Regards,

Naimesh Patel

Read only

0 Likes
932

LOOP AT it_cdhdr.

LOOP AT it_cdpos WHERE objectid = it_cdhdr-ebeln AND changenr2 NE it_cdhdr-changenr1.

.DELETE TABLE it_cdpos.

ENDLOOP.

IF sy-subrc = 0.

DELETE TABLE it_cdhdr.

ENDIF.

ENDLOOP.

Just use this

Regards,

Atish

Read only

Former Member
0 Likes
932

Hi Vipin,

Change code as below

LOOP AT it_cdhdr.

clear it_cdpos.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

<b>IF sy-subrc = 0.</b>

IF it_cdhdr-doc_no1 <b>NE</b> it_cdpos-doc_no2.

<b>DELETE TABLE it_cdhdr.

DELETE TABLE it_cdpos.</b>

ENDIF.

ENDIF.

CLEAR : it_cdhdr,it_cdpos.

ENDLOOP.

Regards,

Atish

Read only

0 Likes
932

As it_cdpos is a item table I think you also need to replace READ with LOOP.

Regards,

Atish

Read only

Former Member
0 Likes
932

With just a quick glance, you need to move your sy-subrc directly after the read so that it looks something like this.

READ TABLE it_cdpos WITH KEY objectid = it_cdhdr-ebeln.

IF sy-subrc <> 0.

IF it_cdhdr-doc_no1 EQ it_cdpos-doc_no2.

DELETE it_cdhdr.

ENDIF.

DELETE TABLE it_cdpos.

ENDIF.

Also is it_cdhdr a header/workspace/structure? If thats the case you need to clear the structure not delete it.