Application Development 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: 

excel file upload from pc to internal table

f_cemunal
Participant
0 Kudos

Hello all,

i am trying to upload an excel file to internal table but i get an error.

i am using fm 'F4_FILENAME' to get the file and then i am using  fm  'ALSM_EXCEL_TO_INTERNAL_TABLE' .


i have searched the net but i couldnt find a solution to that error.



here is my code :


DATA FILE_PATH LIKE  RLGRAP-FILENAME.

DATA: it_raw    TYPE          truxs_t_text_data.

data : BEGIN OF itab OCCURS 0,

        BSKODU like ZR52-BSKODU,

        BSADI LIKE ZR52-BSADI,

        GSBER LIKE ZR52-GSBER,

        GBATARIH LIKE ZR52-GBATARIH,

        GBITARIH LIKE ZR52-GBITARIH,

        AKTIFPASIF LIKE ZR52-AKTIFPASIF,

        MAIL LIKE ZR52-MAIL,

   END OF ITAB.

START-OF-SELECTION.

CALL FUNCTION 'F4_FILENAME'

     EXPORTING

       field_name = 'FILE_LOC' "

     IMPORTING

       file_name  = FILE_PATH.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

     EXPORTING

       FILENAME = FILE_PATH

       I_BEGIN_COL             = '1'

       I_BEGIN_ROW             = '2'

       I_END_COL               = '2'

       I_END_ROW               = '2'

      TABLES

       INTERN                  = ITAB

      EXCEPTIONS

       INCONSISTENT_PARAMETERS = 1

       UPLOAD_OLE              = 2.

regards,

cem

33 REPLIES 33

Former Member
0 Kudos

Hi,

whats the error you get & whats the subrc value after the FM Call ?

0 Kudos

i cant call fm. the error is here

0 Kudos

The below parameters are integers, Pass values without ' ', like below

I_BEGIN_COL                   = 1

I_BEGIN_ROW                   =  2

I_END_COL                     = 10

I_END_ROW                     = 65536

0 Kudos

i tried that too but still i have got the same error.

0 Kudos

HI Cem,

Please refer to the SAP note 933420 - ALSM_EXCEL_TO_INTERNAL_TABLE.

You can refer to the link below to have an idea how to fulfil your requirement:

Upload excel file from PC into SAP using ABAP inc .xls and .xlsx

Regards,

Ashvin

Former Member
0 Kudos

Also your internal table should be of the structure - ALSMEX_TABLINE.

Go to FM - ALSM_EXCEL_TO_INTERNAL_TABLE - Click on where used list, & if you see any programs using this FM, compare your inputs with that.


pavanm592
Contributor
0 Kudos

Hi Cem,

Please Go through This Link.

This will solve your problem.

Regards,

Pavan

former_member183607
Contributor
0 Kudos

Hi,

     Return Itab will be of type ALSMEX_TABLINE as suggested by Seema M, and This itab will have only three fields Row Column and Value. You may declare your Itab like

data: itab like alsmex_tabline occurs 0 with header line.


and Furthur loop this to retrieve data.

former_member202818
Active Contributor
0 Kudos

This may due to type conflict between XL data and internal table fields.

Declare all fields in itab as characters.

VenkatRamesh_V
Active Contributor
0 Kudos

Hi cem,

Hope it helpful.

Declare internal table as

Data :  ist_excel    TYPE  STANDARD TABLE OF alsmex_tabline,

           wa_excel    TYPE alsmex_tabline.



after FM.


LOOP AT ist_excel INTO wa_excel.
     CASE wa_excel-col.
       WHEN '0001'.

  wa_itab-BSKODU = wa_excel-value.

ENDCASE.



AT END OF row.

append wa_itab to itab.

clear wa_itab.

ENDAT.


CLEAR wa_excel.
   ENDLOOP.



Regards,

Venkat.




Former Member
0 Kudos

Hi

I recommend you to use the FM TEXT_CONVERT_XLS_TO_SAP as it is more reliable.

Regards

Vaibhav Juneja

Former Member
0 Kudos

Hi Cem,

      check the below code & update your code it may be solve your issue.

TYPE-POOLS: TRUXS .

DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.

CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      PROGRAM_NAME        = SYST-CPROG

      DYNPRO_NUMBER       = SYST-DYNNR

*   FIELD_NAME           = ' '

    IMPORTING

      FILE_NAME           = FILE_PATH.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

       EXPORTING

*     I_FIELD_SEPERATOR          =

         I_LINE_HEADER              = 'X'

         I_TAB_RAW_DATA             = IT_RAW

         I_FILENAME                 = FILE_PATH

       TABLES

         I_TAB_CONVERTED_DATA       = ITAB[].

Regards,

Mukesh

Former Member
0 Kudos

hi ,

i have use this fm and i have done it in following way , think you can define your itab with type ALSMEX_TABLINE

data :FILENAME TYPE RLGRAP-FILENAME,

        IT_FILE LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

   PROGRAM_NAME        = SY-REPID

   DYNPRO_NUMBER       = SYST-DYNNR

