Upload an excel file input into an itab,display in ALV using ABAP objects

Requirement:
Create a selection screen which takes an excel file as input with parameters emp id, emp name, salary, mnth, ph no.
Create a database table with the same fields.
The program needs to have two modes. Display mode and update mode.
Display mode only displays the file data in alv grid and update mode updates database table with similar parameters as above and also shows alv grid output.
task is to do using Object oriented approach. This should also have the facility to modify the cell values in ALV grid and once saved then it needs to update the database accordingly.
I have done the same functionality in a report program without using ABAP objects but finding difficulty in using object oriented approach.Please help me as i am new to abap-objects.
Thanks in advance.......

Hi,
The selection screen design and all remains the same.
Get all the detials which you need in your final internal table.
This internal table will be used to display in the ALV grid.
The approach remains the same as the normal programing.
Prepare a field catalog table and then use it along with the internal table to display in the grid.
The only change is that instead of FM you will have to make us of classes and their methods.
Firstly you will have to create a screen.
On this screen create a custom control object and give it some name. say for eg. CC_CONTAINER.
This will be a container on which the ALV grid object will be placed.
2 objects are needed to display the grid
CL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID.
In the PBO of the screen first create an instance of object CL_GUI_CUSTOM_CONTAINER
CREATE OBJECT y_lobj_cont
      EXPORTING
         container_name              = 'CC_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 NE 0.
      MESSAGE ID sy-msgid TYPE y_k_s NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
Then create a instance of the GRID
IF y_lobj_grid IS INITIAL.
      CREATE OBJECT y_lobj_grid
        EXPORTING
          i_parent          = y_lobj_cont
         EXCEPTIONS
           error_cntl_create = 1
           error_cntl_init   = 2
           error_cntl_link   = 3
           error_dp_create   = 4
           OTHERS            = 5 .
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE y_k_s NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDIF.
Then call the method SET_TABLE_FOR_FIRST_DISPLAY to display the grid.
CALL METHOD y_lobj_grid->set_table_for_first_display
      EXPORTING
        it_toolbar_excluding          = y_v_lt_exclude
      CHANGING
        it_outtab                     = y_li_tbl
        it_fieldcatalog               = y_li_fcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE y_k_s NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
Check the example program BCALV_GRID_EDIT for better understanding.
Regards,
Ankur Parab

