Skip to Content
0

SLIN Error - Internal table with empty primary key

Nov 25, 2016 at 08:20 PM

177

avatar image

Experts,

I am learning ABAP 7.5 programming from ABAP to Future SAP Press book.

*ZTABLE1 has MATNR,WERKS & RESWK as key fields 
  SELECT * FROM ztable1
      INTO TABLE @DATA(lit_ztab1)
       WHERE werks IN @s_werks and
 	     matnr in @s_matnr.
 if lit_ztab1 is not initial.
 field-symbols: <lfs_ztab1> like line of lit_ztab1.
 loop at lit_ztab1 assigning <lfs_ztab1>.
....Validate some conditions if <<condition is met>>. delete table lit_ztab1 from <lfs_ztab1>. endif. endloop. endif.

Upon running SLIN check for above code, I am getting error message as below,

"LIT_ZTAB1" is a table with an empty primary key. Check the semantics of the statement. Internal message code: MESSAGE G]3 Cannot be deactivated using a pragma. Message Code WRN W095

Is it mandatory to mention primary key for LIT_ZTAB1 table when we declare it inline? If so, how can this be done as part of inline data declaration?

Please share your valuable inputs.

BR,

Aspire

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Sandra Rossi Nov 25, 2016 at 08:56 PM
0

Look at the line mentioned by the error; it's probably for the line DELETE TABLE lit_ztab1 FROM <lfs_ztab1>. It can't find the line if there's no key. Check the ABAP documentation ( http://help.sap.com/abapdocu_751/en/?file=ABAPDELETE_ITAB.htm )

Share
10 |10000 characters needed characters left characters exceeded
Bharath Padmanabhan Nov 25, 2016 at 09:33 PM
0

Hi Sandra,

I am trying to delete a record from internal table when some condition is met. For long, i was under the assumption that delete inside loop is a performance drain as indexes have to be build every single time. I read a thread reply from Moderator Rob where he had mentioned that he does it every time & as long as logic within loop is not driven based on index, there is no problem in deleting the internal table directly.

That is why, instead of delete based on index sy-tabix, i am deleting based on work area.

You reply is extremely helpful to me. I understand why i am getting error message in SLIN. Delete statement is expecting me to provide table key to precisely identify the record to be deleted.

Earlier we could write delete itab from wa. Now, we are getting SLIN proposal that DELETE TABLE ITAB FROM WA is correct approach. I change my code accordingly & then get error again that i need to specify table key.

I tried below:

delete lit_ztab1 from <lfs_ztab1> where
  werks = <lfs_ztab1>-werks and
  matnr = <lfs_ztab1>-matnr.

This raises warning message - After being enhanced, the structure <lfs_ztab1> might no longer be transformable to a 
number. It would then no longer be a valid operand.

DELETE table lit_ztab1 FROM <lfs_ztab1> using key ....

I believe i have to use above statement to delete an internal table inside loop from field symbol. But to make this happen, i should be able to declare lit_ztab1 with UNIQUE KEY statement. I am unable to add this with inline declaration for LIT_ZTAB1 table.

Can you please let me know if it's possible to have UNIQUE KEY addition with inline data declaration?

BR,

Aspire

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I think you got false assumptions from some of the threads you have read, it's difficult to tell you what are the rules because they are too much complex. It depends on the exact context. But:

  • Access based on an index is always very quick.
  • Access based on WHERE or WITH KEY is slower than access by index. The worst is when there's a "full table access" (the whole internal table is accessed).

.

Using SELECT ... INTO TABLE @data(itab), as you can see in the ABAP documentation of SELECT, it's impossible to enter any addition to precise the table type. So, stick to what it says: "INTO TABLE @DATA(itab) declares a standard table itab of this row type with an empty table key." Read also the doc of Inline Declarations.

It means that you cannot use an inline declaration, and you must use TYPES to declare the table type mytype1 with its unique key, then use DATA lit_ztab1 TYPE mytype1, then use SELECT ... INTO TABLE lit_ztab1 (no inline declaration as lit_ztab1 is already declared).

.

Last thing, you may see some performance tests using the program RSHOWTIM (you may also run it from a menu in the ABAP editor).

0