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

populating values to internal table created dynamically

Former Member
0 Likes
613

Hi,

I am creating an internal table(it1) dynamically and assigned it to a field symbol. now i want to upload values

which are present in a field of another internal table being populated from a Funct Module.Could you tell me

how to assign those values across the fields of field symbol?

**************

loop at itab_char.

LS_ALV_CAT-FIELDNAME = itab_char-charact.

append LS_ALV_CAT to I_ALV_CAT.

endloop.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = I_ALV_CAT

IMPORTING

EP_TABLE = D_REF.

ASSIGN D_REF->* TO <F_FS>.

**************

(Above my int tab is generated and now stored in <f_FS>)

**************

loop at itab into w_lifnr.

CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'

EXPORTING

CLASS = p_cname

CLASSTYPE = w_ctype

OBJECT = w_lifnr

TABLES

T_CLASS = t_class

T_OBJECTDATA = t_objectdata

*******************

w-lifnr is vendor number. and here we are populating t_objectdata with that vendor related datas. now i want to pass t_objectdata-ausp1 values for each vendor across the fields in <F_FS>.

FIELD-SYMBOLS : <F_FS> TYPE TABLE.

Please refer me the solution to this problem.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
562

Check below code and try to add in ur code....

IF NOT it_bom_expl[] IS INITIAL.

  • The material number data varies from run to run. For this purpose

  • the data is been used to build dynamic internal table which stores the

  • material number data along the x-axis

PERFORM build_matnr_table.

  • The material numbers data which is stored in the temp internal table

  • is been assigned to the dynamic internal table created along the

  • x-axis for the materials

PERFORM assign_matnr_val_fields.

  • The component data which is stored in the internal table needs to be

  • moved to the dynamic internal table

PERFORM move_bom_data_to_matnr_table.

&----


*& Form build_matnr_table

&----


  • Using the material number data the dynamic internal tables are been

  • built which holds the material number data along x-axis. Here the

  • first 3 columns are always constant which are Components-List,

  • Description, Count. From 4th column it depends on number of materials

----


FORM build_matnr_table .

DATA: l_val(3) TYPE n,

lf_mat(18) TYPE c.

  • Moving the Components-List details to the internal table 1st column

  • which will be used for creation of dynamic internal table

CLEAR gf_xfc.

gf_xfc-fieldname = text-t03.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 18.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

CLEAR gf_xfc.

  • Moving the Description details to the internal table 2nd column

  • which will be used for creation of dynamic internal table

gf_xfc-fieldname = text-t04.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 40.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ipc.

CLEAR gf_xfc.

  • Moving the Count details to the internal table 3rd column which will

  • be used for creation of dynamic internal table

gf_xfc-fieldname = text-t05.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 5.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

  • Moving the Material numbers are moved to the internal table from 4th

  • column onwards till all the material numbers are moved to the columns

  • which will be used for creation of dynamic internal table. Here

  • columns will be reffered to as Material001 ..... Materialxxn

LOOP AT it_mat.

CLEAR gf_xfc.

l_val = l_val + 1.

CONCATENATE text-t06 l_val INTO lf_mat.

gf_xfc-fieldname = lf_mat.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 18.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

ENDLOOP.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ifc

IMPORTING

ep_table = gf_table.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table->* TO <fs_dyn_table>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line LIKE LINE OF <fs_dyn_table>.

ASSIGN gf_line->* TO <fs_dyn_wa>.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ipc

IMPORTING

ep_table = gf_table1.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table1->* TO <fs_dyn_table1>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line1 LIKE LINE OF <fs_dyn_table1>.

ASSIGN gf_line1->* TO <fs_dyn_wa1>.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ifc

IMPORTING

ep_table = gf_table2.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table2->* TO <fs_dyn_table2>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line2 LIKE LINE OF <fs_dyn_table2>.

ASSIGN gf_line2->* TO <fs_dyn_wa2>.

ENDFORM. " build_matnr_table

&----


*& Form assign_matnr_val_fields

&----


  • The material numbers data stored in the temp internal table needs to

  • be assigned to the dynamic internal table along x-axis as the first

  • record. The temp internal table is been looped and using the field

  • symbol concept the data is moved to the dynamic internal table

----


FORM assign_matnr_val_fields .

DATA: l_cnt(3) TYPE n,

l_nam(12),

g_total(3) TYPE n.

DESCRIBE TABLE it_mat LINES g_total.

CLEAR l_cnt.

  • Looping the temp internal table and concatenating material as

  • material001 and the same is been checked against the dynamic

  • internal table and the material number value is moved to the

  • internal table. Finally, the data is been appened as first record.

LOOP AT it_mat.

l_nam = c_mat.