*   FIELD_NAME          = ' '

   IMPORTING

     FILE_NAME           = FILENAME

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

      FILENAME                      = FILENAME

      I_BEGIN_COL                   = '1'

      I_BEGIN_ROW                   = '1'

      I_END_COL                     = '42'

      I_END_ROW                     = '100'

    TABLES

      INTERN                        = IT_FILE

* EXCEPTIONS

*   INCONSISTENT_PARAMETERS       = 1

*   UPLOAD_OLE                    = 2

*   OTHERS                        = 3

            .

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

asim_isik
Active Participant
0 Kudos

Hi Cem ,

Excel and internal table contents should be same sequences. Did u check for it ?

Sudhakargadde
Participant
0 Kudos

Hi Cem,

When i analyse your code you want to read only 2nd row from the excel sheet?

if you have more than 2 records plz change the parameters of the function module of I_BEGIN_ROW, I_BEGIN_COL,I_END_ROW and I_END_COLUMN and try this let us know what happan

Regards

Sudhakar

0 Kudos

i can change these parameters that is no problem.but how will i updata z table from an excel file with 1000 or more records?

raymond_giuseppi
Active Contributor
0 Kudos

This FM will return a table of type ALSMEX_TABLINE, so record with horizontal and vertical index and a value, not what you expected. You MUST use the format specified in FM signature, then loop at this internal table to build your final table.

Create empty record AT NEW ROW, for every COL use an ASSIGN COMPONENT and map value to field of your format, AT END OF ROW append record to your table.

Also you may be required to use some conversion-exit or implicit correction from character values and be ready to catch format conversion errors.

Regards,

Raymond

0 Kudos

how will i do this for 1000 rows ?

f_cemunal
Participant
0 Kudos

thank you all for your answers.

i have solved the error now i can upload from excel to internl table but this fucntion doesnt require my needs.

becase excel file sometimes will have 1 record and sometimes will have 1000 records.

is there any function that i can use for this purpose?

Former Member
0 Kudos

hey,

if the no of colums are remains same in your case then you can use same fm and what you can do is you can ask user to add total no of rows at selection screen and use that variable for no of rows in fm .

Regards

Jaydeep

0 Kudos

Either, you

  • Try to read from 1 to 1000, then 1001 to 2000 til no more records
  • Start coding with OLE2
  • Look at tools like abap2xlsx

Regards,

Raymond

asim_isik
Active Participant
0 Kudos

Hi Cem ,

I use this function.

call function 'TEXT_CONVERT_XLS_TO_SAP'

    exporting

      i_line_header        = 'X'

      i_tab_raw_data       = gv_raw       " WORK TABLE

      i_filename           = p_fname

    tables

      i_tab_converted_data = gt_excel[]    "ACTUAL DATA

    exceptions

      conversion_failed    = 1

      others               = 2.

0 Kudos

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

*     I_FIELD_SEPERATOR    =

       i_line_header        = abap_true

       i_tab_raw_data     = git_raw   

       i_filename             =    p_file      "File path

     TABLES

       i_tab_converted_data = git_excel  "data

     EXCEPTIONS

       conversion_failed    = 1

       OTHERS               = 2.

   IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   ENDIF.

0 Kudos

is git_raw empty?

0 Kudos

yes.

git_raw TYPE truxs_t_text_data.

Former Member
0 Kudos

Hi Cem,

     Use FM TEXT_CONVERT_XLS_TO_SAP and check the below code it may be solve your issue.

TYPE-POOLS: TRUXS .

DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.

CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      PROGRAM_NAME        = SYST-CPROG

      DYNPRO_NUMBER       = SYST-DYNNR

*   FIELD_NAME           = ' '

    IMPORTING

      FILE_NAME           = FILE_PATH.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

       EXPORTING

*     I_FIELD_SEPERATOR          =

         I_LINE_HEADER              = 'X'

         I_TAB_RAW_DATA             = IT_RAW

         I_FILENAME                 = FILE_PATH

       TABLES

         I_TAB_CONVERTED_DATA       = ITAB[].

Regards,

Mukesh

0 Kudos

thank you

0 Kudos

i have done this before but git_excel returns empty.

what am i doing wrong?

0 Kudos

any exception occurred?

ms excel there in your system?

0 Kudos

Hi,

     Try by adding [] after your Itab

     TABLES     

           i_tab_converted_data = git_excel[]

0 Kudos

is git_excel declared with header line?

then use git_excel[].

VenkatRamesh_V
Active Contributor
0 Kudos

type-POOLS: truxs.

Data git_raw type TRUXS_T_TEXT_DATA.

Former Member
0 Kudos

Hi Cem Unal,

The reason for your error is type conflict.In the structure for itab you are having around 5 to 6 fields and in the function module which you are using for uploading data from excel to internal table(ALSM_EXCEL_TO_INTERNAL_TABLE).Should be passed as below

* need changes to your code

  1. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  2.      EXPORTING
  3. FILENAME = FILE_PATH 
  4.        I_BEGIN_COL             = '1'
  5.        I_BEGIN_ROW             = '2'
  6.        I_END_COL               = '2'  * depends on no.of fields present in the excel
  7.        I_END_ROW               = '2'  "depends on the no.of records present in the excel useful if you                                                    specify it as '9999'.
  8.       TABLES
  9.        INTERN                  = ITAB

Regards,

Chakradhar.