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: 

how to pass the import parameters in FM alsm_excel_to_internal_table

Former Member
0 Kudos

I have an openoffice excel file.Even if I store as an xls file the FM is not working

1 ACCEPTED SOLUTION

I355602
Advisor
Advisor
0 Kudos

Hi,

Refer:-


TYPE-POOLS : truxs.

PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.

DATA : BEGIN OF itab OCCURS 0,
         empid(50) TYPE c,
         name(50) TYPE c,
         doj(50) TYPE c,
       END OF itab.

DATA: it_raw TYPE truxs_t_text_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM f4_file_process USING p_file.

START-OF-SELECTION.

  PERFORM upload_data.

*&---------------------------------------------------------------------*
*&      Form  F4_FILE_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILE_PATH  text
*----------------------------------------------------------------------*
FORM f4_file_process USING p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    IMPORTING
      file_name     = p_file.

  IF sy-subrc NE 0.
    MESSAGE e000(zsd).
  ENDIF.

ENDFORM.                    " F4_FILE_PROCESS

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_data .

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = itab[]
    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.

ENDFORM.                    " UPLOAD_DATA

Hope this helps you.

Regards,

Tarun

8 REPLIES 8

Former Member
0 Kudos
DATA: lw_tab LIKE
  STANDARD TABLE
  OF alsmex_tabline WITH HEADER LINE.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = 'D:\TEST.XLS'
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = 7
      i_end_row               = 3
    TABLES
      intern                  = lw_tab
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  CASE sy-subrc.
    WHEN 1.
      MESSAGE 'Inconsistent parameters'(001) TYPE 'S'.
      LEAVE LIST-PROCESSING.
    WHEN 2.
      MESSAGE 'File download failed'(002) TYPE 'S'.
      LEAVE LIST-PROCESSING.
  ENDCASE.                             " CASE SY-SUBRC.

OR use:

call function 'TEXT_CONVERT_XLS_TO_SAP'
    exporting
      i_tab_raw_data       = <TABLE>                   " EMPTY
      i_filename           = 'D:\TEST.XLS'
    tables
      i_tab_converted_data = <ITAB>
    exceptions
      conversion_failed    = 1
      others               = 2.

Regards,

gurpreet

0 Kudos

thanks!

I355602
Advisor
Advisor
0 Kudos

Hi,

Refer:-


TYPE-POOLS : truxs.

PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.

DATA : BEGIN OF itab OCCURS 0,
         empid(50) TYPE c,
         name(50) TYPE c,
         doj(50) TYPE c,
       END OF itab.

DATA: it_raw TYPE truxs_t_text_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM f4_file_process USING p_file.

START-OF-SELECTION.

  PERFORM upload_data.

*&---------------------------------------------------------------------*
*&      Form  F4_FILE_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILE_PATH  text
*----------------------------------------------------------------------*
FORM f4_file_process USING p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    IMPORTING
      file_name     = p_file.

  IF sy-subrc NE 0.
    MESSAGE e000(zsd).
  ENDIF.

ENDFORM.                    " F4_FILE_PROCESS

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_data .

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = itab[]
    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.

ENDFORM.                    " UPLOAD_DATA

Hope this helps you.

Regards,

Tarun

Former Member
0 Kudos

Thanks!

Former Member
0 Kudos

DATA : g_s_col TYPE i VALUE '1',

g_s_row TYPE i VALUE '1',

g_e_col TYPE i VALUE '220',

g_e_row TYPE i VALUE '600',

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_excel

i_begin_col = g_s_col

i_begin_row = g_s_row

i_end_col = g_e_col

i_end_row = g_e_row

TABLES

intern = g_t_excel_upload

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

Regards,

Joan

0 Kudos

My excel is in open office and is not getting uploaded at all. i have tried all the three approaches!

Regards,

priyanka

Edited by: priyanka negi on Apr 20, 2009 11:05 AM

Former Member
0 Kudos

Hi,

You can do like:



TYPE-POOLS truxs.


DATA: it_raw TYPE truxs_t_text_data.
*      internal table declared to be passed in the
*      function module used to convert data from xls to sap
*&---------------------------------------------------------------------*
*&At selection screen
*&---------------------------------------------------------------------*

  SELECTION-SCREEN BEGIN OF BLOCK b2  WITH FRAME TITLE text-004.
* parameter declared to browse file from presentation server
  PARAMETERS : p_file TYPE rlgrap-filename OBLIGATORY .
  SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*&---------------------------------------------------------------------*
*& Subroutine created to put F4 functionality on the selection screen
*& for the user to browse the file from the presentation server
*&---------------------------------------------------------------------*

  PERFORM f4_file_process USING p_file.


START-OF-SELECTION.
*&---------------------------------------------------------------------*
*&Function module called to upload xls data into an internal table
*&---------------------------------------------------------------------*

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw
      i_filename           = p_file                 "file path browsed
    TABLES
      i_tab_converted_data = it_upload[]            "int table populated having fields same as uploaded file
    EXCEPTIONS
      conversion_failed    = 1                      "browsed file's data
      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.

FORM f4_file_process  USING    p_p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    IMPORTING
      file_name     = p_p_file.
  IF sy-subrc NE 0.
    MESSAGE e000(zsd).
  ENDIF.

ENDFORM.                    " F4_FILE_PROCESS

Hope it helps

Regards

Mansi

0 Kudos

Thanks guys!!!