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

Loop!

Former Member
0 Likes
1,549

Hi,

For this simple program I am not getting the output.

REPORT ZATUL_DEMO1.

data: it_spfli TYPE TABLE OF sflight ,

wa_spfli type sflight.

SELECT * from sflight INTO corresponding fields of table it_spfli.

loop at it_spfli into wa_spfli.

endloop.

WRITE : wa_spfli-CARRID.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,522
try this...there might not be any data in table SFLIGHT

REPORT ychatest.

DATA: it_spfli TYPE TABLE OF sflight ,
wa_spfli TYPE sflight.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_spfli.

IF NOT it_spfli[] IS INITIAL.
LOOP at it_spfli into wa_spfli.
  WRITE : / wa_spfli-carrid.
ENDLOOP.
ELSE.
WRITE : / 'No Data found'.
ENDIF.
14 REPLIES 14
Read only

PS_1978
Active Participant
0 Likes
1,522

Please check whether sflight has any data in it or not and then move write statement inside the loop....

loop at it_spfli into wa_spfli.

WRITE : wa_spfli-CARRID.

endloop.

null

Read only

Former Member
0 Likes
1,522

I tried the write statement in side the loop . then also its not working. not gng inside the loop.

Read only

Former Member
0 Likes
1,522

Hi

Can You post your code that u tried...

Biju

Read only

Former Member
0 Likes
1,522

Hi Ajay,

write WRITE statement with in loop.

reward , if useful

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,522

Hi ajay,

Give write statement within the loop.

Look the below one.

*********************************************************

DATA : it_spfli LIKE STANDARD TABLE OF sflight WITH HEADER LINE.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_spfli.

LOOP AT it_spfli.

WRITE 😕 it_spfli-carrid.

ENDLOOP.

*********************************************************

<b>Regards,

jackie..</b>

Message was edited by:

Jackie

Read only

Former Member
0 Likes
1,522

HI,

REPORT ZATUL_DEMO1.

data: it_spfli TYPE TABLE OF sflight ,

wa_spfli type sflight.

SELECT * from sflight INTO corresponding fields of table it_spfli.

loop at it_spfli into wa_spfli.

<b>WRITE : / wa_spfli-CARRID.</b> "putting a / will get next records in new line..

endloop.

*WRITE : wa_spfli-CARRID. this will return the last record

rewards if useful,

regards,

nazeer

Read only

Former Member
0 Likes
1,522

Hi

Keep that write statment inside the LOOP..ENDLOOP.

Wa_spfli will have only one value at a time

incase if it doesnt have last record,it wont display.

Thanks

Read only

Former Member
0 Likes
1,522

Hi

Do Like This.............

REPORT ZATUL_DEMO1.

data: it_spfli TYPE TABLE OF sflight ,

wa_spfli type sflight.

SELECT * from sflight INTO corresponding fields of table it_spfli.

loop at it_spfli into wa_spfli.

WRITE 😕 wa_spfli-CARRID.

endloop.

Read only

Former Member
0 Likes
1,522

hi,

data: it_spfli TYPE TABLE OF sflight ,

wa_spfli type sflight.

SELECT * from sflight INTO corresponding fields of table it_spfli.

loop at it_spfli into wa_spfli.

WRITE : wa_spfli-CARRID.

endloop.

reward with points if helpful.

Read only

graghavendra_sharma
Contributor
0 Likes
1,522

Hi

You just keep the WRITE command inside LOOP and ENDLOOP.

Since the work are is blank of the internal table is blank, you were not getting at single record displayed.

REPORT ZATUL_DEMO1.

data: it_spfli TYPE TABLE OF sflight ,

wa_spfli type sflight.

SELECT * from sflight INTO corresponding fields of table it_spfli.

IF sy-subrc = 0.

loop at it_spfli into wa_spfli.

WRITE : wa_spfli-CARRID.

endloop.

endif.

Read only

Former Member
0 Likes
1,522

Hi,

Are you getting any error message or

Just a blank output screen.

Try it by using the above coding

which i gave..

Regards,

Jackie.

Message was edited by:

Jackie

Read only

Former Member
0 Likes
1,522

Hi Ajay ,

Your code is working fine in my system.

So could you please check if data is selected from the select statement.

I feel no data is being selected by the SQL statement.

Regards

Arun

Read only

Former Member
0 Likes
1,523
try this...there might not be any data in table SFLIGHT

REPORT ychatest.

DATA: it_spfli TYPE TABLE OF sflight ,
wa_spfli TYPE sflight.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_spfli.

IF NOT it_spfli[] IS INITIAL.
LOOP at it_spfli into wa_spfli.
  WRITE : / wa_spfli-carrid.
ENDLOOP.
ELSE.
WRITE : / 'No Data found'.
ENDIF.
Read only

Former Member
0 Likes
1,522

Hi ajay singh,

check sy-subrc before writing loop. IF sy-subrc EQ 0 then only use the loop statement.

If sy-subrc EQ 0 and still if U wont get any output it means U have the CARRID as initial. As it is a primary key this is not possible but programatically if some one has inserted some junk data this is possible. Check ur table entires once.