l_cnt = l_cnt + 1.

CONCATENATE l_nam l_cnt INTO l_nam.

  • Material which is in form Materialxxn is been assigned to the field

  • symbol which is checked against the field of dynamic internal table

  • and the value of the Material Number is been passed to the dynamic

  • internal table field value.

  • After all materials are been assigned the record is been appended

  • to the dynamic internal table.

ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_field>.

<fs_field> = it_mat-matnr.

IF l_cnt = g_total.

INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.

ENDIF.

ENDLOOP.

  • Looping the temp internal table and concatenating material as

  • material001 and the same is been checked against the dynamic

  • internal table and the material number value is moved to the

  • internal table. Finally, the data is been appened as first record.

  • This is been used for downloading of data to excel sheet as it

  • contains additional field which is Description field.

CLEAR l_cnt.

LOOP AT it_mat.

l_nam = c_mat.

l_cnt = l_cnt + 1.

CONCATENATE l_nam l_cnt INTO l_nam.

  • Material which is in form Materialxxn is been assigned to the field

  • symbol which is checked against the field of dynamic internal table

  • and the value of the Material Number is been passed to the dynamic

  • internal table field value.

  • After all materials are been assigned the record is been appended

  • to the dynamic internal table.

ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa1> TO <fs_field>.

<fs_field> = it_mat-matnr.

IF l_cnt = g_total.

INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.

ENDIF.

ENDLOOP.

  • The contents of one internal table is passed on to other internal

  • table for use while moving the component data for count purposes.

<fs_dyn_table2>[] = <fs_dyn_table>[].

ENDFORM. " assign_matnr_val_fields

&----


*& Form move_bom_data_to_matnr_table

&----


  • The component data is been appended to the dynamic internal table

  • The component is checked against a material and if exists the corresp-

  • onding level is been appended to the record

  • The total count is derived as the in how many materials the component

  • exists

----


FORM move_bom_data_to_matnr_table .

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.

  • Looping the component internal table. This is used for the additional

  • Description field which is shown in the excel sheet

LOOP AT it_bom_expl INTO gf_it_bom_expl.

CLEAR: l_cnt1.

AT NEW bom_comp.

CLEAR: l_cnt, <fs_dyn_wa1>, 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_wa1> 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_wa1> 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.

  • The description 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_description OF STRUCTURE <fs_dyn_wa1> TO

<fs_check>.

<fs_check> = gf_it_bom_expl-ojtxp.

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

AT END OF bom_comp.

ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa1> TO <fs_check>.

<fs_check> = l_cnt.

INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.

ENDAT.

ENDLOOP.

ENDFORM. " move_bom_data_to_matnr_table

4 REPLIES 4
Read only

Former Member
0 Likes
562

Hi,

Please check this sample program.

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab.

form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

*Add your new field(s) into table ifc here.

...

endform.

form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

Regards,

Sankar

Read only

Former Member
0 Likes
563

Check below code and try to add in ur code....

IF NOT it_bom_expl[] IS INITIAL.

  • The material number data varies from run to run. For this purpose

  • the data is been used to build dynamic internal table which stores the

  • material number data along the x-axis

PERFORM build_matnr_table.

  • The material numbers data which is stored in the temp internal table

  • is been assigned to the dynamic internal table created along the

  • x-axis for the materials

PERFORM assign_matnr_val_fields.

  • The component data which is stored in the internal table needs to be

  • moved to the dynamic internal table

PERFORM move_bom_data_to_matnr_table.

&----


*& Form build_matnr_table

&----


  • Using the material number data the dynamic internal tables are been

  • built which holds the material number data along x-axis. Here the

  • first 3 columns are always constant which are Components-List,

  • Description, Count. From 4th column it depends on number of materials

----


FORM build_matnr_table .

DATA: l_val(3) TYPE n,

lf_mat(18) TYPE c.

  • Moving the Components-List details to the internal table 1st column

  • which will be used for creation of dynamic internal table

CLEAR gf_xfc.

gf_xfc-fieldname = text-t03.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 18.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

CLEAR gf_xfc.

  • Moving the Description details to the internal table 2nd column

  • which will be used for creation of dynamic internal table

gf_xfc-fieldname = text-t04.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 40.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ipc.

CLEAR gf_xfc.

  • Moving the Count details to the internal table 3rd column which will

  • be used for creation of dynamic internal table

gf_xfc-fieldname = text-t05.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 5.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

  • Moving the Material numbers are moved to the internal table from 4th

  • column onwards till all the material numbers are moved to the columns

  • which will be used for creation of dynamic internal table. Here

  • columns will be reffered to as Material001 ..... Materialxxn

LOOP AT it_mat.

