Application Development 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: 

Hash tables in combination with data references to the line type.

RyanK
Explorer
0 Kudos
157

I'm having an issue with hash tables - in combination with reference variables.

Consider the following: (Which is part of a class) - it attempts to see if a particular id exists in a table; if not add it; if yes change it.

types: BEGIN OF TY_MEASUREMENT,

perfid TYPE zgz_perf_metric_id,

rtime TYPE zgz_perf_runtime,

execount TYPE zgz_perf_execount,

last_start TYPE timestampl,

END OF TY_MEASUREMENT.

METHOD START.

DATA: ls_measurement TYPE REF TO ty_measurement.

READ TABLE gt_measurements WITH TABLE KEY perfid = i_perfid reference into ls_measurement.

if sy-subrc <> 0.

"Didn't find it.

create data ls_measurement.

ls_measurement->perfid = i_perfid.

insert ls_measurement->* into gt_measurements.

endif.

GET TIME STAMP FIELD ls_measurements-last_start.

ls_measurement->execount = ls_measurement->execount + 1.

ENDMETHOD.

I get compile errors on the insert statement - either "You cannot use explicit index operations on tables with types HASHED TABLE" or "ANY TABLE". It is possible that.

If I don't dereference the type then I get the error LS_MEASUREMENT cannot be converted to the line type of GT_MEASUREMENTS.

I'm not looking to solve this with a combination of references and work ares - want a reference solution.

Thanks!

_Ryan

Moderator message - Moved to the correct forum

Edited by: Rob Burbank on Apr 22, 2010 4:43 PM

1 REPLY 1

MarcinPciak
Active Contributor
0 Kudos
109

I think it might work when you change it for


insert ls_measurement->* into TABLE gt_measurements.

For hashed table a new line here will be inserted according to given table key.

Regards

Marcin