Similar Messages

  • Need help in uploading an excel file into SAP

    Hi All,
    I got a requirement to upload an excel file to SAP.
    But When i tried with the FM "ALSM_EXCEL_TO_INTERNAL_TABLE" , file  not getting uploaded to internal table.
    Getting expection 2, UPLOAD_OLE...
    I think the problem is with the file... the following the sample text of the file...
    Technical IdentNo.     Line No.     Text                                 Location
    BS-PZ-180                   1     035-05 EXZENTER-SCHNECKENPUMPE             0026
    BS-PZ-180                   2          LIEFERANT : SOCSIL-INTER SA  ECUBLENS     0026
    BS-PZ-180                   3          HERSTELLER : MONO PUMPS LIMITED  MANCH     0026
    BS-PZ-180                   4          MODELL/TYP : SH 60                             0026
    But when I tried with only one Column..its getting successfully uploaded...
    Pls suggest me how to upload the file? ( May be with sample code)
    Also pls let me know hw to handle the file..which contains 5 differnt sheets of texts.. ( May be with sample code)
    Your suggestion will be highly appreciated...
    Thanks,
    Priya

    Hi,
    Use the FM: TEXT_CONVERT_XLS_TO_SAP.  It will work perfectly.  I used this function module and uploaded data from xls to sap.  check the following code:
    TYPE-POOLS: truxs.
    PARAMETERS: p_file TYPE  rlgrap-filename.
    TYPES: BEGIN OF t_datatab,
          PROP_NAME like SDOKPROP-PROP_NAME,
          PROP_CHECK like SDOKPROP-PROP_CHECK,
          TABNAME like SDOKPROP-TABNAME,
          FIELDNAME like SDOKPROP-FIELDNAME,
          DESCRIPT(30) type c,
          END OF t_datatab.
    DATA: it_datatab type standard table of t_datatab,
          itab  TYPE STANDARD TABLE OF t_datatab,
          wa_itab TYPE t_datatab,
          wa_datatab type t_datatab.
    DATA: it_raw TYPE truxs_t_text_data.
    At selection screen
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          field_name = 'P_FILE'
        IMPORTING
          file_name  = p_file.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    SELECT * FROM sdokprop INTO CORRESPONDING FIELDS OF TABLE itab
    WHERE PROP_NAME LIKE 'DMS%'.
    WRITE / 'Before Modification'.
      LOOP AT itab INTO wa_itab.
        WRITE:/1 wa_itab-PROP_NAME, 27 wa_itab-PROP_CHECK, 31 wa_itab-TABNAME, 65 wa_itab-FIELDNAME, 96 wa_itab-DESCRIPT.
        CLEAR wa_itab.
      ENDLOOP.
      CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
        I_FIELD_SEPERATOR        =
          i_line_header            =  'X'
          i_tab_raw_data           =  it_raw       " WORK TABLE
          i_filename               =  p_file
        TABLES
          i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
       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.
    END-OF-SELECTION.
    END-OF-SELECTION.
      WRITE / 'After Modification'.
    MODIFY sdokprop FROM TABLE it_datatab.
      LOOP AT it_datatab INTO wa_datatab.
        WRITE:/1 wa_datatab-PROP_NAME, 27 wa_datatab-PROP_CHECK, 31 wa_datatab-TABNAME, 65 wa_datatab-FIELDNAME, 96 wa_datatab-DESCRIPT.
        CLEAR wa_datatab.
      ENDLOOP.
      IF sy-subrc = 0.
        MESSAGE 'successfull' TYPE 'S'.
      ELSE.
        MESSAGE 'failed' TYPE 'E'.
      ENDIF.
    Regards,
    Bhaskar

  • CRM ABAP How to upload an Excel file into an internal table?

    How to upload an Excel file using GUI_UPLOAD?? what should be the values of the parameters? The function modules ALSM_EXCEL_TO_INTERNAL_TABLE and KCD_EXCEL_OLE_TO_INT are not present in CRM. Please suggest me a way out!

    Hi saurabh,
    you can try the folowing sample..
    and make modifications according to your requirement..
    TYPE-POOLS: truxs.
    DATA: i_text_data TYPE truxs_t_text_data,
    v_filename_string TYPE string.
    DATA: BEGIN OF itab OCCURS 0,
    Name(30),
    Phone(15),
    Fax(500).
    DATA: END OF itab.
    PARAMETERS: p_file LIKE rlgrap-filename.
    START-OF-SELECTION.
    v_filename_string = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_filename_string
    filetype = 'ASC'
    has_field_separator = 'X'
    * HEADER_LENGTH = 0
    * READ_BY_LINE = 'X'
    dat_mode = ''
    * IMPORTING
    * FILELENGTH =
    * HEADER =
    TABLES
    data_tab = i_text_data
    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.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
    i_field_seperator = 'X'
    * I_LINE_HEADER =
    i_tab_raw_data = i_text_data
    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.
    this is a sample code that uploads a excel file using GUI_UPLOAD, but uses another function module to convert that uploaded data into an internal table..
    regards
    satesh

  • Upload an Excel file into an Internal Table

    Hi,
    I want to upload an Excel file into an internal table but it doesn't work. I'd appreciate if someone could tell me what is wrong.
    My excel file has the following format:
          Col1  Col2
    Row1    1    2
    Row2    2    3
    Row3    3    4
    And the report code is the following one:
    REPORT ZFI_PROKON_PROCESOS.
    DATA: BEGIN OF itab OCCURS 0,
            num1(1),
            num2(1).
    DATA: END OF itab.
    PARAMETERS: p_file LIKE rlgrap-filename obligatory.
    AT SELECTION-SCREEN.
    AT SELECTION-SCREEN on value-request for p_file.
      call function 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                static    = 'X'
           CHANGING
                file_name = p_file.
    START-OF-SELECTION.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
         EXPORTING
              FILENAME                = p_file
              I_BEGIN_COL             = 1
              I_BEGIN_ROW             = 1
              I_END_COL               = 2
              I_END_ROW               = 5
         TABLES
              INTERN                  = itab
        EXCEPTIONS
             INCONSISTENT_PARAMETERS = 1
             UPLOAD_OLE              = 2
             OTHERS                  = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT itab.
      WRITE: / itab-num1, 10 itab-num2.
    ENDLOOP.
    Thanks in advance,
    Gerard

    Try function module
    ALSM_EXCEL_TO_INTERNAL_TABLE
      call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           exporting
                filename                = p_path
                i_begin_col             = 1
                i_begin_row             = 2
                i_end_col               = 70
                i_end_row               = 10000
           tables
                intern                  = i_excel
           exceptions
                inconsistent_parameters = 1
                upload_ole              = 2
                others                  = 3.
    P_PATH is file name with path.
    I_EXCEL is internal table to store data.
    declaration is "i_excel like structure alsmex_tabline"
    then loop at i_Excel and populate your table
    for eg
      loop at i_excel.
        case  i_excel-col.
          when '0001'.
            i_data-compcode              = i_excel-value.
          when '0002'.
            i_data-rcpttyp               = i_excel-value.
          when '0003'.
            i_data-pocimpro              = i_excel-value.
          when '0004'.
            i_data-tranno                = i_excel-value.
          when '0005'.
            i_data-msrpo                 = i_excel-value.
          when '0006'.
            i_data-mporel                = i_excel-value.
        endcase.
        at end of row.
          append i_data.
          clear  i_data.
        endat.
      endloop.

  • How to upload all excel files data from one folder into internal table.

    Dear All,
    I have one requirement, It is like I want to upload the frontend file data into my internal table, But here my scenario is;
    If I have one folder ( Called : Temp) in my frontend system, in this folder ( Called : Temp)  I have 100 excel files. In each excel file I have some 1000u2019s of entries. All these data of every file I want to take into my internal table.
    If I have one file I can go for, CALL METHOD cl_gui_frontend_services=>file_open_dialog and then upload method to upload. But I want to take all these excel files from that folder at a time, is there any class or any thing is there..? plz help..
    Thanks...
    Edited by: satishsuri on Jan 11, 2011 9:33 AM

    Hi satishsuri ,
    You will have to use 3 methods together :
    CALL METHOD cl_gui_frontend_services=>directory_browse "Browse the Directory
    CALL METHOD cl_gui_frontend_services=>directory_list_files "Get all the files from the directory
    CALL METHOD cl_gui_frontend_services=>gui_upload "Upload each file in a loop
    Example:
    TYPES: BEGIN OF ty_data,
             line TYPE string,
          END OF ty_data.
    DATA: str_file TYPE string,
          str_dir TYPE string,
          it_file_table TYPE STANDARD TABLE OF file_info,
          wa_file_table TYPE file_info,
          v_count TYPE i,
          it_data TYPE STANDARD TABLE OF ty_data,
          wa_data TYPE ty_data.
    CALL METHOD cl_gui_frontend_services=>directory_browse
      CHANGING
        selected_folder = str_dir.
    CALL METHOD cl_gui_frontend_services=>directory_list_files
      EXPORTING
        directory  = str_dir
      CHANGING
        file_table = it_file_table
        count      = v_count.
    LOOP AT it_file_table INTO wa_file_table.
      CONCATENATE str_dir wa_file_table-filename INTO str_file SEPARATED BY '\'.
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename = str_file
          filetype = 'ASC'
        CHANGING
          data_tab = it_data.
      LOOP AT it_data INTO wa_data.
        WRITE : / wa_data-line.
      ENDLOOP.
      ULINE.
    ENDLOOP.
    Regards,
    Jovito

  • Can anybody help how to upload an excel file into sap-crm urgent

    hi guys,
    i need the right function module to upload the excel file from the presentation server in to sap-crm.
    1) I know we use the function module 'ALSM_EXCEL_TO_INT_TABLE' in sap-r/3 but this function module is not exist in sap-crm.
    2) i tried with the function moduel 'GUI_UPLOAD' but its not uploading correctly i am gettting hases(#).
    Please can any one provide the right function module to upload the excel into sap-crm with an sample code.
    thanks
    viswa guntha

    Hi Visma,
    Please check this link for sample custom FM.
    Re: function mudule for MS excel file to sap crm
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points if helpful as away to say thanks.

  • Uploading an Excel File

    I'm doing a test on uploading an Excel file using JAVA. Right now I have my code set up to upload to an Access database. Everything works great except the last record in my Excel file is not being uploaded. I can make it load the last record by adding redundant code { stSQL.executeUpdate(strSQL);  }
    outside the loop as shown below. This doesn't really make sense to me since I am printing the last SQL statement twice, once inside the loop and once outside the loop so why the SQL statement isn't executed is beyond me. Any thoughts? Thanks,
    import java.io.*;
    import java.sql.*;
    import java.util.regex.*;
    public class UploadExcel{
    public static void main(String[] args){
    Connection connection = null;
    String TableName = "GSABill";
    String strBeginSQL = "INSERT INTO " + TableName + " VALUES( ";
    try{
    int iCount = 0;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                
    Connection con = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/test3.xls;DriverID=22;READONLY=false;" );
    Connection Access = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/temp/test.mdb;Uid=Admin;Pwd=;");
    Statement st = con.createStatement();
    Statement stSQL = Access.createStatement();
    ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );      
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    int rows;
    String strSQL;
    strSQL = "";
    while (rs.next()) {
    strSQL = strBeginSQL;
    iCount++;
    strSQL = strBeginSQL + iCount + ", ";
         for (int i = 1; i <= numberOfColumns; i++) {                                             
              String columnValue = rs.getString(i);                          
    try{
    if (!columnValue.equals("")){
    strSQL = strSQL.substring(0, strSQL.length()-1) + "'" + columnValue + "', ";
    } else {
    strSQL = strSQL.substring(0, strSQL.length()-1) + "'', ";
    } catch(Exception e) {
    strSQL = strSQL.substring(0, strSQL.length()-1) + "'', ";
    strSQL = strSQL.substring(0, strSQL.length() - 2) + ")";
    System.out.println(strSQL);
    stSQL.executeUpdate(strSQL);
    System.out.println(strSQL);
    stSQL.executeUpdate(strSQL);
    stSQL.close();
         st.close();
         con.close();
    } catch(Exception ex) {
         System.err.print("Exception: ");
         System.err.println(ex.getMessage());

    jsp file upload code (any type of file): (fileUpload.jsp)
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
         String savePath = "", filepath = "", filename = "";
         String contentType = "", fileData = "", strLocalFileName = "";
         int startPos = 0;
         int endPos = 0;
    %>
    <%!
         //copy specified number of bytes from main data buffer to temp data buffer
         void copyByte(byte [] fromBytes, byte [] toBytes, int start, int len)
              for(int i=start;i<(start+len);i++)
                   toBytes[i - start] = fromBytes;
    %>
    <%
         int BOF = 0, EOF = 0;
         contentType = request.getContentType();
         out.println("<br>Content type is :: " +contentType);
         if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
              DataInputStream in = new DataInputStream(request.getInputStream());
              DataInputStream in1 = in;
              int formDataLength = request.getContentLength();
              byte dataBytes[] = new byte[formDataLength];
              int byteRead = 0;
              int totalBytesRead = 0;
              while (totalBytesRead < formDataLength)
                   byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
                   totalBytesRead += byteRead;
              out.println("<br>totalBytesRead : " + totalBytesRead + " : formDataLength = " + formDataLength);
              //String file = new String(dataBytes);
              //out.println("<br>File Contents:<br>////////////////////////////////////<br>" + file + "<br>////////////////////////////////<br>");
              byte[] line = new byte[128];
              if (totalBytesRead < 3)     
              return;     //exit if file length is not sufficiently large
              String boundary = "";
              String s = "";
              int count = 0;          
              int pos = 0;
              //loop for extracting boundry of file
              //could also be extracted from request.getContentType()
              do
                   copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
                   count+=1;
                   s = new String(line, 0, 1);
                   fileData = fileData + s;
                   pos = fileData.indexOf("Content-Disposition: form-data; name=\""); //set the file name
                   if(pos != -1)
                        endPos = pos;
              }while(pos == -1);
              boundary = fileData.substring(startPos, endPos);
              //loop for extracting filename
              startPos = endPos;
              do
                   copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
                   count+=1;
                   s = new String(line, 0, 1);
                   fileData = fileData + s;
                   pos = fileData.indexOf("filename=\"", startPos); //set the file name
                   if(pos != -1)
                        startPos = pos;
              }while(pos == -1);                         
              do
                   copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
                   count+=1;
                   s = new String(line, 0, 1);
                   fileData = fileData + s;
                   pos = fileData.indexOf("Content-Type: ", startPos);
                   if(pos != -1)
                        endPos = pos;                              
              }while(pos == -1);
              filename = fileData.substring(startPos + 10, endPos - 3);     //to eliminate " from start & end
              strLocalFileName = filename;
              int index = filename.lastIndexOf("\\");
              if(index != -1)
                   filename = filename.substring(index + 1);
              else
                   filename = filename;
              //loop for extracting ContentType
              boolean blnNewlnFlag = false;
              startPos = endPos;     //added length of "Content-Type: "
              do
                   copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
                   count+=1;
                   s = new String(line, 0, 1);
                   fileData = fileData + s;               
                   pos = fileData.indexOf("\n", startPos);
                   if(pos != -1)
                        if(blnNewlnFlag == true)
                             endPos = pos;                         
                        else
                             blnNewlnFlag = true;
                             pos = -1;
              }while(pos == -1);
              contentType = fileData.substring(startPos + 14, endPos);
              //loop for extracting actual file data (any type of file)
              startPos = count + 1;
              do
                   copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
                   count+=1;
                   s = new String(line, 0, 1);
                   fileData = fileData + s;
                   pos = fileData.indexOf(boundary, startPos);     //check for end of file data i.e boundry value               
              }while(pos == -1);
              endPos = count - boundary.length();
              //file data extracted
              out.println("<br><br>0. Local File Name = " + strLocalFileName);
              out.println("<br><br>1. filename = " + filename);
              out.println("<br>2. contentType = " + contentType);
              out.println("<br>3. startPos = " + startPos);
              out.println("<br>4. endPos = " + endPos);
              out.println("<br>5. boundary = " + boundary);
              //create destination path & save file there
              String appPath = application.getRealPath("/");
              out.println("<br>appPath : " + appPath);
              String destFolder = appPath + "images/banner/";
              filename= destFolder + filename;
              FileOutputStream fileOut = new FileOutputStream(filename);
              fileOut.write(dataBytes, startPos, (endPos - startPos));
              fileOut.flush();
              fileOut.close();
              out.println("<br>File saved as >> " + filename);          
              //file saved at destination
              //out.println("<br>File data : <br><br>**************************<br>" + (new String(dataBytes,startPos, (endPos - startPos))) + "<br><br>**************************");
         else
              out.println("Error in uploading ");
    %>
    supporting html file:
    <form method="post" action="fileUpload.jsp" name="upform" enctype="multipart/form-data">
      <table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
        <tr>
          <td align="left"><b>Select a file to upload :</b></td>
        </tr>
        <tr>
          <td align="left">
            <input type="file" name="uploadfile" size="50">
            </td>
        </tr>
        <tr>
          <td align="left">
              <input type="hidden" name="todo" value="upload">
            <input type="submit" name="Submit" value="Upload">
            <input type="reset" name="Reset" value="Cancel">
            </td>
        </tr>
      </table> 
    </form>
    </body>
    </html>

  • How to upload an excel file using ABAP.

    Hi,
    Can anyone please help me in understanding how to upload an excel file using ABAP.
    Thanks!!

    http://diocio.wordpress.com/2007/02/12/sap-upload-excel-document-into-internal-table/
    check the link
    TYPES: Begin of t_record,
    name1 like itab-value,
    name2 like itab-value,
    age   like itab-value,
    End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
    wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
    exporting
    filename                = p_infile
    i_begin_col             = ‘1&#8242;
    i_begin_row             = ‘2&#8242;  “Do not require headings
    i_end_col               = ‘14&#8242;
    i_end_row               = ‘31&#8242;
    tables
    intern                  = itab
    exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
    if sy-subrc <> 0.
    message e010(zz) with text-001. “Problem uploading Excel Spreadsheet
    endif.
    Sort table by rows and colums
    sort itab by row col.
    Get first row retrieved
    read table itab index 1.
    Set first row retrieved to current row
    gd_currentrow = itab-row.
    loop at itab.
      Reset values for next row
    if itab-row ne gd_currentrow.
    append wa_record to it_record.
    clear wa_record.
    gd_currentrow = itab-row.
    endif.
    case itab-col.
    when ‘0001&#8242;.                              “First name
    wa_record-name1 = itab-value.
    when ‘0002&#8242;.                              “Surname
    wa_record-name2 = itab-value.
    when ‘0003&#8242;.                              “Age
    wa_record-age   = itab-value.
    endcase.
    endloop.
    append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    Display report data for illustration purposes
    loop at it_record into wa_record.
    write:/     sy-vline,
    (10) wa_record-name1, sy-vline,
    (10) wa_record-name2, sy-vline,
    (10) wa_record-age, sy-vline.
    endloop.

  • What parameters should i pass inorder to upload an excel file in gui_upload

    what parameters should i pass inorder to upload an excel file in gui_upload
    Thanks in advance.
    Ahmed.

    check below program....
    *& Report  UPLOAD_EXCEL                                                *
    *& Upload and excel file into an internal table using the following    *
    *& function module: ALSM_EXCEL_TO_INTERNAL_TABLE                       *
    REPORT  UPLOAD_EXCEL no standard page heading.
    *Data Declaration
    data: itab like alsmex_tabline occurs 0 with header line.
    Has the following format:
                Row number   | Colum Number   |   Value
         i.e.     1                 1             Name1
                  2                 1             Joe
    TYPES: Begin of t_record,
        name1 like itab-value,
        name2 like itab-value,
        age   like itab-value,
        End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
          wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           exporting
                filename                = p_infile
                i_begin_col             = '1'
                i_begin_row             = '2'  "Do not require headings
                i_end_col               = '14'
                i_end_row               = '31'
           tables
                intern                  = itab
           exceptions
                inconsistent_parameters = 1
                upload_ole              = 2
                others                  = 3.
      if sy-subrc <> 0.
        message e010(zz) with text-001. "Problem uploading Excel Spreadsheet
      endif.
    Sort table by rows and colums
      sort itab by row col.
    Get first row retrieved
      read table itab index 1.
    Set first row retrieved to current row
      gd_currentrow = itab-row.
      loop at itab.
      Reset values for next row
        if itab-row ne gd_currentrow.
          append wa_record to it_record.
          clear wa_record.
          gd_currentrow = itab-row.
        endif.
        case itab-col.
          when '0001'.                              "First name
            wa_record-name1 = itab-value.
          when '0002'.                              "Surname
            wa_record-name2 = itab-value.
          when '0003'.                              "Age
            wa_record-age   = itab-value.
        endcase.
      endloop.
      append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    Display report data for illustration purposes
      loop at it_record into wa_record.
        write:/     sy-vline,
               (10) wa_record-name1, sy-vline,
               (10) wa_record-name2, sy-vline,
               (10) wa_record-age, sy-vline.
      endloop.

  • I would like to upload a excel file using jsp

    Hi,
    I would like to upload the excel file using jsp in my netbeans ide. Please help.
    I don Know what is the error in this jsp file. It is not showing any thing and the file is also not getting uploaded.
    Please gothru the code below.
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ page import="java.io.*" errorPage="err.jsp"%>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="<html:rewrite page="/design.css" />" rel="stylesheet" type="text/css">
    <title>Upload Page</title>
    </head>
    <body onKeyDown="DisablingBackFunctionality()" onLoad="DisablingBackFunctionality()">
    <html:form action="download" >
    <div style="position:absolute; left:100;top:200;">Select an excel File :<input type="file" name="uploadfile"></div>
    <div style="position:absolute; left:190;top:250;"><input type="submit" name="Submit" value="Read"></div>
    <div style="position:absolute; left:336;top:250;"><input type="reset" name="Reset" value="Clear"></div>
    mainmenu
    </html:form>
    </body>
    </html>
    <%
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
    DataInputStream in = new DataInputStream(request.getInputStream());
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    while (totalBytesRead < formDataLength) {
    byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
    totalBytesRead += byteRead;
    String file = new String(dataBytes);
    //out.println("<br> file :"+file);
    String saveFile = file.substring(file.indexOf("filename=\"") + 10);
    //out.println("<br> savefile :"+saveFile);
    saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
    //out.println("<br> now file1 :"+saveFile);
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
    //out.println("<br> now file2 :"+saveFile);
    //out.print(dataBytes);
    String ext = "";
    if (saveFile.indexOf(".") != -1) {
    ext = saveFile.substring(saveFile.lastIndexOf("."));
    int lastIndex = contentType.lastIndexOf("=");
    //out.println("<br>lst index of"+lastIndex);
    String boundary = contentType.substring(lastIndex + 1, contentType.length());
    //out.println("<br> boundary"+boundary);
    //out.println("<br> file :"+file);
    int pos;
    pos = file.indexOf("filename=\"");
    //out.println("<br> now 0 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 1 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 2 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 3"+pos);
    int boundaryLocation = file.indexOf(boundary, pos) - 4;
    int startPos = ((file.substring(0, pos)).getBytes()).length;
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
    FileOutputStream fileOut = new FileOutputStream("D:\\" + saveFile);
    //FileOutputStream fileOut = new FileOutputStream(saveFile);
    //fileOut.write(dataBytes);
    fileOut.write(dataBytes, startPos, (endPos - startPos));
    fileOut.flush();
    fileOut.close();
    session.setAttribute("fil", saveFile);
    //out.println("File saved as " +saveFile);
    %>
    <script type="text/javascript" >
    function DisablingBackFunctionality()
    var URL;
    var i ;
    var QryStrValue;
    URL=window.location.href ;
    i=URL.indexOf("?");
    QryStrValue=URL.substring(i+1);
    if (QryStrValue!='X')
    window.location=URL + "?X";
    </script>
    Please let me know the result as soon as possible. Its my very urgent.
    Thanking Yu,
    Muthu Kumar.R

    No.
    Mylenium

  • Problem in uploading an excel file in wd abap

    I am trying to upload an excel file in wd abap but on uploading it shows me the data in the form of some codes but when i try to do the same thing using text file it works well.Plese refer the code .
    METHOD onactionon_upload .
      TYPES : BEGIN OF itab_str1,
       name(10) TYPE c,
       age(10) TYPE c,
       END OF itab_str1.
      DATA : t_table1 TYPE STANDARD TABLE OF itab_str1,
            i_data TYPE STANDARD TABLE OF string,
            lo_nd_sflight TYPE REF TO if_wd_context_node,
            lo_el_sflight TYPE REF TO if_wd_context_element,
            l_string TYPE string,
            fs_table TYPE itab_str1,
            l_xstring TYPE xstring,
            fields TYPE string_table,
            lv_field TYPE string.
      DATA : t_table TYPE if_main=>elements_data_tab,
            data_table TYPE if_main=>elements_data_tab.
      wd_context->get_attribute(
      EXPORTING
        name = 'DATASOURCE'
        IMPORTING
          value = l_xstring
    CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
      EXPORTING
        in_xstring          = l_xstring
    IMPORTING
       out_string          = l_string.
    SPLIT l_string AT cl_abap_char_utilities=>newline  INTO TABLE i_data.
    LOOP AT i_data INTO l_string.
    SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
    READ TABLE fields INTO lv_field index 1.
    fs_table-name = lv_field.
    READ TABLE fields INTO lv_field index 2.
    fs_table-age = lv_field.
    APPEND fs_table TO t_table1.
    ENDLOOP.
    lo_nd_sflight = wd_context->get_child_node( 'DATA_TAB').
    lo_nd_sflight->bind_table( t_table1 ).
    ENDMETHOD.

    Problem is not with the file format  nor Upload element.
    problem is with conversion function module, still now for conversion of xcel data to string format we dont have perfect function module.
    CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
    EXPORTING
    in_xstring = l_xstring
    IMPORTING
    out_string = l_string.
    That's a bug with xcel conversion  As of now I dont find any fm which converts  xcel data to string without any problem.
    Regards
    Srinvivas
    Edited by: sanasrinivas on Dec 23, 2011 7:02 AM

  • Need Function module to upload an excel file to SAP

    Need Function module to upload more than 100 characters of excel file data into SAP internal table.
    Currently i have two function module
    1. ALSM_EXCEL_TO_INTERNAL_TABLE --32 characters max
    2. KCD_EXCEL_OLE_TO_INT_CONVERT --50 characters max
    Please let me know some pointers.
    Thanks in Advance,
    A.Karthikeyan.

    hi,
    use the FM GUI_UPLOAD
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = W_FILENAME
       FILETYPE                      = W_FILETYPE
       HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
       DAT_MODE                      = 'X'
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                      = wp_it_upload
    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.

  • Uploading an excel file in an internal table.

    hi experts,
    I m trying to upload a excel file comprising of 16,000 records using the function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' as follws
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = p_input
                i_begin_col             = 1
                i_begin_row             = 1
                i_end_col               = 30
                i_end_row               = 65000
           TABLES
                intern                  = g_t_excel
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    My problem is I am unable to upload  record number 10001 else all the records are uploaded successfully
    can anyone help me in solving this problem

    FORM upload_itab .
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      CODEPAGE                      = ' '
       FILENAME                      = p_file
       FILETYPE                      = 'ASC'
      HEADLEN                       = ' '
      LINE_EXIT                     = ' '
      TRUNCLEN                      = ' '
      USER_FORM                     = ' '
      USER_PROG                     = ' '
      DAT_D_FORMAT                  = ' '
    IMPORTING
      FILELENGTH                    =
      TABLES
        DATA_TAB                      = itab
    EXCEPTIONS
      CONVERSION_ERROR              = 1
      FILE_OPEN_ERROR               = 2
      FILE_READ_ERROR               = 3
      INVALID_TYPE                  = 4
      NO_BATCH                      = 5
      UNKNOWN_ERROR                 = 6
      INVALID_TABLE_WIDTH           = 7
      GUI_REFUSE_FILETRANSFER       = 8
      CUSTOMER_ERROR                = 9
      NO_AUTHORITY                  = 10
      OTHERS                        = 11
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • Help with uploading an excel file to a table using an application

    Hello,
    Can anyone please help me out with this issue. I have apex application where in the end users upload an excel file to a table. For this I have followed the solution provided in this link
    http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
    Using the above solution, I was able to upload the excel data to a table "sample_tbl1" successfully with fields Id,acct_no,owner_name,process_dt. But the thing is I want accomdate a particular condition while uploading the file data, to check see if the acct_no already exists in another table say "sample_tbl2" or not. If acct_nos already exists in sample_tbl2 then give out an error displaying the list of account numbers that already exists in the database. Below is the code which I am using to upload file data to a table.
    DECLARE
    v_blob_data       BLOB; 
    v_blob_len        NUMBER; 
    v_position        NUMBER; 
    v_raw_chunk       RAW(10000); 
    v_char            CHAR(1); 
    c_chunk_len       number       := 1; 
    v_line            VARCHAR2 (32767)        := NULL; 
    v_data_array      wwv_flow_global.vc_arr2; 
    v_rows            number; 
    v_sr_no           number         := 1; 
    l_cnt             BINARY_INTEGER := 0;
    l_stepid          NUMBER := 10;
    BEGIN
    --Read data from wwv_flow_files</span> 
    select blob_content into v_blob_data 
    from wwv_flow_files 
    where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER) 
    and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER); 
    v_blob_len := dbms_lob.getlength(v_blob_data); 
    v_position := 1; 
    /* Evaluate and skip first line of data
    WHILE (v_position <= v_blob_len ) LOOP
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
    v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk)));
    v_line := v_line || v_char;
    v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved
    IF v_char = CHR(10) THEN
    -- Clear out 
    v_line := NULL;
    EXIT;
    END IF;
    END LOOP;
    -- Read and convert binary to char</span> 
    WHILE ( v_position <= v_blob_len ) LOOP 
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position); 
    v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk))); 
    v_line := v_line || v_char; 
    v_position := v_position + c_chunk_len; 
    -- When a whole line is retrieved </span> 
    IF v_char = CHR(10) THEN
    -- Convert comma to : to use wwv_flow_utilities </span> 
    v_line := REPLACE (v_line, ',', ':'); 
    -- Convert each column separated by : into array of data </span> 
    v_data_array := wwv_flow_utilities.string_to_table (v_line); 
    -- Insert data into target table
    EXECUTE IMMEDIATE 'insert into sample_tbl1(ID,ACCT_NO,OWNER_NAME,PROCESS_DT) 
    values (:1,:2,:3,:4)'
    USING 
    v_sr_no, 
    v_data_array(1), 
    v_data_array(2),
    to_date(v_data_array(3),'MM/DD/YYYY');
    -- Clear out 
    v_line := NULL; 
    v_sr_no := v_sr_no + 1; 
    l_cnt := l_cnt + SQL%ROWCOUNT;
    END IF; 
    END LOOP;
    delete from wwv_flow_files
    where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER)
    and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER);
    l_stepid  := 20;
    IF l_cnt = 0 THEN
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold">Please select a file to upload.</span></p>' ;
    ELSE
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold;color:green">File uploaded and processed ' || l_cnt || ' record(s) successfully.</span></p>';
    END IF;
    l_stepid  := 30;
    EXCEPTION WHEN OTHERS THEN
    ROLLBACK;
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold;color:red">Failed to upload the file. '||REGEXP_REPLACE(SQLERRM,'[('')(<)(>)(,)(;)(:)(")('')]{1,}', '') ||'</span></p>';
    END;
    {code}
    Can anyone please help me, how do i accomdate the condition within my existing code.
    thanks,
    Orton                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Orton,
    From your code it appears that the account No comes in the second column of the file = > v_data_array(1)
    So You can put a conditional block around the execute immediate code that inserts the records
    For instance
      SELECT count(1) INTO ln_account_no_exists from <"sample_tbl2> where account_no = v_data_array(1);
      IF (  ln_account_no_exists > 0 ) THEN
         --Account No: already exists
        <Do what you want to do here >
      ELSE
        EXECUTE IMMEDIATE ...
      END IF:
    {code}
    Inorder to handle the account no records which exists you can
      <li>Raise an exception
      <li> Write record to table or insert into collection and then use a report region in the page based on this table/collection to show error records
      <li> Append errored account No:s to the Success Message Variable programmatically(this variable is used by PLSQL process success/error message )
       {code}
        IF ( record exists)
          apex_application.g_print_success_message := apex_application.g_print_success_message||','|| v_data_array(1) ; -- Comma separated list of errored account no:s
        ELSE ...
       {code}
    Hope it helps                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • I need format for data in excel file load into info cube to planning area.

    Hi gurus,
    I need format for data in excel file load into info cube to planning area.
    can you send me what should i maintain header
    i have knowledge on like
    plant,location,customer,product,history qty,calander
    100,delhi,suresh,nokia,250,2011211
    if it is  right or wrong can u explain  and send me about excel file format.
    babu

    Hi Babu,
    The file format should be same as you want to upload. The sequence of File format should be same communication structure.
    Like,
    Initial columns with Characteristics (ex: plant,location,customer,product)
    date column (check for data format) (ex: calander)
    Last columsn with Key figures (history qty)
    Hope this helps.
    Regards,
    Nawanit

Maybe you are looking for

  • PDF does not Print on Adobe reader 8.0 or above versions

    Hi SDN, I have a webdynpro application in which I have used Adobe LiveCycle Designer for showing a pdf of Sales Order. Now those who are using Adobe reader 8.0 or higher version, the pdf is not getting opened in their systems. We have following: Adob

  • Running reports on Oracle 10.1.2 report server

    I am running a report from the application and this particular report gets stuck randomly at formatting a certain page. On the report server I see the job status as... "Job status: Running the report Formatting page 42. Please wait. " eventually the

  • Date in where clause without Trunc

    Hi, How handle a date comparision in where clause without trunc. Rightnow I am using it with 'trunc', it is very slow.. Select ColumnA,  ColumnB From Sample Where trunc(created_date,'DD-MON-YY') = '15-NOV-2011'; CREATE TABLE SAMPLE      ColumnA NUMBE

  • Outlook 2013 - Exchange 2013 - Prompts for username and password when EWS basic authentication is enabled

    So we have an Exchange 2013 environment, and a CRM solution that requires basic authentication to EWS internally.  Problem is, after a reboot of our Exchange server, all of our Outlook clients begin prompting for username and password (which nothing

  • Error msg FMCF102 and FI228

    Hi SAP Gurus I'm unable to create an invoice for a PO that was created in 2007 (previous fiscal year). Commitments created by this PO were reduced by GRs, also created in 2007. We are now in fiscal year 2008, and would like to create IR for this PO i