Updating internal table with CSV file

I have a flat file as below:
aaaa, bbbb, asdc, dfgfhg, sdfsg, sdf, sdf, sdf, dfg, sdf, sgf, drgftfgh, sgf, drgtf, swftgd, sgf,
'sjhdfjhf','2003-10-11 07:52:37','167','alkjd',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'dkjffdj ,',NULL,NULL,NULL,'1',NULL,NULL,'AR, dfkj ',
Where we can see it is separated by commas.I want to upload this one into onr internal table.I used GUI_UPLOAD and gave the logic as folows:
TYPES: BEGIN OF ttab,
rec(1000) TYPE c,
END OF ttab.
TYPES: BEGIN OF tdat,
aaaa type char10
bbbb type char10,
asdc  type char10,
dfgfhg  type char10,
sdfsg  type char10,
sdf  type char10,
sdf  type char10,
sdf  type char10,
dfg   type char10,
sdf    type char10,
sgf  type char10,
drgftfgh  type char10,
sgf  type char10,
drgtf  type char10,
swftgd  type char10,
sgf  type char10,
END OF tdat.
DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.
DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.
DATA: file_str TYPE string.
PARAMETERS: p_file TYPE localfile.
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.
file_str = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str
TABLES
data_tab = itab
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.
LOOP AT itab.
CLEAR idat.
SPLIT itab-rec AT ',' INTO idat-aaaa
idat-bbbb ,
idat-asdc  ,
idat-dfgfhg  ,
idat-sdfsg  ,
idat-sdf  ,
idat-sdf  ,
idat-sdf  ,
idat-dfg   ,
idat-sdf    ,
idat-sgf  ,
idat-drgftfgh  ,
idat-sgf  ,
idat-drgtf  ,
idat-swftgd  ,
idat-sgf  ,
APPEND idat.
ENDLOOP.
Now the issue is when I use the statement SPLIT itab-rec AT ',' this is not updating the table idat properly.Because the flat file contains the value as 'dkjffdj ,', too.
Can anyone give me some solution to update the internal table.

