Hi all,
Please read through the step 1 to 14, to get a clear understanding of my issue. The crux being i am incorrectly populating a dynamic table. I suspect the Assign statement to be the cause. Your suggestions will be greatly appreciated. Needless to mention the solution provider will be rewarded with handsome points.
Regards,
AG.
1. I have a type declared as follows:
TYPES: BEGIN OF ty_list,
werks LIKE mseg-werks, "Plant
matkl LIKE ekpo-matkl, "Material Group
matnr LIKE mseg-matnr, "Material
erfmg_01 LIKE mseg-erfmg, "Quantity
dmbtr_01 LIKE mseg-dmbtr, "Amount
erfmg_02 LIKE mseg-erfmg, "Quantity
dmbtr_02 LIKE mseg-dmbtr, "Amount
erfmg_03 LIKE mseg-erfmg, "Quantity
dmbtr_03 LIKE mseg-dmbtr, "Amount
erfmg_04 LIKE mseg-erfmg, "Quantity
dmbtr_04 LIKE mseg-dmbtr, "Amount
erfmg_05 LIKE mseg-erfmg, "Quantity
dmbtr_05 LIKE mseg-dmbtr, "Amount
erfmg_06 LIKE mseg-erfmg, "Quantity
dmbtr_06 LIKE mseg-dmbtr, "Amount
erfmg_07 LIKE mseg-erfmg, "Quantity
dmbtr_07 LIKE mseg-dmbtr, "Amount
erfmg_08 LIKE mseg-erfmg, "Quantity
dmbtr_08 LIKE mseg-dmbtr, "Amount
erfmg_09 LIKE mseg-erfmg, "Quantity
dmbtr_09 LIKE mseg-dmbtr, "Amount
erfmg_10 LIKE mseg-erfmg, "Quantity
dmbtr_10 LIKE mseg-dmbtr, "Amount
erfmg_11 LIKE mseg-erfmg, "Quantity
dmbtr_11 LIKE mseg-dmbtr, "Amount
erfmg_12 LIKE mseg-erfmg, "Quantity
dmbtr_12 LIKE mseg-dmbtr, "Amount
END OF ty_list.
2. I have an internal table as follow:
it_list TYPE STANDARD TABLE OF ty_list WITH DEFAULT KEY INITIAL SIZE 0
3. i have a field symbol as follows:
field-symbols <fs_list> LIKE LINE OF it_list,
4. i have a field catalog declared as follows:
DATA: LT_FIELDCATALOG type LVC_T_FCAT.
5. i have a header work area for the fieldcatalog as below:
DATA: LS_FIELDCATALOG type LVC_S_FCAT.
6. i build the field catalog by adding 3 obligatory fields.
*Appending the plant field.
ls_fieldcatalog-col_pos = l_contr.
ls_fieldcatalog-fieldname = 'WERKS'.
ls_fieldcatalog-seltext = 'PLANT'.
ls_fieldcatalog-outputlen = 5.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
*
*Appending the material group field.
add 1 to l_contr.
ls_fieldcatalog-col_pos = l_contr.
ls_fieldcatalog-fieldname = 'MATKL'.
ls_fieldcatalog-seltext = 'MATERIAL_GROUP'.
ls_fieldcatalog-outputlen = 10.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
*Appending the material field.
add 1 to l_contr.
ls_fieldcatalog-col_pos = l_contr.
ls_fieldcatalog-fieldname = 'MATNR'.
ls_fieldcatalog-seltext = 'MATERIAL'.
ls_fieldcatalog-outputlen = 18.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
7. i build the rest of the field catalog dynamically based on a value from table p_it_mnth
if the month is present i add into the field catalog.
LOOP AT p_it_mnth ASSIGNING <fs_mnth>.
CASE <fs_mnth>-month_id.
WHEN 4.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_04'. l_mcurr = 'DMBTR_04'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 5.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_05'. l_mcurr = 'DMBTR_05'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 6.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_06'. l_mcurr = 'DMBTR_06'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 7.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_07'. l_mcurr = 'DMBTR_07'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 8.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_08'. l_mcurr = 'DMBTR_08'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 9.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_09'. l_mcurr = 'DMBTR_09'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 10.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_10'. l_mcurr = 'DMBTR_10'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 11.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_11'. l_mcurr = 'DMBTR_11'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 12.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_12'. l_mcurr = 'DMBTR_12'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 1.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_01'. l_mcurr = 'DMBTR_01'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 2.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_02'. l_mcurr = 'DMBTR_02'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN 3.
ADD 1 TO l_contr.
l_mquan = 'ERFMG_03'. l_mcurr = 'DMBTR_03'.
PERFORM append_to_fldcatalog USING l_mquan l_mcurr l_contr.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
8. i am declaring some field symbols as follows:
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
<FS_1> type STaNDARD table,
<FS_2>,
9. i am declaring a new line as follows:
DATA: NEW_LINE type ref to data.
10. i am declaring another field symbol as follows:
DATA: LT_DATA type ref to DATA.
11. assign the target table and call function to create a dynamic internal table based on the field catalog.
assign LT_DATA to <FS_DATA>.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = <FS_DATA>
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
12. assigning values to the work areas as below after creating the dynamic table.
So <FS_1> now points to our dynamic internal table.
assign <FS_DATA>->* to <FS_1>.
Next step is to create a work area for our dynamic internal table.
create data NEW_LINE like line of <FS_1>.
Access contents of internal table
ASSIGN NEW_LINE->* TO <FS_2>.
13. appending values into the dynamic internal table as below:
LOOP AT IT_LIST ASSIGNING <FS_LIST>.
assign lt_fieldcatalog to <fs_fldc>.
LOOP AT LT_FIELDCATALOG assigning <fs_fldc>.
assign component <fs_fldc>-fieldname of structure <fs_list> to <fs_2>.
append <fs_2> to <fs_1>.
ENDLOOP.
ENDLOOP.
14. i get the below output:
1. werks is populated with "CHEN" and appended as first row.
2. werks is again populated with "SERVI" and the remaining "CES" is carried to the MATKL field and populated as second row ( instead of being the second field in the first row of the dynamic internal table).
3. the quantity and amount are populated in the last amount field and appended instead of being distributed to the corresponding fields in the same row .
CHEN
SERVI CES
0.000
0.00
0.000
0.00
0.000
0.00
0.000
0.00
0.000
0.00
0.000
0.00
0.000
0.00
4.000
50010.00