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

Read Internal Table record

Former Member
0 Likes
875

Hi All,

my requirement is:

suppose we have N rows in internal table

I want to read 1st row of particular column in var1.

and the last row for same column in var 2.

this is for same sales order.

like my internal table is:

vbeln airport

4520 agra

4520 delhi

4520 jaipur

4520 mumbai

so i want

var1 = agra

var2 = mumbai

transfer

it_final-airport = var1.

it_final-airport1 = var2.

thanks

babbal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
835

Hi,

There are several ways in whihc you can achieve this solution.

Use LOOP and the control break statements AT-NEW, AT-END.

Read the SAP help on the same and try to achieve your output.

Regards,

Ankur Parab

7 REPLIES 7
Read only

Former Member
0 Likes
836

Hi,

There are several ways in whihc you can achieve this solution.

Use LOOP and the control break statements AT-NEW, AT-END.

Read the SAP help on the same and try to achieve your output.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
835

be a bit more precise please.

do you need the first and last row of your group of sales oreders (same vbeln) or do you need just the first and last row?

Read only

Former Member
0 Likes
835

Dear babbal,

You can use events in the loop.

e.g.

Loop at Itab into wa.

at first

wa = <field>.

endat.

at last.

wa = <Field>

endat.

endloop.

Try this . Hope this will help you to solve your problem.

Regards,

Vijay

Read only

Former Member
0 Likes
835

Hi,

U can use in loop as follows.

LOOP AT t_final.

AT NEW AIRPORT.

t_final-airport = var1.

ENDAT.

AT END OF AIRPORT.

it_final-airport1 = var2.

ENDAT.

APPEND t_final.

ENDLOOP.

Read only

Former Member
0 Likes
835

Picking up first and last row:

sort itab by vbeln airport ascending.

read itab into workarea index 1.

sort itab by vbeln airport descending.

read itab into workarea index 1.

Best regards,

Guido Koopmann

Read only

Former Member
0 Likes
835

hi

try this logic

create a variable of vbeln type (vbeln1)

just loop through table

if vbeln1is initial

vbeln1 = vbeln.

var1 = airport.

elseif.

vbeln nq vbeln1.

var2 = airport.

vbeln1 = vbeln.

endif.

endloop.

var2 = airport.

i assume that your table is shorted by vbeln as your example.

Edited by: mayank jain on May 25, 2009 2:11 PM

Read only

former_member188829
Active Contributor
0 Likes
835

Hi,

DATA:BEGIN OF itab OCCURS 0,
     field1 TYPE i,
     field2(10) TYPE c,
     END OF itab.

DATA:var1(10),var2(10).

DATA:BEGIN OF itab_first OCCURS 0,
     field1 TYPE i,
     field2(10) TYPE c,
     END OF itab_first.

DATA:BEGIN OF itab_last OCCURS 0,
     field1 TYPE i,
     field2(10) TYPE c,
     END OF itab_last.

START-OF-SELECTION.
  itab-field1 = 4520.
  itab-field2 = 'agra'.
  APPEND itab.
  CLEAR itab.

  itab-field1 = '4520'.
  itab-field2 = 'delhi'.
  APPEND itab.
  CLEAR itab.

  itab-field1 = '4520'.
  itab-field2 = 'jaipur'.
  APPEND itab.
  CLEAR itab.

  itab-field1 = '4520'.
  itab-field2 = 'mumbai'.
  APPEND itab.
  CLEAR itab.
  SORT  itab BY field1 field2.

  LOOP AT itab.
    AT NEW field1.
      READ TABLE itab INDEX sy-tabix.
      IF sy-subrc EQ 0.
        MOVE itab TO itab_first.
        APPEND itab_first.
        CLEAR itab_first.
      ENDIF.
    ENDAT.
  ENDLOOP.

  LOOP AT itab.
    AT END OF field1.
      READ TABLE itab INDEX sy-tabix.
      IF sy-subrc EQ 0.
        MOVE itab TO itab_last.
        APPEND itab_last.
        CLEAR itab_last.
      ENDIF.

    ENDAT.
  ENDLOOP.

  LOOP AT itab_first.
    WRITE:/ itab_first-field1,itab_first-field2.
  ENDLOOP.

  LOOP AT itab_last.
    WRITE:/ itab_last-field1,itab_last-field2.
  ENDLOOP.