hI
or you delete ' from csv file before uploading it or after uploading it, in this last case u can use statament replace:
REPLACE ''' WITH SPACE INTO ITAB-FIELD.
Max

Similar Messages

  • Problem in convering internal table to CSV file

    Hi,
    Iam converting internal table data to CSV format with the code given below.
    LOOP AT it_details_final INTO wa_details_final.
    CLEAR : t_attachment.
    CONSTANTS : c_sep TYPE c VALUE ','.
    CONCATENATE wa_details_final-wf_rectype
                             wa_details_final-wf_bankn
                             wa_details_final-wf_znme1
                             wa_details_final-wf_rzawe
                             wa_details_final-wf_lifnr
                             wa_details_final-wf_chect
                             wa_details_final-wf_rwbtr
                             wa_details_final-wf_chkladat
                        cl_abap_char_utilities=>newline
               INTO t_attachment SEPARATED BY c_sep.
    APPEND t_attachment.
        CLEAR t_attachment.
      ENDLOOP.
    Problem is ,data in one of the fields contain comma ( , ).
    So, data after comma is getting shifted to the adjacent cell.
    Please help me
    Thanks & Regards,
    Sravanthi

    Hello,
    Try this perform
    the ignorefields variable is used if you dont want a particular field in the output. You can ignore it for now
      DATA: p_ignoredfields(1024).
    CONSTANTS : const_sep TYPE c VALUE ','.
    * itab to store data ready to be sent to csv file
      DATA: BEGIN OF wa_csvdata,
        line(4096),
      END OF wa_csvdata.
      DATA: gt_csvdata LIKE TABLE OF wa_csvdata.
    *&      Form  CONVERT_TO_CSV
    *       text
    FORM convert_to_csv  TABLES   lt_datatab USING value(p_ignoredfields).
      FIELD-SYMBOLS: <wa_datatab> TYPE ANY.
      FIELD-SYMBOLS: <wa_field> TYPE ANY.
    * character variable incase table fields are of a diff type (ie: int)
      DATA: lv_data TYPE string.
    * set to X if the no data has been put into the csv workarea
      DATA: flag_firstcol TYPE xflag.
    * move the structure one character to the right since first char
    *  is position 0 in SAP
      SHIFT p_ignoredfields BY 1 PLACES RIGHT.
      REFRESH gt_csvdata.
      CLEAR wa_csvdata.
      LOOP AT lt_datatab ASSIGNING <wa_datatab>.
        flag_firstcol = 'X'.
        DO.
    *  one by one assign each position of the structure to the field
          ASSIGN COMPONENT sy-index OF STRUCTURE <wa_datatab> TO <wa_field>.
          IF sy-subrc <> 0.
            EXIT.
          ELSE.
    *  if the current field needs to be ignored then continue the do loop
            IF p_ignoredfields+sy-index(1) = '.'.
              CONTINUE.
            ENDIF.
    *  we use lv_data since concatenate fails for integer types
            lv_data = <wa_field>.
    *  remove commas in the data
            WHILE sy-subrc = 0.
              REPLACE const_sep WITH '' INTO lv_data.
            ENDWHILE.
    *       if this data belongs to the first non ignored column
            IF flag_firstcol = 'X'.
              wa_csvdata = lv_data.
              flag_firstcol = ''.
            ELSE.
              CONCATENATE wa_csvdata const_sep lv_data INTO wa_csvdata.
            ENDIF.
          ENDIF.
        ENDDO.
        APPEND wa_csvdata TO gt_csvdata.
        CLEAR wa_csvdata.
      ENDLOOP.
    ENDFORM.                    " CONVERT_TO_CSV

  • Dynamically creating oracle table with csv file as source

    Hi,
    We have a requirment..TO create a dynamic external table.. Whenever the data or number of columns change in the CSV file the table should be replaced with current data and current number of columns...as we are naive experienced people in oracle please give us a clear solution.. We have tried with a code already ..But getting some errors. Code given below..
    thank you
    we have executed this code by changing the schema name and table name ..Remaining everything same ...
    Assume the following:
    - Oracle User and Schema name is ALLEXPERTS
    - Database name is EXPERTS
    - The directory object is file_dir
    - CSV file directory is /export/home/log
    - The csv file name is ALLEXPERTS_CSV.log
    - The table name is all_experts_tbl
    1. Create a directory object in Oracle. The directory will point to the directory where the file located.
    conn sys/{password}@EXPERTS as sysdba;
    CREATE OR REPLACE DIRECTORY file_dir AS '/export/home/log';
    2. Grant the directory privilege to the user
    GRANT READ ON DIRECTORY file_dir TO ALLEXPERTS;
    3. Create the table
    Connect as ALLEXPERTS user
    create table ALLEXPERTS.all_experts_tbl
    (txt_line varchar2(512))
    organization external
    (type ORACLE_LOADER
    default directory file_dir
    access parameters (records delimited by newline
    fields
    (txt_line char(512)))
    location ('ALLEXPERTS_CSV.log')
    This will create a table that links the data to a file. Now you can treat this file as a regular table where you can use SELECT statement to retrieve the data.
    PL/SQL to create the data (PSEUDO code)
    CREATE OR REPLACE PROCEDURE new_proc IS
    -- Setup the cursor
    CURSOR c_main IS SELECT *
    FROM allexperts.all_experts_tbl;
    CURSOR c_first_row IS ALLEXPERTS_CSV.logSELECT *
    FROM allexperts.all_experts_tbl
    WHERE ROWNUM = 1;
    -- Declare Variable
    l_delimiter_count NUMBER;
    l_temp_counter NUMBER:=1;
    l_current_row VARCHAR2(100);
    l_create_statements VARCHAR2(1000);
    BEGIN
    -- Get the first row
    -- Open the c_first_row and fetch the data into l_current_row
    -- Count the number of delimiter l_current_row and set the l_delimiter_count
    OPEN c_first_row;
    FETCH c_first_row INTO l_current_row;
    CLOSE c_first_row;
    l_delimiter_count := number of delimiter in l_current_row;
    -- Create the table with the right number of columns
    l_create_statements := 'CREATE TABLE csv_table ( ';
    WHILE l_temp_counter <= l_delimiter_count
    LOOP
    l_create_statement := l_create_statement || 'COL' || l_temp_counter || ' VARCHAR2(100)'
    l_temp_counter := l_temp_counter + 1;
    IF l_temp_counter <=l_delimiter_count THEN
    l_create_statement := l_create_statement || ',';
    END IF;
    END;
    l_create_statement := l_create_statement || ')';
    EXECUTE IMMEDIATE l_create_statement;
    -- Open the c_main to parse all the rows and insert into the table
    WHILE rec IN c_main
    LOOP
    -- Loop thru all the records and parse them
    -- Insert the data into the table created above
    END LOOP;

    The initial table is showing errors and the procedure is created with compilation errors
    After executing the create table i am getting the following errors
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-00554: error encountered while parsing access parameters
    KUP-01005: syntax error: found "identifier": expecting one of: "badfile,
    byteordermark, characterset, column, data, delimited, discardfile,
    disable_directory_link_check, exit, fields, fixed, load, logfile, language,
    nodiscardfile, nobadfile, nologfile, date_cache, processing, readsize, string,
    skip, territory, varia"
    KUP-01008: the bad identifier was: deli
    KUP-01007: at line 1 column 9
    ORA-06512: at "SYS.ORACLE_LOADER", line 19

  • Csvde update user info with csv file

    I see many ways how to do this online but I don't understand how to write the entire script myself from what's being showed online, being it from a video or from another forum - due to everyone else s' methods involves different scenarios.
    I would like know what does my excel/csv file need to look like if I'm updating only each AD object inside an OU with the following:
    TELEPHONE NUMBER, FAX NUMBER, MOBILE NUMBER, TITLE - the other entries are already there, such as web address, email address, display name.
    And then what am I going to add in the command line: CSVDE -i -f mailboxdetails.csv ect?

    I agree with Ed.
    If you have a Windows 2008 R2 AD in place , you can achive this goal by using a .csv file and a script with couple of lines in PowerShell  .
    First create the csv file which must contains the following header and its value  (any other if you want) :
    SamAccountName,Title,FaxNumber,MobilNumber,TelephoneNumber 
    then use the below script :
    Import-Module activeDirectory
    $allusers =Import-Csv c:\users.csv
    foreach($user in $allusers)
    Set-aduser -identity $user.samaccountname -Title $user.title -mobilePhone $user.mobileNumber -Fax $user.faxNumber -add @{TelephoneNumber=$user.telephonenumber }
    Note : just change the .csv file name and it's path .
    If you found my post helpful, please give it a Helpful vote. If it answered your question, remember to mark it as an Answer. ---------- MCITP - Exchange 2010 | MCITP - Windows Server 2008 R2

  • Download int table into csv file with each column in separate column in csv

    Hi All,
    I want to download the data in internal table to CSV file. but each column in the table should come as separate column in csv format.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                = GD_FILE
          FILETYPE                = 'ASC'
          WRITE_FIELD_SEPARATOR   = 'X'
        tables
          DATA_TAB                = I_LINES_NEW
        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 NE 0.
        WRITE: 'Error ', SY-SUBRC, 'returned from GUI_DOWNLOAD SAP OUTBOUND'.
        SKIP.
      ENDIF.
    with the above values passd , I am getting csv file but all the columns in one column separated by some square symbol.
    How to separate them into different columns.
    Thanks in advance
    rgds,
    Madhuri

    Below example might help you understand on dowloading CSV file:
    TYPE-POOLS: truxs.
    DATA: i_t001 TYPE STANDARD TABLE OF t001,
          i_data TYPE truxs_t_text_data.
    SELECT * FROM t001 INTO TABLE i_t001 UP TO 20 ROWS.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
      EXPORTING
        i_field_seperator          = ','
    *   I_LINE_HEADER              =
    *   I_FILENAME                 =
    *   I_APPL_KEEP                = ' '
      TABLES
        i_tab_sap_data             = i_t001
    CHANGING
       i_tab_converted_data       = i_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.
    DATA: file TYPE string VALUE 'C:\testing.csv'.
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = file
      CHANGING
        data_tab                = i_data[]
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Regards
    Eswar

  • Upload data from Internal table to text file with  '~' separator

    can anyone help me to download data from internal table to flat file with  ''  separator. GUI_DOWNLOAD is not working in my case ....like for ''  separator

    Here it is
    REPORT  zkb_test1.
    TYPE-POOLS: truxs.
    DATA: i_scarr TYPE TABLE OF scarr,
    i_conv_data TYPE truxs_t_text_data.
    SELECT * FROM scarr INTO TABLE i_scarr.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
      EXPORTING
        i_field_seperator    = '~'
      TABLES
        i_tab_sap_data       = i_scarr
      CHANGING
        i_tab_converted_data = i_conv_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.
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = 'C:\Test1.txt'
        filetype                = 'ASC'
      CHANGING
        data_tab                = i_conv_data
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Regards
    Kathirvel

  • How to create an dynamic internal table with the structure of a ddic table

    Hi all,
    I want to fill ddic-tables (which I already created) in my abap dictionary with data out of CSV-files (which are located on the CRM-Server).  The ddic tables have different amount of fields.
    I started with creating a table which contains the name of the tables and the path to the matching CSV-file.
    At the beginning I'm filling an internal table with part of this data (the name of the ddic-tables) - after that I am looping at this internal table.
    LOOP AT lt_struc ASSIGNING <lfs_struc>.
         LOOP AT lv_itab1 INTO lv_wa1 WHERE ztab_name = <lfs_struc>.
         lv_feld = lv_wa1-zdat_name.
        ENDLOOP.
        CONCATENATE 'C:\-tmp\Exportierte Tabellen\' lv_feld INTO lv_pfad.
        Do.
        OPEN DATASET lv_pfad FOR INPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
        READ DATASET lv_pfad INTO lv_rec.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        enddo.
        REPLACE ALL OCCURRENCES OF '"' IN lv_rec WITH ''.
        SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
        INSERT into (<lfs_struc>) values lr_str_value.
        CLOSE DATASET lv_pfad.
    endloop.
    This is not the whole code, but it's working until
    SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
    I want to split all the data of lv_rec into an internal table which has the structure of the current ddic-table, but I didn't find out how to do give the internal table the structure of the ddic-table. In the code I used an internal tyble type string but I should be the structure of the matching tabel.
    If I try to create an internal table by using a fiel symbol, I am told, that the data types are not matching.
    Has anyone an idea?

    Hi Mayari,
    though you were successfull with
    METHOD cl_alv_table_create=>create_dynamic_table
    I must warn you not to use it. The reason is that the number of tables created is limited, the method uses GENERATE SUBROUTINE statement and this triggers an unwanted database commit.
    If you know the DDIC structure, it is (starting with ECC6.0) much easier:
    field-symbols:
      <table> type standard table.
    data:
      lr_data type ref to data.
    Create data lr_data type table of (<DDIC structure>).
    assign lr_data->* to <table>.
    The split code can be simplified gaining speed loosing complexity not loosing functionality.
    field-symbols:<fs_s> type any.
    field-symbols:<fs_t> type any.
    SPLIT lv_rec AT ';' INTO table it_string.
    loop at it_string assigning <fs_s>.
      assign component sy-tabix of wa_string to <fs_t>.
    if sy-subrc = 0.
      <fs_t> = <fs_s>.
    endif.
    at last.
      append <fs_itwa3> to <ft_itab3>.
    endat.
    endloop.
    Though it may work as Keshav.T suggested, there is no need to do that way.     
    Regards,
    Clemens

  • Download Internal Table in CSV format it gets downloaded in single column

    Hi All
    I am converting Internal Table in CSV format using the FM CONVERT TO CSV FORMAT and then downloading data using GUI_DOWNLOAD FM.
    I have given separator as ','.
    However when I download the data the file is opened in Excel and first 2 to 3 column are merged in to single column and there was separator shown ';'.
    How to overcome this problem.
    Amol

    hI..,
    Check this code..
    <b>
    It first downloads the data in internal table to a CSV format file..
    and then uploads the same data into another internal table and prints it..</b>
    analyze this and use accordingly..
    tables:
      spfli.
    field-symbols : <fs>, <fs1>.
    data:
      w_line(1000),
      w_field(20) type c,
      wa_spfli type spfli.
    data:
      begin of fs_spfli,
        carrid    type spfli-carrid,
        connid    type spfli-connid,
        countryfr type spfli-countryfr,
        countryto type spfli-countryto,
        fltime    type spfli-fltime,
      end of fs_spfli.
    data :
      t_file like standard table
               of w_line
          initial size 0.
    data:
      t_spfli like
    standard table
           of fs_spfli
      initial size 0.
    data:
      t_spfli_up like
        standard table
              of fs_spfli
         initial size 0.
    select carrid
           connid
           countryfr
           countryto
           fltime
      into corresponding fields of table t_spfli
      from spfli.
    loop at t_spfli into fs_spfli.
      do.
        assign component sy-index of structure fs_spfli to <fs>.
        if sy-subrc ne 0.
          exit.
        endif.
        w_field = <fs>.
        condense w_field no-gaps.
        if sy-index eq 1.
          w_line = w_field.
        else.
          concatenate w_line ',' w_field into w_line.
        endif.
      enddo.
      append w_line to t_file.
    endloop.
    call function 'GUI_DOWNLOAD'
      exporting
         BIN_FILESIZE                    =
           filename                        = 'D:\file.txt'
           filetype                        = 'ASC'
         APPEND                          = ' '
         write_field_separator           = ' '
         header                          = '00'
         TRUNC_TRAILING_BLANKS           = ' '
         WRITE_LF                        = 'X'
         COL_SELECT                      = ' '
         COL_SELECT_MASK                 = ' '
         DAT_MODE                        = ' '
         CONFIRM_OVERWRITE               = ' '
         NO_AUTH_CHECK                   = ' '
         CODEPAGE                        = ' '
         IGNORE_CERR                     = ABAP_TRUE
         REPLACEMENT                     = '#'
         WRITE_BOM                       = ' '
         TRUNC_TRAILING_BLANKS_EOL       = 'X'
         WK1_N_FORMAT                    = ' '
         WK1_N_SIZE                      = ' '
         WK1_T_FORMAT                    = ' '
         WK1_T_SIZE                      = ' '
       IMPORTING
         FILELENGTH                      =
      tables
        data_tab                           = t_FILE
         FIELDNAMES                      =
    exceptions
       file_write_error                = 1
       no_batch                        = 2
       gui_refuse_filetransfer         = 3
       invalid_type                    = 4
       no_authority                    = 5
       unknown_error                   = 6
       header_not_allowed              = 7
       separator_not_allowed           = 8
       filesize_not_allowed            = 9
       header_too_long                 = 10
       dp_error_create                 = 11
       dp_error_send                   = 12
       dp_error_write                  = 13
       unknown_dp_error                = 14
       access_denied                   = 15
       dp_out_of_memory                = 16
       disk_full                       = 17
       dp_timeout                      = 18
       file_not_found                  = 19
       dataprovider_exception          = 20
       control_flush_error             = 21
       others                          = 22.
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    clear t_FILE.
    call function 'GUI_UPLOAD'
      exporting
        filename                      = 'D:\file.txt'
       FILETYPE                       = 'ASC'
      HAS_FIELD_SEPARATOR            = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      tables
        data_tab                      = t_FILE
    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.
    clear fs_spfli.
    *constants :
    *C_HTAB value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    loop at t_file into w_line.
      do.
        if w_line eq space.
          exit.
        endif.
        split w_line at ',' into w_field w_line.
        condense w_field no-gaps.
        assign component sy-index of structure fs_spfli to <fs>.
        <fs> = w_field.
      enddo.
      append fs_spfli to t_spfli_up.
    endloop.
    loop at t_spfli_up into fs_spfli.
      do.
        assign component sy-index of structure fs_spfli to <fs>.
        if sy-subrc ne 0.
          exit.
        endif.
        write <fs>.
      enddo.
      skip.
    endloop.
    reward if it helps u..
    sai ramesh

  • How to download leading zeros from internal table to XL file

    Hi,
    i am dowanloading data from interna table to XL file using GUI_DOWNLOAD FM. i want download the leading zeros  also into xl file
    EX: 012345
    at present only "12345" is down loading into XL file. But i want "012345" into XL file.
    Please help me.

    Hi,
    Can you try with DBF format(Pass FILETYPE = 'DBF'? I remember that in this format data will be downloaded in database storage format. Just check and update if it works!!!
    This is what FM documentation says.
    'DBF' :
    The data is downloaded in dBase format. With this format, the data types are stored as well, For this reason, import problems can be avoided - for example, problems with Microsoft Excel. In particular, you can avoid problems with the interpretation of numeric values.
    Thanks,
    Vinod.

  • Dynamic Creation of Internal table WITH HEADER LINE

    Dear,
    Please show me the way of creating Internal table WITH HEADER LINE dynamically..
    Thanks,
    Nirav

    <font color='blue'>Hi Parekh,
    Have a look at the sample program for Dynamic internal table
    This program has been developed to update any table data in the dictionary. We give table name and File name as Input fields.
    <pre>
    REPORT znpmmm0201.
    *Types
    TYPES:
          BEGIN OF ty_file,
            data(4096) TYPE c,
          END OF ty_file.
    *Type-pools
    TYPE-POOLS:
          truxs.
    *Work areas
    DATA:
          wa_file      TYPE ty_file.
    *Internal tables
    DATA:
          it_file      TYPE STANDARD TABLE OF ty_file,
          it_data      TYPE truxs_t_text_data.
    DATA:
          gv_dref TYPE REF TO data,
          file_name TYPE string.
    *FIELD-SYMBOLS
    FIELD-SYMBOLS:
                   <gf_itab> TYPE STANDARD TABLE,
                   <wa>      TYPE ANY.
    *& Selection-screen
    PARAMETERS:
          p_table TYPE rsrd1-tbma_val,
          p_file  TYPE ibipparms-path.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      PERFORM f4_for_p_file CHANGING file_name .
    *& START-OF-SELECTION
    START-OF-SELECTION.
      CREATE DATA gv_dref TYPE TABLE OF (p_table).
      ASSIGN gv_dref->* TO <gf_itab>.
      PERFORM upload_data USING file_name.
      MODIFY (p_table) FROM TABLE <gf_itab>.
    *&      Form  UPLOAD_DATA
    FORM upload_data USING file.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = file
          filetype                = 'ASC'
        TABLES
          data_tab                = it_file.
      APPEND LINES OF it_file TO it_data.
      CLASS cl_abap_char_utilities DEFINITION LOAD.
      DATA: l_field_seperator.
      l_field_seperator = cl_abap_char_utilities=>horizontal_tab.
      REPLACE ALL OCCURRENCES OF '|' IN TABLE it_data WITH l_field_seperator.
      CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
        EXPORTING
          i_field_seperator    = l_field_seperator
          i_tab_raw_data       = it_data
        TABLES
          i_tab_converted_data = <gf_itab>.
    ENDFORM.                    " UPLOAD_DATA
    *&      Form  F4_FOR_p_file
    FORM f4_for_p_file CHANGING file.
      DATA:
            l_field_name LIKE  dynpread-fieldname VALUE 'P_FILE'.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = l_field_name
        IMPORTING
          file_name     = p_file.
      file = p_file.
    ENDFORM.                    " F4_FOR_p_file </pre>
    Thanks,
    Venkat.O</font>

  • Problem with .csv file

    Hi,
    I need to download the contents of my internal table in .csv format file.
    So, I am separating the contents of the internal table with ',' (comma) and storing it in another internal table t_download.
    DATA: BEGIN OF t_download OCCURS 100,
            rec(800),
          END   OF t_download.
    Now I download the contents using the FM GUI_DOWNLOAD.
    The file should contain 19 records, but it downloads only 13.
    If I separate the columns with '|' and then download, I get all 19 records downloaded.
    Please let me know if I am doing something wrong.
    Regards.

    Hi,
    Pls chk below link..
    Download CSV file
    This shud answer your question.
    Regds,
    Lalit

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_tab_converted_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.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • Excel data transfer into SAP internal table with GUI_UPLOAD

    hi all,
      i m using SRM4 system and i wanted to develop one report which will upload data from excel and convert it into IT.
    i know that many threads are posted on this topic.
    but my requirement is slight different. in the system only one function module is available that is "GUI_UPLOAD" and we want that user shd not save file as tab delimited before calling this fm. instead, program shd take care of all these things...
    please suggest something asap..
    helpful ans will be rewarded..
    thanks,
    jigs.

    Dear Jigs,
    Please go though the following lines of code:
    D A T A D E C L A R A T I O N *
    TABLES: ANEP,
    BKPF.
    TYPES: BEGIN OF TY_TABDATA,
    MANDT LIKE SY-MANDT, " Client
    ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
    ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
    ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
    ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
    ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
    ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
    ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
    END OF TY_TABDATA.
    Declaration of the Internal Table with Header Line comprising of the uploaded data.
    DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
    INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
    DATA: END OF IT_FILE_UPLOAD.
    S E L E C T I O N - S C R E E N *
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
    BEGIN OF BLOCK B2 WITH FRAME.
    PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK B2,
    END OF BLOCK B1.
    E V E N T : AT S E L E C T I O N - S C R E E N *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    PROGRAM_NAME = SYST-REPID
    DYNPRO_NUMBER = SYST-DYNNR
    FIELD_NAME = ' '
    STATIC = 'X'
    MASK = '.'
    CHANGING
    FILE_NAME = P_FNAME
    EXCEPTIONS
    MASK_TOO_LONG = 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.
    E V E N T : S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Upload Excel file into Internal Table.
    PERFORM UPLOAD_EXCEL_FILE.
    Organize the uploaded data into another Internal Table.
    PERFORM ORGANIZE_UPLOADED_DATA.
    E V E N T : E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    *& Form UPLOAD_EXCEL_FILE
    text
    --> p1 text
    <-- p2 text
    FORM UPLOAD_EXCEL_FILE .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = P_FNAME
    I_BEGIN_COL = 1
    I_BEGIN_ROW = 3
    I_END_COL = 7
    I_END_ROW = 32000
    TABLES
    INTERN = IT_FILE_UPLOAD
    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.
    ENDFORM. " UPLOAD_EXCEL_FILE
    *& Form ORGANIZE_UPLOADED_DATA
    text
    --> p1 text
    <-- p2 text
    FORM ORGANIZE_UPLOADED_DATA .
    SORT IT_FILE_UPLOAD BY ROW
    COL.
    LOOP AT IT_FILE_UPLOAD.
    CASE IT_FILE_UPLOAD-COL.
    WHEN 1.
    WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
    WHEN 2.
    WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
    WHEN 3.
    WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
    WHEN 4.
    WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
    WHEN 5.
    WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
    WHEN 6.
    WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
    WHEN 7.
    WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
    ENDCASE.
    AT END OF ROW.
    WA_TABDATA-MANDT = SY-MANDT.
    APPEND WA_TABDATA TO IT_TABDATA.
    CLEAR: WA_TABDATA.
    ENDAT.
    ENDLOOP.
    ENDFORM. " ORGANIZE_UPLOADED_DATA
    In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
    Regards,
    Abir
    Don't forget to award points *

  • Downloading the internal table with header to FTP folder

    Hi All,
    I have one requirement in downloading the internal table details with the fixed header line to FTP folder. The header line having the fixed text of 425 characters length.
    Note: We are not suppose to use WS_DOWNLOAD and GUI_DOWNLOAD function modules.
    Thanks in advance for your reply.
    Regards
    Kamini.

    Hi,
    I can download the internal table details successfully to FTP folder using the FTP function modules like(FTP_CONNECT, FTP_COMMAND , FTP_R/3_TO_SERVER and FTP_DISCONNECT). Here my problem is I am unable to download the internation table with some header text.
    You can see the format (example) of file to be download.
    Here I can successfully download the below details without the header. But I am unable to download with header line. Could you please suggest me.
    seq_no|record_action|trans_date|sku|description|
    1|N|2008-01-03 07:52:31|TTASA5025CBO     
    2|N|2008-01-03 10:28:33|411014        
    3|N|2008-01-03 10:01:03|TTASA6030CBO  
    4|N|2008-01-03 10:01:15|TTASA6630CBO
    5|N|2008-01-03 10:01:25|TTASA7035CBO 
    6|N|2008-01-08 16:57:39|TT6G       
    Regards
    Kamini.

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

Maybe you are looking for