Application Development 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: 

Where clause on loop at any_itab assign <FS>

ricky_shaw
Contributor
0 Kudos
4,420

Dear Experts,

I want to use loop at where clause on a table type declared as ANY and a field Symbol<FS>.

At run time, in this table there is a field called 'SELECTED' which holds the value of selected rows from
ouput of ALV GRID.

I am writing this code inside an external subroutine.

form user_release_coll_so  using  p_ucomm like sy-ucomm
                                                       p_selfield type slis_selfield
                                                      it_selected_objects type any table.

data: <fs1> type any,
  <lv_sel> type any.

loop at it_selected_objects assigning <FS1>.   --> how to write where clause here?


assign component 'SELECTED' of structure <fs1> to <lv_sel>.

if <lv_sel> = 'X'.

endif.

endloop.

This is working fine but i need to loop at EVERY record in the loop.


Can some one tell me how can i use where clause in the above loop.

Thanks

12 REPLIES 12

Former Member
0 Kudos
740

I'm assuming your difficulty is in determining the field names you want to filter on because it's type ANY TABLE?

I suppose you could use the RTTS classes to dynamically determine the structure, and then move it to a data object with the proper type.

0 Kudos
740

Hi Jorg, Can you pls give me an example of how to use the RTTS classes?

Kartik2
Contributor
0 Kudos
740

Hi,

For an untyped field symbol you cannot give where clause, because the system does not really know if the feilds mentioned in where clause are really present in the structure of field symbol. Your approach is correct. That is to use an if condition inside the loop. And as you said, all the records should get processed.

Regards,

Kartik

0 Kudos
740

Kartik, Sounds you are right.

pushkar_dhale
Participant
0 Kudos
740

Hi Ricky,

You can do like this

data: <fs1> type any,
     <lv_sel> type any.

loop at it_selected_objects into wa_selected_objects where SELECTED = 'X'.

*Then

assign wa_selected_objects TO <FS1>.  

*Your code here

endif.

endloop.

Regards,

Pushkar Dhale.

0 Kudos
740

Hello Pushkar, KATRICE, AMARINDER< AMIT KUMAR : Did you try this yourself first?

0 Kudos
740

I tried ...it is working....it takes hardly 2 mins to try....

0 Kudos
740

Hello,

Ok.

Its throwing an error "the line type of the table must be statically defined" when i use where clause:

Eg: Here selected is a field in it_selected_objects.

loop at it_selected_objects assigning <wa_sel_obj> where selected = 'X' .

Any suggestions?

0 Kudos
740

yes, you're right. You cannot use a where clause in a dynamically typed table. That is to say, not in the version we're running at my company. Perhaps later versions might allow it. It will throw that error because it_selected_objects is defined as any table. I tried with the runtime type classes to cast it into a properly typed but dynamic object (type ref to data) and it throws the same error. Your best bet will probably be to do the checking in the loop.

What exactly are you trying to accomplish? Is this an event in an ALV or something? There might be better way. Class CL_SALV_TABLE has events for that, have a look at demo program SALV_DEMO_TABLE_SELECTIONS

Former Member
0 Kudos
740

Hello Ricky,

Following is the code for your reference

    FIELD-SYMBOLS  <lfs_users>  TYPE any.

     LOOP AT lt_data ASSIGNING <lfs_smusers> WHERE FIELDNAME = 'X'.

      IF <lfs_smusers> is assigned

     * data manipulations.

      endif.

     ENDLOOP.

Katirce

Former Member
0 Kudos
740

you can use dynamic where condition

something like below

data: <fs1> type any,
  <lv_sel> type any.

data: lv_where type string.

lv_where = 'SELECTED = X'.

loop at it_selected_objects assigning <FS1> WHERE (lv_where).   --> how to write where clause here?

endoop.

Former Member
0 Kudos
740

Hi Ricky ,

First Please refer to the below links ....

http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb387a358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3605358411d1829f0000e829fbfe/content.htm

Read both the links and then You can use this code e.g :-

    Field-symbols  <a>  TYPE any.

     LOOP AT i_tab ASSIGNING <a> WHERE field = 'X'.

      IF <a> is assigned

       your code functionality.

      endif.

     ENDLOOP.

Hope this will help .....

Regards,

AKS