Skip to Content
0
Apr 22, 2010 at 08:28 PM

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

48 Views

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