CLEAR gf_xfc.

l_val = l_val + 1.

CONCATENATE text-t06 l_val INTO lf_mat.

gf_xfc-fieldname = lf_mat.

gf_xfc-datatype = c_val_c.

gf_xfc-inttype = c_val_c.

gf_xfc-intlen = 18.

gf_xfc-decimals = 0.

APPEND gf_xfc TO gf_ifc.

APPEND gf_xfc TO gf_ipc.

ENDLOOP.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ifc

IMPORTING

ep_table = gf_table.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table->* TO <fs_dyn_table>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line LIKE LINE OF <fs_dyn_table>.

ASSIGN gf_line->* TO <fs_dyn_wa>.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ipc

IMPORTING

ep_table = gf_table1.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table1->* TO <fs_dyn_table1>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line1 LIKE LINE OF <fs_dyn_table1>.

ASSIGN gf_line1->* TO <fs_dyn_wa1>.

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ifc

IMPORTING

ep_table = gf_table2.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table2->* TO <fs_dyn_table2>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line2 LIKE LINE OF <fs_dyn_table2>.

ASSIGN gf_line2->* TO <fs_dyn_wa2>.

ENDFORM. " build_matnr_table

&----


*& Form assign_matnr_val_fields

&----


  • The material numbers data stored in the temp internal table needs to

  • be assigned to the dynamic internal table along x-axis as the first

  • record. The temp internal table is been looped and using the field

  • symbol concept the data is moved to the dynamic internal table

----


FORM assign_matnr_val_fields .

DATA: l_cnt(3) TYPE n,

l_nam(12),

g_total(3) TYPE n.

DESCRIBE TABLE it_mat LINES g_total.

CLEAR l_cnt.

  • Looping the temp internal table and concatenating material as

  • material001 and the same is been checked against the dynamic

  • internal table and the material number value is moved to the

  • internal table. Finally, the data is been appened as first record.

LOOP AT it_mat.

l_nam = c_mat.

l_cnt = l_cnt + 1.

CONCATENATE l_nam l_cnt INTO l_nam.

  • Material which is in form Materialxxn is been assigned to the field

  • symbol which is checked against the field of dynamic internal table

  • and the value of the Material Number is been passed to the dynamic

  • internal table field value.

  • After all materials are been assigned the record is been appended

  • to the dynamic internal table.

ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_field>.

<fs_field> = it_mat-matnr.

IF l_cnt = g_total.

INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.

ENDIF.

ENDLOOP.

  • Looping the temp internal table and concatenating material as

  • material001 and the same is been checked against the dynamic

  • internal table and the material number value is moved to the

  • internal table. Finally, the data is been appened as first record.

  • This is been used for downloading of data to excel sheet as it

  • contains additional field which is Description field.

CLEAR l_cnt.

LOOP AT it_mat.

l_nam = c_mat.

l_cnt = l_cnt + 1.

CONCATENATE l_nam l_cnt INTO l_nam.

  • Material which is in form Materialxxn is been assigned to the field

  • symbol which is checked against the field of dynamic internal table

  • and the value of the Material Number is been passed to the dynamic

  • internal table field value.

  • After all materials are been assigned the record is been appended

  • to the dynamic internal table.

ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa1> TO <fs_field>.

<fs_field> = it_mat-matnr.

IF l_cnt = g_total.

INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.

ENDIF.

ENDLOOP.

  • The contents of one internal table is passed on to other internal

  • table for use while moving the component data for count purposes.

<fs_dyn_table2>[] = <fs_dyn_table>[].

ENDFORM. " assign_matnr_val_fields

&----


*& Form move_bom_data_to_matnr_table

&----


  • The component data is been appended to the dynamic internal table

  • The component is checked against a material and if exists the corresp-

  • onding level is been appended to the record

  • The total count is derived as the in how many materials the component

  • exists

----


FORM move_bom_data_to_matnr_table .

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.

  • Looping the component internal table. This is used for the additional

  • Description field which is shown in the excel sheet

LOOP AT it_bom_expl INTO gf_it_bom_expl.

CLEAR: l_cnt1.

AT NEW bom_comp.

CLEAR: l_cnt, <fs_dyn_wa1>, 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_wa1> 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_wa1> 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.

  • The description 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_description OF STRUCTURE <fs_dyn_wa1> TO

<fs_check>.

<fs_check> = gf_it_bom_expl-ojtxp.

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

AT END OF bom_comp.

ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa1> TO <fs_check>.

<fs_check> = l_cnt.

INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.

ENDAT.

ENDLOOP.

ENDFORM. " move_bom_data_to_matnr_table

Read only

Former Member
0 Likes
562

Hi,

Here is the example Program

