Hello,
I am new in ABAP, and i am trying to upload an Excel file to ALV. I am using the function "GUI_UPLOAD" to get the data from the excel to the internal table, but the data is not passing to my itenral table, i dont know what i am doing wrong, and would appreciate any help you guys could give me. The Excel file i am trying to pass is a table of Assets from a company.
Thank you very much in advance
Regards
Miguel
- *&---------------------------------------------------------------------*
- *& Report ZOPEN_XLS
- *&
- *&---------------------------------------------------------------------*
- *&
- *&
- *&---------------------------------------------------------------------*
- INCLUDE ZOPEN_XLS_TOP . " global Data
- * INCLUDE ZOPEN_XLS_O01 . " PBO-Modules
- * INCLUDE ZOPEN_XLS_I01 . " PAI-Modules
- INCLUDE ZOPEN_XLS_F01 . " FORM-Routines
- *****************Defenição de parametro de seleção
- PARAMETERS P_FILE(1024) TYPE C.
- *****************Evento para ativar o matchcode
- AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
- *****************Metodo para exibir o popup de seleção de arquivos
- CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
- CHANGING
- FILE_TABLE = IT_FILE
- RC = V_RC
- EXCEPTIONS
- FILE_OPEN_DIALOG_FAILED = 1
- CNTL_ERROR = 2
- ERROR_NO_GUI = 3
- NOT_SUPPORTED_BY_GUI = 4
- OTHERS = 5.
- IF SY-SUBRC <> 0.
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
- ELSE.
- ******************Identifica o arquivo selecionado e joga para o parametro de seleção
- READ TABLE IT_FILE INTO WA_FILE INDEX 1.
- P_FILE = WA_FILE-FILENAME.
- ENDIF.
- LV_FILE = P_FILE.
- START-OF-SELECTION.
- PERFORM F_UPLOAD.
- END-OF-SELECTION.
- IF NOT IT_OUTDATA IS INITIAL.
- PERFORM F_FIELDCAT_ALV.
- PERFORM F_DISPLAY_ALV.
- ENDIF.
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- *&---------------------------------------------------------------------*
- *& Include ZOPEN_XLS_TOP Report ZOPEN_XLS
- *&
- *&---------------------------------------------------------------------*
- REPORT ZOPEN_XLS.
- TYPE-POOLS : SLIS.
- DATA: IT_FILE TYPE FILETABLE,
- WA_FILE TYPE FILE_TABLE,
- V_RC TYPE I.
- TYPES : BEGIN OF TY_OUTDATA,
- BUKRS TYPE ANLA-BUKRS,
- ANLN1 TYPE ANLA-ANLN1,
- ANLN2 TYPE ANLA-ANLN2,
- ANLKL TYPE ANLA-ANLKL,
- TXT50 TYPE ANLA-TXT50,
- MENGE TYPE ANLA-MENGE,
- GSBER TYPE ANLZ-GSBER,
- KOSTL TYPE ANLZ-KOSTL,
- STORT TYPE ANLZ-STORT,
- END OF TY_OUTDATA.
- DATA : IT_OUTDATA TYPE TABLE OF TY_OUTDATA,
- WA_OUTDATA TYPE TY_OUTDATA,
- IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
- WA_FCAT TYPE SLIS_FIELDCAT_ALV.
- **********************Variáveis para o GUI UPLOAD
- DATA LV_FILE TYPE STRING.
- //////////////////////////////////////////////////////////////////////////////////////////////////////
- *&---------------------------------------------------------------------*
- *& Include ZOPEN_XLS_F01
- *&---------------------------------------------------------------------*
- *&---------------------------------------------------------------------*
- *& Form F_UPLOAD
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM F_UPLOAD .
- *Função para fazer o upload e passar para a tabela interna.
- *Neste caso o tipo ASC é para arquivos TXT e Excel.
- *O tipo BIN é para word e pdf.
- CALL FUNCTION 'GUI_UPLOAD'
- EXPORTING
- FILENAME = LV_FILE
- FILETYPE = 'ASC'
- * HAS_FIELD_SEPARATOR = ' '
- * HEADER_LENGTH = 0
- * READ_BY_LINE = 'X'
- * DAT_MODE = ' '
- * CODEPAGE = ' '
- * IGNORE_CERR = ABAP_TRUE
- * REPLACEMENT = '#'
- * CHECK_BOM = ' '
- * VIRUS_SCAN_PROFILE =
- * NO_AUTH_CHECK = ' '
- * IMPORTING
- * FILELENGTH =
- * HEADER =
- TABLES
- DATA_TAB = IT_OUTDATA
- EXCEPTIONS
- FILE_OPEN_ERROR = 1
- FILE_READ_ERROR = 2
- NO_BATCH = 3
- GUI_REFUSE_FILETRANSFER = 4
- INVALID_TYPE = 5
- NO_AUTHORITY = 6
- UNKNOWN_ERROR = 7
- BAD_DATA_FORMAT = 8
- HEADER_NOT_ALLOWED = 9
- SEPARATOR_NOT_ALLOWED = 10
- HEADER_TOO_LONG = 11
- UNKNOWN_DP_ERROR = 12
- ACCESS_DENIED = 13
- DP_OUT_OF_MEMORY = 14
- DISK_FULL = 15
- DP_TIMEOUT = 16
- OTHERS = 17.
- 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.
- *&---------------------------------------------------------------------*
- *& Form F_FIELDCAT_ALV
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM F_FIELDCAT_ALV .
- REFRESH : IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '1'.
- WA_FCAT-FIELDNAME = 'BUKRS'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-001.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '2'.
- WA_FCAT-FIELDNAME = 'ANLN1'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-002.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '3'.
- WA_FCAT-FIELDNAME = 'ANLN2'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-003.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '4'.
- WA_FCAT-FIELDNAME = 'ANLKL'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-004.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '5'.
- WA_FCAT-FIELDNAME = 'TXT50'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-005.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '6'.
- WA_FCAT-FIELDNAME = 'MENGE'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-006.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '7'.
- WA_FCAT-FIELDNAME = 'GSBER'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-007.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '8'.
- WA_FCAT-FIELDNAME = 'KOSTL'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-008.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- WA_FCAT-ROW_POS = '1'.
- WA_FCAT-COL_POS = '9'.
- WA_FCAT-FIELDNAME = 'STORT'.
- WA_FCAT-TABNAME = 'IT_OUTDATA'.
- WA_FCAT-SELTEXT_L = TEXT-009.
- APPEND WA_FCAT TO IT_FCAT.
- CLEAR : WA_FCAT.
- ENDFORM.
- *&---------------------------------------------------------------------*
- *& Form F_DISPLAY_ALV
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM F_DISPLAY_ALV .
- CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
- EXPORTING
- * I_INTERFACE_CHECK = ' '
- * I_BYPASSING_BUFFER = ' '
- * I_BUFFER_ACTIVE = ' '
- I_CALLBACK_PROGRAM = SY-REPID
- * I_CALLBACK_PF_STATUS_SET = ' '
- * I_CALLBACK_USER_COMMAND = ' '
- * I_CALLBACK_TOP_OF_PAGE = ' '
- * I_CALLBACK_HTML_TOP_OF_PAGE = ' '
- * I_CALLBACK_HTML_END_OF_LIST = ' '
- * I_STRUCTURE_NAME =
- * I_BACKGROUND_ID = ' '
- * I_GRID_TITLE =
- * I_GRID_SETTINGS =
- * IS_LAYOUT =
- IT_FIELDCAT = IT_FCAT
- * IT_EXCLUDING =
- * IT_SPECIAL_GROUPS =
- * IT_SORT =
- * IT_FILTER =
- * IS_SEL_HIDE =
- * I_DEFAULT = 'X'
- I_SAVE = 'A'
- * IS_VARIANT =
- * IT_EVENTS =
- * IT_EVENT_EXIT =
- * IS_PRINT =
- * IS_REPREP_ID =
- * I_SCREEN_START_COLUMN = 0
- * I_SCREEN_START_LINE = 0
- * I_SCREEN_END_COLUMN = 0
- * I_SCREEN_END_LINE = 0
- * I_HTML_HEIGHT_TOP = 0
- * I_HTML_HEIGHT_END = 0
- * IT_ALV_GRAPHICS =
- * IT_HYPERLINK =
- * IT_ADD_FIELDCAT =
- * IT_EXCEPT_QINFO =
- * IR_SALV_FULLSCREEN_ADAPTER =
- * IMPORTING
- * E_EXIT_CAUSED_BY_CALLER =
- * ES_EXIT_CAUSED_BY_USER =
- TABLES
- T_OUTTAB = IT_OUTDATA
- EXCEPTIONS
- PROGRAM_ERROR = 1
- OTHERS = 2.
- IF SY-SUBRC <> 0.
- * Implement suitable error handling here
- ENDIF.
- ENDFORM.