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

Filter Records From Internal table

Former Member
0 Likes
2,261

Hi,

Here is my Internal table and need to filter the records based on some condition.

OBJID | ENDDA | MC_SHORT | MC_STEXT

-


1 20000027|20061231|20000027 |WIT-SP

2 20000027|99991230|20000027 |WIT-SP

3 20000027|20051131|20000027 |WIT-SP

4 20000033|20070131|20000033 |WIT-SP-BC

5 20000033|99990931|20000027 |WIT-SP

6 20000034|20061231|20000034 |WIT-SP-SA

7 20000035|20061231|20000035 |WIT-SP-Q

8 20000036|20070131|20000036 |WIT-SP-E

9 20000036|99991231|20000027 |WIT-SP

This is my internal table data. Now i need to delete the records for each OBJID where ENDDA(Date field) is not eaual to the year 9999. And also if there is no OBJID with year as 9999 then need to keep the reocrd for further processing.Here in this case i should not delete that record.

Please help me out in writing the logic for the same.

Regards

Ramesh

Hi,

Here is my Internal table and need to filter the records based on some condition.

OBJID | ENDDA | MC_SHORT | MC_STEXT

-


1 20000027|20061231|20000027 |WIT-SP

2 20000027|99991230|20000027 |WIT-SP

3 20000027|20051131|20000027 |WIT-SP

4 20000033|20070131|20000033 |WIT-SP-BC

5 20000033|99990931|20000027 |WIT-SP

6 20000034|20061231|20000034 |WIT-SP-SA

7 20000035|20061231|20000035 |WIT-SP-Q

8 20000036|20070131|20000036 |WIT-SP-E

9 20000036|99991231|20000027 |WIT-SP

This is my internal table data. Now i need to delete the records for each OBJID where ENDDA(Date field) is not eaual to the year 9999. And also if there is no OBJID with year as 9999 then need to keep the reocrd for further processing.Here in this case i should not delete that record.

Please help me out in writing the logic for the same.

Regards

Ramesh

10 REPLIES 10
Read only

Former Member
0 Likes
1,316

Hi Ramesh,

You can add one more compoenent in the internal table named year.

It should be populated by this logic.

loop at itab.

itab-year = itab-endda(4).

modify itab index sy-tabix.

endloop.

And after that write a code like this.

delete itab where year ne '9999'.

Hope that helps.

Regards

Kapadia

***Assigning points is the way to say thanks in SDN.***

Read only

0 Likes
1,316

Hi,

My Requirement is as below.

The internal table data i have is..

OBJID | ENDDA | MC_SHORT | MC_STEXT

-


1 20000027|20061231|20000027 |WIT-SP

2 20000027|99991230|20000027 |WIT-SP

3 20000027|20051131|20000027 |WIT-SP

4 20000033|20070131|20000033 |WIT-SP-BC

5 20000033|99990931|20000027 |WIT-SP

6 20000034|20061231|20000034 |WIT-SP-SA

7 20000035|20061231|20000035 |WIT-SP-Q

8 20000036|20070131|20000036 |WIT-SP-E

9 20000036|99991231|20000027 |WIT-SP

Now i need to get the result after filtering is...

OBJID | ENDDA | MC_SHORT | MC_STEXT

-


2 20000027|99991230|20000027 |WIT-SP

5 20000033|99990931|20000027 |WIT-SP

6 20000034|20061231|20000034 |WIT-SP-SA

7 20000035|20061231|20000035 |WIT-SP-Q

9 20000036|99991231|20000027 |WIT-SP

i.e. if there is no reocrd with date as 9999 then i don't want to delete that record but i need to get that also.

regards,

Ramesh

Read only

Former Member
0 Likes
1,316

Hi Ram Mohan....

<b>DELETE ITAB WHERE ( WA-OBJID IS INITIAL AND WA-ENDDA+(4) NE '9999' ) AND

( WA-OBJID IS NOT INITIAL AND WA-ENDDA+(4) EQ '9999' ).

</b>

Hope this works for u

Reward points if useful......

Suresh......

Read only

0 Likes
1,316

Hi Suresh,

Its not working with the logiv prvided.

Regards,

Ramesh

Read only

Former Member
0 Likes
1,316

HI Ram,

I hope you can do like below.

LOOP AT Internaltable.

IF NOT inttab-objectid is initial.

IF inttab-endda+0(4) <> '9999'.

delete inttab index sy-tabx.

ENDIF.

ENDif.

ENDloop.

Regards,

Nava

Read only

Former Member
0 Likes
1,316

Hi ram mohan,

I hope this will help u.

sort itab by endda.

read itab with key endda+0(4) = '9999' binary search.

if sy-subrc = 0.

DELETE itab where endda <> '9999'.

endif.

Regards,

Kasinath.

Read only

0 Likes
1,316

Hi,

Its not working with the logic provided.

Regards,

Ramesh

Read only

0 Likes
1,316

Hi ram mohan,

I hope this will help u.

sort itab by objid endda.

loop at itab.

read itab with key objid = itab-objid

endda+0(4) = '9999' binary search.

if sy-subrc = 0.

DELETE itab where objid = itab-objid and endda+0(4) <> '9999'.

endif.

endloop.

Regards,

Kasinath.

Read only

Former Member
0 Likes
1,316

loop at lt_table.

if lt_table-endda+0(4) = '9999'.

lt_objid-objid = lt_table-objid.

append lt_objid.

endif.

endloop.

loop at lt_objid.

loop at lt_table where objid = lt_objid-objid.

if lt_table-endda+0(4) ne '9999'.

delete lt_table.

endif.

endloop.

endloop.

Here lt_table is your internal table.

And lt_objid is another internal table of type objid.

Regards,

Balakrishna.N

Read only

Former Member
0 Likes
1,316

Hi Ram Mohan...

Try the following code....

<b>data obj_temp like itab-objid.

sort itab by objid.

loop at itab where objid os not initial.

at new itab-objid.

obj_temp = itab-objid.

read itab with key objid = itab-objid endda+0(4) = '9999'.

if sy-subrc = 0.

DELETE itab where objid eq obj_temp and endda+(4) ne '9999'.

endif.

endat.

endloop.</b>

Reward points if useful......

Suresh......