Application Development 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 internal table with both index and key.

Former Member
0 Kudos

Hi Friends,

I have an internal table with two fields.

1.date

2.char field which contain value 'Y' or 'N'.

After appending the internal table i want to read the row with earliest date of all the records with [the char field value Y or

the char field value N].

Can anyone help me to resolve this issue.

Best regards,

Ramineni

8 REPLIES 8

Former Member
0 Kudos

Hi

sort the itab by DATE and CHAR field

read table itab index 1.

this will be the ealiest date for Y or N

Regards

Anji

former_member404244
Active Contributor
0 Kudos

Hi,

after u get the data in internal table..try like this..

sort itab by date descending..

the first record in itab is the latest record.

Reward if helpful.

Regards,

Nagaraj

Former Member
0 Kudos

sort itab by date.

read table itab index 1.

0 Kudos

hello....

what is the case if i have more than 2 values in the char field.....

I wanna retrieve

the latest date with char field = 'Y'

the latest date with char field = 'N'

the latest date with char field = 'O'

0 Kudos

sort itab by date descending.

itab1[] = itab[].

delete itab1 where charfield ne 'Y'.

read table itab1 index 1.

if sy-subrc = 0.

*--latest record with charfield = 'Y'

endif.

clear itab1[].

itab1 = itab[].

delete itab1 where charfield ne 'N'.

read table itab1 index 1.

if sy-subrc = 0.

*--latest record with charfield = 'N'

endif.

clear itab1[].

itab1 = itab[].

delete itab1 where charfield ne 'O'.

read table itab1 index 1.

if sy-subrc = 0.

*--latest record with charfield = 'O'

endif.

0 Kudos

SORT ITAB BY DATE.

READ TABLE ITAB WITH KEY CHAR_FIELD = 'Y'.
WRITE: / ITAB-DATE, ITAB-CHAR_FIELD.

READ TABLE ITAB WITH KEY CHAR_FIELD = 'N'.
WRITE: / ITAB-DATE, ITAB-CHAR_FIELD.

READ TABLE ITAB WITH KEY CHAR_FIELD = 'O'.
WRITE: / ITAB-DATE, ITAB-CHAR_FIELD.

0 Kudos

Hi,

try like this

LOOP AT ITAB.

CASE CHAR.

WHEN 'Y'.

sort itab by date char.

WHEN 'N'.

sort itab by date char.

WHEN 'O'.

sort itab by date char.

endcase

endloop.

Regards,

Nagaraj

0 Kudos

Hi,

Go through below code,

sort itab by date.

read table itab index 1.

temp_date = itab-date.

loop at itab where date = temp_date.

<ur logic>

endloop.

thanks!

Brunda

'Reward if useful'.