2008 Nov 12 3:01 PM
Hi All
Here is the code i have written to create dynamic internal table
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
UNASSIGN: <dyn_table>, <dyn_wa>, <dyn_field>.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( table-low ).
idetails[] = ref_table_des->components[].
w_out-rec = table-low.
APPEND w_out TO i_out.
CLEAR w_out.
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name.
CONCATENATE w_out xdetails-name INTO w_out
SEPARATED BY ','.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
APPEND w_out TO i_out.
* 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>.
the 1st internal table is created successfully
when it is executing the class cl_alv_table_create=>create_dynamic_table
for creating the 2nd internal table, it errors out.
Error message
"LT_GENTAB-MANDT" has already been declared. 9 MANDT(000006)
Please let me know how to solve this.
2008 Nov 12 3:08 PM
Please change the code this way and try
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name.
CONCATENATE w_out xdetails-name INTO w_out
SEPARATED BY ','.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
read table ifc with key fieldname = xfc-fieldname. "<
if sy-subrc ne 0. "<
APPEND xfc TO ifc. "<
endif.
ENDLOOP.
a®
Please change the code this way and try
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name.
CONCATENATE w_out xdetails-name INTO w_out
SEPARATED BY ','.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
read table ifc with key fieldname = xfc-fieldname. "<
if sy-subrc ne 0. "<
APPEND xfc TO ifc. "<
endif.
ENDLOOP.
a®
2008 Nov 12 3:08 PM
Please change the code this way and try
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name.
CONCATENATE w_out xdetails-name INTO w_out
SEPARATED BY ','.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
read table ifc with key fieldname = xfc-fieldname. "<
if sy-subrc ne 0. "<
APPEND xfc TO ifc. "<
endif.
ENDLOOP.
a®
2008 Nov 12 5:48 PM
but now it goes to short dump on the select query
LOOP AT table.
PERFORM create_dynamic_itab.
SELECT * INTO TABLE <dyn_table>
FROM (table-low).
PERFORM fill_it.
ENDLOOP.
Short Dump Description
Short text
The types of operands "dbtab" and "itab" cannot be converted into one another.
Error analysis
In a Unicode system, the type of the operand "dbtab" must be convertible
into that of the operand "itab" for the statement "SELECT * FROM dbtab INTO
TABLE itab". Regardless of the
length of a Unicode character, both operands must have the same
structure layout.
In this case, this condition has not been met.
i checked the fields, they are same
If i change the select statement clause to
into corresponding fields
it is going to dump in PERFORM fill_it. statement.
2008 Nov 12 6:25 PM
2008 Nov 13 9:36 AM
FORM fill_it.
* Write out data from table.
LOOP AT <dyn_table> INTO <dyn_wa>.
CLEAR w_out.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc <> 0.
APPEND w_out TO i_out.
EXIT.
ELSE.
CONCATENATE w_out <dyn_field>
INTO w_out SEPARATED BY ','.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "fill_it
2008 Nov 13 10:39 AM
Hi Sairam,
What do u mean by 2nd internal table creation.
Will it happen in the same ABAP session or a different session.
The errors is with respect to duplication of fields. When u declare two fields with same name in an internal table , it will throw an error message. The same thing is happening when u r creating an internal table dynamically.
-Satya Priya
2008 Nov 13 10:44 AM
Try clearing the field catalog table ifc. U can check the fields of this fieldcatalog table in debugging mode.
-Satya Priya
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |