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

Table with objects

Former Member
0 Likes
954

i have internla table

my_belnr type ref to table of <other_calss> .

wa_belnr type ref to <other_class>.

Now after i have different instances of belnr's appened in my_belnr.

How is it possible to acess this my_belnr table with key?

I have a requirement that i haev to

loop at my_belnr into wa_belnr with key : ....

Can any one explain me if it possible at all ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
927


method CONSTRUCTOR.

DATA: ls_record type /evuit/exch_vbel.
DATA: ls_beleg type ref to /evuit/exch_prd_vert_nn_belgv2.

   my_header = i_header.
	
	LOOP AT i_records INTO ls_Record.
	   ls_beleg = me->FACTORY_BELEG( i_record  = l_record ).
	   APPEND ls_beleg TO my_belege.
	ENDLOOP.
endmethod.


method send.

DATA: Ls_beleg type ref to /evuit/exch_prd_vert_nn_belgv2.

read table my_beleg into ls_beleg with key u_status = co_avis .


endmethod.

Edited by: Trivenn Mudivar on Jul 31, 2008 10:20 AM

Edited by: Trivenn Mudivar on Jul 31, 2008 10:21 AM

9 REPLIES 9
Read only

Former Member
0 Likes
927

Hi!

I didn't get your question. If you are appending instances in your internal table, then what is the need of key in that table?

Read only

former_member69765
Contributor
0 Likes
927

I believe BELNR is some kind of account number ... so it must be unique identifier...

(Basically there should be a unique identifierr.. lets say it is ACC_NO )

So try out this ..

loop at my_belnr into wa_belnr where object->acc_no = <your value>

Here .. object is the field in the internal table where the object ref is stored ..

and Assumption is that ACC_NO is public ... so object->acc_no can be accessed..

This works..

Cheeres

Read only

Former Member
0 Likes
927

Tm,

have a requirement that i haev to

loop at my_belnr into wa_belnr with key : ....

there is no such syntex we have in SAP.

i think you need to loop then use read for reading my_belnr.

Read only

uwe_schieferstein
Active Contributor
0 Likes
927

Hello Trivenn

First a remark to your coding sample:


my_belnr type ref to table of <other_calss> .  " Syntax incorrect -> guess you mean a table type of references
wa_belnr type ref to <other_class>.

If my assumption is correct (see comment above) then you can access your instances quite easily:


" Assumpting: the instances collected in the itab have a public key attribute BELNR.

" Recommendation: your naming conventions are a mess -> use better ones:

DATA: lt_account     TYPE <table type with line type: REF TO <account class>,
          lo_account     TYPE REF TO <account class>.

" LOOP statement:
LOOP AT lt_account INTO lo_account
                               WHERE ( table_line->belnr = <...> ).
...
ENDLOOP.

" READ statement:
READ TABLE lt_account INTO lo_account
          WITH KEY table_line->belnr = <...>.
...

Regards

Uwe

Read only

Former Member
0 Likes
927

Herr Schieferstein,

Vielen Danke.

I apologise for not putting the code in the question properly and not correct question either. i wanted to generalize the question.

well my requirement is that i have to read the table my_belnr which is attribute of a class.

Can i read it like this

read table lt_account into lo_account with key (belnr) ?

Read only

0 Likes
927

Hello Trivenn

No need to apologize for anything.

However, I still do not fully understand the typing and contents of your itab my_belnr.

Perhaps you can paste your coding. Then it should become clear.

Regards

Uwe

Read only

Former Member
0 Likes
928


method CONSTRUCTOR.

DATA: ls_record type /evuit/exch_vbel.
DATA: ls_beleg type ref to /evuit/exch_prd_vert_nn_belgv2.

   my_header = i_header.
	
	LOOP AT i_records INTO ls_Record.
	   ls_beleg = me->FACTORY_BELEG( i_record  = l_record ).
	   APPEND ls_beleg TO my_belege.
	ENDLOOP.
endmethod.


method send.

DATA: Ls_beleg type ref to /evuit/exch_prd_vert_nn_belgv2.

read table my_beleg into ls_beleg with key u_status = co_avis .


endmethod.

Edited by: Trivenn Mudivar on Jul 31, 2008 10:20 AM

Edited by: Trivenn Mudivar on Jul 31, 2008 10:21 AM

Read only

0 Likes
927

Hello Trivenn

The definition of my_belege is still missing yet it should be clear how it looks like.


method send.

" NOTE: Assuming that U_STATUS is a PUBLIC instance attribute you should be able to write:
 
DATA: Ls_beleg type ref to /evuit/exch_prd_vert_nn_belgv2.
<span style="color:red">
  READ TABLE my_beleg INTO ls_beleg
    WITH KEY table_line->u_status = co_avis.
</span>
 
endmethod.

Regards

Uwe

Read only

Former Member
0 Likes
927

Dear Uwe,

Now i understand that my_beleg must have public attribute u_status. and that this status must be filled by the constructor.

Thank you very much.

Regards.