report ztest_0003.
 
<b>field-symbols: <dyn_table> type standard table,
               <dyn_wa>.
 
data: new_table type ref to data,
      new_line  type ref to data,
      is_fieldcat type lvc_s_fcat,
      it_fieldcat type lvc_t_fcat..
 
data: i type i.
data: date1 type sy-datum.
 
parameters: P_SPBUP type SPBUP.
parameters: n type i.</b>
is_fieldcat-fieldname = 'BEZEI'.
<b>*is_fieldcat-ref_field = 'BEZEI'.
*is_fieldcat-ref_table = 'S858'.</b>
is_fieldcat-scrtext_l = 'CSR'.
is_fieldcat-scrtext_m = 'CSR'.
is_fieldcat-scrtext_s = 'CSR'.
 
append is_fieldcat to it_fieldcat.
 
do n times.
  is_fieldcat-fieldname = p_SPBUP.
<b>*  is_fieldcat-ref_field = 'SPBUP'.
*  is_fieldcat-ref_table = 'S858'.</b>
  is_fieldcat-scrtext_l = p_SPBUP.
  is_fieldcat-scrtext_m = p_SPBUP.
  is_fieldcat-scrtext_s = p_SPBUP.
  append is_fieldcat to it_fieldcat.
 
<b>  p_SPBUP+4(2) = p_SPBUP+4(2) + 1.
  if p_SPBUP+4(2) = 13.
    p_SPBUP+0(4) = p_SPBUP+0(4) + 1.
    p_SPBUP+4(2) = '01'.
  endif.
 
*  if date+4(2) = 12.
*    date+3(1) = date+3(1) + 1.
*    date+4(2) = '00'.
*  endif.
*  date+4(2) = date+4(2) + i.
*  date1+4(1) = date+4(1).
*  if date+5(1) = ' '.
*    date+4(1) = 0.
*    date+5(1) = date1+4(1).
*  endif.</b>
enddo.
 
is_fieldcat-fieldname = 'TOTALS'.
<b>*is_fieldcat-ref_field = 'UMNETWR'.
*is_fieldcat-ref_table = 'S858'.</b>
is_fieldcat-scrtext_l = 'TOTALS'.
is_fieldcat-scrtext_m = 'TOTALS'.
is_fieldcat-scrtext_s = 'TOTALS'.
append is_fieldcat to it_fieldcat.
 
<b>*FIELD-SYMBOLS : <new_table> TYPE REF TO data.
*DATA : lt_data TYPE REF TO data.
*ASSIGN lt_data TO <new_table>.</b>
call method cl_alv_table_create=>create_dynamic_table
        exporting
              it_fieldcatalog = it_fieldcat
        importing
              ep_table = <b>new_table.</b>
 
<b>
assign new_table->* to <dyn_table>.
 
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.</b>

Regards

Sudheer

Read only

Former Member
0 Likes
562

Hi,

Check the code below:

ASSIGN d_ref->* TO <f_fs>.

<b>Create work area similar to <F_FS></b>

CREATE DATA gv_wa LIKE LINE OF <f_fs>.

ASSIGN gv_wa->* TO <fs_wa>.

FIELD-SYMBOLS: <f_fs2> TYPE itab2, "

<f_fs6> TYPE ANY,

<f_fs7> TYPE ANY.

DATA: l_quant TYPE p.

LOOP AT g_itab5 ASSIGNING <f_fs2>. <b>(Data in Final Internal table).</b>

ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <f_fs2> TO <f_fs6>.

ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <fs_wa> TO <f_fs7>.

<f_fs7> = <f_fs6>.

CONDENSE <f_fs2>-vhilm NO-GAPS.

ASSIGN COMPONENT 'VHILM' OF STRUCTURE <f_fs2> TO <f_fs3>.

ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.

MOVE <f_fs3> TO l_var1.

ASSIGN COMPONENT l_var1 OF STRUCTURE <fs_wa> TO <f_fs5>.

<f_fs5> = <f_fs4>.

CLEAR total_tab-quantity.

READ TABLE total_tab WITH KEY tknum = <f_fs6>.

IF sy-subrc = 0.

ASSIGN total_tab-quantity TO <f_fs12>.

ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.

<f_fs13> = <f_fs12>.

ENDIF.

L_FILL = L_FILL + 1.

IF L_FILL = L_TOT.

ASSIGN L_TOTAL TO <f_fs12>.

ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.

<f_fs13> = <f_fs12>.

ENDIF.

AT END OF <f_fs2>-tknum.

APPEND <fs_wa> TO <f_fs>. <b>(Appending final work area to final structure)</b>

CLEAR <fs_wa>.

ENDAT.

ENDLOOP.

Regards

Kannaiah