Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

file with header

Former Member
0 Likes
2,902

hi,

i have to upload file which has header in the first line.

and from second line the actual data will be there which is to be uploaded.

now the problem is hove to move this file data to internal table with header,

can any one has code plz send me.

7 REPLIES 7
Read only

Former Member
0 Likes
1,144

Hi,

Once you upload the file using GUI_UPLOAD , the data will sit in Internal table.

Then use statement

DELETE itab INDEX 1. so it will remove the first record(header).

Regards

Eswar

Read only

piyush_mathur
Active Participant
0 Likes
1,144

Hi,

If you are using GUI_UPLOAD function then first uplaod the file into an interbal table and late delete the first row form the table.

Or if you are uploading data from Excel file usinf below fiunction, then pass Row value as 2. Then function will ignore the first row while uploading the data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = infile

i_begin_col = '1'

i_begin_row = 2

i_end_col = '6'

i_end_row = end_row

TABLES

intern = excel_tab

  • EXCEPTIONS

  • INCONSISTENT_PARAMETERS = 1

  • UPLOAD_OLE = 2

  • OTHERS = 3

.

IF sy-subrc 0.

ENDIF.

Regards,

Piyush

Read only

0 Likes
1,144

if the first row has field names in the file and then the actual data from 2nd row how to pass the file data into internal table as the field names has more length than the actual data.

Read only

0 Likes
1,144

If you r upload data fromexcel Sheet, use below function:

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = infile

i_begin_col = '1'

i_begin_row = 2 " 2 value will start reading the file from 2nd row.

i_end_col = '6'

i_end_row = end_row

TABLES

intern = excel_tab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

IF sy-subrc 0.

ENDIF.

or if you are uploading from text file and using GUI_UPLOAD file,

then use an ubternal table with column data type as String. After uploading the data delet the first line from internal table.

Let me know where you are facing the problem.

Regards,

Piyush

Read only

Former Member
0 Likes
1,144

hi,

try this Fm...

DATA l_count TYPE sy-tabix.

   CONSTANTS: lc_begin_col TYPE i VALUE '1',

              lc_begin_row TYPE i VALUE '2',

              lc_end_col   TYPE i VALUE '2',

              lc_end_row   TYPE i VALUE '3000'.

* Begin of CALK912848 - Carlos Werberich - 16Sep08

  CLEAR p_i_excel_data. REFRESH p_i_excel_data.

* End   of CALK912848 - Carlos Werberich - 16Sep08

* Function module to read excel file and convert it into internal table

   CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'

     EXPORTING

       filename                = p_p_file

       i_begin_col             = lc_begin_col

       i_begin_row             = lc_begin_row

       i_end_col               = lc_end_col

       i_end_row               = lc_end_row

     TABLES

       intern                  = i_data

     EXCEPTIONS

       inconsistent_parameters = 1

       upload_ole              = 2

       OTHERS                  = 3.

* Error in file upload

   IF sy-subrc NE 0 .

     MESSAGE text-006 TYPE 'E'.

     EXIT.

   ENDIF.

   IF i_data[] IS INITIAL .

     MESSAGE text-007 TYPE 'E'.

     EXIT.

   ELSE.

     SORT i_data BY row col .

* Loop to fill data in Internal Table

     LOOP AT i_data .

       MOVE i_data-col TO l_count .

       ASSIGN COMPONENT l_count OF STRUCTURE p_i_excel_data TO  .

       AT END OF row .

* Append data into internal table

         APPEND p_i_excel_data.

         CLEAR p_i_excel_data.

       ENDAT .

     ENDLOOP .

   ENDIF 

Read only

0 Likes
1,144

Hi,

my requirement is I have to provide both presentation and application server option in my selection screen.If the presentation server option is selected then user can select the file type like Text or Excel.

Also it would be better if we can add the logic to upload the file with dynamic columns so that this upload Program can be reused.

The first row of the file contain the field name always. The data will start from the second row.If it is excel we will provide row as 2.Whereas with txt file what we hav to do?

Read only

0 Likes
1,144

hi,

when read the data from Dataset ...

Open dataset file....

Do.

Check sy-index Ne 1.

READ DATASET file INTO itab.

IF sy-subrc NE 0.

EXIT.

ELSE.

APPEND itatab.

ENDIF.

Enddo.