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 declared hash table

Former Member
0 Likes
1,289

Hi

i have this problem

types : begin of stru,

workcenter type /bi0/oiworkcenter,

end of stru.

data:

tb_work1 type hashed table of stru with key workcenter,

tb_work2 type hashed table of stru with key workcenter.

But this code generate an error.

why?

8 REPLIES 8
Read only

Former Member
0 Likes
1,152

no key specified

Read only

Former Member
0 Likes
1,152

Use Addition Unique key

Data: Itab like Hashed table of stru with Unique key workcenter.

Hashed table has to be declared with unique key.It will only have unique key entries

Regards,

Gurpreet

Read only

0 Likes
1,152

this is my error

You cannot use explicit or implicit index operations on tables with

types "HASHED TABLE" or "ANY TABLE". "TB_WORKGOOD_EP" has the type

"HASHED TABLE".

Read only

0 Likes
1,152

Index operation is not Possible with HASHED table.Only key operation is possible

Check in your code you have used INDEX to access data from hashed internal table.

Ex:

Delete itab index 5. " Not possible with Hashed table.

[ Hashed table|http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm]

Regards,

Gurpreet

Read only

matt
Active Contributor
0 Likes
1,152

When I type in your code, I get the error:

"Use UNIQUE when declaring internal tables of type HSAHS for specification of the key type". Which means exactly what it says. You're not using the correct syntax for defining a table - you should declare the tables as:

TYPES : BEGIN OF stru,
          workcenter TYPE /bi0/oiworkcenter,
END OF stru.

DATA:
  tb_work1 TYPE HASHED TABLE OF stru WITH UNIQUE KEY workcenter,
  tb_work2 TYPE HASHED TABLE OF stru WITH UNIQUE KEY workcenter.

Now, the error you say your getting isn't related to the code you've pasted. Why not paste the code that has that problem.

( As an aside, I wouldn't declare the tables like that anyway - I'd use tb_work1 TYPE HASHED TABLE OF /bi0/oiworkcenter WITH UNIQUE KEY table_line. )

matt

Read only

Former Member
0 Likes
1,152

> Delete itab index 5. " Not possible with Hashed table.

not necessary .... hash is fast.

@Matt

I see no advantage in your recommendation, it is adviable to define a structure which can be used as

a workarea.

Really advisable is the definition in the dictionary.

Siegfried

Read only

matt
Active Contributor
0 Likes
1,152

>

> @Matt

> I see no advantage in your recommendation, it is adviable to define a structure which can be used as

> a workarea.

Clarity, really. A structure with one element seems to me to be an unnecessary complication. For example:

FIELD-SYMBOLS: <l_workcenter> TYPE /bi0/oiworkcenter.

LOOP AT th_workcenter ASSIGNING <l_workcenter>.
  " Do something with <l_workcenter>.

seems to me more semantically obvious than:

FIELD-SYMBOLS: <ls_workcenter> TYPE workcenter_structure.

LOOP AT th_workcenter ASSIGNING <ls_workcenter>.
  " Do something with <ls_workcenter>-workcenter.

Read only

Former Member
0 Likes
1,152
  • You can use the following declaration.

  • Here you have an advantage of using stru as work area.

DATA: BEGIN OF stru,
        workcenter TYPE /bi0/oiworkcenter,
      END OF stru,
      tb_work1 TYPE HASHED TABLE OF stru WITH UNIQUE KEY workcenter,
      tb_work2 TYPE HASHED TABLE OF stru WITH UNIQUE KEY workcenter.