2008 Jul 31 6:33 AM
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 ?
2008 Jul 31 9:18 AM
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
2008 Jul 31 7:00 AM
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?
2008 Jul 31 7:11 AM
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
2008 Jul 31 7:19 AM
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.
2008 Jul 31 7:33 AM
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
2008 Jul 31 8:04 AM
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) ?
2008 Jul 31 8:21 AM
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
2008 Jul 31 9:18 AM
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
2008 Jul 31 9:22 AM
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
2008 Jul 31 9:27 AM
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.