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

uploading data from application server which in excvel format.

Former Member
0 Likes
592

hi experts ..

please send details about how to upload the data from application server which is in excel format to internal table.

thanks & regards,

karthik.M

1 ACCEPTED SOLUTION
Read only

former_member125661
Contributor
0 Likes
568

Quick and simple.. When you read excel file, the columns are seperated by '#' or cl_abap_char_utilities=>horizontal_tab . So you need to use the following code :

OPEN DATASET '/tmp/test.xls' FOR INPUT IN TEXT MODE.

CHECK sy-subrc = 0.

DO.

READ DATASET '/tmp/test.xls' INTO v_string.

IF sy-subrc ne 0.
EXIT.
ENDIF.

SPLIT v_string AT cl_abap_char_utilities=>horizontal_tab
INTO itab-field1 itab-field2 itab-fieldn....
APPEND itab.

ENDDO.

CLOSE DATASET '/tmp/test.xls'.

3 REPLIES 3
Read only

Former Member
0 Likes
568

OPEN DATASET FILE_NAME FOR input IN TEXT MODE .

DO.

READ DATASET FILE_NAme INTO inttab.

if sy-subrc ne 0.

exit.

else.

append inttab.

endif.

enddo.

CLOSE DATASET file_name.

let me know, if u need further assistance.

Edited by: Sujamol Augustine on Apr 15, 2008 5:15 PM

Edited by: Sujamol Augustine on Apr 15, 2008 5:17 PM

Edited by: Sujamol Augustine on Apr 15, 2008 5:23 PM

Read only

venkat_o
Active Contributor
0 Likes
568

Hi Karthik, Check this sample program how interact with Application server. Everywhere comments have been given.

REPORT  zvenkitest.
DATA fname(60) VALUE '.\myfile2'.
DATA num TYPE pa0008-bet01.

OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
"opens the file for writing(OUTPUT)
DO 10 TIMES.
  num = num + 1.
  TRANSFER num TO fname.
  "This statement passes the content of data object(num) to the file specified in fname.
ENDDO.
CLOSE DATASET fname.
"this statement closes the file specified in fname.

OPEN DATASET fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
  READ DATASET fname INTO num.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  WRITE / num.
ENDDO
. Read an Excel file from presentation server We can use the Function module TEXT_CONVERT_XLS_TO_SAP to read the Excel file into the internal table. From this internal table you can fill the target internal table.
report  zvenkat-upload-xl  no standard page heading.
"----------------------------------------------------------------------
"Declarations.
"----------------------------------------------------------------------
"types
types:
      begin of t_bank_det,
        pernr(8)  type c,
        bnksa(4)  type c,
        zlsch(1)  type c,
        bkplz(10) type c,
        bkort(25) type c,
        bankn(18) type c,
      end of t_bank_det.
"work areas
data:
      w_bank_det type t_bank_det.
"internal tables
data:
      i_bank_det type table of t_bank_det.
"---------------------------------------------------------------------
" selection-screen
"----------------------------------------------------------------------
selection-screen begin of block b1 with frame title text_001.
parameters p_file type localfile.
selection-screen end of block b1.
*---------------------------------------------------------------------
"At selection-screen on value-request for p_file.
*---------------------------------------------------------------------
at selection-screen on value-request for p_file.
  perform f4_help.
*---------------------------------------------------------------------
  "Start-of-selection.
*---------------------------------------------------------------------
start-of-selection.
  perform upload_data.
*---------------------------------------------------------------------
  "End-of-selection.
*---------------------------------------------------------------------
end-of-selection.
  perform display_data.
*&---------------------------------------------------------------------*
  "Form  f4_help
*&---------------------------------------------------------------------*
form f4_help .
  data:
        l_file_name like  ibipparms-path  .

  call function 'F4_FILENAME'
    exporting
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    importing
      file_name     = l_file_name.

  p_file = l_file_name.

endform.                                                    " f4_help
*---------------------------------------------------------------------*
"Form  upload_data
*---------------------------------------------------------------------*
form upload_data .
  type-pools:truxs.
  data:li_tab_raw_data type  truxs_t_text_data.
  data:l_filename      like  rlgrap-filename.

  l_filename = p_file.
  call function 'TEXT_CONVERT_XLS_TO_SAP'
    exporting
      i_tab_raw_data       = li_tab_raw_data
      i_filename           = l_filename
    tables
      i_tab_converted_data = i_bank_det
    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
*---------------------------------------------------------------------*
" Form  display_data
*---------------------------------------------------------------------*
form display_data .
  data: char100 type char100.
  loop at i_bank_det into w_bank_det .
    if sy-tabix = 1.
      write w_bank_det.
      write / '------------------------------------------------------------'.
    else.
      write / w_bank_det.
    endif.
  endloop.

endform.                    " display_data
I hope that it helps u . Regards, Venkat.O

Read only

former_member125661
Contributor
0 Likes
569

Quick and simple.. When you read excel file, the columns are seperated by '#' or cl_abap_char_utilities=>horizontal_tab . So you need to use the following code :

OPEN DATASET '/tmp/test.xls' FOR INPUT IN TEXT MODE.

CHECK sy-subrc = 0.

DO.

READ DATASET '/tmp/test.xls' INTO v_string.

IF sy-subrc ne 0.
EXIT.
ENDIF.

SPLIT v_string AT cl_abap_char_utilities=>horizontal_tab
INTO itab-field1 itab-field2 itab-fieldn....
APPEND itab.

ENDDO.

CLOSE DATASET '/tmp/test.xls'.