Skip to Content
avatar image
Former Member

Getting error on 'gui_upload'

Hi,

I am trying to upload excel sheet into an internal table, But i am getting error - bad data format. Can any body throw some light on it.

Thanks & Regards,

Senthil

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Oct 06, 2008 at 09:12 AM

    have you exported the excel file to CSV or tab delimited ??

    that's the format for qui upload

    kind regards

    arthur de smidt

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 06, 2008 at 09:14 AM

    Hi

    Good

    Check your formatting of data in the excel sheet ,and check the place of data fields is similar to the fields you have declare in the internal table or not.

    Thanks

    mrutyun^

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 06, 2008 at 09:15 AM

    Hi pranil,

    you may paste the part of code where u r performing the mentioned functionality.

    Which FM's are u using for this?

    You probably can use 'ALSM_EXCEL_TO_INTERNAL_TABLE' .

    Make sure the data in the file is delimeted correctly.

    Ensure the data type of the flat file matches with that of your structure of the internal table.

    Regards,

    Kiran

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 06, 2008 at 09:15 AM

    Hi,

    Check your file, the data in that file must have been in incorrect format, ie, check the separator , or the data must be of same type as specified in internal tbale fields.

    Regards,

    Omkar.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 06, 2008 at 10:23 AM

    Try out the following Code.

    It uploads the excel sheet and also all the worksheets in the single excel.

    It may be useful I guess.

    ===========

    &----


    *& Report ZSCD_TEST16

    *&

    &----


    *&

    *&

    &----


    REPORT ZSCD_TEST16.

    TYPE-POOLS: SLIS.

    • Define Screen Container

    DATA: OBJ_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

    DATA: O_ERROR TYPE REF TO I_OI_ERROR,

    O_CONTROL TYPE REF TO I_OI_CONTAINER_CONTROL,

    O_DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,

    G_SHEETS TYPE SOI_SHEETS_TABLE,

    G_SHEETNAME(20) TYPE C,

    O_SPREADSHEET TYPE REF TO I_OI_SPREADSHEET.

    DATA: G_RS_SELFIELD TYPE SLIS_SELFIELD.

    DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV. "Field catalogue

    DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

    DATA: GT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV. "Field catalogue

    DATA: GT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV. "Field catalogue

    DATA: I_LAYOUT TYPE LVC_S_LAYO.

    DATA : BEGIN OF ITAB OCCURS 0,

    NAME(30),

    SURNAME(30),

    END OF ITAB .

    DATA : BEGIN OF ITAB2 OCCURS 0,

    NAME(30),

    SURNAME(30),

    END OF ITAB2 .

    DATA : BEGIN OF ITAB1 OCCURS 0,

    NAME(30),

    SURNAME(30),

    END OF ITAB1 .

    • Data declarations.

    DATA: T_FILES1 TYPE FILETABLE,

    LS_FILE TYPE FILE_TABLE,

    S_FILES TYPE FILE_TABLE,

    V_DOC_NAME TYPE CHAR256,

    V_CHANGED TYPE INT4,

    V_RCODE TYPE INT4,

    T_RANGES TYPE SOI_RANGE_LIST,

    S_RANGES TYPE SOI_RANGE_ITEM,

    T_DATA TYPE SOI_GENERIC_TABLE,

    T_DATA1 TYPE SOI_GENERIC_TABLE,

    S_DATA TYPE SOI_GENERIC_ITEM,

    V_ACTION TYPE INT4.

    PARAMETERS : T_FILES TYPE STRING.

    • Initialization event.

    INITIALIZATION.

    CLASS C_OI_ERRORS DEFINITION LOAD.

    • Create Instance control for container

    CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_CONTAINER_CONTROL

    IMPORTING

    CONTROL = O_CONTROL

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Create generic container linked to container in screen 100

    CREATE OBJECT OBJ_CONTAINER

    EXPORTING

    CONTAINER_NAME = 'CONTAINER'

    EXCEPTIONS

    CNTL_ERROR = 1

    CNTL_SYSTEM_ERROR = 2

    CREATE_ERROR = 3

    LIFETIME_ERROR = 4

    LIFETIME_DYNPRO_DYNPRO_LINK = 5

    OTHERS = 6.

    IF SY-SUBRC <> 0.

    MESSAGE E208(00) WITH 'Error creating container'.

    ENDIF.

    • Establish connection to GUI Control

    CALL METHOD O_CONTROL->INIT_CONTROL

    EXPORTING

    R3_APPLICATION_NAME = 'Excel Document Container'

    INPLACE_ENABLED = 'X'

    PARENT = OBJ_CONTAINER

    IMPORTING

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Create Document Proxy

    CALL METHOD O_CONTROL->GET_DOCUMENT_PROXY

    EXPORTING

    DOCUMENT_TYPE = SOI_DOCTYPE_EXCEL_SHEET

    IMPORTING

    DOCUMENT_PROXY = O_DOCUMENT

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR T_FILES.

    • Call dialog to navigate to file

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

    EXPORTING

    DEFAULT_EXTENSION = '.xls'

    FILE_FILTER = '*.xls'

    INITIAL_DIRECTORY = 'C:\'

    CHANGING

    FILE_TABLE = T_FILES1

    RC = V_RCODE

    USER_ACTION = V_ACTION

    EXCEPTIONS

    FILE_OPEN_DIALOG_FAILED = 1

    CNTL_ERROR = 2

    ERROR_NO_GUI = 3

    OTHERS = 4.

    IF SY-SUBRC <> 0.

    MESSAGE E208(00) WITH 'FILE_OPEN_DIALOG'.

    ENDIF.

    READ TABLE T_FILES1 INTO LS_FILE INDEX 1.

    T_FILES = LS_FILE .

    • Start-of-selection.

    START-OF-SELECTION.

    • Only continue if User hasn't cancelled

    CHECK: V_ACTION = 0.

    *

    CONCATENATE 'FILE://' T_FILES INTO V_DOC_NAME.

    • Open Spreadsheet in SAPWORKDIR

    CALL METHOD O_DOCUMENT->OPEN_DOCUMENT

    EXPORTING

    OPEN_INPLACE = 'X'

    DOCUMENT_TITLE = 'Excel'

    DOCUMENT_URL = V_DOC_NAME

    NO_FLUSH = ''

    IMPORTING

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Open Spreadsheet interface

    CALL METHOD O_DOCUMENT->GET_SPREADSHEET_INTERFACE

    EXPORTING

    NO_FLUSH = ' '

    IMPORTING

    SHEET_INTERFACE = O_SPREADSHEET

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    perform get_sheet1.

    perform get_sheet2.

    • Close the document

    CALL METHOD O_DOCUMENT->CLOSE_DOCUMENT

    EXPORTING

    DO_SAVE = ''

    NO_FLUSH = ''

    IMPORTING

    HAS_CHANGED = V_CHANGED

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Clear Document Resources

    CALL METHOD O_DOCUMENT->RELEASE_DOCUMENT

    EXPORTING

    NO_FLUSH = ''

    IMPORTING

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Clear table of file names

    FREE: T_FILES,

    O_CONTROL.

    DATA : I TYPE I VALUE 0.

    DATA : J TYPE I VALUE 1.

    • Display the data

    LOOP AT T_DATA1 INTO S_DATA.

    AT NEW ROW.

    I = I + 1.

    J = 1.

    ENDAT.

    IF S_DATA-ROW = I.

    IF S_DATA-COLUMN = 1.

    ITAB-NAME = S_DATA-VALUE.

    ENDIF.

    IF S_DATA-COLUMN = 2.

    ITAB-SURNAME = S_DATA-VALUE.

    APPEND ITAB.

    CLEAR ITAB.

    ENDIF.

    J = J + 1.

    ENDIF.

    • WRITE:s_data-value.

    ENDLOOP.

    delete itab where name = ' ' and surname = ' '.

    • Read Sheet two

    • Display the data

    CLEAR S_DATA.

    I = 0.

    J = 1.

    LOOP AT T_DATA INTO S_DATA.

    AT NEW ROW.

    I = I + 1.

    J = 1.

    ENDAT.

    IF S_DATA-ROW = I.

    IF S_DATA-COLUMN = 1.

    ITAB2-NAME = S_DATA-VALUE.

    ENDIF.

    IF S_DATA-COLUMN = 2.

    ITAB2-SURNAME = S_DATA-VALUE.

    APPEND ITAB2.

    CLEAR ITAB2.

    ENDIF.

    J = J + 1.

    ENDIF.

    • WRITE:s_data-value.

    ENDLOOP.

    delete itab2 where name = ' ' and surname = ' '.

    PERFORM CREATE_CATALOG.

    • PERFORM DISPLAY_AVL.

    CALL SCREEN 100.

    LOOP AT ITAB.

    WRITE:/ ITAB.

    ENDLOOP.

    &----


    *& Form CREATE_CATALOG

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM CREATE_CATALOG .

    DATA WA_FCAT TYPE SLIS_FIELDCAT_ALV. "Field catalogue

    CLEAR WA_FCAT .

    WA_FCAT-TABNAME = 'ITAB1'.

    WA_FCAT-FIELDNAME = 'NAME'.

    • WA_FCAT-SELTEXT_L = 'Name'.

    • WA_FCAT-EDIT = 'X'.

    • WA_FCAT-INPUT = 'X'.

    APPEND WA_FCAT TO GT_FIELDCAT .

    CLEAR WA_FCAT .

    CLEAR WA_FCAT .

    WA_FCAT-TABNAME = 'ITAB'.

    WA_FCAT-FIELDNAME = 'NAME'.

    WA_FCAT-SELTEXT_L = 'Name'.

    WA_FCAT-EDIT = 'X'.

    WA_FCAT-INPUT = 'X'.

    APPEND WA_FCAT TO GT_FIELDCAT1 .

    CLEAR WA_FCAT .

    CLEAR WA_FCAT .

    WA_FCAT-TABNAME = 'ITAB'.

    WA_FCAT-FIELDNAME = 'SURNAME'.

    WA_FCAT-SELTEXT_L = 'Surname'.

    WA_FCAT-EDIT = 'X'.

    WA_FCAT-INPUT = 'X'.

    APPEND WA_FCAT TO GT_FIELDCAT1 .

    CLEAR WA_FCAT .

    CLEAR WA_FCAT .

    WA_FCAT-TABNAME = 'ITAB'.

    WA_FCAT-FIELDNAME = 'NAME'.

    WA_FCAT-SELTEXT_L = 'Name'.

    WA_FCAT-EDIT = 'X'.

    WA_FCAT-INPUT = 'X'.

    APPEND WA_FCAT TO GT_FIELDCAT2 .

    CLEAR WA_FCAT .

    CLEAR WA_FCAT .

    WA_FCAT-TABNAME = 'ITAB'.

    WA_FCAT-FIELDNAME = 'SURNAME'.

    WA_FCAT-SELTEXT_L = 'Surname'.

    WA_FCAT-EDIT = 'X'.

    WA_FCAT-INPUT = 'X'.

    APPEND WA_FCAT TO GT_FIELDCAT2 .

    CLEAR WA_FCAT .

    ENDFORM. " CREATE_CATALOG

    &----


    *& Form DISPLAY_SHEETONE

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM DISPLAY_SHEETONE .

    DATA WA_FCAT TYPE SLIS_FIELDCAT_ALV. "Field catalogue

    DATA: I_REPID LIKE SY-REPID.

    I_REPID = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = I_REPID

    I_CALLBACK_PF_STATUS_SET = 'STATUS1'

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND1'

    IT_FIELDCAT = GT_FIELDCAT1

    TABLES

    T_OUTTAB = ITAB

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2.

    IF SY-SUBRC <> 0.

    WRITE:/ 'Error in ALV Grid Display'.

    ENDIF.

    ENDFORM. " DISPLAY_SHEETONE

    &----


    *& Form STATUS

    &----


    • text

    ----


    • -->P_EXTAB text

    ----


    FORM STATUS1 USING P_EXTAB TYPE SLIS_T_EXTAB.

    *Pf status

    SET PF-STATUS 'STATUS1'.

    ENDFORM. " STATUS1

    &----


    *& Form USER_COMMAND

    &----


    • text

    ----


    • -->R_UCOMM text

    • -->RS_SELFIELD text

    ----


    FORM USER_COMMAND1 USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD.

    G_RS_SELFIELD = RS_SELFIELD.

    DATA : L_UCOMM TYPE SY-UCOMM.

    L_UCOMM = SY-UCOMM.

    CASE SY-UCOMM.

    WHEN 'BACK'.

    • LEAVE TO SCREEN 100.

    WHEN 'LEAV'.

    LEAVE SCREEN.

    WHEN 'SAVE'.

    DATA: L_VALID TYPE C.

    DATA: GD_REPID LIKE SY-REPID, "Exists

    REF_GRID TYPE REF TO CL_GUI_ALV_GRID.

    IF REF_GRID IS INITIAL.

    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

    IMPORTING

    E_GRID = REF_GRID.

    ENDIF.

    IF NOT REF_GRID IS INITIAL.

    CALL METHOD REF_GRID->CHECK_CHANGED_DATA

    IMPORTING

    E_VALID = L_VALID.

    ENDIF.

    G_RS_SELFIELD-REFRESH = 'X'.

    WHEN OTHERS.

    MESSAGE 'Error' TYPE 'E'.

    ENDCASE.

    ENDFORM. "USER_COMMAND1

    &----


    *& Form DISPLAY_SHEETTWO

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM DISPLAY_SHEETTWO .

    DATA WA_FCAT TYPE SLIS_FIELDCAT_ALV. "Field catalogue

    DATA: I_REPID LIKE SY-REPID.

    I_REPID = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = I_REPID

    I_CALLBACK_PF_STATUS_SET = 'STATUS1'

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND1'

    IT_FIELDCAT = GT_FIELDCAT2

    TABLES

    T_OUTTAB = ITAB2

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2.

    IF SY-SUBRC <> 0.

    WRITE:/ 'Error in ALV Grid Display'.

    ENDIF.

    ENDFORM. " DISPLAY_SHEETTWO

    &----


    *& Module STATUS_0100 OUTPUT

    &----


    • text

    ----


    MODULE STATUS_0100 OUTPUT.

    SET PF-STATUS 'SCREEN'.

    • SET TITLEBAR 'SCREEN'.

    ENDMODULE. " STATUS_0100 OUTPUT

    &----


    *& Module USER_COMMAND_0100 INPUT

    &----


    • text

    ----


    MODULE USER_COMMAND_0100 INPUT.

    CASE SY-UCOMM.

    WHEN 'SHEET1'.

    PERFORM DISPLAY_SHEETONE.

    WHEN 'SHEET2'.

    perform DISPLAY_SHEETTWO.

    WHEN 'BACK'.

    LEAVE PROGRAM.

    WHEN 'LEAV'.

    SET SCREEN 0.

    LEAVE SCREEN.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0100 INPUT

    &----


    *& Form GET_SHEET1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_SHEET1 .

    CALL METHOD O_SPREADSHEET->GET_SHEETS

    IMPORTING

    SHEETS = G_SHEETS.

    • Get Sheet

    CALL METHOD O_SPREADSHEET->SELECT_SHEET

    EXPORTING

    NAME = 'Data3'

    IMPORTING

    ERROR = O_ERROR.

    CALL METHOD O_SPREADSHEET->GET_ACTIVE_SHEET

    IMPORTING

    SHEETNAME = G_SHEETNAME.

    • Set selection for 1000 rows

    CALL METHOD O_SPREADSHEET->SET_SELECTION

    EXPORTING

    TOP = 1

    LEFT = 1

    ROWS = '100'

    COLUMNS = '2'.

    • Define Range in spreadsheet

    CALL METHOD O_SPREADSHEET->INSERT_RANGE

    EXPORTING

    NAME = 'Test'

    ROWS = '100'

    COLUMNS = '2'

    NO_FLUSH = ''

    IMPORTING

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    S_RANGES-NAME = 'Sheet3'.

    S_RANGES-ROWS = '100'.

    S_RANGES-COLUMNS = '2'.

    APPEND S_RANGES TO T_RANGES.

    • Get data

    CALL METHOD O_SPREADSHEET->GET_RANGES_DATA

    EXPORTING ALL = 'X'

    • no_flush = ' '

    IMPORTING CONTENTS = T_DATA

    ERROR = O_ERROR

    CHANGING RANGES = T_RANGES.

    **************

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    • Close document

    ENDFORM. " GET_SHEET1

    &----


    *& Form GET_SHEET2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_SHEET2 .

    • Get Sheet

    CALL METHOD O_SPREADSHEET->SELECT_SHEET

    EXPORTING

    NAME = 'Data2'

    IMPORTING

    ERROR = O_ERROR.

    CALL METHOD O_SPREADSHEET->GET_ACTIVE_SHEET

    IMPORTING

    SHEETNAME = G_SHEETNAME.

    • Set selection for 1000 rows

    CALL METHOD O_SPREADSHEET->SET_SELECTION

    EXPORTING

    TOP = 1

    LEFT = 1

    ROWS = '100'

    COLUMNS = '2'.

    • Define Range in spreadsheet

    CALL METHOD O_SPREADSHEET->INSERT_RANGE

    EXPORTING

    NAME = 'Test'

    ROWS = '100'

    COLUMNS = '2'

    NO_FLUSH = ''

    IMPORTING

    ERROR = O_ERROR.

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    CLEAR S_RANGES.

    REFRESH T_RANGES.

    S_RANGES-NAME = 'Sheet2'.

    S_RANGES-ROWS = '100'.

    S_RANGES-COLUMNS = '2'.

    APPEND S_RANGES TO T_RANGES.

    • Get data

    CALL METHOD O_SPREADSHEET->GET_RANGES_DATA

    EXPORTING ALL = 'X'

    • no_flush = ' '

    IMPORTING CONTENTS = T_DATA1

    ERROR = O_ERROR

    CHANGING RANGES = T_RANGES.

    **************

    IF O_ERROR->HAS_FAILED = 'X'.

    CALL METHOD O_ERROR->RAISE_MESSAGE

    EXPORTING

    TYPE = 'E'.

    ENDIF.

    ENDFORM. " GET_SHEET2

    ===========

    Add comment
    10|10000 characters needed characters exceeded