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: 

its very urgent ... regarding dynamic internal table

selvi1
Explorer
0 Kudos
62

hi all,

can we sort the dynamic internal table by a field.

how to do this,

please send me the sample code for it

its very urgent.

thanks and regards,

selvi

2 REPLIES 2

Former Member
0 Kudos
40

hi this is the code.

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

Sample 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.

with regards,

Hema.

pls give points if helpful.

Former Member
0 Kudos
40

hi selvi

u can use SORT itself. it is very simple logic.

SORT itab BY FIELD1 /* this is would sort itab by default in ascending order*/

for sorting in descending order , u hav to mentio explicitly.

SORT itab BY FIELD1 DESCENDING

REWARD IF USEFUL

thanks and regards

suma sailaja pvn