2015 Jan 28 12:51 PM
Hi all.
I am trying to do loop inside a loop with field symbols to add some values checking same Profit center. I am doing loops on a BPC model data
FS : <ct_data> type standard table, <ls_data> type any.
e.g.
assign component of ls_profit_center of structure <ls_data> to <Profit_center>.
assign component of ls_profit_center of structure <ls_data1> to <Profit_center1>.
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1> where <Profit_center> EQ <ls_data>-<profit_center>
logic...
endloop.
endloop.
It says Loop where " the row type of the table must be statically defined...
This helps me as I can reduce many number of loops...
Thanks
Krishna
Hi all.
I am trying to do loop inside a loop with field symbols to add some values checking same Profit center. I am doing loops on a BPC model data
FS : <ct_data> type standard table, <ls_data> type any.
e.g.
assign component of ls_profit_center of structure <ls_data> to <Profit_center>.
assign component of ls_profit_center of structure <ls_data1> to <Profit_center1>.
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1> where <Profit_center> EQ <ls_data>-<profit_center>
logic...
endloop.
endloop.
It says Loop where " the row type of the table must be statically defined...
This helps me as I can reduce many number of loops...
Thanks
Krishna
2015 Jan 28 1:03 PM
you have defined the field symbols as TYPE any,
you need to give the exact data type.
for e.g. FIELD-SYMBOLS: <ct_data> type table of mara,
<ls_data> like line of <ct_data>.
2015 Jan 28 1:07 PM
Hi Krishna,
Replace the WHERE statement with IF statement.:
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1>.
IF <Profit_center> EQ <ls_data>-<profit_center>
logic...
ENDIF.
endloop.
endloop.
2015 Jan 28 1:16 PM
Hi Krishna,
I think your where condition need correction.
Old code:
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1> where <Profit_center> EQ <ls_data>-<profit_center>
logic...
endloop.
endloop.
New Code:
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1> where Profit_center EQ <ls_data>-profit_center
logic...
endloop.
endloop.
By the way this is not parallel cursor method. Parallel cursor will have second loop with index and not with where condition.
it should be like,
LOOP AT <ct_data> ASSIGNING <ls_data>.
lv_index = sy-tabix.
LOOP AT <ct_data> ASSIGNING <ls_data1> FROM lv_index.
IF <ct_data>-profit_center EQ <ls_data>-profit_center
<....your code logic...>
ELSE.
EXIT.
ENDIF.
ENDLOOP.
Let me know if I am right.
Regards,
Sid
2015 Jan 28 2:18 PM
Hello guys, thanks for the interest.
John,
I know using if condition is a possibility but wanted to avoid that. If I can get the where condition, i will have less loops so faster performance.
Sid,
I meant loop inside loop, I am aware parallel cursor needs index in 2nd loop.
loop at <ct_data> into <ls_data>.
loop at <ct_data> assigning <ls_data1> where Profit_center EQ <ls_data>-profit_center
this statement also gives the same error message..
Syntax accepts where clause..but not sure what it meant by statically defined...
Sharath,
am using this in getting data from BPC model, backend its a cube data in BW that I am reading using an interface method if_ujo_query~run_rsdri_query and it has returning parameter as Type Standard Table.
Therefore it takes the structure dynamically...
Any other inputs please....
2015 Jan 28 2:47 PM
If I can get the where condition, i will have less loops so faster performance.
I don't know what you mean by this. Fyi, LOOP...WHERE does a full table scan if the appropriate keys are not used.
I am reading using an interface method if_ujo_query~run_rsdri_query and it has returning parameter as Type Standard Table
Afaik you cannot type RETURNING parameters generically. Can you please provide additional details about your code, so that it'll be easier to analyse.
2015 Jan 28 3:12 PM
Hi,
1. there is no way to use where clause with dynamic structure!
If you don't know the structure at design-time, you can't use where.
2. Think again on how (and why) you use field-symbols.
assign component of ls_profit_center of structure <ls_data> to <Profit_center>.
You cannot use this statement. You must either provide the component-name (literally or in an upper-case variable) or the number in the structure, for the assign to take effect.
3. When you successfully managed to assign the desired fields to your field-symbols, you're ready to proceed. But still whithout where clause
data: ld_ix type i.
loop at <ct_data> into <ls_data>.
ld_ix = sy-tabix + 1.
* Assuming previously processed entries are of no further interest
loop at <ct_data> assigning <ls_data1> from ld_ix.
check <profit_center1> EQ <profit_center>.
logic...
endloop.
endloop.
Alternatively, read about find in table and consider, whether you can benefit from result_tab.
This would allow you to loop on result_tab (containing only matching lines) and then do a
read_table <ct_data> assigning <ls_data1> index result_wa-line.
Best regards - Jörg
2015 Jan 29 12:09 PM
Are you looking for logic like below? Here where clause in loop is dynamic..
DATA lt_t100 TYPE STANDARD TABLE OF t100.
DATA l_string TYPE string.
FIELD-SYMBOLS <ls_work> TYPE any.
FIELD-SYMBOLS <ls_work2> TYPE any.
SELECT *
INTO TABLE lt_t100
FROM t100
UP TO 10 ROWS.
LOOP AT lt_t100 ASSIGNING <ls_work>.
l_string = 'MSGNR = <LS_WORK>-MSGNR'.
LOOP AT lt_t100 ASSIGNING <ls_work2> WHERE (l_string).
* Some logic
ENDLOOP.
ENDLOOP.
2015 Feb 12 9:03 AM
Sorry for coming back on this after long time..
Just one thing, this Dynamic where condition while using field symbols is allowed only after a certain patch level I believe.
I am using BW 7.0 with SP 7.0 and when I try this ..it says it should be statically defined or similar to that but does not allow me to use dynamic where condition.
LOOP AT lt_t100 ASSIGNING <ls_work>.
l_string = 'MSGNR = <LS_WORK>-MSGNR'.
LOOP AT lt_t100 ASSIGNING <ls_work2> WHERE
(l_string).
* Some logic
ENDLOOP.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |