Skip to Content

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

KUNNR LAND1 NAME1

into an internal table with structure

KUNNR NAME1 LAND1

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 13, 2015 at 09:52 AM

    Hi Benjamin,

    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.    

    endloop.

    reagrds.

    Praveer.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12, 2015 at 04:14 PM

    Hi Benamin,

      Use ALSM_EXCEL_TO_INTERNAL_TABLE, that will read the header row. Based on the technical names received in the First row, form the Dynamic internal table and assign the data into the same.

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

           EXPORTING

                FILENAME                = P_file

                I_BEGIN_COL             = 1      "First Column

                I_BEGIN_ROW             = 1      "Header Row

                I_END_COL               = L_MAX_COL_NB

                I_END_ROW               = 9999

           TABLES

                INTERN                  = IT_EXCEL

           EXCEPTIONS

                INCONSISTENT_PARAMETERS = 1

                UPLOAD_OLE              = 2

                OTHERS                  = 3.

    Please find the link to create dynamic internal table.

    Create Dynamic Table using RTTS and display in ALV

    Regards

    Rajkumar Narasimman

    Add comment
    10|10000 characters needed characters exceeded