Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

Upload Excel File data to ALV GRID

$
0
0

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

 

  1. *&---------------------------------------------------------------------*
  2. *& Report  ZOPEN_XLS
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. INCLUDE ZOPEN_XLS_TOP                           .    " global Data
  9. * INCLUDE ZOPEN_XLS_O01                           .  " PBO-Modules
  10. * INCLUDE ZOPEN_XLS_I01                           .  " PAI-Modules
  11. INCLUDE ZOPEN_XLS_F01                           .  " FORM-Routines
  12. *****************Defenição de parametro de seleção
  13. PARAMETERS P_FILE(1024) TYPE C.
  14. *****************Evento para ativar o matchcode
  15. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  16. *****************Metodo para exibir o popup de seleção de arquivos
  17.   CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
  18.     CHANGING
  19.       FILE_TABLE              = IT_FILE
  20.       RC                      = V_RC
  21.     EXCEPTIONS
  22.       FILE_OPEN_DIALOG_FAILED = 1
  23.       CNTL_ERROR              = 2
  24.       ERROR_NO_GUI            = 3
  25.       NOT_SUPPORTED_BY_GUI    = 4
  26.       OTHERS                  = 5.
  27.   IF SY-SUBRC <> 0.
  28.     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  29.               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  30.   ELSE.
  31. ******************Identifica o arquivo selecionado e joga para o parametro de seleção
  32.     READ TABLE IT_FILE INTO WA_FILE INDEX 1.
  33.     P_FILE = WA_FILE-FILENAME.
  34.   ENDIF.
  35. LV_FILE = P_FILE.
  36. START-OF-SELECTION.
  37.   PERFORM F_UPLOAD.
  38. END-OF-SELECTION.
  39.   IF NOT IT_OUTDATA IS INITIAL.
  40.     PERFORM F_FIELDCAT_ALV.
  41.     PERFORM F_DISPLAY_ALV.
  42.   ENDIF.
  43. /////////////////////////////////////////////////////////////////////////////////////////////////////
  44. *&---------------------------------------------------------------------*
  45. *& Include ZOPEN_XLS_TOP                                     Report ZOPEN_XLS
  46. *&
  47. *&---------------------------------------------------------------------*
  48. REPORT ZOPEN_XLS.
  49. TYPE-POOLS : SLIS.
  50. DATA: IT_FILE TYPE FILETABLE,
  51.       WA_FILE TYPE FILE_TABLE,
  52.       V_RC    TYPE I.
  53. TYPES : BEGIN OF TY_OUTDATA,
  54.           BUKRS TYPE ANLA-BUKRS,
  55.           ANLN1 TYPE ANLA-ANLN1,
  56.           ANLN2 TYPE ANLA-ANLN2,
  57.           ANLKL TYPE ANLA-ANLKL,
  58.           TXT50 TYPE ANLA-TXT50,
  59.           MENGE TYPE ANLA-MENGE,
  60.           GSBER TYPE ANLZ-GSBER,
  61.           KOSTL TYPE ANLZ-KOSTL,
  62.           STORT TYPE ANLZ-STORT,
  63.         END OF TY_OUTDATA.
  64. DATA :  IT_OUTDATA TYPE TABLE OF TY_OUTDATA,
  65.         WA_OUTDATA TYPE          TY_OUTDATA,
  66.         IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
  67.         WA_FCAT TYPE SLIS_FIELDCAT_ALV.
  68. **********************Variáveis para o GUI UPLOAD
  69. DATA LV_FILE TYPE STRING.
  70. //////////////////////////////////////////////////////////////////////////////////////////////////////
  71. *&---------------------------------------------------------------------*
  72. *&  Include           ZOPEN_XLS_F01
  73. *&---------------------------------------------------------------------*
  74. *&---------------------------------------------------------------------*
  75. *&      Form  F_UPLOAD
  76. *&---------------------------------------------------------------------*
  77. *       text
  78. *----------------------------------------------------------------------*
  79. *  -->  p1        text
  80. *  <--  p2        text
  81. *----------------------------------------------------------------------*
  82. FORM F_UPLOAD .
  83. *Função para fazer o upload e passar para a tabela interna.
  84. *Neste caso o tipo ASC é para arquivos TXT e Excel.
  85. *O tipo BIN é para word e pdf.
  86.   CALL FUNCTION 'GUI_UPLOAD'
  87.     EXPORTING
  88.       FILENAME                = LV_FILE
  89.       FILETYPE                = 'ASC'
  90. *     HAS_FIELD_SEPARATOR     = ' '
  91. *     HEADER_LENGTH           = 0
  92. *     READ_BY_LINE            = 'X'
  93. *     DAT_MODE                = ' '
  94. *     CODEPAGE                = ' '
  95. *     IGNORE_CERR             = ABAP_TRUE
  96. *     REPLACEMENT             = '#'
  97. *     CHECK_BOM               = ' '
  98. *     VIRUS_SCAN_PROFILE      =
  99. *     NO_AUTH_CHECK           = ' '
  100. * IMPORTING
  101. *     FILELENGTH              =
  102. *     HEADER                  =
  103.     TABLES
  104.       DATA_TAB                = IT_OUTDATA
  105.     EXCEPTIONS
  106.       FILE_OPEN_ERROR         = 1
  107.       FILE_READ_ERROR         = 2
  108.       NO_BATCH                = 3
  109.       GUI_REFUSE_FILETRANSFER = 4
  110.       INVALID_TYPE            = 5
  111.       NO_AUTHORITY            = 6
  112.       UNKNOWN_ERROR           = 7
  113.       BAD_DATA_FORMAT         = 8
  114.       HEADER_NOT_ALLOWED      = 9
  115.       SEPARATOR_NOT_ALLOWED   = 10
  116.       HEADER_TOO_LONG         = 11
  117.       UNKNOWN_DP_ERROR        = 12
  118.       ACCESS_DENIED           = 13
  119.       DP_OUT_OF_MEMORY        = 14
  120.       DISK_FULL               = 15
  121.       DP_TIMEOUT              = 16
  122.       OTHERS                  = 17.
  123.   IF SY-SUBRC <> 0.
  124. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  125. *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  126.   ENDIF.
  127. ENDFORM.
  128. *&---------------------------------------------------------------------*
  129. *&      Form  F_FIELDCAT_ALV
  130. *&---------------------------------------------------------------------*
  131. *       text
  132. *----------------------------------------------------------------------*
  133. *  -->  p1        text
  134. *  <--  p2        text
  135. *----------------------------------------------------------------------*
  136. FORM F_FIELDCAT_ALV .
  137.   REFRESH : IT_FCAT.
  138.   CLEAR : WA_FCAT.
  139.   WA_FCAT-ROW_POS = '1'.
  140.   WA_FCAT-COL_POS = '1'.
  141.   WA_FCAT-FIELDNAME = 'BUKRS'.
  142.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  143.   WA_FCAT-SELTEXT_L = TEXT-001.
  144.   APPEND WA_FCAT TO IT_FCAT.
  145.   CLEAR : WA_FCAT.
  146.   WA_FCAT-ROW_POS = '1'.
  147.   WA_FCAT-COL_POS = '2'.
  148.   WA_FCAT-FIELDNAME = 'ANLN1'.
  149.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  150.   WA_FCAT-SELTEXT_L = TEXT-002.
  151.   APPEND WA_FCAT TO IT_FCAT.
  152.   CLEAR : WA_FCAT.
  153.   WA_FCAT-ROW_POS = '1'.
  154.   WA_FCAT-COL_POS = '3'.
  155.   WA_FCAT-FIELDNAME = 'ANLN2'.
  156.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  157.   WA_FCAT-SELTEXT_L = TEXT-003.
  158.   APPEND WA_FCAT TO IT_FCAT.
  159.   CLEAR : WA_FCAT.
  160.   WA_FCAT-ROW_POS = '1'.
  161.   WA_FCAT-COL_POS = '4'.
  162.   WA_FCAT-FIELDNAME = 'ANLKL'.
  163.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  164.   WA_FCAT-SELTEXT_L = TEXT-004.
  165.   APPEND WA_FCAT TO IT_FCAT.
  166.   CLEAR : WA_FCAT.
  167.   WA_FCAT-ROW_POS = '1'.
  168.   WA_FCAT-COL_POS = '5'.
  169.   WA_FCAT-FIELDNAME = 'TXT50'.
  170.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  171.   WA_FCAT-SELTEXT_L = TEXT-005.
  172.   APPEND WA_FCAT TO IT_FCAT.
  173.   CLEAR : WA_FCAT.
  174.   WA_FCAT-ROW_POS = '1'.
  175.   WA_FCAT-COL_POS = '6'.
  176.   WA_FCAT-FIELDNAME = 'MENGE'.
  177.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  178.   WA_FCAT-SELTEXT_L = TEXT-006.
  179.   APPEND WA_FCAT TO IT_FCAT.
  180.   CLEAR : WA_FCAT.
  181.   WA_FCAT-ROW_POS = '1'.
  182.   WA_FCAT-COL_POS = '7'.
  183.   WA_FCAT-FIELDNAME = 'GSBER'.
  184.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  185.   WA_FCAT-SELTEXT_L = TEXT-007.
  186.   APPEND WA_FCAT TO IT_FCAT.
  187.   CLEAR : WA_FCAT.
  188.   WA_FCAT-ROW_POS = '1'.
  189.   WA_FCAT-COL_POS = '8'.
  190.   WA_FCAT-FIELDNAME = 'KOSTL'.
  191.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  192.   WA_FCAT-SELTEXT_L = TEXT-008.
  193.   APPEND WA_FCAT TO IT_FCAT.
  194.   CLEAR : WA_FCAT.
  195.   WA_FCAT-ROW_POS = '1'.
  196.   WA_FCAT-COL_POS = '9'.
  197.   WA_FCAT-FIELDNAME = 'STORT'.
  198.   WA_FCAT-TABNAME = 'IT_OUTDATA'.
  199.   WA_FCAT-SELTEXT_L = TEXT-009.
  200.   APPEND WA_FCAT TO IT_FCAT.
  201.   CLEAR : WA_FCAT.
  202. ENDFORM.
  203. *&---------------------------------------------------------------------*
  204. *&      Form  F_DISPLAY_ALV
  205. *&---------------------------------------------------------------------*
  206. *       text
  207. *----------------------------------------------------------------------*
  208. *  -->  p1        text
  209. *  <--  p2        text
  210. *----------------------------------------------------------------------*
  211. FORM F_DISPLAY_ALV .
  212.     CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  213.       EXPORTING
  214. *       I_INTERFACE_CHECK  = ' '
  215. *       I_BYPASSING_BUFFER = ' '
  216. *       I_BUFFER_ACTIVE    = ' '
  217.         I_CALLBACK_PROGRAM = SY-REPID
  218. *       I_CALLBACK_PF_STATUS_SET          = ' '
  219. *       I_CALLBACK_USER_COMMAND           = ' '
  220. *       I_CALLBACK_TOP_OF_PAGE            = ' '
  221. *       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
  222. *       I_CALLBACK_HTML_END_OF_LIST       = ' '
  223. *       I_STRUCTURE_NAME   =
  224. *       I_BACKGROUND_ID    = ' '
  225. *       I_GRID_TITLE       =
  226. *       I_GRID_SETTINGS    =
  227. *       IS_LAYOUT          =
  228.         IT_FIELDCAT        = IT_FCAT
  229. *       IT_EXCLUDING       =
  230. *       IT_SPECIAL_GROUPS  =
  231. *       IT_SORT            =
  232. *       IT_FILTER          =
  233. *       IS_SEL_HIDE        =
  234. *       I_DEFAULT          = 'X'
  235.         I_SAVE             = 'A'
  236. *       IS_VARIANT         =
  237. *       IT_EVENTS          =
  238. *       IT_EVENT_EXIT      =
  239. *       IS_PRINT           =
  240. *       IS_REPREP_ID       =
  241. *       I_SCREEN_START_COLUMN             = 0
  242. *       I_SCREEN_START_LINE               = 0
  243. *       I_SCREEN_END_COLUMN               = 0
  244. *       I_SCREEN_END_LINE  = 0
  245. *       I_HTML_HEIGHT_TOP  = 0
  246. *       I_HTML_HEIGHT_END  = 0
  247. *       IT_ALV_GRAPHICS    =
  248. *       IT_HYPERLINK       =
  249. *       IT_ADD_FIELDCAT    =
  250. *       IT_EXCEPT_QINFO    =
  251. *       IR_SALV_FULLSCREEN_ADAPTER        =
  252. *   IMPORTING
  253. *       E_EXIT_CAUSED_BY_CALLER           =
  254. *       ES_EXIT_CAUSED_BY_USER            =
  255.       TABLES
  256.         T_OUTTAB           = IT_OUTDATA
  257.       EXCEPTIONS
  258.         PROGRAM_ERROR      = 1
  259.         OTHERS             = 2.
  260.     IF SY-SUBRC <> 0.
  261. * Implement suitable error handling here
  262.     ENDIF.
  263. ENDFORM.

Viewing all articles
Browse latest Browse all 3523

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>