09-30-2008 6:12 AM
Hi All
I am working on upgrade project from 4.6 to Ecc6
I am facing a problem with delete internal table statement in ECC 6
The statement is going to dump - " SQL Error in data base when accessing the table"
The statement is
Delete it_table where not ( fld1 in s_fld1
09-30-2008 6:16 AM
Internal table with header line is obsolete in 6.0. You need to use work area of table.
Use -
Delete it_table from wa_itab where not ( fld1 in s_fld1).
Regards,
Aparna Gaikwad
09-30-2008 6:19 AM
The statement is
Delete it_table where not ( fld1 in s_fld1 and flds in s_fld2)
This is not causing problem in 4.6
Please help me how can I use work area and solve
09-30-2008 6:23 AM
Hi Lokesh,
Use -
DATA: it_table TYPE STANDARD TABLE OF x_table, "->> x_table is ur structure
wa_table TYPE x_table.
Delete it_table from wa_table where not ( fld1 in s_fld1 and flds in s_fld2)
Regards,
Aparna Gaikwad
09-30-2008 6:26 AM
Hi,
Please see below example.
Alternative 1
... FROM wa ...
Effect
The work area wa must be a data object that is compatible with the row type of the internal table. The statement deletes the first internal table row whose values in the columns of the table key match those of the corresponding components of wa. If the key fields in wa are empty, no entry is deleted.
Note
Outside of classes, you can omit the FROM wa addition if the internal table has an identically named header line itab. The statement then implicitly uses the header line as the work area.
Example
A work area scarr_wa is used to delete the table row that has the same value as p_carrid in the key field carrid.
PARAMETERS p_carrid TYPE scarr-carrid.
DATA: scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrid,
scarr_wa LIKE LINE OF scarr_tab.
SELECT *
FROM scarr
INTO TABLE scarr_tab.
IF sy-subrc = 0.
scarr_wa-carrid = p_carrid.
DELETE TABLE scarr_tab FROM scarr_wa.
ENDIF.
Regards
Jana
09-30-2008 6:27 AM
@ Aparna
Do I need to loop the internal table to work area?
or just the statement you provided will delete line matching the condition
09-30-2008 6:42 AM
I just checked in 6.0. Your statement should not give error.
To avoid this error you can do-
loop at it_table into wa_table.
if fld1 in s_fld1 and flds in s_fld2.
DELETE TABLE it_table FROM wa_table.
endif.
endloop.
Regards,
Aparna Gaikwad
09-30-2008 6:22 AM
HI
DELETE t_tab1 WHERE <fieldname> NE <values> " Values that you don't want to delete
check this snippet
DATA :
BEGIN OF fs_tab,
a TYPE i,
b TYPE i,
END OF fs_tab.
DATA :
t_tab1 LIKE
STANDARD TABLE
OF fs_tab,
t_tab2 LIKE
STANDARD TABLE
OF fs_tab.
DO 10 TIMES.
fs_tab-a = -1 * sy-index.
fs_tab-b = fs_tab-a * sy-index.
APPEND fs_tab TO t_tab1.
ENDDO.
DELETE t_tab1 WHERE a NE -2.
LOOP AT t_tab1 INTO fs_tab.
WRITE :
/ fs_tab-a , fs_tab-b.
ENDLOOP.
In the above snippet all teh values in the internal table are deleted except the entry whose A field value is '-2'.
Regards
Pavan