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

select from itab

Former Member
0 Likes
1,299

i need to find line in itab.

when i find it i need to take the line before and the line after how i can do it?

PLS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,229

Hi,

Consider this ,


    DATA : ind1 TYPE   sy-tabix,
           ind2 TYPE   sy-tabix.
    READ TABLE it_test INTO wa_test WITH TABLE KEY k1 = v1
                                   kn = v2.
    IF sy-subrc EQ 0.
      ind1 = sy-tabix + 1.
      ind2 = sy-tabix - 1.

      READ TABLE it_test INTO wa_after INDEX ind1.

      READ TABLE it_test INTO wa_before INDEX ind2.


    ENDIF.

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi

Message was edited by: Arun Sambargi

11 REPLIES 11
Read only

Former Member
0 Likes
1,229

hi,

could u pls explain clearly ..

Regards,

Ramesh.

Read only

0 Likes
1,229

i have loop on mardh and before i have mard.

LOOP AT imardh ASSIGNING <ls_mardh>.

IF <ls_mardh>-lfmon = z_period+0(2) AND

<ls_mardh>-lfgja = z_period+2(4).

<b>here i found the line and end stock now i need to find the start and it's the line before

and if i didnt find i need to take the line before and after</b>

<ls_mard>-e_stock = <ls_mardh>-labst.

ENDIF.

ENDLOOP.

Read only

0 Likes
1,229

Use the READ statement.



data: index type i.

* Read the line with key
read table itab with key field1 = 'some_value'.

* Read the line before it
index = sy-tabix - 1.
read table itab index index.

* Read the line after it
index = sy-tabix + 1.
read table itab index index.








Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,229

Hi,

Use SY-Tabix.

Sy-tabix will point to current line.

lv_next_line type I.

lv_next_line = sytabix + 1.

take temp work area.

wa_temp

read table itab into wa_temp index lv_next_line.

update current line with wa_temp.

update next line with previous data

Read only

Former Member
0 Likes
1,229

hi rani,

use read stmt.

im not sure but try this..

read table itab index sy-tabix.

to read before the line

data: v_tabix type sy-tabix.

v_tabix = sy-tabix - 1.

read table itab index v_tabix.

to read after the line

data: v_tabix1 type sy-tabix.

v_tabix1 = sy-tabix + 1.

read table itab index v_tabix1.

Read only

Former Member
0 Likes
1,229

READ table something with key = sometning

temp = sy-tabix + 1.

temp2= sy-tabix - 1.

READ table something index temp.

read table something index temp2.

Something like that.

BR, JAcek

Read only

Former Member
0 Likes
1,229

Hi rani,

u can find it thru sy-tabix.

example.

loop at itab.

l_tabix = sy-tabix." current line no.

.....

  • For line before

read table itab index l_tabix -1.

  • For line after

read table itab index l_tabix +1.

endloop.

Regards,

kiran B

Read only

Former Member
0 Likes
1,229

Hi Rani,

The line you find in the itab will have a specific index. So you can do index + 1 and index - 1 to get the next and the before line.

Ex: your internal table has 5 records. you are taking the the 3rd record, your tabix will be 3.

Then do this.

lws_index = sy-tabix + 1.

lws_ind = sy-tabix - 1.

read table index lws_index. (next record)

read table index lws_ind. (before record)

Read only

Former Member
0 Likes
1,229

Hi,

loop at itab where 'condition'.

itab_index = sy-tabix.

itab_prev_index = itab_index - 1.

read itab index itab_prev_index .

itab_next_index = itab_index + 1.

read itab index itab_next_index .

endloop.

Read only

Former Member
0 Likes
1,230

Hi,

Consider this ,


    DATA : ind1 TYPE   sy-tabix,
           ind2 TYPE   sy-tabix.
    READ TABLE it_test INTO wa_test WITH TABLE KEY k1 = v1
                                   kn = v2.
    IF sy-subrc EQ 0.
      ind1 = sy-tabix + 1.
      ind2 = sy-tabix - 1.

      READ TABLE it_test INTO wa_after INDEX ind1.

      READ TABLE it_test INTO wa_before INDEX ind2.


    ENDIF.

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi

Message was edited by: Arun Sambargi

Read only

Former Member
0 Likes
1,229

hello,

here is the pseudo-code for your reqmt.

*- 
data: l_tabix1 like sy-tabix.
data: l_tabix2 like sy-tabix.
*-
data: g_s_itab1 like line of g_t_itab.
data: g_s_itab2 like line of g_t_itab.

READ TABLE g_t_itab 
TRANSPORTING NO FIELDS WITH KEY 
key = 'KEY'
BINARY SEARCH. 
*-                                     
 if sy-subrc = 0.
 clear: l_tabix1, l_tabix2,g_s_itab1, g_s_itab2.
 l_tabix1 = sy-tabix - 1.
 l_tabix2 = sy-tabix + 1.
 read table g_t_itab into g_s_itab1 index l_tabix1.
*- check SY-SUBRC
 read table g_t_itab into g_s_itab2 index l_tabix2.
*- check SY-SUBRC
 endif.

hope this helps

best regards, Murugesh AS