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

Access object attribute in table

Former Member
0 Likes
1,359

Greetings-

What is the syntax used to access an attribute of an object that is itself embedded within a cell of a table row? I normally use field symbols to access complex structures, but that doesn't seem to work here (or I'm not doing it right!)

Thanks in advance!

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
949

Do you mean something like this?



report zrich_0003.


*---------------------------------------------------------------------*
*       CLASS lcl_temp DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_temp definition.

  public section.

    data: it001 type table of t001.

    methods: constructor.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_temp IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_temp implementation.

  method constructor.

    select * into table it001 from t001.

  endmethod.

endclass.

data: a_object      type ref to lcl_temp.
data: a_object_list type table of ref to lcl_temp.
data: xt001 type t001.

start-of-selection.

* Create the object and put it in a internal table
create object a_object.
append a_object to a_object_list.

* Read the internal table in the first row and get the object
read table a_object_list into a_object index 1.


* Access the table from the object to write it out.
loop at a_object->it001 into xt001.
  write:/ xt001-bukrs, xt001-butxt.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
949

Rich-

Thanks for your reply.

You're headed the right direction, but I need to add a couple of items (that should have been included in my original post!). I'm attempting to access the object's content in the context of a badi. Given this, can I create a class to encapsulate my table as you provided in your example?

Here's the specifics:

Implementation:

Z_MY_IMPLEMENTATION

Interface Name:

IF_EX_HRPAD00INFTYDB

Method:

UPDATE_DB

Importing Parameter:

OPERATION_TAB Type HRAD_DBOPER_LOG_TAB

Structure of HRAD_DBOPER_LOG_TAB

>>Line Type: HRAD_DBOPER_LOG

>>one component of HRAD_DBOPER_LOG = NEW_PNNNN TYPE DATA (at runtime this gets populated with an object)

>>I need to access Field INFTY

I don't like pasting all of my code in as I feel like a kid who is getting his friends to do his homework, but I (obviously) couldn't explain the situation generically without causing confusion.

Message was edited by: Dwight Jones

Read only

0 Likes
949

Can you please post the code where you are trying to access via field-symbols?

Regards,

Rich Heilman

Read only

0 Likes
949

FIELD-SYMBOLS <GENERAL_FIELD> TYPE string.

FIELD-SYMBOLS <GENERAL_STRUC> TYPE HRPAD_DBOPER_LOG.

FIELD-SYMBOLS <GENERAL_SUBSTRUC> TYPE ANY.

FIELD-SYMBOLS <GENERAL_VALUE> TYPE string.

READ TABLE operation_tab INTO ls_operation_tab INDEX 1.

ASSIGN ls_operation_tab-new_pnnnn TO <GENERAL_SUBSTRUC>.

l_struc_type = 'INFTY'.

ASSIGN l_struc_type TO <GENERAL_FIELD>.

ASSIGN COMPONENT <GENERAL_FIELD> OF

STRUCTURE <GENERAL_SUBSTRUC> TO

<GENERAL_VALUE>.

l_infotype = <GENERAL_VALUE>.

-


I get a short dump b/c <GENERAL_VALUE> is not getting set.

Read only

0 Likes
949

Please change as the following.



FIELD-SYMBOLS <GENERAL_FIELD> TYPE string.
FIELD-SYMBOLS <GENERAL_STRUC> TYPE HRPAD_DBOPER_LOG.
FIELD-SYMBOLS <GENERAL_SUBSTRUC> TYPE ANY.
<b>*FIELD-SYMBOLS <GENERAL_VALUE> TYPE string.
FIELD-SYMBOLS <GENERAL_VALUE> .</b>

READ TABLE operation_tab INTO ls_operation_tab INDEX 1.

ASSIGN ls_operation_tab-new_pnnnn TO <GENERAL_SUBSTRUC>.

l_struc_type = 'INFTY'.

<b>*ASSIGN l_struc_type TO <GENERAL_FIELD>.</b>
ASSIGN COMPONENT <b>l_struc_type</b> OF
                  STRUCTURE <GENERAL_SUBSTRUC> TO
                             <GENERAL_VALUE>.

l_infotype = <GENERAL_VALUE>.



I hope this works for ya.

Regards,

Rich Heilman

Read only

0 Likes
949

Thanks again Rich. I'm still getting a "Field symbol has not yet been assigned" short dump error.

One question--did you intend this?

FIELD-SYMBOLS <GENERAL_VALUE> TYPE string.

FIELD-SYMBOLS <GENERAL_VALUE> .

That gives a compile error. I tried with <GENERAL_VALUE> TYPE ANY without success.

I think the error is arising because <GENERAL_SUBSTRUC> is a data object rather than a table. What gets passed into GENERAL_SUBSTRUC looks something like . INFTY is the second component. I know that there must be an easy way to get at the component, but I can't figure out the syntax.

The structure p0006 is getting passed into the new_pnnnn if that helps.

Read only

0 Likes
949

Oh sorry, I meant to comment the first.

*FIELD-SYMBOLS <GENERAL_VALUE> TYPE string.
FIELD-SYMBOLS <GENERAL_VALUE> .

Try that.

Regards,

RIch Heilman