2007 Jul 25 1:20 PM
Hi friends,
i have a problem with the following:
i have an internal table <dyn_table> created dynamically with a column 'aaa'.
Now, in this column are groupid's are stored like
2
2
3
3
Now what i want to do is to loop at <dyn_table> but only within the same group, so i would loop where 'aaa' = 2. After that where 'aaa' = 3.
How to achieve that with dynamic internal tables ?
Thank you, i will be fast with assigning points!
Clemens
2007 Jul 25 3:18 PM
Hi clemens,
try something like this
field-symbols : <FS> type any.
loop at <ITAB> ASSIGNING <WA_ITAB>.
DO.
ASSIGN COMPONENT 'AAA' OF STRUCTURE <WA_ITAB> TO <FS>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
CASE <FS>.
WHEN '2'.
* do something
WHEN '3'.
* do something
ENDCASE.
ENDDO.
ENDLOOP.
Hi friends,
i have a problem with the following:
i have an internal table <dyn_table> created dynamically with a column 'aaa'.
Now, in this column are groupid's are stored like
2
2
3
3
Now what i want to do is to loop at <dyn_table> but only within the same group, so i would loop where 'aaa' = 2. After that where 'aaa' = 3.
How to achieve that with dynamic internal tables ?
Thank you, i will be fast with assigning points!
Clemens
2007 Jul 25 1:25 PM
Hi
Check this
Dynamic internal table is internal table that we create on the fly with flexible column numbers.
For sample code, please look at this code tutorial. Hopefully it can help you
Check this link:
http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
<b>Reward points for useful Answers</b>
Regards
Anji
2007 Jul 25 1:25 PM
check below code....
DATA: l_cnt(2) TYPE n,
l_cnt1(3) TYPE n,
l_nam(12),
l_con(18) TYPE c,
l_con1(18) TYPE c,
lf_mat TYPE matnr.
SORT it_bom_expl BY bom_comp bom_mat level.
CLEAR: l_cnt1, <fs_dyn_wa>.
Looping the component internal table
LOOP AT it_bom_expl INTO gf_it_bom_expl.
CLEAR: l_cnt1.
AT NEW bom_comp.
CLEAR: l_cnt, <fs_dyn_wa>, lf_mat.
For every new bom component the material data is moved to
temp material table which will be used for assigning the levels
checking the count
it_mat_temp[] = it_mat[].
Component data is been assigned to the field symbol which is checked
against the field of dynamic internal table and the value of the
component number is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa> TO
<fs_check>.
<fs_check> = gf_it_bom_expl-bom_comp.
ENDAT.
AT NEW bom_mat.
CLEAR l_con.
ENDAT.
lf_mat = gf_it_bom_expl-bom_mat.
Looping the temp internal table and looping the dynamic internal table
*by reading line by line into workarea, the materialxxn is been assigned
to field symbol which will be checked and used.
LOOP AT it_mat_temp.
l_nam = c_mat.
l_cnt1 = l_cnt1 + 1.
CONCATENATE l_nam l_cnt1 INTO l_nam.
LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
ENDLOOP.
IF <fs_xy> = lf_mat.
CLEAR lf_mat.
l_con1 = l_con.
ENDIF.
Checking whether the material exists for a component and if so it is
been assigned to the field symbol which is checked against the field
of dynamic internal table and the level of the component number
against material is been passed to the dynamic internal table field
value.
IF <fs_xy> = gf_it_bom_expl-bom_mat.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
CLEAR l_con.
MOVE gf_it_bom_expl-level TO l_con.
CONCATENATE c_val_l l_con INTO l_con.
CONDENSE l_con NO-GAPS.
IF l_con1 NE space.
CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
CLEAR l_con1.
l_cnt = l_cnt - 1.
ENDIF.
<fs_check> = l_con.
l_cnt = l_cnt + 1.
ENDIF.
ENDLOOP.
AT END OF bom_comp.
At end of every new bom component the count is moved to the field
symbol which is checked against the field of dynamic internal table
and the count is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
<fs_check> = l_cnt.
INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
ENDAT.
ENDLOOP.
2007 Jul 25 3:12 PM
Hi Ramesh,
thank you, but i do not really get the point how to solve the issue out of your sample.
the lack really is, that i cannot use where clause in dynamic internal table - so how could i solve the problem ?
clemens
2007 Jul 25 3:18 PM
Hi clemens,
try something like this
field-symbols : <FS> type any.
loop at <ITAB> ASSIGNING <WA_ITAB>.
DO.
ASSIGN COMPONENT 'AAA' OF STRUCTURE <WA_ITAB> TO <FS>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
CASE <FS>.
WHEN '2'.
* do something
WHEN '3'.
* do something
ENDCASE.
ENDDO.
ENDLOOP.
2007 Jul 26 9:31 AM
Hi, what i have is:
READ TABLE <dyn_table> INTO <dyn_wa> INDEX 1.
ASSIGN COMPONENT 'CLSID' OF STRUCTURE <dyn_wa> TO <dyn_field_g>.
grpid = <dyn_field_g>.
ze = 1.
LOOP AT <dyn_table> INTO <dyn_wa> FROM ze.
ASSIGN COMPONENT 'CLSID' OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF <dyn_field> = grpid.
WRITE:/ <dyn_field>.
WRITE: grpid.
ze = ze + 1.
ELSE.
* ze = ze - 1.
READ TABLE <dyn_table> INTO <dyn_wa> INDEX ze.
ASSIGN COMPONENT 'CLSID' OF STRUCTURE <dyn_wa> TO <dyn_field_g>.
grpid = <dyn_field_g>.
ENDIF.
ENDLOOP.What i want to achieve is, that when the CLSID changes, it does loop only within the rows that have same CLSID. If it is finished with the loop, it should go to the next row ( which has the different CLSID ) and loop within this group.
Where am I wrong ?
2007 Jul 26 11:03 AM
SORT <dyn_table> BY (filename). <------dynamic.
LOOP AT <dyn_table> INTO <dyn_wa>.
ASSIGN COMPONENT (filename) OF <dyn_wa> TO <dyn_field>.
IF <dyn_field> IS ASSIGNED.
IF <dyn_field> EQ <last_val> OR SY-INDEX EQ 1.
WRITE:/ <dyn_field>.
ESLE.
WRITE:/ 'New group'
WRITE:/ <dyn_field>.
ENDIF.
ENDIF.
<last_val> = <dyn_field>
ENDLOOP.
Regards,
A.Singh
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |