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: 

Loop only one time

Former Member
0 Kudos

Hi guys,

I have multiple record in an internal table

for that i have to loop only once

ie only first record i have to loop rest i dont want to loop.

How this can be done?

Regards

senthil

1 ACCEPTED SOLUTION

former_member188827
Active Contributor
0 Kudos

data:BEGIN OF itab OCCURS 0,

z2 type i,

END OF ITAB.

ITAB-z2 = 1.

APPEND ITAB.

ITAB-z2 = 5.

APPEND itab.

loop at itab.

if sy-tabix = 1.

WRITE / itab-z2.

else.

exit.

endif.

ENDLOOP.

6 REPLIES 6

Former Member
0 Kudos

What is your actual requirement ? Please let us know. so that we can help you. What do you want to fetch from the internal table ?

Former Member
0 Kudos

Hi!

Clear lv_mblnr.

LOOP AT gt_main INTO wa_main.

IF wa_main-mblnr = lv_mblnr.

CONTINUE.

ELSE.

MOVE wa_main-mblnr TO lv_mblnr.

ENDIF.

  • other codings

ENDLOOP.

Regards

Tamá

Former Member
0 Kudos

Hi Senthil

Pleae check

Read table ... with index 1 ...

Regards,

Arun

varma_narayana
Active Contributor
0 Kudos

Hi Senthil..

If you want to Read only single record then use the READ TABLE statement.

For 1st Record :

READ TABLE <ITAB> INTO <WA> INDEX 1.

if sy-subrc = 0.

endif.

For reading a single record based on some condition:

READ TABLE <ITAB> INTO <wA> WITH KEY MATNR = P_MATNR.

if sy-subrc = 0.

endif.

REWARD IF HELPFUL.

Former Member
0 Kudos

Hi Senthil,

If reading a single record is the case. I think you can also use SELECT SINGLE *

Regards,

Sai

former_member188827
Active Contributor
0 Kudos

data:BEGIN OF itab OCCURS 0,

z2 type i,

END OF ITAB.

ITAB-z2 = 1.

APPEND ITAB.

ITAB-z2 = 5.

APPEND itab.

loop at itab.

if sy-tabix = 1.

WRITE / itab-z2.

else.

exit.

endif.

ENDLOOP.