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

move data from excel to internal table

Former Member
0 Likes
2,460

Hi, all,

I am using ALSM_EXCEL_TO_INTERNAL_TABLE to move data from excel to a internal table. I got following errors. Please anyone can tell me where is wrong. Thanks. (the excel file does not have header line).

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was

not caught in

procedure "ALSM_EXCEL_TO_INTERNAL_TABLE" "(FUNCTION)", nor was it propagated by

a RAISING clause.

Since the caller of the procedure could not have anticipated that the

exception would occur, the current program is terminated.

The reason for the exception is:

The FORM "SEPARATED_TO_INTERN_CONVERT" was called incorrectly.

The call of the FORM is incorrect for parameter nr. 2:

The internal table that is transferred to the formal table parameter has

a type that is not compatible with the type of the formal parameter.

The FORM "SEPARATED_TO_INTERN_CONVERT" is defined in the program "SAPLALSMEX".

The conditions flagged below have been violated:

(" ") The access types specified for the table are not compatible. The

compatibility rules are defined by the following hierarchy:

ANY_TABLE (INDEX_TABLE (STANDARD_TABLE, SORTED_TABLE), HASHED_TABLE)

A fixed access type is only compatible with its predecessors in

the hierarchy (example: STANDARD_TABLE is compatible with

INDEX_TABLE and ANY_TABLE, but is not compatible with HASHED_TABLE).

("X") The row types of the two tables are not compatible.

("X") The table keys of the two tables do not match.

(" ") One of the two tables is defined with a unique key (UNIQUE); the

other is defined with a non-unique key (NON-UNIQUE).

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
2,131

May be you can try with this.


data :    wa_raw             type truxs_t_text_data.

    call function 'TEXT_CONVERT_XLS_TO_SAP'
      exporting
        i_tab_raw_data       = wa_raw
        i_filename           = p_filename
      tables
        i_tab_converted_data = i_etab[]
      exceptions
        conversion_failed    = 1
        others               = 2.

aRs

Hi, all,

I am using ALSM_EXCEL_TO_INTERNAL_TABLE to move data from excel to a internal table. I got following errors. Please anyone can tell me where is wrong. Thanks. (the excel file does not have header line).

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was

not caught in

procedure "ALSM_EXCEL_TO_INTERNAL_TABLE" "(FUNCTION)", nor was it propagated by

a RAISING clause.

Since the caller of the procedure could not have anticipated that the

exception would occur, the current program is terminated.

The reason for the exception is:

The FORM "SEPARATED_TO_INTERN_CONVERT" was called incorrectly.

The call of the FORM is incorrect for parameter nr. 2:

The internal table that is transferred to the formal table parameter has

a type that is not compatible with the type of the formal parameter.

The FORM "SEPARATED_TO_INTERN_CONVERT" is defined in the program "SAPLALSMEX".

The conditions flagged below have been violated:

(" ") The access types specified for the table are not compatible. The

compatibility rules are defined by the following hierarchy:

ANY_TABLE (INDEX_TABLE (STANDARD_TABLE, SORTED_TABLE), HASHED_TABLE)

A fixed access type is only compatible with its predecessors in

the hierarchy (example: STANDARD_TABLE is compatible with

INDEX_TABLE and ANY_TABLE, but is not compatible with HASHED_TABLE).

("X") The row types of the two tables are not compatible.

("X") The table keys of the two tables do not match.

(" ") One of the two tables is defined with a unique key (UNIQUE); the

other is defined with a non-unique key (NON-UNIQUE).

14 REPLIES 14
Read only

amit_khare
Active Contributor
0 Likes
2,131

This error is due to the error in table format used for passing data from the FM.

Check your table declarations for the FM & for final table for moving the data.

Also, if you have declared you file fields as-

PARAMETERS : P_FILE LIKE RLGRAP-FILENAME.

then pass it to string before passing it to Function module for upload.

Regards,

Amit

Read only

0 Likes
2,131

Hi, Amit,

What I am doing is, I downloaded the table A's contents from PRD to my PC as excel file using GUI_DOWNLOAD. And then I want to put the data from that excel into the same table A in QA for my program testing. I declared the table for FM with "type table of A with header line". Do you think it is wrong? Thank you!

Meiying

Read only

0 Likes
2,131

You have downloaded using GUI_DOWNLOAD.

Do check the downloaded file as if it is not formatted then all the data is actually downloaded in a single cell only, which is creating problem while uploading.

Regards,

Amit

Read only

0 Likes
2,131

I checked the the downloaded file. It is well formartted. But I am wandering if I need to delete the collum mandt (client) field? Thank you!

Meiying

Read only

0 Likes
2,131

Yes that field need to be deleted.

And if still error persis can you poset your code here for uploading the excel.

Regards,

Amit

Read only

0 Likes
2,131

Hi, Amit,

I see where is my problem now. I got the answer from thread

I declared my int_excel as "type table of A(my database table) with header line. I should declare it as " LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE."

Then when I put int_excel to my actual inter table, do I HAVE TO do like the thread said go thru each column? I have over 10000 rows and 54 columns. Thank you!

LOOP AT int_excel.
CASE int_excel-col. "go thru each column.
WHEN 1.
record-name = int_excel-value. 
WHEN 2.
record-age = int_excel-value. 
ENDCASE.
AT END OF row.
APPEND record.
CLEAR record.
ENDAT.
ENDLOOP.

Read only

former_member194669
Active Contributor
2,132

May be you can try with this.


data :    wa_raw             type truxs_t_text_data.

    call function 'TEXT_CONVERT_XLS_TO_SAP'
      exporting
        i_tab_raw_data       = wa_raw
        i_filename           = p_filename
      tables
        i_tab_converted_data = i_etab[]
      exceptions
        conversion_failed    = 1
        others               = 2.

aRs

Read only

former_member194669
Active Contributor
0 Likes
2,131

Hi,

I think there will be a limitation for this fm ALSM_EXCEL_TO_INTERNAL_TABLE

less than equal 50 character length field only can upload.

aRs

Read only

0 Likes
2,131

Hi, aRs,

Thanks for the reply. I tried your FM 'TEXT_CONVERT_XLS_TO_SAP'. But I got error says " conversion_failed ". Would you please provide sample program for how to use this FM? Thanks. I am trying to save my excel to txt, and then use FM "GUI_UPLOAD". Still give me error says " BAD_DATA_FORMAT".

Read only

former_member194669
Active Contributor
2,131

Hi,

Example u asked for


REPORT  zupload_excel_to_itab.
 
TYPE-POOLS: truxs.
 
PARAMETERS: p_file TYPE  rlgrap-filename.
 
TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.
 
DATA: it_raw TYPE truxs_t_text_data.
 
* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.
 
 
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
 
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw       " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL 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.
 
 
***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
  LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
            wa_datatab-col2,
            wa_datatab-col3.
  ENDLOOP.


Read only

0 Likes
2,131

Thank you very much, aRs! But still saying conversion_failed. I am out of enage.

Read only

former_member194669
Active Contributor
0 Likes
2,131

Please give your email id, i will send u the excel format and program

aRs

Read only

0 Likes
2,131

I will get back to this one later. I have an urgent task right now. Thanks all. I will certainly award useful answer.

Meiying

Read only

0 Likes
2,131

The problem has been solved by myself. I successful did it using FM GUI_UPLOAD.

Meiying