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

Error with internal table

Former Member
0 Likes
1,879

Hello Experts,

Am using the preview AS version to learn abap.I just encountered a Run time error.Please help.

It says TABLE ILLEGAL STATEMENT.

You attempted to change , delete , or create a line in the internal table it_sflight but no valid cursor exists.

Source Code.

REPORT ZBC400_47_SELECT_FLIGHT_ITAB.

TYPES: BEGIN OF sbc400focc,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

fldate TYPE sflight-fldate,

seatsocc TYPE sflight-seatsocc,

seatsmax TYPE sflight-seatsmax,

percentage TYPE i,

END of sbc400focc.

TYPES sbc_400_focc

TYPE STANDARD TABLE OF sbc400focc

WITH NON-UNIQUE KEY carrid connid fldate.

DATA it_sflight TYPE sbc_400_focc.

DATA wa_sflight LIKE LINE OF it_sflight.

PARAMETER pa_carr TYPE sflight-carrid.

SELECT carrid connid fldate seatsmax seatsocc

FROM sflight

INTO CORRESPONDING FIELDS OF wa_sflight

WHERE carrid = pa_carr.

wa_sflight-percentage = 100 * wa_sflight-seatsocc / wa_sflight-seatsmax.

INSERT wa_sflight INTO it_sflight.

ENDSELECT.

IF sy-subrc = 0.

SORT it_sflight by percentage.

LOOP AT it_sflight INTO wa_sflight.

WRITE: / wa_sflight-carrid,

wa_sflight-connid,

wa_sflight-fldate,

wa_sflight-seatsocc,

wa_sflight-seatsmax,

wa_sflight-percentage.

ENDLOOP.

WRITE: 'Sorted'.

ELSE.

WRITE: 'NOT FOUND' .

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,354

Use APPEND instead of INSERT.



INSERT wa_sflight INTO it_sflight." Replace this by APPEND

4 REPLIES 4
Read only

Former Member
0 Likes
1,355

Use APPEND instead of INSERT.



INSERT wa_sflight INTO it_sflight." Replace this by APPEND

Read only

0 Likes
1,354

Thanks a lot that worked.Could u explain why INSERT was giving error and why APPEND was to be used?

Read only

0 Likes
1,354

Hi,

You have declared your Internal Table as Standard Internal Table and so you need to use APPEND. Insert can be used once you have sorted the Standard internal Table.

Hope this is clear.

Thanks,

Prashanth

Read only

Former Member
0 Likes
1,354

Hi,

You have to use APPEND to insert a line to the internal table instead of INSERT.

Regards

Abhii