How to handle newline within quotes in csv

Hello experts,
I have an issue with reading a csv file which contains newline as a part of one of the fields (within double quotes).
I'm using the file content conversion in sender file adapter with the following
NameA.fieldNames = field1, field2, field3, field4
NameA.fieldSeparator = ,
NameA.processFieldNames = fromConfiguration
NameA.enclosureSign = "
NameA.enclosureSignEscape = ""
NameA.endSeparator = 'nl'
This doesn't work. The sender channel treats the newline within double quotes as a new record and is not reading the file correctly.
I though the NameA.enclosureSign and NameA.enclosureSignEscape parameters would do the trick and ignore text that's between the double quotes?
An I missing some Content conversion cofiguration here? Some parameter that I need to set?
Please help resolve this.
Thanks
Karthik

Hi,
I have a scenario similar to this.
ClaimsRecords.fieldNames  :  CompanyName,Invoice,InvoiceDate....,Location Name,...
ClaimsRecords.fieldSeparator  :  ,
ClaimsRecords.enclosureSign  :  "
ClaimsRecords.endSeparator  :  'nl'
The sample file will look like this:
XYZ,123,21122011,......,"Delhi
India",312,...
ABC,234,22122011,......,"Bangalore
India",432,....
The new line character comes inside the value of the LocationName field. But the above entries made in FCC will handle this kind of file correctly.
Recheck the FCC entries and even check if the file is coming in correct format.
Regards,
Aravind

