Export batch data into CSV file using SQL SP

Hi,
I have created WCF-Custom receive adapter to poll Sql SP (WITH xmlnamespaces(DEFAULT 'Namespace' and For XML PATH(''), Type) . Get the result properly in batch while polling and but getting error while converting into CSV by using map.
Please can anyone give me some idea to export SQL data into CSV file using SP.

How are you doing this.
You would have got XML representation for the XML batch received from SQL
You should have a flat-file schema representing the CSV file which you want to send.
Map the received XML representation of data from SQL to flat-file schema
have custom pipeline with flat-file assembler on the assembler stage of the send pipeline.
In the send port use the map which convert received XML from SQL to flat file schema and use the above custom flat-file disassembler send port
If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

Similar Messages

  • How to give path in plsql while exporting table data into .csv file

    hi,
    i have a code like this
    PROCEDURE dump_table_to_csv (
    p_tname IN VARCHAR2,
    p_dir IN VARCHAR2,
    p_filename IN VARCHAR2
    IS
    l_output UTL_FILE.file_type;
    l_thecursor INTEGER DEFAULT DBMS_SQL.open_cursor;
    l_columnvalue VARCHAR2 (4000);
    l_status INTEGER;
    l_query VARCHAR2 (1000) DEFAULT 'select * from ' || p_tname;
    l_colcnt NUMBER := 0;
    l_separator VARCHAR2 (1);
    l_desctbl DBMS_SQL.desc_tab;
    BEGIN
    l_output := UTL_FILE.fopen (p_dir, p_filename, 'w');
    EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-mon-yyyy hh24:mi:ss''';
    DBMS_SQL.parse (l_thecursor, l_query, DBMS_SQL.native);
    DBMS_SQL.describe_columns (l_thecursor, l_colcnt, l_desctbl);
    FOR i IN 1 .. l_colcnt
    LOOP
    UTL_FILE.put (l_output,
    l_separator || '"' || l_desctbl (i).col_name || '"'
    DBMS_SQL.define_column (l_thecursor, i, l_columnvalue, 4000);
    l_separator := ',';
    END LOOP;
    UTL_FILE.new_line (l_output);
    l_status := DBMS_SQL.EXECUTE (l_thecursor);
    WHILE (DBMS_SQL.fetch_rows (l_thecursor) > 0)
    LOOP
    l_separator := '';
    FOR i IN 1 .. l_colcnt
    LOOP
    DBMS_SQL.column_value (l_thecursor, i, l_columnvalue);
    UTL_FILE.put (l_output, l_separator || l_columnvalue);
    l_separator := ',';
    END LOOP;
    UTL_FILE.new_line (l_output);
    END LOOP;
    DBMS_SQL.close_cursor (l_thecursor);
    UTL_FILE.fclose (l_output);
    EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-MON-yy'' ';
    EXCEPTION
    WHEN OTHERS
    THEN
    EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-MON-yy'' ';
    RAISE;
    END;
    I am getting error like :-------
    SQL> exec dump_table_to_csv('deptair','c:/csv','aa.deptair');
    BEGIN dump_table_to_csv('deptair','c:/csv','aa.deptair'); END;
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 8
    ORA-29280: invalid directory path
    ORA-06512: at "SCOTT.DUMP_TABLE_TO_CSV", line 58
    ORA-06512: at line 1
    pplease help me out
    thanks
    vicky

    look at your other thread, answer is already there.

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

  • Problem in converting table data into CSV file

    Hi All,
    In my Process i need to convert my error table data into csv file,my data is converted as csv file by using OdisqlUnload function,but the column headers are not converted,i use another procedure for converting column headers but iam getting below error ...
    com.sunopsis.sql.SnpsMissingParametersException: Missing parameter string.find, string.find
    SQL: import string import java.sql as sql import java.lang as lang import re sourceConnection = odiRef.getJDBCConnection("SRC") output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+') myStmt = sourceConnection.createStatement() my_query = "select * FROM E$_LOCAL_F0911Z1" my_query=my_query.upper() if string.find(my_query, '*') > 0: myRs = myStmt.executeQuery(my_query) md=myRs.getMetaData() collect=[] i=1 while (i <= md.getColumnCount()): collect.append(md.getColumnName(i)) i += 1 header=','.join(map(string.strip, collect)) elif string.find(my_query,'||') > 0: header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',') else: header = my_query[7:string.find(my_query, 'FROM')] print header old=output_write.read() output_write.seek(0) output_write.write (header+'\n'+old) sourceConnection.close() output_write.close()
    And i used below code for converting.......
    import string
    import java.sql as sql
    import java.lang as lang
    import re
    sourceConnection = odiRef.getJDBCConnection("SRC")
    output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+')
    myStmt = sourceConnection.createStatement()
    my_query = "select FROM E$_COMPANY"*
    *my_query=my_query.upper()*
    *if string.find(my_query, '*') > 0:*
    *myRs = myStmt.executeQuery(my_query)*
    *md=myRs.getMetaData()*
    *collect=[]*
    *i=1*
    *while (i <= md.getColumnCount()):*
    *collect.append(md.getColumnName(i))*
    *i += 1*
    *header=','.join(map(string.strip, collect))*
    *elif string.find(my_query,'||') > 0:*
    *header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',')*
    *else:*
    *header = my_query[7:string.find(my_query, 'FROM')]*
    *print header*
    *old=output_write.read()*
    *output_write.seek(0)*
    *output_write.write (header+'\n'+old)*
    *sourceConnection.close()*
    *output_write.close()*
    Any one can you help regarding this
    Edited by: 30021986 on Oct 1, 2012 6:04 PM

    This may not be an option for you but in pinch you may want to consider outputing your data to an MS Spreadsheet, then saving it as a CSV. It's somewhat of a cumbersome process, but it will get you by for now.
    You will need to change your content type to application/vnd.ms-excel.
    <% response.setContentType("application/vnd.ms-excel"); %>

  • Issue while loading a csv file using sql*loader...

    Hi,
    I am loading a csv file using sql*loader.
    On the number columns where there is data populated in them, decimal number/integers, the row errors out on the error -
    ORA-01722: invalid number
    I tried checking the value picking from the excel,
    and found the chr(13),chr(32),chr(10) values characters on the value.
    ex: select length('0.21') from dual is giving a value of 7.
    When i checked each character as
    select ascii(substr('0.21',5,1) from dual is returning a value 9...etc.
    I tried the following command....
    "to_number(trim(replace(replace(replace(replace(:std_cost_price_scala,chr(9),''),chr(32),''),chr(13),''),chr(10),'')))",
    to remove all the non-number special characters. But still facing the error.
    Please let me know, any solution for this error.
    Thanks in advance.
    Kiran

    control file:
    OPTIONS (ROWS=1, ERRORS=10000)
    LOAD DATA
    CHARACTERSET WE8ISO8859P1
    INFILE '$Xx_TOP/bin/ITEMS.csv'
    APPEND INTO TABLE XXINF.ITEMS_STAGE
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
    ItemNum                    "trim(replace(replace(:ItemNum,chr(9),''),chr(13),''))",
    cross_ref_old_item_num               "trim(replace(replace(:cross_ref_old_item_num,chr(9),''),chr(13),''))",
    Mas_description               "trim(replace(replace(:Mas_description,chr(9),''),chr(13),''))",
    Mas_long_description               "trim(replace(replace(:Mas_long_description,chr(9),''),chr(13),''))",
    Org_description               "trim(replace(replace(:Org_description,chr(9),''),chr(13),''))",
    Org_long_description               "trim(replace(replace(:Org_long_description,chr(9),''),chr(13),''))",
    user_item_type                    "trim(replace(replace(:user_item_type,chr(9),''),chr(13),''))",
    organization_code               "trim(replace(replace(:organization_code,chr(9),''),chr(13),''))",
    primary_uom_code               "trim(replace(replace(:primary_uom_code,chr(9),''),chr(13),''))",
    inv_default_item_status          "trim(replace(replace(:inv_default_item_status,chr(9),''),chr(13),''))",
    inventory_item_flag               "trim(replace(replace(:inventory_item_flag,chr(9),''),chr(13),''))",
    stock_enabled_flag               "trim(replace(replace(:stock_enabled_flag,chr(9),''),chr(13),''))",
    mtl_transactions_enabled_flag          "trim(replace(replace(:mtl_transactions_enabled_flag,chr(9),''),chr(13),''))",
    revision_qty_control_code          "trim(replace(replace(:revision_qty_control_code,chr(9),''),chr(13),''))",
    reservable_type               "trim(replace(replace(:reservable_type,chr(9),''),chr(13),''))",
    check_shortages_flag               "trim(replace(replace(:check_shortages_flag,chr(9),''),chr(13),''))",
    shelf_life_code               "trim(replace(replace(replace(replace(:shelf_life_code,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    shelf_life_days               "trim(replace(replace(replace(replace(:shelf_life_days,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    lot_control_code               "trim(replace(replace(:lot_control_code,chr(9),''),chr(13),''))",
    auto_lot_alpha_prefix               "trim(replace(replace(:auto_lot_alpha_prefix,chr(9),''),chr(13),''))",
    start_auto_lot_number               "trim(replace(replace(:start_auto_lot_number,chr(9),''),chr(13),''))",
    negative_measurement_error          "trim(replace(replace(replace(replace(:negative_measurement_error,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    positive_measurement_error          "trim(replace(replace(replace(replace(:positive_measurement_error,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    serial_number_control_code          "trim(replace(replace(:serial_number_control_code,chr(9),''),chr(13),''))",
    auto_serial_alpha_prefix          "trim(replace(replace(:auto_serial_alpha_prefix,chr(9),''),chr(13),''))",
    start_auto_serial_number          "trim(replace(replace(:start_auto_serial_number,chr(9),''),chr(13),''))",
    location_control_code               "trim(replace(replace(:location_control_code,chr(9),''),chr(13),''))",
    restrict_subinventories_code          "trim(replace(replace(:restrict_subinventories_code,chr(9),''),chr(13),''))",
    restrict_locators_code               "trim(replace(replace(:restrict_locators_code,chr(9),''),chr(13),''))",
    bom_enabled_flag               "trim(replace(replace(:bom_enabled_flag,chr(9),''),chr(13),''))",
    costing_enabled_flag               "trim(replace(replace(:costing_enabled_flag,chr(9),''),chr(13),''))",
    inventory_asset_flag               "trim(replace(replace(:inventory_asset_flag,chr(9),''),chr(13),''))",
    default_include_in_rollup_flag          "trim(replace(replace(:default_include_in_rollup_flag,chr(9),''),chr(13),''))",
    cost_of_goods_sold_account          "trim(replace(replace(:cost_of_goods_sold_account,chr(9),''),chr(13),''))",
    std_lot_size                    "trim(replace(replace(replace(replace(:std_lot_size,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    sales_account                    "trim(replace(replace(:sales_account,chr(9),''),chr(13),''))",
    purchasing_item_flag               "trim(replace(replace(:purchasing_item_flag,chr(9),''),chr(13),''))",
    purchasing_enabled_flag          "trim(replace(replace(:purchasing_enabled_flag,chr(9),''),chr(13),''))",
    must_use_approved_vendor_flag          "trim(replace(replace(:must_use_approved_vendor_flag,chr(9),''),chr(13),''))",
    allow_item_desc_update_flag          "trim(replace(replace(:allow_item_desc_update_flag,chr(9),''),chr(13),''))",
    rfq_required_flag               "trim(replace(replace(:rfq_required_flag,chr(9),''),chr(13),''))",
    buyer_name                    "trim(replace(replace(:buyer_name,chr(9),''),chr(13),''))",
    list_price_per_unit               "trim(replace(replace(replace(replace(:list_price_per_unit,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    taxable_flag                    "trim(replace(replace(:taxable_flag,chr(9),''),chr(13),''))",
    purchasing_tax_code               "trim(replace(replace(:purchasing_tax_code,chr(9),''),chr(13),''))",
    receipt_required_flag               "trim(replace(replace(:receipt_required_flag,chr(9),''),chr(13),''))",
    inspection_required_flag          "trim(replace(replace(:inspection_required_flag,chr(9),''),chr(13),''))",
    price_tolerance_percent          "trim(replace(replace(replace(replace(:price_tolerance_percent,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    expense_account               "trim(replace(replace(:expense_account,chr(9),''),chr(13),''))",
    allow_substitute_receipts_flag          "trim(replace(replace(:allow_substitute_receipts_flag,chr(9),''),chr(13),''))",
    allow_unordered_receipts_flag          "trim(replace(replace(:allow_unordered_receipts_flag,chr(9),''),chr(13),''))",
    receiving_routing_code               "trim(replace(replace(:receiving_routing_code,chr(9),''),chr(13),''))",
    inventory_planning_code          "trim(replace(replace(:inventory_planning_code,chr(9),''),chr(13),''))",
    min_minmax_quantity               "trim(replace(replace(replace(replace(:min_minmax_quantity,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    max_minmax_quantity               "trim(replace(replace(replace(replace(:max_minmax_quantity,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    planning_make_buy_code               "trim(replace(replace(:planning_make_buy_code,chr(9),''),chr(13),''))",
    source_type                    "trim(replace(replace(:source_type,chr(9),''),chr(13),''))",
    mrp_safety_stock_code               "trim(replace(replace(:mrp_safety_stock_code,chr(9),''),chr(13),''))",
    material_cost                    "trim(replace(replace(:material_cost,chr(9),''),chr(13),''))",
    mrp_planning_code               "trim(replace(replace(:mrp_planning_code,chr(9),''),chr(13),''))",
    customer_order_enabled_flag          "trim(replace(replace(:customer_order_enabled_flag,chr(9),''),chr(13),''))",
    customer_order_flag               "trim(replace(replace(:customer_order_flag,chr(9),''),chr(13),''))",
    shippable_item_flag               "trim(replace(replace(:shippable_item_flag,chr(9),''),chr(13),''))",
    internal_order_flag               "trim(replace(replace(:internal_order_flag,chr(9),''),chr(13),''))",
    internal_order_enabled_flag          "trim(replace(replace(:internal_order_enabled_flag,chr(9),''),chr(13),''))",
    invoice_enabled_flag               "trim(replace(replace(:invoice_enabled_flag,chr(9),''),chr(13),''))",
    invoiceable_item_flag               "trim(replace(replace(:invoiceable_item_flag,chr(9),''),chr(13),''))",
    cross_ref_ean_code               "trim(replace(replace(:cross_ref_ean_code,chr(9),''),chr(13),''))",
    category_set_intrastat               "trim(replace(replace(:category_set_intrastat,chr(9),''),chr(13),''))",
    CustomCode                    "trim(replace(replace(:CustomCode,chr(9),''),chr(13),''))",
    net_weight                    "trim(replace(replace(replace(replace(:net_weight,chr(9),''),chr(13),''),chr(32),''),chr(10),''))",
    production_speed               "trim(replace(replace(:production_speed,chr(9),''),chr(13),''))",
    LABEL                         "trim(replace(replace(:LABEL,chr(9),''),chr(13),''))",
    comment1_org_level               "trim(replace(replace(:comment1_org_level,chr(9),''),chr(13),''))",
    comment2_org_level               "trim(replace(replace(:comment2_org_level,chr(9),''),chr(13),''))",
    std_cost_price_scala               "to_number(trim(replace(replace(replace(replace(:std_cost_price_scala,chr(9),''),chr(32),''),chr(13),''),chr(10),'')))",
    supply_type                    "trim(replace(replace(:supply_type,chr(9),''),chr(13),''))",
    subinventory_code               "trim(replace(replace(:subinventory_code,chr(9),''),chr(13),''))",
    preprocessing_lead_time          "trim(replace(replace(replace(replace(:preprocessing_lead_time,chr(9),''),chr(32),''),chr(13),''),chr(10),''))",
    processing_lead_time                "trim(replace(replace(replace(replace(:processing_lead_time,chr(9),''),chr(32),''),chr(13),''),chr(10),''))",
    wip_supply_locator               "trim(replace(replace(:wip_supply_locator,chr(9),''),chr(13),''))"
    Sample data from csv file.
    "9901-0001-35","390000","JMKL16 Pipe bend 16 mm","","JMKL16 Putkikaari 16 mm","","AI","FJE","Ea","","","","","","","","","","","","","","","","","","","","","","","","","21-21100-22200-00000-00000-00-00000-00000","0","21-11100-22110-00000-00000-00-00000-00000","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","0.1","Pull","AFTER PROD","","","Locator for Production"
    The load errors out on especially two columns :
    1) std_cost_price_scala
    2) list_price_per_unit
    both are number columns.
    And when there is data being provided on them. It errors out. But, if they are holding null values, the records go through fine.
    Message was edited by:
    KK28

  • Exporting table data to .csv file

    How to export the table data (this table is having 18 million records) to .csv file. using SQL Developer and PL/SQL deveoloper it is taking too long time to complete. Please let me know is there any faster way to complete this task.
    Thanks in advance

    Also bear in mind that SQL Developer and PL/SQL Developer are running on your local client, so it's transferring all 18 million rows to the client before formatting and putting them out to a file. If you had some PL/SQL code to export it on the database server it would run a lot faster as you wouldn't have the network traffic delay to deal with, although your file would then reside on the server rather than the client (which isn't necessarily a bad thing as a lot of companies would be concerned about the security of their data especially if it ends up being stored on local machines rather than on a secure server).
    As already asked, why on earth do you need to store 18 million rows in a CSV file? The database is the best place to keep the data.

  • To download data into csv file format

    Hi All
    I have to download data into csv file format. I use the FM
    GUI_DOWNLOAD and gave the filename text.csv. But data is stored in excel
    file in place of csv file.
    Can anyone tell me what should i do to load the data into csv file or any other function module should used?
    Regards

    see this sample code
    REPORT  YSG_MATSTK_REPT    LINE-SIZE 220
                               LINE-COUNT 50(5).
    *&                       DATA DECLARATION                              *
    TABLES: MARA,                      "GENERAL MASTER DATA
            MARC,                      "PLANT DATA FOR MATERIAL
            MARD,                      "STORAGE LOCATION DATA FOR MATERIAL
            MVKE,                      "SALES DATA FOR MATERIAL
            MAKT,                      "MATERIAL DESCRIPTION
            EKKO,                      "PURCHASING DOCUMENT HEADER
            EKPO,                      "PURCHASING DOCUMENT ITEM
            VBAK,                      "SALES DOCUMENT HEADER DATA
            VBAP.                      "SALES DOCUMENT ITEM DATA
    TYPE-POOLS : SLIS.
    DATA: VT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
          V_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
          V_LAYOUT TYPE SLIS_LAYOUT_ALV,
          BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
          BEGIN OF I_MARA OCCURS 0,
             MATNR LIKE MARA-MATNR,  "MATERIAL NUMBER
             MBRSH LIKE MARA-MBRSH,  "INDUSTRY SECTOR
             MEINS LIKE MARA-MEINS,  "BASE UNIT OF MEASURE
             MATKL LIKE MARA-MATKL,  "MATERIAL GROUP
          END OF I_MARA,
          BEGIN OF I_MARC OCCURS 0,
             MATNR LIKE MARC-MATNR,  "MATERIAL NUMBER
             WERKS LIKE MARC-WERKS,  "PLANT
             LVORM LIKE MARC-LVORM,  "FLAG MATERIAL FOR DELETION AT PLANT
                                     "LEVEL
             DISPO LIKE MARC-DISPO,  "MRP CONTROLLER
          END OF I_MARC,
          BEGIN OF I_MAKT OCCURS 0,
             MATNR LIKE MAKT-MATNR,  "MATERIAL NUMBER
             MAKTX LIKE MAKT-MAKTX,  "MATERIAL DESCRIPTION
             SPRAS LIKE MAKT-SPRAS,  "LANGUAGE KEY
          END OF I_MAKT,
          BEGIN OF I_MVKE OCCURS 0,
             MATNR LIKE MVKE-MATNR,  "MATERIAL NUMBER
             VKORG LIKE MVKE-VKORG,  "SALES ORGANIZATION
             VTWEG LIKE MVKE-VTWEG,  "DISTRIBUTION CHANNEL
          END OF I_MVKE,
          BEGIN OF I_MARD OCCURS 0,
            MATNR LIKE MARD-MATNR,  "MATERIAL NUMBER
            LGORT LIKE MARD-LGORT,  "STORAGE LOCATION
            LABST LIKE MARD-LABST,  "VALUATED STOCK WITH UNRESTRICTED USE
          END OF I_MARD,
          BEGIN OF I_EKPO OCCURS 0,
            EBELN LIKE EKPO-EBELN,  "PURCHASING DOCUMENT NUMBER
            EBELP LIKE EKPO-EBELP,  "ITEM NUMBER OF PURCHASING DOCUMENT
            MATNR LIKE EKPO-MATNR,  "MATERIAL NUMBER
          END OF I_EKPO,
          BEGIN OF I_VBAP OCCURS 0,
            VBELN LIKE VBAP-VBELN,  "SALES DOCUMENT
            POSNR LIKE VBAP-POSNR,  "SALES DOCUMENT ITEM
            MATNR LIKE VBAP-MATNR,  "MATERIAL NUMBER
          END OF I_VBAP,
          BEGIN OF I_OUT OCCURS 0,
            MATNR LIKE MARC-MATNR,
            WERKS LIKE MARC-WERKS,
            LVORM LIKE MARC-LVORM,
            DISPO LIKE MARC-DISPO,
            MBRSH LIKE MARA-MBRSH,
            MEINS LIKE MARA-MEINS,
            MATKL LIKE MARA-MATKL,
            VKORG LIKE MVKE-VKORG,
            VTWEG LIKE MVKE-VTWEG,
            SPRAS LIKE MAKT-SPRAS,
            MAKTX LIKE MAKT-MAKTX,
            LGORT LIKE MARD-LGORT,
            LABST LIKE MARD-LABST,
            EBELN LIKE EKPO-EBELN,
            EBELP LIKE EKPO-EBELP,
            VBELN LIKE VBAP-VBELN,
            POSNR LIKE VBAP-POSNR,
          END OF I_OUT,
          BEGIN OF I_HEADING OCCURS 0,
            TEXT1(20),
            TEXT2(20),
            TEXT3(20),
            TEXT4(20),
            TEXT5(20),
            TEXT6(20),
            TEXT7(20),
            TEXT8(20),
            TEXT9(20),
            TEXT10(20),
            TEXT11(40),
            TEXT12(20),
            TEXT13(20),
            TEXT14(20),
            TEXT15(20),
            TEXT16(20),
            TEXT17(20),
          END OF I_HEADING.
    *&                   S E L E C T I O N - S C R E E N                   *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR. "OBLIGATORY.
    PARAMETERS: P_WERKS LIKE MARC-WERKS. "OBLIGATORY.
    SELECT-OPTIONS: S_LGORT FOR MARD-LGORT,
                    S_DISPO FOR MARC-DISPO,
                    S_EBELN FOR EKPO-EBELN .
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-101.
    PARAMETERS : RB1 RADIOBUTTON GROUP G1,
                 RB2 RADIOBUTTON GROUP G1,
                 RB3 RADIOBUTTON GROUP G1.
    SELECTION-SCREEN END OF BLOCK B2.
    *&                  I N I T I A L I Z A T I O N                      *
    *INITIALIZATION.
    *&             S T A R T - O F - S E L E C T I O N                     *
    START-OF-SELECTION.
      SELECT MATNR WERKS LVORM DISPO FROM MARC
      INTO CORRESPONDING FIELDS OF TABLE I_MARC
                          WHERE MATNR IN S_MATNR
                          AND DISPO IN S_DISPO
                          AND WERKS = P_WERKS.
      IF I_MARC[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARC'.
        EXIT.
      ENDIF.
      PERFORM PURCHASEDATA_VALIDATION.
      PERFORM SALESDATA_VALIDATION.
      SELECT MATNR LGORT LABST FROM MARD INTO TABLE  I_MARD
                          FOR ALL ENTRIES IN I_MARC
                          WHERE MATNR = I_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND LGORT IN S_LGORT.
      IF I_MARD[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARD'.
        EXIT.
      ENDIF.
      SELECT MATNR VKORG VTWEG FROM MVKE INTO TABLE I_MVKE
                          FOR ALL ENTRIES IN I_MARC
                          WHERE MATNR = I_MARC-MATNR.
      IF I_MVKE[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MVKE'.
        EXIT.
      ENDIF.
      LOOP AT I_MARC.
        MOVE-CORRESPONDING I_MARC TO I_OUT.
        CLEAR MARC.
        SELECT SINGLE MATNR MBRSH MEINS MATKL FROM MARA
                          INTO CORRESPONDING FIELDS OF MARA
                          WHERE MATNR = I_OUT-MATNR.
        IF SY-SUBRC = 0.
          MOVE: MARA-MBRSH TO I_OUT-MBRSH,
                MARA-MEINS TO I_OUT-MEINS,
                MARA-MATKL TO I_OUT-MATKL.
        ELSE.
          CONTINUE.
        ENDIF.
        SELECT SINGLE MATNR MAKTX SPRAS FROM MAKT
                        INTO  CORRESPONDING FIELDS OF MAKT
                        WHERE  MATNR = I_OUT-MATNR.
        IF SY-SUBRC = 0.
          MOVE: MAKT-MAKTX TO I_OUT-MAKTX,
                MAKT-SPRAS TO I_OUT-SPRAS.
        ELSE.
          CONTINUE.
        ENDIF.
        LOOP AT I_EKPO WHERE MATNR =  I_MARC-MATNR.
          MOVE: I_EKPO-EBELN TO I_OUT-EBELN,
                I_EKPO-EBELP TO I_OUT-EBELP.
        ENDLOOP.
        LOOP AT I_VBAP WHERE MATNR =  I_MARC-MATNR.
          MOVE: I_VBAP-VBELN TO I_OUT-VBELN,
                I_VBAP-POSNR TO I_OUT-POSNR.
        ENDLOOP.
        LOOP AT I_MARD WHERE MATNR = I_MARC-MATNR.
          MOVE: I_MARD-LABST TO I_OUT-LABST,
                I_MARD-LGORT TO I_OUT-LGORT.
        ENDLOOP.
        LOOP AT I_MVKE WHERE MATNR = I_MARC-MATNR.
          MOVE: I_MVKE-VKORG TO I_OUT-VKORG,
                I_MVKE-VTWEG TO I_OUT-VTWEG.
        ENDLOOP.
        APPEND I_OUT.
        CLEAR I_OUT.
      ENDLOOP.
      PERFORM OPTIONS.
                         FORM  OPTIONS                                *
    FORM OPTIONS.
      IF RB2 = 'X'.
        PERFORM FIELDCAT.
        PERFORM OUTPUT.
      ELSE.
        IF RB1 = 'X'.
          PERFORM HEADINGS.
          PERFORM DLOAD.
        ELSE.
          IF RB3 = 'X'.
            PERFORM HEADINGS.
            PERFORM DLOAD.
            PERFORM FIELDCAT.
            PERFORM OUTPUT.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    "OPTIONS
                         FORM  HEADINGS                               *
    FORM HEADINGS.
      I_HEADING-TEXT1 = 'MATNR'.
      I_HEADING-TEXT2 = 'WERKS'.
      I_HEADING-TEXT3 = 'LVORM'.
      I_HEADING-TEXT4 = 'DISPO'.
      I_HEADING-TEXT5 = 'MBRSH'.
      I_HEADING-TEXT6 = 'MEINS'.
      I_HEADING-TEXT7 = 'MATKL'.
      I_HEADING-TEXT8 = 'VKORG'.
      I_HEADING-TEXT9 = 'VTWEG'.
      I_HEADING-TEXT10 = 'SPRAS'.
      I_HEADING-TEXT11 = 'MAKTX'.
      I_HEADING-TEXT12 = 'LGORT'.
      I_HEADING-TEXT13 = 'LABST'.
      I_HEADING-TEXT14 = 'EBELN'.
      I_HEADING-TEXT15 = 'EBELP'.
      I_HEADING-TEXT16 = 'VBELN'.
      I_HEADING-TEXT17 = 'POSNR'.
      APPEND I_HEADING.
    ENDFORM.                    "HEADINGS
                         FORM  DLOAD                                  *
    FORM DLOAD.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME              = 'C:\MATSTK.csv'
          FILETYPE              = 'DAT'
          WRITE_FIELD_SEPARATOR = 'X'
        TABLES
          DATA_TAB              = I_HEADING
        EXCEPTIONS
          FILE_WRITE_ERROR      = 1.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME              = 'C:\MATSTK.csv'
          FILETYPE              = 'DAT'
          APPEND                = 'X'
          WRITE_FIELD_SEPARATOR = 'X'
        TABLES
          DATA_TAB              = I_OUT.
    ENDFORM.                    "DLOAD
                              FORM  FIELDCAT                          *
    FORM FIELDCAT.
      V_FIELDCAT-COL_POS = '1'.
      V_FIELDCAT-FIELDNAME     = 'MATNR'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-HOTSPOT = 'X'.
      V_FIELDCAT-REF_FIELDNAME = 'MATNR'.
      V_FIELDCAT-REF_TABNAME   = 'MARC'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '2'.
      V_FIELDCAT-FIELDNAME     = 'WERKS'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'WERKS'.
      V_FIELDCAT-REF_TABNAME   = 'MARC'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '3'.
      V_FIELDCAT-FIELDNAME     = 'LVORM'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'LVORM'.
      V_FIELDCAT-REF_TABNAME   = 'MARC'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '4'.
      V_FIELDCAT-FIELDNAME     = 'DISPO'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'DISPO'.
      V_FIELDCAT-REF_TABNAME   = 'MARC'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '5'.
      V_FIELDCAT-FIELDNAME     = 'MBRSH'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'MBRSH'.
      V_FIELDCAT-REF_TABNAME   = 'MARA'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '6'.
      V_FIELDCAT-FIELDNAME     = 'MEINS'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'MEINS'.
      V_FIELDCAT-REF_TABNAME   = 'MARA'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '7'.
      V_FIELDCAT-FIELDNAME     = 'MATKL'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'MATKL'.
      V_FIELDCAT-REF_TABNAME   = 'MARA'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '8'.
      V_FIELDCAT-FIELDNAME     = 'VKORG'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'VKORG'.
      V_FIELDCAT-REF_TABNAME   = 'MVKE'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '9'.
      V_FIELDCAT-FIELDNAME     = 'VTWEG'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'VTWEG'.
      V_FIELDCAT-REF_TABNAME   = 'MVKE'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '10'.
      V_FIELDCAT-FIELDNAME     = 'SPRAS'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'SPRAS'.
      V_FIELDCAT-REF_TABNAME   = 'MAKT'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '11'.
      V_FIELDCAT-FIELDNAME     = 'MAKTX'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'MAKTX'.
      V_FIELDCAT-REF_TABNAME   = 'MAKT'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '12'.
      V_FIELDCAT-FIELDNAME     = 'LGORT'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
    V_FIELDCAT-REF_FIELDNAME = 'LGORT'.
    V_FIELDCAT-REF_TABNAME   = 'MARD'.
      V_FIELDCAT-SELTEXT_L = 'STRG LOCT'.
      V_FIELDCAT-OUTPUTLEN = 10.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '13'.
      V_FIELDCAT-FIELDNAME     = 'LABST'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-SELTEXT_M = 'STOCK'.
      V_FIELDCAT-OUTPUTLEN = 15.
    V_FIELDCAT-REF_FIELDNAME = 'LABST'.
    V_FIELDCAT-REF_TABNAME   = 'MARD'.
      V_FIELDCAT-DO_SUM = 'X'.
      V_LAYOUT-TOTALS_TEXT = 'TOTAL STOCK:'.
      V_FIELDCAT-HOTSPOT = 'X'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '14'.
      V_FIELDCAT-FIELDNAME     = 'EBELN'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-HOTSPOT = 'X'.
      V_FIELDCAT-REF_FIELDNAME = 'EBELN'.
      V_FIELDCAT-REF_TABNAME   = 'EKPO'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '15'.
      V_FIELDCAT-FIELDNAME     = 'EBELP'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'EBELP'.
      V_FIELDCAT-REF_TABNAME   = 'EKPO'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '16'.
      V_FIELDCAT-FIELDNAME     = 'VBELN'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-HOTSPOT = 'X'.
      V_FIELDCAT-REF_FIELDNAME = 'VBELN'.
      V_FIELDCAT-REF_TABNAME   = 'VBAP'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
      V_FIELDCAT-COL_POS = '17'.
      V_FIELDCAT-FIELDNAME     = 'POSNR'.
      V_FIELDCAT-TABNAME = 'I_OUT'.
      V_FIELDCAT-REF_FIELDNAME = 'POSNR'.
      V_FIELDCAT-REF_TABNAME   = 'VBAP'.
      APPEND V_FIELDCAT TO VT_FIELDCAT1.
      CLEAR  V_FIELDCAT.
    ENDFORM.                      "FIELDCAT
                              FORM  OUTPUT                            *
    FORM OUTPUT.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM      = SY-REPID
          I_CALLBACK_TOP_OF_PAGE  = 'TOP-OF-PAGE'
          I_GRID_TITLE = 'CLICK ON MATERIAL/PURDOC/SALESDOC FOR DETAILS'
          I_CALLBACK_USER_COMMAND = 'DISPLAYDETAILS'
          IS_LAYOUT               = V_LAYOUT
          IT_FIELDCAT             = VT_FIELDCAT1
        TABLES
          T_OUTTAB                = I_OUT.
      IF SY-SUBRC <> 0.
      ENDIF.
    ENDFORM.                    "OUTPUT
                            FORM  TOP-OF-PAGE                         *
    FORM TOP-OF-PAGE.
      DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
            WA_HEADER TYPE SLIS_LISTHEADER.
      WA_HEADER-TYP = 'H'.
      WA_HEADER-INFO = 'REPORT FOR : '.
      APPEND WA_HEADER TO T_HEADER.
      CLEAR WA_HEADER.
      WA_HEADER-TYP = 'S'.
      WA_HEADER-INFO = 'MATERIAL DETAILS'.
      APPEND WA_HEADER TO T_HEADER.
      CLEAR WA_HEADER.
      WA_HEADER-TYP = 'S'.
      WA_HEADER-INFO = 'PURCHASE ORDER DETAILS'.
      APPEND WA_HEADER TO T_HEADER.
      CLEAR WA_HEADER.
      WA_HEADER-TYP = 'S'.
      WA_HEADER-INFO = 'SALES ORDER DETAILS'.
      APPEND WA_HEADER TO T_HEADER.
      CLEAR WA_HEADER.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          I_LOGO             = 'GEAR'
          IT_LIST_COMMENTARY = T_HEADER.
    ENDFORM.                    "TOP-OF-PAGE
    *&                       FORM  DISPLAYDETAILS                          *
    FORM DISPLAYDETAILS USING UCOMM LIKE SY-UCOMM
          SELFIELD TYPE SLIS_SELFIELD.
      IF SELFIELD-FIELDNAME = 'EBELN'.
        IF UCOMM = '&IC1'.
          READ TABLE I_OUT INDEX SELFIELD-TABINDEX.
          PERFORM PORECDNG.
          CLEAR BDCDATA[].
        ENDIF.
      ELSE.
        IF SELFIELD-FIELDNAME = 'MATNR'.
          IF UCOMM = '&IC1'.
            READ TABLE I_OUT INDEX SELFIELD-TABINDEX.
            PERFORM MMRECDNG.
            CLEAR BDCDATA[].
          ENDIF.
        ELSE.
          IF SELFIELD-FIELDNAME = 'VBELN'.
            IF UCOMM = '&IC1'.
              READ TABLE I_OUT INDEX SELFIELD-TABINDEX.
              PERFORM SALESRECDNG.
              CLEAR BDCDATA[].
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    "DISPLAYDETAILS
                        FORM PORECDNG                                   *
    FORM PORECDNG.
      PERFORM BDC_DYNPRO      USING 'SAPMM06E' '0105'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'RM06E-BSTNR'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM BDC_FIELD       USING 'RM06E-BSTNR'
                                    I_OUT-EBELN.
      PERFORM BDC_DYNPRO      USING 'SAPMM06E' '0120'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'RM06E-BSTPO(01)'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=AH'.
      PERFORM BDC_FIELD       USING 'RM06E-EBELP'
                                    I_OUT-EBELP.
      PERFORM BDC_FIELD       USING 'RM06E-TCSELFLAG(01)'
                                    'X'.
      PERFORM BDC_TRANSACTION USING 'ME23'.
    ENDFORM.                    "PORECDNG
                        FORM MMRECDNG                                   *
    FORM MMRECDNG.
      PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0060'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'RMMG1-MATNR'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM BDC_FIELD       USING 'RMMG1-MATNR'
                                    I_OUT-MATNR.
      PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'MSICHTAUSW-DYTXT(01)'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=ENTR'.
      PERFORM BDC_FIELD       USING 'MSICHTAUSW-KZSEL(01)'
                                    'X'.
      PERFORM BDC_TRANSACTION USING 'MM03'.
    ENDFORM.                    "MMRECDNG
                        FORM SALESRECDNG                                *
    FORM SALESRECDNG.
      PERFORM BDC_DYNPRO      USING 'SAPMV45A' '0102'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'VBAK-VBELN'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM BDC_FIELD       USING 'VBAK-VBELN'
                                    I_OUT-VBELN.
      PERFORM BDC_TRANSACTION USING 'VA03'.
    ENDFORM.                    "SALESRECDNG
                     FORM BDC_TRANSACTION                               *
    FORM BDC_TRANSACTION USING TCODE.
      CALL TRANSACTION TCODE USING BDCDATA MODE 'E'.
    ENDFORM.                    "BDC_TRANSACTION
                           FORM BDC_DYNPRO                              *
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCDATA.
      BDCDATA-PROGRAM = PROGRAM.
      BDCDATA-DYNPRO = DYNPRO.
      BDCDATA-DYNBEGIN = 'X'.
      APPEND BDCDATA.
    ENDFORM.                    "BDC_DYNPRO
                           INSERT FIELD                                  *
    FORM BDC_FIELD USING FNAM FVAL.
      CLEAR BDCDATA.
      BDCDATA-FNAM = FNAM.
      BDCDATA-FVAL = FVAL.
      APPEND BDCDATA.
    ENDFORM.                    "BDC_FIELD
    *&                  FORM  PURCHASEDATA_VALIDATION                      *
    FORM PURCHASEDATA_VALIDATION.
      SELECT EBELN EBELP MATNR
                 FROM EKPO
                 INTO TABLE I_EKPO
                 FOR ALL ENTRIES IN I_MARC
                 WHERE MATNR = I_MARC-MATNR
                 AND EBELN IN S_EBELN
                 AND WERKS EQ P_WERKS.
      IF I_EKPO[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM TABLE EKPO'.
        EXIT.
      ENDIF.
      DATA: T_EKPO LIKE I_EKPO OCCURS 0 WITH HEADER LINE.
      T_EKPO[] = I_EKPO[].
      REFRESH I_EKPO.
      FREE I_EKPO.
      LOOP AT T_EKPO.
        SELECT SINGLE EBELN FROM EKKO INTO EKPO-EBELN
        WHERE EBELN = T_EKPO-EBELN.
        IF SY-SUBRC = 0.
          MOVE-CORRESPONDING T_EKPO TO I_EKPO.
          APPEND I_EKPO.
          CLEAR I_EKPO.
        ELSE.
          CONTINUE.
        ENDIF.
      ENDLOOP.
      SORT I_EKPO.
    ENDFORM.                    "PURCHASEDATA_VALIDATION
    *&                  FORM  SALESDATA_VALIDATION                         *
    FORM SALESDATA_VALIDATION.
      SELECT VBELN POSNR MATNR
              FROM VBAP
              INTO CORRESPONDING FIELDS OF TABLE
              I_VBAP FOR ALL ENTRIES IN I_MARC
              WHERE MATNR = I_MARC-MATNR.
    IF I_VBAP[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM TABLE VBAP'.
        EXIT.
      ENDIF.
      DATA: T_VBAP LIKE I_VBAP OCCURS 0 WITH HEADER LINE.
      T_VBAP[] = I_VBAP[].
      REFRESH I_VBAP.
      FREE I_VBAP.
      LOOP AT T_VBAP.
        SELECT SINGLE VBELN FROM VBAK INTO VBAK-VBELN
        WHERE VBELN = T_VBAP-VBELN.
        IF SY-SUBRC = 0.
          MOVE-CORRESPONDING T_VBAP TO I_VBAP.
          APPEND I_VBAP.
          CLEAR I_VBAP.
        ELSE.
          CONTINUE.
        ENDIF.
      ENDLOOP.
      SORT I_VBAP.
    ENDFORM.                    "SALESDATA_VALIDATION
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • CLR to get the SQL Server Data into .CSV File

    Hi,
    I transformed 10 columns 1000 rows from the source table to 1 column 1000 rows in the destination table by making the comma separated columns ( Just like ..
    Insert into DestinationTable
    SELECT col1+','+col2 ....
    FROM SourceTable
    Then I want to take this column into CSV file.
    I dont have the rights to command shell.
    I heard that we may use CLR procedure for this. Can someone throw light?

    using System;
    using System.IOM
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    public class ExportFileClass {
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void export_file()
    using (SqlConnection connection = new SqlConnection(
    "context connection=true"))
    connection.Open();
    // Operation to open file goes here.
    SqlCommand command = new SqlCommand("SELECT col FROM YourTable");
    // Consume result set and write rows.
    Build this from the command line:
    sn -k keypair.snk
    csc /target:library /keyfile:keypair.snk exportfile.cs
    Then run in SQL Server (assuming that the files are in C:\temp on the SQL
    Server machine:
    [sql]
    USE master
    go
    -- To be able to create an external-access assembly, we need to load
    -- the key, the assembly is signed with. The key needs a password, but we
    -- don't need to know the password.
    DECLARE @sql nvarchar(MAX),
            @password char(40)
    SELECT @password = convert(char(36), newid()) + 'Ab4?'
    SELECT @sql = 'CREATE ASYMMETRIC KEY slog_loopback FROM FILE = ' +
                  '''C:\temp\keypair.snk'' ' +
                  'ENCRYPTION BY PASSWORD = ''' + @password + ''''
    PRINT @sql
    EXEC(@sql)
    -- And then a login to carry the permission.
    CREATE LOGIN exportfile$asymkey FROM ASYMMETRIC KEY ExportFile
    GRANT EXTERNAL ACCESS ASSEMBLY TO exportfile$asymkey
    go
    -- Now we can go back to our regular database and create the assembly.
    USE youddatabase
    go
    CREATE ASSEMBLY ExportFile FROM 'C:\temp\exportfile.dll'
    WITH PERMISSION_SET = EXTERNAL_ACCESS
    go
    CREATE PROCEDURE ExportFile AS
    EXTERNAL NAME ExportFile.ExportFileClass.export_file
    [sql]
    It is likely that you will have to do ask your DBA to do things in the
    master database.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • BCP data into a file using Runtime class

    Hi,
         I have a problem in using the Runtime class.
    I am trying to bcp a table's data into a file.I am working on a Unix environment.
    My bcp is not getting completed fully.The total records to be bcped is 1 million,but only one lakh records is getting bcped and then it hangs up..But if i issue the bcp command from my telnet session it is bcping it to the file without any problem.Can anyone help me out on how to overcome this..
    Is there anything specific with Runtime class..I am pasting the code that i tried out below.
    String l_s_bcpQuery="bcp mubstage.dbo.HousingUnitSampleMarket out /dun/d3nmb0/mariaps/subracheckprototype -c -t~ -Umariaps -Prykwz5ba -SD3NMB_MUB";
    try{
    Runtime time=Runtime.getRuntime();
    Process p=time.exec(l_s_bcpQuery);
    p.waitFor();
    System.out.println("The exit value is:"+p.exitValue());
    }catch(Exception ioe){
         ioe.printStackTrace();
         System.out.println("IOException"+ioe.getMessage());

    you might need to capture the stout & sterr from the process. see http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Process.html, or many other similar questions on this forum.
    try this:
    try{
    Runtime time=Runtime.getRuntime();
    Process p=time.exec(l_s_bcpQuery);
    BufferedReader stout = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader sterr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String out = stout.readLine();
    String err = sterr.readLine();
    while((out != null)||(err != null))
    if(out != null)
    System.out.println(out);
    if(err != null)
    System.err.println(err);
    out = stout.readLine();
    err = sterr.readLine();
    int exit_value = p.waitFor();
    System.out.println("The exit value is:"+ exit_value);
    }catch(Exception ioe){
    ioe.printStackTrace();
    System.out.println("IOException"+ioe.getMessage());
    }

  • Exporting query result set into CSV file using Forms

    Hi ,
    My requirement is
    -> I need to create a form where I have a Multi line text box and two button.
    -> When I enter a query in text box and click on Execute button, It should execute a select query.
    -> After execution, Result set needs to be exported into an Excel file.
    Please give a hint how to do this????
    Thanks,
    maddy

    as you are using text item to write SQL query by the user
    so for that you need to use the exec_sql package to parse the text items query and get definitions and values of the columns being
    resulted in the result set of the query.
    once your query is execute to the desired connection then you need to use fetch the result to the CSV file by use of the TEXT_io package
    which will open the text file with .csv extension and you have to pass the each line to that text file with comma separated values as "ss","rr" etc.
    or you can use the ole2 package to call the excel application and then fetch the data of exe_sql query to that.

  • Export arabic character into csv file turns into question mark in sql dev

    Hi,
    I am trying to export a table's output that contains some arabic and english mixed data, when I try to export it in csv, all the arabic characters change into question mark (?) but the same export is working fine on .xls or .xlsx.
    Since we have to export a huge data and csv is much faster thar .xls, kindly let me know why it is happening and what is the solution for this.
    Well, we are on Oracle 11gR2 and Sql Dev is 3.1
    Appreciate your time and experience sharing.
    Regards.

    Hi,
    Since you say it works for xls but not csv, and the only applicable preference setting ( Tools|Preferences|Database|Utilities|Export|Encoding ) should apply to all export formats, I would imagine this is a bug. Especially if the encoding specified in Preferences is consistent with the client OS settings. I was not able to find any prior bug logged against the Export utility for this issue.
    I logged a bug for this:
    Bug 13993410 - FORUM: ARABIC CHARACTER ENCODING RESPECTED FOR XLS BUT NOT CSV
    Regards,
    Gary
    SQL Developer Team

  • Data convertion while exporting data into flat files using export wizard in ssis

    Hi ,
    while exporting data to flat file through export wizard the source table is having NVARCHAR types.
    could you please help me on how to do the data convertion while using the export wizard?
    Thanks.

    Hi Avs sai,
    By default, the columns in the destination flat file will be non-Unicode columns, e.g. the data type of the columns will be DT_STR. If you want to keep the original DT_WSTR data type of the input column when outputting to the destination file, you can check
    the Unicode option on the “Choose a Destination” page of the SQL Server Import and Export Wizard. Then, on the “Configure Flat File Destination” page, you can click the Edit Mappings…“ button to check the data types. Please see the screenshot:
    Regards,
    Mike Yin
    TechNet Community Support

  • Reg: Export table data into CSV

    Hi Experts,
    I'm stuck up with a requirement, where I have to export data of all tables from a schema into separate table specific CSV files.
    I tried using SQL Plus 'SPOOL' but it gives me additional queries executed on top of CSV generated.
    Also, i'm not getting the headers (coz i'm using pagesize 0 )
    Any help id highly appreciated?
    Ranit B.

    Starting point...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.
    With this you can call the procedure for each of your tables, querying whatever columns you want, and specifying whatever filename(s) you want.

  • How to Load Arabic Data from flat file using SQL Loader ?

    Hi All,
    We need to load Arabic data from an xls file to Oracle database, Request you to provide a very good note/step to achieve the same.
    Below are the database parameters used
    NLS_CHARACTERSET AR8ISO8859P6
    nls_language american
    DB version:-10g release 2
    OS: rhel 5
    Thanks in advance,
    Satish

    Try to save your XLS file into CSV format and set either NLS_LANG to the right value or use SQL*Loader control file parameter CHARACTERSET.
    See http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_control_file.htm#i1005287

  • How do I export phone contacts into CSV file?

    I can't seem to export the contacts in my iPhone into a CSV file so I can import them into Yahoo Mail or Gmail to edit.

    Contacts are designed to be synced with a supported application on your computer. This is so common with Windows users - here anyway - not having contacts available on their computer. How does one get by without having contact info available on their computer, or having email addresses only for contacts on their computer, telephone numbers only for contacts on their cell phone, and mailing addresses who knows where? Not a good idea to depend on an iPhone or any cell phone only for contact info - along with having to manually enter all contact info on a cell phone, which can be lost or stolen.
    With Windoze, you can sync contacts with Outlook 2003 or 2007 along with syncing calendar events, or with the address book used by Outlook Express or by Windows Mail (depending on the Windoze version) called Windows Contacts for syncing contacts only. You may not have Outlook 2003 or 2007, but you have Windows Contacts available.
    If Windows Contacts is empty - no contact info, before the first sync enter one contact in Windows Contacts. Make the contact up if needed, which can be deleted later. This will provide a merge prompt with the first sync for this data, which you want to select. Syncing contacts with Windows Contacts is selected under the Info tab for your iPhone sync preferences with iTunes.
    After your contacts are available in Windows Contacts, you can export the contacts from there in a CSV file for import by Yahoo or Gmail.

Maybe you are looking for

  • Closing the browser without popup message

    Hi Experts, I refered the following thread and done the below steps 1.Create a Button called Exit. 2.Create an action for this button. 3. In the event handler for this button, write the following code: String Url; try { Url = WDURLGenerator.getWebRes

  • Frozen on re-building library, plus connection problems (Zen Mic

    Yes, I read the FAQ :smileytongue: I JUST got my new Zen Micro and started putting songs on it. It started giving me trouble with the connection, but was ok for a little bit. After awhile I couldn't get a connection at all. My computer says there's n

  • Status of an export via Share?

    I searched the forums for the answer to this question and couldn't find any answer. Where is the status of Motion rendering via the Share command? I have no idea when this thing will be done or how much has been rendered... Thanks! Hope everyone is d

  • Scanning and tracing

    I'm kinda new to the LiveCycle Designer and I want to scan old forms and trace them in LiveCycle. Is it something possible? For now, i'm inserting an image and I trace over it, but the problem is: I don't know how to reduce the margins of the page to

  • Pages re-numbers paragraphs in a document!

    Hi all -- thanks in advance for any insight you may have. I received an email on my iPad with a Word attachment. I opened the attached in Mail, and when going through the document with someone on the phone, we realized that the paragraphs were not nu