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

Howto Loop at from variable type any table

sistemes_emaya
Explorer
0 Likes
8,901

Hi,

I'm trying to use a BAdI (BADI_EAM_RIQMEL20_FCODE_CUS1) which has an input parameter called IT_SELECTED_OBJECTS which declaration is TYPE ANY TABLE, the question is simple how can I do a "loop at IT_SELECTED_OBJECTS".

I tried the following code:

Input parameters of method EXECUTE_FUNCTION_CODE

IV_FUNCTION_CODE	TYPE SYUCOMM OPTIONAL	Funktionscode, der PAI ausgelöst hat
IV_ACTIVITY_TYPE	TYPE AKTYP  DEFAULT 'A'	Aktivitätstyp in der Transaktion
IT_SELECTED_OBJECTS	TYPE ANY TABLE	Selektierte Objekte

Method Code

DATA: T_OBJ type ZCAU_T_1206_MAPA,
        wa_obj type ZCAU_1206_MAPA,
        w_dref TYPE REF TO data.

*      wa_selected_objets like line of IT_SELECTED_OBJECTS.
  FIELD-SYMBOLS: <t_itab> TYPE ANY.

  CREATE DATA w_dref like IT_SELECTED_OBJECTS.

  ASSIGN w_dref TO <t_itab>.

  loop at it_selected_objects assigning <t_itab>.

    wa_obj-tipo          = 'AVISO'.
    wa_obj-numero        = <t_itab>-qmnum.
    wa_obj-clase           = <t_itab>-qmmart.
    wa_obj-calle            = <t_itab>-street.
    wa_obj-ciudad         = <t_itab>-city1.
    wa_obj-codigo_postal = <t_itab>-post_code1.

    append wa_obj to t_obj.

  endloop.

The compiler throws the following error:

The data object "" has no structure and therefore no component

called "QMNUM".

Any help??

Thanks.

Juan.

Edited by: Sistemes Emaya on Sep 7, 2010 11:23 AM

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
3,100

The answer is simple too. <t_itab> has static type ANY but dynamic type as like line of IT_SELECTED_OBJECTS .

Therefore statically syntax checker doesn't recognize any components of <t_itab> but dynamically it does (components of your table). So the acces to these components mustn't also be static but must be dynamic


"GMNUM statically unknow 
wa_obj-numero        = <t_itab>-qmnum.

"...but dynamically known
field-symbols <comp> type any.

assign component 'GMNUM' of structure <t_itab> to <comp>. "<comp> if our field now
wa_obj-numero  = <comp>.

Regards

Marcin

5 REPLIES 5
Read only

MarcinPciak
Active Contributor
3,101

The answer is simple too. <t_itab> has static type ANY but dynamic type as like line of IT_SELECTED_OBJECTS .

Therefore statically syntax checker doesn't recognize any components of <t_itab> but dynamically it does (components of your table). So the acces to these components mustn't also be static but must be dynamic


"GMNUM statically unknow 
wa_obj-numero        = <t_itab>-qmnum.

"...but dynamically known
field-symbols <comp> type any.

assign component 'GMNUM' of structure <t_itab> to <comp>. "<comp> if our field now
wa_obj-numero  = <comp>.

Regards

Marcin

Read only

0 Likes
3,100

Wooooowww!!!!

thanks a lot!!!!

It works perfect!!!!

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,100

Hello Juan,

No need to create data reference w_dref you can directly use the generic field-symbol directly.

FIELD-SYMBOLS: 
<fieldval> TYPE ANY,
<t_itab> TYPE ANY.

loop at it_selected_objects assigning <t_itab>.
" Why & how to use ASSIGN COMPONENT has been elaborated by Marcin
endloop.

BR,

Suhas

Read only

0 Likes
3,100

Ok, thanks, I'll fix it.

Read only

0 Likes
3,100

Hello friend from the internet!

Maybe you are trying to find this?

DATA t_table TYPE "****" .
PERFORM loop_any_table USING t_table.


FORM loop_any_table USING my_table TYPE TABLE.

  LOOP AT my_table ASSIGNING FIELD-SYMBOL(<l_line>).
    BREAK-POINT.
  ENDLOOP.

ENDFORM