Similar Messages

  • How to handle line break embeded inside CSV column

    Hi there,
    I am under the pressure to make it work. I already put this question on APEX forum, but on second thought, I think it relates more to PL/SQL rather than APEX since APEX 4.1 already have utility to handle CSV Upload.
    If you read it already in APEX forum, please ignore.
    I am sorry for that. Thanks for reading.
    I need to develop an app that allows user to upload CSV file to a interface table.
    The APEX version at my workplace is 4.0.2.
    I used the code from
    http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:11000346061523
    It all works well till recently I find out
    If a column in a CSV file cotain a line break (or new line) e.g. (The tester copy and paste this text which has line break into a column in a spreadsheet)
    This is the first sentence.
    This is the second sentence.
    It will break the “This is the second sentence”. To a new column.
    The contents of the CSV viewed in Notepad look as below
    Assessment Date,Scheduled Date,Assessment Provider,Assessor Name,Court,First Name,Middle Name,Last Name,PRN Person Record Number,NHI Number,Defendant Attended Y/N,Is Dependent Y/N,Notes,Primary Ethnicity,"Ethnicity Other, please specify",Gender,Currently in Treatment Y/N,Substance of Concern 5,Other Substance Specified
    22/09/2012,,Provider Co Name,Warren Edgley,Wellington,,,Salty,2545554,dgsdf,ergerg,,"This is the first sentence.
    This is the second sentence.",Japanese,,Female,b,,
    Here is the code from the CSV UTIL, please help me to find out how can I replace the line break to a space so that the uploading process is correct.
      CREATE OR REPLACE PACKAGE BODY "CSV_UTIL"
    AS
         --strip the beginning and the end quotes, then replace double quotation with single
       FUNCTION de_quote (p_str IN VARCHAR2, p_enc_by IN VARCHAR2)
          RETURN VARCHAR2
       IS
       v_str VARCHAR2(32767) := p_str;
       BEGIN
          IF (p_enc_by IS NULL)
          THEN
             RETURN p_str;
          ELSE
            IF SUBSTR(p_str,-1) = p_enc_by THEN
               v_str := SUBSTR(p_str,1,LENGTH(p_str)-1);
            END IF;
            IF SUBSTR(p_str,1,1) = p_enc_by THEN
               v_str := SUBSTR(v_str,2);
            END IF; 
            RETURN REPLACE (v_str,
                             p_enc_by || p_enc_by,
                             p_enc_by
          END IF;
       END de_quote;
       PROCEDURE parse (p_str IN VARCHAR2, p_enc_by IN VARCHAR2, p_sep IN VARCHAR2)
       IS
          l_n          NUMBER   DEFAULT 1;
          l_in_quote   BOOLEAN  DEFAULT FALSE;
          l_ch         NCHAR (1);
          l_len        NUMBER   DEFAULT NVL (LENGTH (p_str), 0);
       BEGIN
          IF (l_len = 0)
          THEN
             RETURN;
          END IF;
          g_words := g_empty;
          g_words (1) := NULL;
          FOR i IN 1 .. l_len
          LOOP
             l_ch := SUBSTR (p_str, i, 1);
             IF (l_ch = p_enc_by)
             THEN
                l_in_quote := NOT l_in_quote;
             END IF;
             IF (l_ch = p_sep AND NOT l_in_quote)
             THEN
                l_n := l_n + 1;
                g_words (l_n) := NULL;
             ELSE
                g_words (l_n) := g_words (l_n) || l_ch;
             END IF;
          END LOOP;
          g_words (l_n) := de_quote (g_words (l_n), CHR(10));
          g_words (l_n) := de_quote (g_words (l_n), CHR(13));
          FOR i IN 1 .. l_n
          LOOP
             g_words (i) := de_quote (g_words (i), p_enc_by);
          END LOOP;
       END parse;
    Author: Oleg Lihvoinen
    Company: DbSWH
    Changes:
    10.02.2011, There was a miscalculation of the file line last position in case it is the end of file
       PROCEDURE upload (p_file_name VARCHAR2, p_collection_name VARCHAR2, p_enc_by IN VARCHAR2, p_sep_by IN VARCHAR2, p_rows NUMBER)
       IS
          v_blob_data    BLOB;
          v_clob_data    CLOB;
          v_clob_len     NUMBER;
          v_position     NUMBER;
          v_char         NCHAR (1);
          c_chunk_len    NUMBER           := 1;
          v_line         VARCHAR2 (32767) := NULL;
          v_data_array   vcarray;
          v_rows         NUMBER           := 0;
          n_seq          NUMBER           := 1;
          dest_offset    NUMBER           := 1;
          src_offset     NUMBER           := 1;
          amount         INTEGER          := DBMS_LOB.lobmaxsize;
          blob_csid      NUMBER           := DBMS_LOB.default_csid;
          lang_ctx       INTEGER          := DBMS_LOB.default_lang_ctx;
          warning        INTEGER;
          l_sep          VARCHAR2(100)    := CASE WHEN p_sep_by = '\t' THEN chr(9) ELSE p_sep_by END;
       BEGIN
          htmldb_collection.create_or_truncate_collection
                                          (p_collection_name      => p_collection_name);
          -- Read blob from wwv_flow_files
          SELECT blob_content
            INTO v_blob_data
            FROM wwv_flow_files
           WHERE NAME = p_file_name;
          v_position := 1;
          DBMS_LOB.createtemporary (lob_loc      => v_clob_data,
                                    CACHE        => TRUE,
                                    dur          => DBMS_LOB.SESSION
          DBMS_LOB.converttoclob (v_clob_data,
                                  v_blob_data,
                                  amount,
                                  dest_offset,
                                  src_offset,
                                  blob_csid,
                                  lang_ctx,
                                  warning
          v_clob_len := DBMS_LOB.getlength (v_clob_data);
          IF v_clob_len = 0 THEN
             RETURN;
          END IF;
          WHILE (v_position <= v_clob_len + 1)
          LOOP
             v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
             v_line := v_line || v_char;
             v_position := v_position + c_chunk_len;
             -- When the whole line is retrieved and not end of file or end of file
             IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
             THEN
                parse (p_str => v_line, p_enc_by => p_enc_by, p_sep => l_sep);
                v_data_array := g_words;
                FOR i IN 1..g_words.count LOOP
                   IF i <= 50 THEN
                      v_data_array(i) := g_words(i);
                   ELSE
                      exit;
                   END IF;
                END LOOP;
                FOR i IN g_words.count + 1..50 LOOP
                   v_data_array(i) := null;
                END LOOP;           
                v_rows := v_rows + 1;
                -- exit if uploaded specified number of rows
                IF p_rows IS NOT NULL AND v_rows > p_rows THEN
                   EXIT;
                END IF;
                -- Store data to collection
                n_seq :=
                   htmldb_collection.add_member
                                         (p_collection_name      => p_collection_name,
                                          p_c001                 => v_data_array
                                                                               (1),
                                          p_c002                 => v_data_array
                                                                               (2),
                                          p_c003                 => v_data_array
                                                                               (3),
                                          p_c004                 => v_data_array
                                                                               (4),
                                          p_c005                 => v_data_array
                                                                               (5),
                                          p_c006                 => v_data_array
                                                                               (6),
                                          p_c007                 => v_data_array
                                                                               (7),
                                          p_c008                 => v_data_array
                                                                               (8),
                                          p_c009                 => v_data_array
                                                                               (9),
                                          p_c010                 => v_data_array
                                                                               (10),
                                          p_c011                 => v_data_array
                                                                               (11),
                                          p_c012                 => v_data_array
                                                                               (12),
                                          p_c013                 => v_data_array
                                                                               (13),
                                          p_c014                 => v_data_array
                                                                               (14),
                                          p_c015                 => v_data_array
                                                                               (15),
                                          p_c016                 => v_data_array
                                                                               (16),
                                          p_c017                 => v_data_array
                                                                               (17),
                                          p_c018                 => v_data_array
                                                                               (18),
                                          p_c019                 => v_data_array
                                                                               (19),
                                          p_c020                 => v_data_array
                                                                               (20),
                                          p_c021                 => v_data_array
                                                                               (21),
                                          p_c022                 => v_data_array
                                                                               (22),
                                          p_c023                 => v_data_array
                                                                               (23),
                                          p_c024                 => v_data_array
                                                                               (24),
                                          p_c025                 => v_data_array
                                                                               (25),
                                          p_c026                 => v_data_array
                                                                               (26),
                                          p_c027                 => v_data_array
                                                                               (27),
                                          p_c028                 => v_data_array
                                                                               (28),
                                          p_c029                 => v_data_array
                                                                               (29),
                                          p_c030                 => v_data_array
                                                                               (30),
                                          p_c031                 => v_data_array
                                                                               (31),
                                          p_c032                 => v_data_array
                                                                               (32),
                                          p_c033                 => v_data_array
                                                                               (33),
                                          p_c034                 => v_data_array
                                                                               (34),
                                          p_c035                 => v_data_array
                                                                               (35),
                                          p_c036                 => v_data_array
                                                                               (36),
                                          p_c037                 => v_data_array
                                                                               (37),
                                          p_c038                 => v_data_array
                                                                               (38),
                                          p_c039                 => v_data_array
                                                                               (39),
                                          p_c040                 => v_data_array
                                                                               (40),
                                          p_c041                 => v_data_array
                                                                               (41),
                                          p_c042                 => v_data_array
                                                                               (42),
                                          p_c043                 => v_data_array
                                                                               (43),
                                          p_c044                 => v_data_array
                                                                               (44),
                                          p_c045                 => v_data_array
                                                                               (45),
                                          p_c046                 => v_data_array
                                                                               (46),
                                          p_c047                 => v_data_array
                                                                               (47),
                                          p_c048                 => v_data_array
                                                                               (48),
                                          p_c049                 => v_data_array
                                                                               (49),
                                          p_c050                 => v_data_array
                                                                               (50)                                                                          
                -- Clear the line
                v_line := NULL;
             END IF;
          END LOOP;
       END;
    END;In my apps, I save these straight into a table rather than an APEX collection because the number of columns can be longer than 50.
    I want to find out how can replace these line break inside a column to a space.
    If any one has any ideas, please let me know.
    Thanks a lot in advance.
    Ann

    Ann586341 wrote:
    I think the code split the whole thing by this line
    -- When the whole line is retrieved and not end of file or end of file
    IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
    THEN
    Yes, exactly. That piece of code believes all CHR(10) occurences are record delimiters.
    It is not smart enough to recognize that a CHR(10) within quotation marks are part of the data.
    Optimally a solution should keep the CHR(10) rather than replacing with spaces, but that will be a bigger rewrite of the UTL_CSV code ;-)
    If you are happy with replacing with spaces, a "simple" solution could be something like:
    Declare a boolean variable in upload procedure:
    v_within_text_column   boolean := false;And use it like this:
          WHILE (v_position <= v_clob_len + 1)
          LOOP
             v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
             IF v_char = '"' THEN
               v_within_text_column := NOT v_within_text_column;
             ELSIF v_char = CHR(10) AND v_within_text_column THEN
               v_char := ' ';
             END IF;
             v_line := v_line || v_char;
             v_position := v_position + c_chunk_len;
             -- When the whole line is retrieved and not end of file or end of file
             IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
             THEN
               v_within_text_column := false; -- To be safe always set this on "true" linebreaks
    {code}
    +(This is untested code just written here in the text editor.)+
    It should work by toggling a flag whether you are "within" the quotes or not and then replacing CHR(10) with a space if you are within a text column.
    This way we avoid having to go through the clob more than once (it is enough that this code walks the clob one character at a time...)
    It will not handle if the clob contains situations like:
    {code}
    abc,123,"This is a text with a quote from a man who said \"To Be,
    or Not To Be\" some hundred years ago",123,xyz
    {code}
    Escaped quotes would need separate attention ;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to handle single, double quotes

    Hi,
    I have a dataset which contains single- and doubble quotes.
    But when using the DS in javascript, I have problems in handing strings containing  single- and doubble quotes.
                <td onclick="myFunction('{TITLE}');">{TITLE}</td>
    {TITLE} is equal to:  I'm working with spry.
    Spry replaces it in the code as: <td onclick="myFunction('I'm working with spry');">I'm working with spry</td>
    Which leads to a quote error in the functionCall onclick().
    I've tried to solve the problem by escaping these special characters in PHP;
    - addslashes() > solves the javascript error, but give a readable text: I\'m working with spry
    - htmlspecialchars() > no change in existing problem.
    Any clues how to solve this.
    Thanks,
    Pieter

    Hi Pieter,
    When writing text in an HTML document I always use entity references (like &lsquo; for a single quote)  for special characters to not only overcome the sort of problem that you are faced with, but this is also good practice for normal rendering of text in most languages including HTML, XML and JS.
    You could also use character reference (like &#8217; for a single quote) with the same result, but DW has inbuilt functions to help with entity reference.
    Having said this, and assuming that you cannot or it is impracticable to change the data within the database, why not have two fields in your dataset, one called JS_TITLE and the other just TITLE and use each one accordingly.
    This still does not satisfy the fact that the single quote for rendering purposes is not represented by a reference, but that is another matter.
    Gramps

  • How to handle error within a FOR loop

    Hi all,
    For the code:
    begin
        for vc1 in (select *
                      from xx_primavera_invoices_detail
                     where transfered_to_ar = 0
                       and cust_trx_type_id not in (1000, 1003, 1016, 1023, 1040)
                       and act_end_date is not null) loop
          insert_into_ar_interface(vc1.amount, vc1.uom_code, vc1.quantity, vc1.unit_standard_price, vc1.cust_trx_type_id
                                  ,vc1.description, vc1.interface_line_attribute1, vc1.interface_line_attribute2, vc1.interface_line_attribute3, vc1.service_code
                                  ,vc1.gl_date, vc1.orig_system_bill_address_id, vc1.orig_system_bill_customer_id, vc1.segment2, vc1.segment3,vc1.customer_name,vc1.payment_type,vc1.currency_code)
        end loop;
        update xx_primavera_invoices_detail
           set transfered_to_ar = 1
         where transfered_to_ar = 0
           and cust_trx_type_id not in (1000, 1003, 1016, 1023, 1040)
        end;I want to add an exception statement if there is no value returned in VC1. I guess i'll never go into the loop statement because no data found in VC1 but the UPDATE will be executed...
    Any ideas?
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    "CORE     11.1.0.7.0     Production"
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionThanks in advance,
    Bahchevanov.

    Hi,
    declare
      v_i_was_in_loop  boolean;
    begin
      v_i_was_in_loop ;= false;
      for cur in (select ..)
      loop
        null;
        v_i_was_in_loop := true;
      end loop; 
    if v_i_was_in_loop = true
    then
       update...
    end if;    
    end;

  • How to handle Loop within Select For all entries

    hi all,
    i have a requirement where I need to include 2 country code .
    so in selection screen s_bukrs has AU00 - AU99 & NZ00 -NZ99
    select countrycode
             from ZCTYCOD
             into table lt_zctycod
            where ( land1 ge  s_bukrs-low(02) AND
                          land1 Le  s_bukrs-HIGH(02).
    SO countrycode entries r in table lt_zctycod.
    Now I need to loop into this SELECT ...FOR ALL ENTRIES....
    LOOP AT LT_ZCTCOD.
        SELECT * FROM zbase
                 APPENDING TABLE ts_base
                 FOR ALL ENTRIES IN ts_zdocket
                 WHERE zzumicur = ts_docket-zzumicur AND
                       ( status = c_rej OR
                         status = c_sus ) AND
                   CTYCOD = LT_ZCTCOD-Ctycod.                 
      ENDIF.
    Is there any best approach to AVOID LOOP INSIDE FOR ALL ENTRIES...any alternative approach to have good performance
    APPRECIATE UR HELP
    THANKS

    Hi,
    You can create ranges for your ZCTYCOD
    DATA: R_ZTYCODE TYPE RANGE OF ...
    so your program flow will be like this
    1. select ZTYCOD into LT_ZTYCOD
    2. loop at LT_ZTYCOD, assign each value to R_ZTYCODE
    3. select form zbase ..... where CTYCOD in R_ZTYCODE
    hope it helps

  • Handling smart/curly quotes in Java

    Hi - I want to know how to handle smart / curly quotes in Java. I need to replace them with actual quotes. I was trying somethin like below.
    xmlString = xmlString .replaceAll( "‘", "&apos;" );
    but this is not working. Just tried to print indexOf( ""‘") and it only returns -1. I was trying to use the html equiv value inside i.e &#8216(folowed by semicolon. the preview replaces it with actual value)
    Pls guide me on this. Its urgent!!
    -Thanks,
    Magesh
    Edited by: magesh_rathnam on Jan 31, 2010 7:09 PM
    Edited by: magesh_rathnam on Jan 31, 2010 7:10 PM

    I guess not then...
    Anyhow try this:
    public static String replaceSmartQuotes(String smartQuotedString) {
      return smartQuotedString.replaceAll("[“”]", "\"").replaceAll("[‘’]", "'");
    }{code}
    Mel                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to handle the quotes('') in the procedure?

    Hi all,
    I have been struggling with an issue in the procedure. Let us go to the functionality of the preocedure.
    I am passing a parameter that has text like
    ' INDIA,BANGALORE,"INOX,BLR","THILAK NAGAR,JAYA NAGAR "4TH 'T' BLOCK,BANGALORE",560030'
    Here, INDIA = country field
    BANGALORE = city field
    INOX,BLR = Theatre field
    THILAK NAGAR,JAYA NAGAR "4TH 'T' BLOCK,BANGALORE = address field
    560030 = pin field
    I want to load these fields into the table thru procedure. Here the issue is if any field value come with quotes(") inside the quotes like above address field. Since , please guide me how to handle that quotes while identifying the field value for either or address field or some other one.
    Table structure:
    country varchar2(100 char)
    city varchar2(100 char)
    theatre varchar2(100 char)
    address varchar2(2000 char)
    pin NUMBER
    Procedure Code:
    create or replace
    PROCEDURE prc_rollout_upload( p_text VARCHAR2 )
    AS
    v_quote_ind NUMBER := 0;
    v_first_pos NUMBER := 0;
    v_end_pos NUMBER := 0;
    v_text_data varchar2(32767 CHAR) := p_text;
    v_text_data1 varchar2(32767 CHAR);
    v_text_arr_ind NUMBER := 0;
    v_quote_pos NUMBER := 0;
    v_comma_pos NUMBER := 0;
    type text_rec IS RECORD(country VARCHAR2(20 CHAR),
    CITY VARCHAR2(1000 CHAR),
    exhibitor VARCHAR2(1000 CHAR),
    address VARCHAR2(10000 CHAR),
    PIN varchar2(6)
    type v_text_tab is table of text_rec;
    v_text_array v_text_tab := v_text_tab();
    BEGIN
    -- Fetch the values from the string to a PL/SQL table
    v_text_data1 := v_text_data;
    v_text_arr_ind := v_text_arr_ind + 1;
    v_text_array.extend(v_text_arr_ind);
    -- Country
    IF (INSTR(v_text_data1, CHR(34)) > 0 )
    THEN
    v_quote_ind := INSTR(v_text_data1, CHR(34));
    v_first_pos := INSTR(v_text_data1, CHR(34));
    v_end_pos := INSTR(v_text_data1, CHR(34),1,2);
    v_text_array(v_text_arr_ind).country := SUBSTR(v_text_data1,v_first_pos+1,v_end_pos-2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).country);
    v_text_data1 := SUBSTR(v_text_data1,v_end_pos+2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    END IF;
    IF ( v_quote_ind = 0 ) THEN
    v_text_array(v_text_arr_ind).country := SUBSTR(v_text_data1,1,INSTR(v_text_data1,CHR(44))-1);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).country);
    v_text_data1 := SUBSTR(v_text_data1,INSTR(v_text_data1,CHR(44))+1);
    -- DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_first_pos := 0;
    v_end_pos := 0;
    v_quote_ind := 0;
    END IF;
    -- City
    v_quote_pos := INSTR(v_text_data1,CHR(34));
    v_comma_pos := INSTR(v_text_data1,CHR(44));
    IF ( v_quote_pos < v_comma_pos )
    THEN
    v_quote_ind := INSTR(v_text_data1, CHR(34));
    v_first_pos := INSTR(v_text_data1, CHR(34));
    v_end_pos := INSTR(v_text_data1, CHR(34),1,2);
    v_text_array(v_text_arr_ind).city := SUBSTR(v_text_data1,v_first_pos+1,v_end_pos-2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).city);
    v_text_data1 := SUBSTR(v_text_data1,v_end_pos+2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    IF ( v_quote_pos > v_comma_pos ) THEN
    v_text_array(v_text_arr_ind).city := SUBSTR(v_text_data1,1,INSTR(v_text_data1,CHR(44))-1);
    -- DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).city);
    v_text_data1 := SUBSTR(v_text_data1,INSTR(v_text_data1,CHR(44))+1);
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_first_pos := 0;
    v_end_pos := 0;
    v_quote_ind := 0;
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    -- Exhibitor
    v_quote_pos := INSTR(v_text_data1,CHR(34));
    v_comma_pos := INSTR(v_text_data1,CHR(44));
    IF ( v_quote_pos < v_comma_pos )
    THEN
    v_first_pos := INSTR(v_text_data1, CHR(34));
    v_end_pos := INSTR(v_text_data1, CHR(34),1,2);
    v_text_array(v_text_arr_ind).exhibitor := SUBSTR(v_text_data1,v_first_pos+1,v_end_pos-2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).exhibitor);
    v_text_data1 := SUBSTR(v_text_data1,v_end_pos+2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    IF ( v_quote_pos > v_comma_pos ) THEN
    v_text_array(v_text_arr_ind).exhibitor := SUBSTR(v_text_data1,1,INSTR(v_text_data1,CHR(44))-1);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).exhibitor);
    v_text_data1 := SUBSTR(v_text_data1,INSTR(v_text_data1,CHR(44))+1);
    -- DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_first_pos := 0;
    v_end_pos := 0;
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    --Address
    v_quote_pos := INSTR(v_text_data1,CHR(34));
    v_comma_pos := INSTR(v_text_data1,CHR(44));
    IF ( v_quote_pos < v_comma_pos )
    THEN
    v_first_pos := INSTR(v_text_data1, CHR(34));
    v_end_pos := INSTR(v_text_data1, CHR(34),1,2);
    v_text_array(v_text_arr_ind).address := SUBSTR(v_text_data1,v_first_pos+1,v_end_pos-2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).address);
    v_text_data1 := SUBSTR(v_text_data1,v_end_pos+2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    IF ( v_quote_pos > v_comma_pos ) THEN
    v_text_array(v_text_arr_ind).address := SUBSTR(v_text_data1,1,INSTR(v_text_data1,CHR(44))-1);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).address);
    v_text_data1 := SUBSTR(v_text_data1,INSTR(v_text_data1,CHR(44))+1);
    -- DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_first_pos :=0;
    v_end_pos := 0;
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    --PIN
    v_quote_pos := INSTR(v_text_data1,CHR(34));
    v_comma_pos := INSTR(v_text_data1,CHR(44));
    IF ( v_quote_pos < v_comma_pos )
    THEN
    v_first_pos := INSTR(v_text_data1, CHR(34));
    v_end_pos := INSTR(v_text_data1, CHR(34),1,2);
    v_text_array(v_text_arr_ind).pin := SUBSTR(v_text_data1,v_first_pos+1,v_end_pos-2);
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).pin);
    v_text_data1 := 0;
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    IF ( v_comma_pos IS NULL OR v_quote_pos > v_comma_pos ) THEN
    v_text_array(v_text_arr_ind).pin := v_text_data1;
    --DBMS_OUTPUT.PUT_LiNE(v_text_array(v_text_arr_ind).pin);
    v_text_data1 := 0;
    --DBMS_OUTPUT.PUT_LiNE(v_text_data1);
    v_first_pos := 0;
    v_end_pos := 0;
    v_quote_pos := 0;
    v_comma_pos := 0;
    END IF;
    EXCEPTION
    WHEN others then
    DBMS_OUTPUT.PUT_LiNE(SUBSTR(SQLERRM,1,200));
    END prc_rollout_upload;
    Oracle version :
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    Your help would be highly appreciated !!!
    Regards,
    Vissu.....

    To start with Try this:
    SQL> ed
    Wrote file afiedt.buf
      1    declare
      2   v_var VARCHAR2(10000) := 'INDIA,BANGALORE,"INOX,BLR","THILAK NAGAR,JAYA NAGAR ';
      3    v_delim VARCHAR2(1) := ',';
      4    v_enclose VARCHAR2(1) := '"';
      5    v_val VARCHAR2(1000) := NULL;
      6    begin
      7    v_var := v_var||'"4TH T BLOCK,BANGALORE",500365'||',';
      8    FOR I IN 1..5 LOOP
      9    v_val :=  CASE WHEN SUBSTR(v_Var,1,1) <> '"' THEN
    10              SUBSTR(v_Var,1,INSTR(v_Var,',',1,1)-1)
    11              ELSE
    12              SUBSTR(v_Var,2,INSTR(v_Var,'",',1,1) - INSTR(v_Var,'"',1,1) - 1)
    13              END;
    14    v_Var :=  CASE WHEN SUBSTR(v_Var,1,1) <> '"' THEN
    15              SUBSTR(v_Var,INSTR(v_Var,',',1,1) + 1)
    16              ELSE
    17              SUBSTR(v_Var,INSTR(v_Var,'",',1,1) + 2)
    18              END;
    19    dbms_output.put_line(v_Val);
    20    END LOOP;
    21*  end;
    SQL> /
    INDIA
    BANGALORE
    INOX,BLR
    THILAK NAGAR,JAYA NAGAR "4TH T BLOCK,BANGALORE
    500365
    PL/SQL procedure successfully completed.
    SQL>

  • Need help on how to handle zip & text/csv as a resposne payload from Concur RestWebservice

    Hi All,
    We are getting zip(if there are multiple files) and test/csv(single file) as a response payload from the concur rest API and need your help on how to handle in NWBPM and SAP PO.
    Zip response coming in response looks like below -
    PKÀ˜F7extract_attendee_detail_p0600908soav_20150424022159.txts� rt©1204Õ50Ñ52©1¨áåPKzà@ÆPKÀ˜F2extract_CES_SAE_v3_p0600908soav_20150424022148.txts� rt©1204Õ50Ñ52©1¨©1ãåPKå늟PKÀ˜Fzà
    Text/csv response looks like below -
    Extract|2015-24-40|20|0
    Need you help on how to handle the zip content response.
    Also need help on how to handle when text/csv response comes and when zip response comes.
    As per the scenario, there are 4 calls to be made and we are using NWBPM and in the last call the actual respons (text/csv or zip) will come.
    Please provide your inputs.
    Thanks
    Narayanareddy B

    Hi Aaron,
    Thanks for your reply.
    I tried with Payload zip bean and the java mapping as mentioned in the response mapping of OM.
    Payload zip bean - Zip  zip.mode  unzip
    I am getting the error below in the receiver rest channel -
    "Transmitting the message using connection JPR failed, due to: com.sap.aii.af.lib.mp.module.ModuleException: Zip: error occured during processing: java.util.zip.ZipException: invalid stored block lengths"
    Java Mapping - used the java mapping in the response of Operation mapping
    Here also i am seeing the same error in the channel log as it is synchronous step and the message got cancelled.
    "Transmitting the message using connection JPR failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeApplication mapping program com/equalize/xpi/esr/mapping/java/UnzipAndAttach throws a stream transformation exception: Exception: invalid stored block lengths"
    The below is the response i am seeing and is it proper zip response payload(any encryption) , kindly advise.
    PKâE�F:ws_extract_attendee_detail_p0600908soav_20150424083413.txts� rt©1204Õ50Ñ52©1¨áåPKzà@ÆPKâE�F5ws_extract_CES_SAE_v3_p0600908soav_20150424084014.txtíTß��@~oÒÿ�÷Fº»ìV}ëòCÏz Qljß8ÜöL�`N�ùão8�Ò«�´M�Ü@�awvçûfgÇùâϤå#Ttï0Ø�B�²·olÇ�£[4Ï](L�]«�ÑbÀôÁÒc�0ÀÏdAªÙТ¨Ìû�Êv¡�b¤eJA%��=Þ7Í>PÚ=í2��7ò[�¼¡=q/°¶�*ø)
    K|<`BgÉÔºÜWs[§J�&Ñ:Ìá:´�ç«�RÐv�ÚÅAD'\�ÁtR²*DP3gî:B@JëhU�Ò'¬�ùQ\�È\D{·O×±JS\ï�-ò�¸�Þ²êó�{Å¡2®â,MmÉù XAzßüBn&®Sl-§�l¶A�×ú½³ÙFI®0¿©Ú¯¤�oT�iV²RÀJ��¼«`õ»�í Ûéwa#�àpY�««óq)U°JaøÁA�ûì>Ù³üHåÒe¾�7��Ð/§£u°Nzã÷ç4×·èãþ�¾}õ0ÙµYÄ�+J��eX\�E±ïsR%®yÜÕðsªáÚ$qÚÎÇ�Û$^%1¸AF*ý¶VÑêxÏZÏ¢U½T~Ñ®ØkW5ç×®õ¿w5¬zò:oN»�ô���íø÷úÛÙ=¬å�[ôÚ�þmczPKhÏ��i PKâE�Fzà@Æ:ws_extract_attendee_detail_p0600908soav_20150424083413.txtPKâE�FhÏ��i 5�ws_extract_CES_SAE_v3_p0600908soav_20150424084014.txtPKËö
    Thanks
    Narayanareddy B

  • How to handle a fixed length file without newline?

    Hi Experts,
    I'd like to handle a fixed length file without newline by sender file adapter.
    A file like following.
    It contains three recores."AAXBBBXCCCCX" is one record.
    AA1BBB1CCCC1AA2BBB2CCCC2AA3BBB3CCCC3
    I tried that following two parameters set. But only first recored was read.
    fieldFixedLengths
    fieldFixedLengthType
    Please tell me how to handle.
    Thanks
    Shinya Kawagoe.

    For this case we wrote a simple Adapter Module inserting an end of line character after an offset.
    This way it can be reused in many interfaces.
    And reading the whole file may not be an option in case of large source files. May cause performance / memory issues.
    eolbean.offset = <recordLlen>
    XMLPayload xmlpayload = msg.getDocument();
    byte[] content = xmlpayload.getContent();
    byte crlf = 0x0A;
    int current = 0;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int lines = content.length / recordLen;
    do
         lines--;
         baos.write(content, current, recordLen);
         if (lines > 0) // if other lines, eol required
              baos.write(crlf);
              current += recordLen;
    } while (lines > 0);
    xmlpayload.setContent(baos.toByteArray());
    baos.close();
    Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,     MODULE + " Done EOLing.");

  • How to handle comma in DMEE when your file format is CSV

    Does anyone knows how DMEE handles comma when its part of the field value and when the file format requirement is CSV?
    Thanks all in advance.
    Aloy

    Wrong forum.
    You should be here.
    Oracle Application Express (APEX)

  • How to handle a comma in a field in CSV file during FCC ?

    Hi,
    I am having a requirement where we have to convert a CSV file into XML using File Content Conversion . The issue is one of the field in the file is having a comma inside. So the XML parser is taking it as a field separator and throwing an error.
    The contents of the file are as follows:
    "02975859","New Key","9","Failed, rejected by RTI server"
    How to handle a comma inside field "Failed, rejected by RTI server".
    Any help would be appreciated.
    Regards
    Pravesh

    Hi ,
    You have to write an java mapping programm to perdromance this task , in a estandar way i think is not possible , because the fiel adapter have just one option for the delimiter character.
    Here's some code that could help you
    Supouse a file in this way:
    1,rahul,siemens,mumbai
    2,consultant,12032005
    1,viswanath,sisl,hyderabad
    2,systemeng,23052005
    package TXTMapping;
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.util.Map;
    import com.sap.aii.mapping.api.StreamTransformation;
    public class TMapping implements StreamTransformation {
    private Map map;
    public void setParameter (Map param){
    map = param;
    public void execute (InputStream in, OutputStream out){
    try{
    out.write("<?xml version ='1.0' encoding='UTF-8'?>".getBytes());
    out.write("<ns0:Output_Data xmlns:ns0=\"urn:javamapping_test\">".getBytes());
    String line = null;
    BufferedReader bin = new BufferedReader(new InputStreamReader(in));
    StringBuffer buffer = new StringBuffer();
    while((line = bin.readLine())!= null){
    String Company = null;
    String Name = null;
    String Place = null;
    String Desgn = null;
    String Since = null;
    char[] str= new char[100];
    str = line.toCharArray();
    String[] Data = new String[10];
    int S1 = 0;
    int s2 = 2;
    for (int i=2; i<line.length(); i++)
    if (str<i>==',' && str[0]=='1')
    Data[S1]= line.substring(s2,i);
    S1=S1+1;
    s2 = i+1;
    if (i == line.length()-1 && str[0] == '1')
    Data[S1]= line.substring(s2,i+1);
    Name = Data[0];
    Company = Data[1];
    Place = Data[2];
    out.write ("<Data>".getBytes());
    out.write ("<Header>".getBytes());
    out.write (("<Name>"Name"</Name>").getBytes());
    out.write (("<Company>"Company"</Company>").getBytes());
    out.write (("<Place>"Place"</Place>").getBytes());
    out.write ("</Header>".getBytes());
    if (str<i>==',' && str[0]=='2')
    Data[S1]= line.substring(s2,i);
    S1=S1+1;
    s2 = i+1;
    if (i == line.length()-1 && str[0] == '2')
    Data[S1]= line.substring(s2,i+1);
    Desgn = Data[0];
    Since = Data[1];
    out.write ("<Item>".getBytes());
    out.write (("<Designation>"Desgn"</Designation>").getBytes());
    out.write (("<Since>"Since"</Since>").getBytes());
    out.write ("</Item>".getBytes());
    out.write ("</Data>".getBytes());
    out.write("</ns0:Output_Data>".getBytes());
    catch(Throwable t){
    t.printStackTrace();

  • How to handle 3 different fact tables and measures within a DAX query?

    I am writing a DAX query in DAX studio in Excel against a tabular model that has 4 different Fact tables, but they share the same dimensions. (There's some long story I can't get into here, but unfortunately this is the structure) I want to
    include measures from the 4 fact tables, summarize by the dimensions in a single query output that can be used for a pivot table.  So far I have something like this:
     EVALUATE
    FILTER
        SUMMARIZE
            FactTable1,
            DimensionTable1[Value],        DimensionTable2[Value],
            DimensionTable3[Value],
            Dimensiontable4[Value],
            'dimDateTime'[Month PST],
            DimDateTIme[FiscalYear PST],
            "Measure Score",
            FactTable1[Measure 1],
            "Measure Score 2",
            FactTable1[Measure 2],
        ,Company[CompanyName]="Company ABC" 
    What I want to do is summarize the 3 fact tables by the same dimensions, but I am not sure how to do that within a DAX query.  I am getting an error if I try to include another table statement in the original SUMMARIZE function, even though the FACTS
    do share the same dimension.  Is there an easy way to do this?

    You can use ADDCOLUMNS to add the data from other tables, but you need to use within the SUMMARIZE the fact table that determines the cardinality of the output. If you are not sure (e.g. you project cost and revenues from two fact tables by month and there
    could me months with cost and no revenues, but also months with revenues and no costs), then you should use CROSSJOIN and then FILTER.
    You query might be written as (please note CALCULATETABLE instead of FILTER to improve performance):
    EVALUATE
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                FactTable1,
                DimensionTable1[Value],
                DimensionTable2[Value],
                DimensionTable3[Value],
                Dimensiontable4[Value],
                'dimDateTime'[Month PST],
                DimDateTIme[FiscalYear PST]
            "Measure Score", FactTable1[Measure 1],
            "Measure Score 2", FactTable1[Measure 2]
        Company[CompanyName] = "Company ABC"
    Marco Russo http://www.sqlbi.com http://www.powerpivotworkshop.com http://sqlblog.com/blogs/marco_russo

  • How to handle XML string with Single Quotes as a parameter to SP dynamically?

    Hi,
    I would like to know if there is a way to handle the Single Quotes in XML value when it is passed to Stored Procedure?
    I should be able to handle it without adding another Single Quote to it.
    Thanks,
    Chandra Shekar

    Hi Chandra,
    Your requirement is not precise. Based on my understanding and guessing, are you metioning something like the below sample?
    /*If the xml is generated you have no need to escape the singe quote(')*/
    DECLARE @xmlTbl TABLE (ID INT,name VARCHAR(99));
    INSERT INTO @xmlTbl VALUES(1,'Eric''s')
    INSERT INTO @xmlTbl VALUES(2,'Zhang''s')
    DECLARE @xmlDoc1 XML
    SELECT @xmlDoc1
    FROM @xmlTbl FOR XML PATH('PERSON'),ROOT('PERSONS')
    EXEC yourProcedure @xmlDoc1
    /*If your copy and paste the xml, you have to escape the single quote(') with 2s('')*/
    DECLARE @xmlDoc2 XML
    SET @xmlDoc2 = '<PERSONS>
    <PERSON>
    <ID>1</ID>
    <name>Eric''s</name>
    </PERSON>
    <PERSON>
    <ID>2</ID>
    <name>Zhang''s</name>
    </PERSON>
    </PERSONS>'
    EXEC yourProcedure @xmlDoc2
    If that is not regarding your requirement, please elaborate with more details.
    Eric Zhang
    TechNet Community Support

  • How to handle exception CX_SY_REF_IS_INITIAL

    hi experts,
    im working on a test scenario for abap mapping in SAP XI im getting this error
    An exception with the type CX_SY_REF_IS_INITIAL occurred, but was neither handled locally, nor declared in a RAISING clause Dereferencing of the NULL reference
    i understand that i need to catch this exception in the abap coding but i'm not familiar with oops concepts
    can any one please suggest me how to handle this exception for the following code...
    method IF_MAPPING~EXECUTE.
      break x1149.
    * initialize iXML
      TYPE-POOLS: ixml.
      class cl_ixml definition load.
    ** Instances & Variable declaration =======================
    * instance main factory
      TYPES: BEGIN OF t_xml_line,
              data(256) TYPE x,
            END OF t_xml_line.
      DATA: l_ixml TYPE REF TO if_ixml,
    * instance input stream factory
       l_streamfactory TYPE REF TO if_ixml_stream_factory,
    * instance input stream
      l_istream  TYPE REF TO if_ixml_istream,
    * instance input document
      l_document TYPE REF TO if_ixml_document,
    * instance parse input document
      l_parser TYPE REF TO if_ixml_parser,
    * instance for elements within the nodes
      node      TYPE REF TO if_ixml_node,
    *instance of nodemap
      nodemap   TYPE REF TO if_ixml_named_node_map,
    * instance for iterator
      iterator  TYPE REF TO if_ixml_node_iterator,
      name      TYPE string,
      value     TYPE string,
    * instance main factory
       o_ixml   TYPE REF TO if_ixml,
    * instance output document
       o_document TYPE REF TO if_ixml_document,
    * instance output stream
      o_istream  TYPE REF TO if_ixml_ostream,
    * instance parse output document
      o_parser  TYPE REF TO if_ixml_parser,
    * instance fot renderer
      renderer type ref to if_ixml_renderer,
      irc type i,
      l_xml_size   TYPE i,
    *ROOT ELEMENT
    l_element_MT_DEMANDTEC_COST TYPE REF TO if_ixml_element,
    *NEXT CHILD ELEMENT FROM THE ABOVE PARENT
    l_element_DT_DEMANDTEC TYPE REF TO if_ixml_element,
    *CHILDREN1 ELEMENT FOR DT_DEMANDTEC
    l_element_DT_WHSE  TYPE REF TO if_ixml_element,
    *CHILDREN2 ELEMENT FOR DT_DEMANDTEC
    l_element_DT_DC    TYPE REF TO if_ixml_element,
    *CHILDREN3 ELEMENT FOR DT_DEMANDTEC
    l_element_DT_PLANT    TYPE REF TO if_ixml_element,
    *CHILDREN4 ELEMENT FOR DT_DEMANDTEC
    l_element_DT_QTY    TYPE REF TO if_ixml_element.
    *saving the xml document
      DATA: l_xml_table       TYPE TABLE OF t_xml_line.
      types: begin of t_source,
              whse(5),
              dc(4) ,
              plant(4),
              qty    type i,
             end of t_source.
      types: tt_source TYPE STANDARD TABLE OF t_source.
      data:  wa_source type t_source.
      data: it_source TYPE  tt_source,
            ivalue type string.
    * Procedures and business logic =======================================
    *   Creating the main iXML factory
      l_ixml = cl_ixml=>create( ).
    *   Creating a stream factory
      l_streamfactory = l_ixml->create_stream_factory( ).
    * create input stream
      l_istream = l_streamfactory->create_istream_xstring( source ).
    *  initialize input document
      l_document = l_ixml->create_document( ).
    *  Create a Parser
      l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
                                          istream        = l_istream
                                          document       = l_document ).
    * parse input document
      l_parser->parse( ).
    *   Validate a document
      l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    *   Parse the stream
      IF l_parser->parse( ) NE 0.
        IF l_parser->num_errors( ) NE 0.
          DATA: parseerror TYPE REF TO if_ixml_parse_error,
                str        TYPE string,
                i          TYPE i,
                count      TYPE i,
                index      TYPE i.
          count = l_parser->num_errors( ).
          WRITE: count, ' parse errors have occured:'.
          index = 0.
          WHILE index < count.
            parseerror = l_parser->get_error( index = index ).
            i = parseerror->get_line( ).
            WRITE: 'line: ', i.
            i = parseerror->get_column( ).
            WRITE: 'column: ', i.
            str = parseerror->get_reason( ).
            WRITE: str.
            index = index + 1.
          ENDWHILE.
        ENDIF.
      ENDIF.
    *   Process the document
      IF l_parser->is_dom_generating( ) EQ 'X'.
        refresh : it_source.
        node ?= l_document.
        CHECK NOT node IS INITIAL.
    *   create a node iterator
        iterator  = node->create_iterator( ).
    *   get current node
        node = iterator->get_next( ).
    *   loop over all nodes
        WHILE NOT node IS INITIAL.
          CASE node->get_type( ).
            WHEN if_ixml_node=>co_node_element.
    *         element node
              name    = node->get_name( ).
              nodemap = node->get_attributes( ).
            WHEN if_ixml_node=>co_node_text.
    *         text node
              value  = node->get_value( ).
              if name eq 'DT_WHSE'.
                wa_source-whse = value.
              ELSEIF name eq 'DT_DC'.
                wa_source-DC = value.
              ELSEIF name eq 'DT_PLANT'.
                wa_source-PLANT = value.
              ELSEIF name eq 'DT_QTY'.
                wa_source-QTY = value.
                COLLECT wa_source INto it_source.
                CLEAR   wa_source.
              ENDIF.
          endcase.
          node = iterator->get_next( ).
        endwhile.
      ENDIF.
      loop at it_source into wa_source .
        at first.
    *       Creating a ixml factory
          o_ixml = cl_ixml=>create( ).
    *       Creating the dom object model
          o_document = l_ixml->create_document( ).
        endat.
    *       Build and Fill  root node MT_DEMANDTEC_COST
        AT FIRST.
          l_element_MT_DEMANDTEC_COST    =
    O_document->create_simple_element(
                                  name   = 'MT_DEMANDTEC_COST'
                                  parent = o_document ).
        ENDAT.
    *      Build and Fill  Child node DT_DEMANDTEC for parent
    *                                                  MT_DEMANDTEC_COST
        l_element_DT_DEMANDTEC    = O_document->create_simple_element(
                                     name   = 'DT_DEMANDTEC'
                                     parent = l_element_MT_DEMANDTEC_COST ).
    *      Build and Fill  Child node1 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-WHSE.
        l_element_DT_WHSE    = O_document->create_simple_element(
                                         name   = 'DT_WHSE'
                                         VALUE  = ivalue
                                         parent = l_element_DT_DEMANDTEC  ).
    *      Build and Fill  Child node2 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-DC.
        l_element_DT_DC   = O_document->create_simple_element(
                                             name   = 'DT_DC'
                                              VALUE  = ivalue
                                    parent = l_element_DT_DEMANDTEC ).
    *      Build and Fill  Child node3 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-PLANT.
        l_element_DT_PLANT   = O_document->create_simple_element(
                                                 name   = 'DT_PLANT'
                                                  VALUE  = ivalue
                                   parent = l_element_DT_DEMANDTEC  ).
    *      Build and Fill  Child node4 DT_QTY for parent DT_DEMANDTEC
        ivalue              = wa_source-QTY.
        l_element_DT_QTY     = O_document->create_simple_element(
                                                 name   = 'DT_QTY'
                                                  VALUE  = ivalue
                                   parent = l_element_DT_DEMANDTEC  ).
      endloop.
    * render document ======================================================
    * create output stream
      o_istream  = l_streamfactory->create_ostream_xstring( result ).
    *   Connect internal XML table to stream factory
      o_istream  = l_streamfactory->create_ostream_itable( table =
    l_xml_table ).
      renderer = o_ixml->create_renderer( ostream = o_istream
                                              document = o_document ).
      irc = renderer->render( ).
    * how do i catch the exception for type CX_SY_REF_IS_INITIAL ...?
    endmethod.
    full reward points for answers.
    Thanks & Regards,
    Uday Kumar.
    Edited by: UDAY on May 6, 2008 9:32 PM

    Hi Uday,
    Its occurs because you're trying to access a objects with null reference. Or you forgot to create an instance or an error occurs during the instance creation. So You should put all your "Procedures and business logic" inside a Try/catch block. as follow.
    " Define a class exception object to get error message......
    DATA o_exception TYPE REF TO cx_sy_ref_is_initial.
    "// Use the statment Try block to catch the error.
    TRY.
    *   Creating the main iXML factory
      l_ixml = cl_ixml=>create( ).
    *   Creating a stream factory
      l_streamfactory = l_ixml->create_stream_factory( ).
    * create input stream
      l_istream = l_streamfactory->create_istream_xstring( source ).
    *  initialize input document
      l_document = l_ixml->create_document( ).
    *  Create a Parser
      l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
                                          istream        = l_istream
                                          document       = l_document ).
    * parse input document
      l_parser->parse( ).
    *   Validate a document
      l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    *   Parse the stream
      IF l_parser->parse( ) NE 0.
        IF l_parser->num_errors( ) NE 0.
          DATA: parseerror TYPE REF TO if_ixml_parse_error,
                str        TYPE string,
                i          TYPE i,
                count      TYPE i,
                index      TYPE i.
          count = l_parser->num_errors( ).
          WRITE: count, ' parse errors have occured:'.
          index = 0.
          WHILE index < count.
            parseerror = l_parser->get_error( index = index ).
            i = parseerror->get_line( ).
            WRITE: 'line: ', i.
            i = parseerror->get_column( ).
            WRITE: 'column: ', i.
            str = parseerror->get_reason( ).
            WRITE: str.
            index = index + 1.
          ENDWHILE.
        ENDIF.
      ENDIF.
    *   Process the document
      IF l_parser->is_dom_generating( ) EQ 'X'.
        refresh : it_source.
        node ?= l_document.
        CHECK NOT node IS INITIAL.
    *   create a node iterator
        iterator  = node->create_iterator( ).
    *   get current node
        node = iterator->get_next( ).
    *   loop over all nodes
        WHILE NOT node IS INITIAL.
          CASE node->get_type( ).
            WHEN if_ixml_node=>co_node_element.
    *         element node
              name    = node->get_name( ).
              nodemap = node->get_attributes( ).
            WHEN if_ixml_node=>co_node_text.
    *         text node
              value  = node->get_value( ).
              if name eq 'DT_WHSE'.
                wa_source-whse = value.
              ELSEIF name eq 'DT_DC'.
                wa_source-DC = value.
              ELSEIF name eq 'DT_PLANT'.
                wa_source-PLANT = value.
              ELSEIF name eq 'DT_QTY'.
                wa_source-QTY = value.
                COLLECT wa_source INto it_source.
                CLEAR   wa_source.
              ENDIF.
          endcase.
          node = iterator->get_next( ).
        endwhile.
      ENDIF.
      loop at it_source into wa_source .
        at first.
    *       Creating a ixml factory
          o_ixml = cl_ixml=>create( ).
    *       Creating the dom object model
          o_document = l_ixml->create_document( ).
        endat.
    *       Build and Fill  root node MT_DEMANDTEC_COST
        AT FIRST.
          l_element_MT_DEMANDTEC_COST    =
    O_document->create_simple_element(
                                  name   = 'MT_DEMANDTEC_COST'
                                  parent = o_document ).
        ENDAT.
    *      Build and Fill  Child node DT_DEMANDTEC for parent
    *                                                  MT_DEMANDTEC_COST
        l_element_DT_DEMANDTEC    = O_document->create_simple_element(
                                     name   = 'DT_DEMANDTEC'
                                     parent = l_element_MT_DEMANDTEC_COST ).
    *      Build and Fill  Child node1 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-WHSE.
        l_element_DT_WHSE    = O_document->create_simple_element(
                                         name   = 'DT_WHSE'
                                         VALUE  = ivalue
                                         parent = l_element_DT_DEMANDTEC  ).
    *      Build and Fill  Child node2 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-DC.
        l_element_DT_DC   = O_document->create_simple_element(
                                             name   = 'DT_DC'
                                              VALUE  = ivalue
                                    parent = l_element_DT_DEMANDTEC ).
    *      Build and Fill  Child node3 DT_WHSE for parent DT_DEMANDTEC
        ivalue              = wa_source-PLANT.
        l_element_DT_PLANT   = O_document->create_simple_element(
                                                 name   = 'DT_PLANT'
                                                  VALUE  = ivalue
                                   parent = l_element_DT_DEMANDTEC  ).
    *      Build and Fill  Child node4 DT_QTY for parent DT_DEMANDTEC
        ivalue              = wa_source-QTY.
        l_element_DT_QTY     = O_document->create_simple_element(
                                                 name   = 'DT_QTY'
                                                  VALUE  = ivalue
                                   parent = l_element_DT_DEMANDTEC  ).
      endloop.
    * render document ======================================================
    * create output stream
      o_istream  = l_streamfactory->create_ostream_xstring( result ).
    *   Connect internal XML table to stream factory
      o_istream  = l_streamfactory->create_ostream_itable( table =
    l_xml_table ).
      renderer = o_ixml->create_renderer( ostream = o_istream
                                              document = o_document ).
      irc = renderer->render( ).
    "   The Statement CATCH define a block that catches the exceptions of the
    "   exception class cx_sy_ref_is_initial
        CATCH cx_sy_ref_is_initial INTO o_exception.
    " If you need to get the error message text do as follow
    DATA errorMsg type string.
    " Get the message text
      errorMsg = o_exception->GET_TEXT( ).
    " Display the error information
      MESSAGE errorMsg TYPE 'I'.
      ENDTRY.
    The TRY block defines a guarded area whose class-based exceptions can be caught in the subsequent CATCH blocks. If no exception occurs in the TRY block and it reaches its end, the system continues the processing after ENDTRY. If a class-based exception occurs in the TRY block, the system searches for an exception handler in the same or an external TRY control structure.
    Font: SAP Help
    You can see a how to create and use an exception in this example [ ABAP Objects - Defining a Class-based exceptions|https://wiki.sdn.sap.com/wiki/x/19w] .
    Best Regards.
    Marcelo Ramos

  • How to escape a single quotes from a string of dynamic sql clause?

    if a single quotes exist in a dynamic sql clause for a string,
    like
    v_string :='select tname from tab where tabtype='table'',
    there tabtype='table' will conflict with the single quote ahead.
    could somebody tell me how to escape this single quotes?
    thanks for your tips,
    frederick

    fredrick,
    To represent one single quotation mark within a literal, enter two single quotation marks. For example :
    v_string :='select tname from tab where tabtype=''table'''
    Regards,
    Srinivas

Maybe you are looking for