‎2012 Jun 01 9:43 AM
Hi Gurus,
We are having a requirement wherein we need to upload an excel file( containing only two static data and the remaining columns are dynamic based on the fiscal year ) to a internal table.
Is there any way in SAP ABAP to do this?
Waiting for your replies.
‎2012 Jun 01 10:25 AM
Hello,
I assume, that you know how to upload a CSV-File.
I would suggest, that you create the following datatypes:
1) An internal table representing the whole line of your Excel-File including all static fields
2) An internal table representing your dynamic values
The concrete structure should looks like this:
types: begin of dyn_data
field type string, "or number or key or...
value type string,
end of dyn_data.
types: tt_dynvalues type table of dyn_data.
types: begin of csv_data
field1 type string,
field2 type string,
dyn_values type tt_dynvalues,
end of csv_data.
with this data-structures, you can make a loop over your csv-data and place the static data in your csv_data-table and after this, you can iterate over your dynamic values and place them into the concrete dyn_values-table of your current line.
Kind regards,
Hendrik
‎2012 Jun 01 10:53 AM
Hi,
We are comfortable in making a dynamic internal table,
We are facing problem in uploading a dynamic file.
We are not sure how the data will be uploaded to a dynamic internal table.
Also, how can we know about the file format prior to capture this uploaded data.
‎2012 Jun 01 10:37 AM
You can create a dynamic internal table for handling this.
TYPE-POOLS: slis.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, “ Dynamic internal table name
<fs_dyntable>, “ Field symbol to create work area
<fs_fldval> type any. “ Field symbol to assign values
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_fldcat TYPE slis_t_fldcat_alv,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat.
* Create fields .
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'STATIC1'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'STATIC2'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
IF fiscalyear = '2011'.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'DYNAMIC1'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
else.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'DYNAMIC2'.
wa_it_fldcat-datatype = 'NUMC'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
endif.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
* Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
Upload the data from excel to the <t_dyntable> table.
Thanks,
Shambu
‎2012 Jun 01 10:53 AM
Hey Shambu,
We are comfortable in making a dynamic internal table,
We are facing problem in uploading a dynamic file.
We are not sure how the data will be uploaded to a dynamic internal table.
Also, how can we know about the file format prior to capture this uploaded data.
‎2012 Jun 01 11:09 AM
What kind of file are you uploading?
CSV, Tab Delimited or simple excel file.
Do you know the maximum number of columns this file will have?
‎2012 Jun 01 11:34 AM
We are uploading simple excel file, the thing is we are unable to identify the maximum number of columns, as number of columns may vary with respect to year.
‎2012 Jun 01 11:55 AM
Hi,
Probably you can use a Tab delimited file and upload the contents into a string table.
Loop at the string table and split the contents at TAB into another table .
Split wa_Data AT seperator into table lt_values.
The number of rows correspond to the number of columns in the sheet.
After that create a dynamic table with the same no of columns.
Thanks,
Shambu
‎2012 Jun 01 11:57 AM
Hi,
just look at my coding above. There you will a have an initial structure to handle unlimited columns of data without any dynamic table-programming.
Regard: Using a dynamic table means, that you are using a non-typed data-type within your application and this leads into very complex coding.
I assume, that your dynamic value are always the same datatype. If not, you can think about using reference data.
Kind regards,
Hendrik
‎2012 Sep 05 10:32 AM
i tried this but it's showing run time error. that field symbol is not assigned.