Dynamic Read from File into Internal Table
I'm trying to create a program that will read a file, perform some validation and then out put some messages based on the validation.
The program works perfectly (it's too large and complex to post on here) except when the columns in the source file are not in the correct order, because it is then reading the wrong data into the wrong columns.
I assume the use of field catalogs and field-symbols is needed but how can I read a text file
into an internal table with structure
where the field names will always equal the names of the columns in the structure.
The text file may not always be in the same order.
Thanks in advance.
Praveer Sen replied
If you are uploading the Information from Test File, then read the all text file in default string based Internal table,(Field would be the same number as per your final requirement ).
and then based on the Columns Name (Exist on Text File), you have to create a dynamic table, and then the same you have to use for the further Logic.
But if you are using Excel, then you can use the ALSM_EXCEL_TO_INTERNAL_TABLE function module, after that the process would be the same to create dynamic table.
Though, text based internal table (Dynamic) and your primary internal table, columns would be the same only the sequence will be different
So through the help of FIELD-SYMBOL, you can arrange the Information.
Loop at test_intern_table (Dynamic) assign <text>.
assign component FIELD_NAME of structure <text> to <val>.
Main_intern_table-FIELD_NAME = <val>.
Like above logic append the text fiel information to Main internal table.