Output in one line

Hi all,
I have a table T of the kind:
N
a
a
a
b
b
b
c
c
I want the result as:
a  b    c
3   3   2
For that i have writtena query
select decode(n,'a',count)a,decode(n,'b',count)b,decode(n,'c',count)c
from(select n,count(*)count from t group by n);
But it is giving the output as:
a      b        c
3
         3
                    2 How can i get the output in one line?
Thanks

DimaCit has given a good solution for when you know how many different values you have in advance. If you do not know this, you can code for a number that is higher than you expect or use generated sql to product the desired output. Also I allow for values that are not valid column names.
SQL> host type tmp.sql
set feedback off
set termout off
create table t (N varchar2(4));
insert into t values ('A');
insert into t values ('A');
insert into t values ('A');
insert into t values ('B');
insert into t values ('b');
insert into t values ('b');
insert into t values ('c');
insert into t values ('c');
insert into t values ('c');
insert into t values ('c');
insert into t values ('c');
insert into t values ('6');
insert into t values ('6');
insert into t values ('6');
set pagesize 0
set linesize 32767
set trimspool on
column nl newline
spool tmp.ufi
prompt select
select
  ' count(decode(n,'''||n||
     ''',1, null)) "'||n||
     decode(rv,1,'"','",') nl
from
(select
   n,
   row_number() over (order by n) rn,
   row_number() over (order by n desc) rv,
   sum(1) over() tot from (select distinct n from t)
order by rn
prompt from t;;
spool off
set pagesize 50000
set termout on
@tmp.ufi
drop table t;
SQL> @tmp
         6          A          B          b          c
         3          3          1          2          5
SQL> Edited by: Old DBA on Feb 5, 2009 8:32 PM
Formatting

Similar Messages

  • Report output on one Line, without new line (cariage return)

    Hello I use a user defined report with style plsql. The output is with many dbms_output.put_line and is displays in only one line. May I ask you to get the output on more the one line. For eatch dbms_output I wont to have a new line (cariage return). Many thanks for help in advance

    In the body of the report, I used HTML tags to control the appearance.
    For example, to see what database features you have used in your database today, the following code works well:
    begin
    dbms_output.enable(1000000);
    dbms_output.put_line('<PRE>');
    for rc in ( select output from
       table(dbms_feature_usage_report.display_text)
               ) loop
       dbms_output.put_line(rc.output);
    end loop;
    dbms_output.put_line('</PRE>');
    end; This yields the following output
    DB FEATURE USAGE report for
    DB Name         DB Id     Release    Total Samples Last Sample Time 
    ABCPROD        900004321 10.2.0.1.0             78 09-Oct-09 18:29:17
    DB Feature Usage Summary                       DB/Release: ABCPROD/10.2.0.1.0
    -> This section displays the summary of Usage for Database Features.
    -> The Currently Used column is TRUE if usage was detected for
    -> the feature at the last sample time.
                                              Curr-                                
                                              ently Detected    Total Last Usage   
    Feature Name                              Used    Usages  Samples    Time      
    Automatic SQL Execution Memory            TRUE        78       78 10/09/09 18:29
    Automatic Segment Space Management (syste TRUE        78       78 10/09/09 18:29
    etc.However if you comment the lines with the beginning and terminating tags for preformatted text, then you get output confined to one line that starts out like:
    DB FEATURE USAGE report for DB Name DB Id Release Total Samples Last Sample Time ------------ ----------- and you'll have to scroll to the right or figure how you want to break it up -- That's too much work.
    My configuration:
    Windows XP SP3
    SQL Developer 1.5.5 Build MAIN-5969
    Java(TM) Platform     1.6.0_06

  • Only one line is getting printed in Table in Smartforms (ECC 6.0)

    Hello Sir,
    I am new in ABAP and doing Smartforms (ECC 6.0) on project from customer side.
    I have to deliver the object in time and it is already late, please help me.
    This is my question:
    Object :  Stock Transport Order.
    =======================
    I have created Table in main window after Program Line Node.
    >Main Window
    >>Code2
    >>Table1
    >>>Header
    >>>>Row1
    >>>>>Cell1 to Cell10
    >>>Main Area
    >>>>Row2
    >>>>>Cell1 to Cell10
    >>>Footer
    >>>>Row3
    >>>>>Cell1 to Cell10
    I have mentioned internal tabel as well work area table in "DATA" tab in table Node.
    In Row1 I have created Text Node in every cell having Column Heading.
    In Row2 I have created Text Node in every cell having variable.
    In Row3 all cells are blank.
    On output only one line is getting printed
    What could be the reason.
    =====================================================================
    This is Code1 (is in the beginning of the form in window1)
    ==========
    *& Selection of Purchasing Document No,Plant,Short Text,Quantity,Material No,
    *& Gross order value in PO currency
    select single ebeln werks txz01 menge matnr brtwr
    from ekpo into
    (v_ebeln,v_werks,v_txz01,v_menge,v_matnr,v_brtwr)
    where ebeln = DOCNO.
    *& Selection of Plant address
    select single adrnr from t001w into v_adrnr
    where werks = v_werks.
    *& For Selection of phone,fax
    select single name1 tel_number fax_number from adrc into (v_name1,phone,fax)
    where addrnumber = v_adrnr.
    *& For E-Mail Selection
    select single SMTP_ADDR from adr6 into mail where addrnumber = v_adrnr.
    *& For CST No.,GST No.
    select single J_1ICSTNO J_1ILSTNO
                  from J_1IMOCOMP into (CST,GST)
                  where werks = v_werks.
    *& Selection of Vendor Address No., PO date
    select single reswk aedat from ekko into (v_reswk,v_aedat) where
    ebeln = v_ebeln.
    *& Selection of Supplying (Issuing) Plant address
    select single adrnr from t001w into vendor
    where werks = v_reswk.
    *& Selection of storage location
    select single lgort from ekpo into v_lgort where werks = v_werks
    and ebeln = v_ebeln.
    *& Selection of description of storage location
    select single lgobe from t001l into v_lgobe where werks = v_werks.
    *& Fetching data into internal table from ekpo
    select ebeln ebelp matnr txz01 menge brtwr from ekpo into corresponding fields
    of table iekpo where ebeln = v_ebeln and werks = v_werks.
    Fetching data into internal table from marm for Pck
    select * from marm into corresponding fields of table imarm for all entries
    in iekpo where matnr = iekpo-matnr.
    Fetching data into internal table from mara for Pack Type Code
    select * from mara into corresponding fields of table imara for all entries
    in iekpo where matnr = iekpo-matnr.
    Fetching data into internal table from tvegrt for Pack Type Description
    select * from tvegrt into corresponding fields of table itvegrt
    for all entries in imara where magrv = imara-magrv.
    Fetching data into internal table from eket for Receipt Date
    select * from eket into corresponding fields of table ieket
    where ebeln = v_ebeln.
    Selection of Order Type from mepo_topline
    *select single bsart from mepo_topline into v_bsart where ebeln = v_ebeln
    *and superfield = v_werks.
    *if v_bsart = 'UB'.
    xhead = 'Replenishment Order'.
    *eleseif v_bsart = 'ZSTO'.
    xhead = 'Purchase Order'.
    *endif.
    *& Defining of variable for Printing Line Serial Number,Total Quantity,
    *& Total Value
    =====================================================================
    This is Code2 (is in the main window)
    ==========
    xln = 0.
    tmenge = 0.
    tvalue = 0.
    Loop for printing table
    loop at iekpo into wekpo.
      xln = xln + 1.
      xmatnr = wekpo-matnr.      " Material Number (Code)
      xtxz01 = wekpo-txz01.      " Material Name
      xmenge = wekpo-menge.      " Line Quantiy
      xbrtwr = wekpo-brtwr.      " Basic Rate
    *& Pck
      read table imarm into wmarm with key matnr = wekpo-matnr.
      xpck = wmarm-umren.        " Packing Size
    *& Num
      xnum = xmenge / xpck.      " Numbers of Packing
    *& Line Value
      xvalue = xmenge * xbrtwr.  " Line Basic Value
    *& Packing Type
      read table imara into wmara with key matnr = wekpo-matnr.
      xpacktype = wmara-magrv.   " Packing Type Code
    *& Packing Type Description
    read table itvegrt into wtvegrt with key magrv = imara-magrv.
    xpackdesc = wtvegrt-bezei. " Packing Type Description
    *& Receipt Date
      read table ieket into weket with key ebeln = v_ebeln.
      xrcpdt = weket-eindt.      " Receipt Date
    *& Report Total
      tmenge = tmenge + xmenge.
      tvalue = tvalue + xvalue.
    *& Serial No. increment
    endloop.
    =====================================================================
    Thanks and Regards,
    Yogesh Pathak

    Did you debug and check the umber of values in internal table before calling the TABLE Node....
    seeing all SELECT SINGLE along with WHERE = condition and no loop call on them, my assumption  is there will be on record only. Check in Debug mood. Search forum to find how to debug a smartform.

  • Same sql statement gives output in different lines in 12.1.3 vs 11i

    Hi all,
    DB:11.2.0.3.0
    EBS:11i and 12.1.3
    O/S: Solaris SPARC 64 bits 5.10
    The below query gives the output in one line in 11i as expected but it gives the output in two separate lines in 12.1.3. Are there any server level settings for linesize and pagesize to be performed?
    set term off;
      set serveroutput on size 1000000;
      set feedback off;
      set pagesize 0;
      set head off;
      set linesize 72;
      set pause off;
      set colsep '';
    select
            lpad(code_combination_id,15,0)||
            rpad(to_char(start_date_active,'YYYYMMDD'),8,' ')||
            rpad(to_char(end_date_active,'YYYYMMDD'),8,' '),
            substr(SEGMENT1,1,3)||  --entity
            rpad(substr(SEGMENT2,1,6),6,' ')||  --account
            rpad(substr(SEGMENT3,1,5),5,' ')||  --costcenter
            rpad(substr(SEGMENT4,1,6),6,' ')||  --activity
            substr(SEGMENT6,1,3)||  --product
            substr(SEGMENT7,1,3)||  --service
            substr(SEGMENT5,1,3)||  --country
            substr(SEGMENT8,1,3)||  --intercompany
            rpad(substr(SEGMENT9,1,8),8,' ')||  --regional
            substr(enabled_flag,1,1) -- active flag
    from gl_code_combinations
    where last_update_date >=
          (select nvl(max(actual_start_date),'01-JAN-1951')
           from fnd_concurrent_requests
           where concurrent_program_id = (select concurrent_program_id
                                          from fnd_concurrent_programs
                                          where
                                          concurrent_program_name = 'XYZACCT')
           and status_code = 'C'
           and actual_completion_date is not null)
    order by 1;
    OUTPUT in 11i
    ============
    00000000000100020120930        7014912000000000000000000000000000000000Y
    00000000000100120120930        5014912000000000000000000000000000000000Y
    OUTPUT in 12.1.3
    ==============
    00000000000116020120930
    4881124010000000000000000000000000000000Y
    000000000001161
    6103229990000000000000000000000000000000Y
    11i and 12.1.3 should get the output in one line as per the above sql statement.
    Could anyone please share the fix on the above issue?
    Thanks for your time
    Regards,

    Hi,
    Can you confirm in what session are you running this query.
    Try this
    Column Code_Date_Range format a25
    Column Segments format a50
    set lines 300
    set pages 200
    set term off;
      set serveroutput on size 1000000;
      set feedback off;
      set pagesize 0;
      set head off;
      set linesize 72;
      set pause off;
      set colsep '';
    select
            lpad(code_combination_id,15,0)||
            rpad(to_char(start_date_active,'YYYYMMDD'),8,' ')||
            rpad(to_char(end_date_active,'YYYYMMDD'),8,' ') Code_Date_Range,
            substr(SEGMENT1,1,3)||  --entity
            rpad(substr(SEGMENT2,1,6),6,' ')||  --account
            rpad(substr(SEGMENT3,1,5),5,' ')||  --costcenter
            rpad(substr(SEGMENT4,1,6),6,' ')||  --activity
            substr(SEGMENT6,1,3)||  --product
            substr(SEGMENT7,1,3)||  --service
            substr(SEGMENT5,1,3)||  --country
            substr(SEGMENT8,1,3)||  --intercompany
            rpad(substr(SEGMENT9,1,8),8,' ')||  --regional
            substr(enabled_flag,1,1) Segments -- active flag
    from gl_code_combinations
    where last_update_date >=
          (select nvl(max(actual_start_date),'01-JAN-1951')
           from fnd_concurrent_requests
           where concurrent_program_id = (select concurrent_program_id
                                          from fnd_concurrent_programs
                                          where
                                          concurrent_program_name = 'XYZACCT')
           and status_code = 'C'
           and actual_completion_date is not null)
    For more details, please see:
    Formatting SQL*Plus Reports
    Thanks &
    Best Regards

  • Sending report output to Excel worksheet- Why all labels R put in one line?

    We need to export data from Oracle database to MS Excel work sheet. We developed a report and put all required things in the report. Set DESFORMAT and DESNAME parameters accordingly. Every thing works fine. But all the labels at the start of report are put in one line when we open output file in Excel worksheet. That is report heading, sub heading and column headings are all put in one line. Rest of the data is fine.
    To make excel worksheet more readable, we need to show these lines as these appear in layout and Line Previewer.
    Pl. help.

    Thanks Siva,
    Yes I am setting destination format to DELIMITED. But I do NOT want to suppress headers. In fact I do want headers in proper manner. The reason is that a no of files are produced by the same report for different columns as per user option in parameter form. So I want to put headers at the top of Excel file so that later on, at the time of using file for graphs in excel, user is able to properly recognize what the file contains. So I do want headers in manner in which they appear in Live Previewer and printed report.
    Waiting for reply from U and support group.
    M. Tariq

  • Mail adapter, All tags are in one line in the  output message

    Hi PI gurus,
    I'm facing a problem in my scenario SRM to JMS, my output mail is not suitable for my case since i don't get each tag per line, iu2019m getting the whole xml in one line
    Edited by: hakimos on Jul 13, 2010 2:45 PM

    > I'm facing a problem in my scenario SRM to JMS, my output mail is not suitable for my case since i don't get each tag per line, iu2019m getting the whole xml in one line
    XML generated by PI does not have any whitespaces, so it is aleays in one line.
    That should not be an issue at all.

  • How to get the results in one line

    Hi
    if i use the script below i get the name of path and then : and in next line i get the results.is there a way to get the results from every path after the : and not in the next line?
    another question - is there a way that the script will not show the server name on every path?
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter
    THC

    If you take you script and pipe it to get member, it will give you a list of various script properties.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | get-member
    You will see that the object type returned by "Get-Counter" is Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet.
    TypeName:
    Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet
    Name MemberType Definition
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    CounterSamples Property Microsoft.PowerShell.Commands.GetCounter.Perfo...
    Timestamp Property datetime Timestamp {get;set;}
    Readings ScriptProperty System.Object Readings {get=$strPaths = ""...
    You can try grabbing different properties, and they will print out differently, displaying the data on the same line in some cases. For example, pipe your output to a "foreach-object" block, and then for each object print out the CounterSamples property.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | foreach-object { ($_).CounterSamples }
    This should all print on one line now. However, you also asked if there was a way to not have the server print out on every line. The way to control the format of these outputs is to use the "format-table" cmdlet. So you would pipe your output to format-table
    and then give it various options. This is how you would pipe it (without any options).
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | object { ($_).CounterSamples | format-table }#OR USE YOUR ORIGINAL CODE(Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | format-table }
    Now, it's up to you to give format-table the options you want. With no options, output will look unchanged. To see what options are available to you, use get-help.
    get-help format-table
    I hope this helps!
    Thank for all the info...

  • My test instrument is outputting a 5 line string but labview only read until the carriage return. how can I get it to read the whole string?

    I have a labview sub-VI reading the string being outputted by a pH meter.  The meter outputs a 5 line string and labview is only reading up to each lines carriage return, there-by giving me 5 separate strings is there anyway to rectify this and have the 5 line read as one string?
    NAS1
    St Petersburg FL
    Labview 2010

    Yes, LabVIEW will automatically update. What happens is that the old serial functions still exist in 7.1 and above but the code (the block diagram) has been modified to use VISA functions. Older versions of LabVIEW are fully supported in this manner. The only way you can avoid the automatic update is to have the old serial functions in an llb and your top level VI refer to these. Having any VI that was part of vi.lib in an llb is a very bad idea and the way to fix things is to remove any VIs in the llb that are part of the LabVIEW distribution.
    I don't remember how the old serial config worked and what the new version does with the VISA Configure Serial Port. Your program should only have a single serial config and you might just be able to directly replace that with the VISA configure Serial Port.

  • How to bring the url in one line ?

    Hi Experts,
    - I have used a Url in the smartfrom.
    - When the link comes through in an email it the format seems messed up because it's forcing it to be all on one line.  I think it might work better if it was possible to make this a hyperlink instead of typing the whole address.
    Can we try the basic <a href="http://cgtapp61.esc.win.colpal.com:8061/sap/bc/bsp/sap/crm_ui_frame/default.htm?sap-client=321&sap-sessioncmd=open">CRM System Login</a> - Like this
    Is this possible in the smartfrom ?
    Please Help.
    Prem.

    Hi prem kumar,
    In the smartstyles -->
    create the character format -->
    Font tab -->check the check box underline and color blue.
    save and activate.
    In the smartform inlcude smartstyle in the output options tab .
    Create the text node select the text and display as URL.
    Regards,
    Sravanthi

  • 'Calendar UI' which will display current month's calendar in one line

    Hi Experts,
    I have to create a calendar in following way. Here I have to display calendar of current month for the employee. The entire month detail has to appear in one line. In fact it is needed for Leave Overview iView.
    Manager needs to view the Leave details of all employees working in his department
       1                 2                  3              4           5         6                 7              8            9               10   11     12     13     14     15  16 17 18 19  20 21  22 23  24  25  26  27  28  29 30 31
       Mon    Tues    Wed    Thurs   Friday  Sat            Sun
    Smith  
    Marteen
    Thomas
    I am not sure how to do it? Do we have any ready made UI element which we can use. I can see Date navigator. However it
    displays the calendar in 4 rows.
    Please help.
    Regards,
    Gary

    Hi Abhinav, Experts
    Thanks. The design of my RFC will be like this:
    1) Input Org Unit, Month, Year
    2) Output
    Pernr (datatype number 8)
    Name (datatype string)
    Day1 (datatype string)
    Day2 (datatype string)
    Day3 (datatype string)
    Day4 (datatype string)
    Day29 (datatype string)
    Day30 (datatype string)
    Day31 (datatype string)
    3) The default value Day1, Day2  etc will be null
    4) I will find out Leave Details. If Leave has been approved for say Day5 then I will populate Day5 = 'AP'.
    5) I will write another logic to make the color of cell as 'Green' for Day5.
    6) In Feb 2011, there are 28 days. There will be another logic to make the Day29, Day30, Day31 invisible for months like Feb 2011.
    Please let me know if this approach is correct.
    Please also let me know how to display day i.e. 01.04.2011 is Friday. In Calendar I have to display
                     1.4.2011  2.4.2011   3.4.2011
                     Friday      Saturday   Sunday
    Smith
    Tony
    I did small Proof of Concept. The table does not look good although displays the information.
    Please help.
    Regards,
    Gary

  • Analog Input and Output in One Single VI

    I need help in setting both analog input and output in one single VI. How do I assign channels to be either input or output? How do I simultaneously uses both in one single VI with a while loop structure?? Which AO am I suppose to use to obtain signal from the function generator I have built to feed into the DAQCard-1200?? Help!!
    Attachments:
    Test1.vi ‏48 KB

    One thing you'll need to be aware of is that you will need to DMA lines: one for AI and one for AO. If you don't, then you can configure the DAQCard to do without DMA using the Config VI. But you certainly can do this.
    As far as your function generator, you will want to do a buffered analog output. You will write your buffer of points to the buffer, and then tell NI-DAQ how fast to update your analog output channel with these values.
    So, you can be reading from AI and checking the AO process in the same while loop. Just make sure you handle the while loop execution (the wait it exits) correctly. This can get tricky when you're doing two types of measurements.
    J.R. Allen

  • Writing all the rows in one line but cannot write more than 32767 character

    Dear All,
    i am trying to write the column of a table to a file with the '||' seperators. i want to write all the rows in one line of the file.
    for E.g
    Column1 Column2
    A B
    C D
    in the file the output needs to be gone like
    A||B||C||D
    but after 32767 character it gives a write error. could please someone let me know what is wrong with my function below or how can i write more than 32767 character in one one.
    CREATE OR REPLACE FUNCTION CORP_IB_DUMP_FILE (
    P_QUERY IN VARCHAR2,
    P_SEPARATOR IN VARCHAR2 DEFAULT '',
    P_DIR IN VARCHAR2,
    P_FILENAME IN VARCHAR2
    RETURN NUMBER AUTHID CURRENT_USER
    IS
    L_OUTPUT UTL_FILE.FILE_TYPE;
    L_THECURSOR INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
    L_THECURSOR2 INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
    L_COLUMNVALUE VARCHAR2 (4000);
    L_STATUS INTEGER;
    L_COLCNT NUMBER DEFAULT 0;
    L_SEPARATOR VARCHAR2 (10) DEFAULT '';
    L_CNT NUMBER DEFAULT 0;
    BEGIN
    L_OUTPUT := UTL_FILE.FOPEN (P_DIR, P_FILENAME, 'w', 32767);
    DBMS_SQL.PARSE (L_THECURSOR, P_QUERY, DBMS_SQL.NATIVE);
    FOR I IN 1 .. 255
    LOOP
    BEGIN
    DBMS_SQL.DEFINE_COLUMN (L_THECURSOR, I, L_COLUMNVALUE, 4000);
    L_COLCNT := I;
    EXCEPTION
    WHEN OTHERS
    THEN
    IF (SQLCODE = -1007)
    THEN
    EXIT;
    ELSE
    RAISE;
    END IF;
    END;
    END LOOP;
    DBMS_SQL.DEFINE_COLUMN (L_THECURSOR, 1, L_COLUMNVALUE, 4000);
    L_STATUS := DBMS_SQL.EXECUTE (L_THECURSOR);
    LOOP
    EXIT WHEN (DBMS_SQL.FETCH_ROWS (L_THECURSOR) <= 0);
    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 := P_SEPARATOR;
    UTL_FILE.FFLUSH (L_OUTPUT);
    END LOOP;
    UTL_FILE.FFLUSH (L_OUTPUT);
    L_CNT := L_CNT + 1;
    END LOOP;
    DBMS_SQL.CLOSE_CURSOR (L_THECURSOR);
    UTL_FILE.FCLOSE (L_OUTPUT);
    RETURN L_CNT;
    END CORP_IB_DUMP_FILE;
    /

    user577300 wrote:
    Dear All,
    i am trying to write the column of a table to a file with the '||' seperators. i want to write all the rows in one line of the file.
    for E.g
    Column1 Column2
    A B
    C D
    in the file the output needs to be gone like
    A||B||C||D
    but after 32767 character it gives a write error. could please someone let me know what is wrong with my function below or how can i write more than 32767 character in one one.
    CREATE OR REPLACE FUNCTION CORP_IB_DUMP_FILE (
    P_QUERY IN VARCHAR2,
    P_SEPARATOR IN VARCHAR2 DEFAULT '',
    P_DIR IN VARCHAR2,
    P_FILENAME IN VARCHAR2
    RETURN NUMBER AUTHID CURRENT_USER
    IS
    L_OUTPUT UTL_FILE.FILE_TYPE;
    L_THECURSOR INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
    L_THECURSOR2 INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
    L_COLUMNVALUE VARCHAR2 (4000);
    L_STATUS INTEGER;
    L_COLCNT NUMBER DEFAULT 0;
    L_SEPARATOR VARCHAR2 (10) DEFAULT '';
    L_CNT NUMBER DEFAULT 0;
    BEGIN
    L_OUTPUT := UTL_FILE.FOPEN (P_DIR, P_FILENAME, 'w', 32767);
    DBMS_SQL.PARSE (L_THECURSOR, P_QUERY, DBMS_SQL.NATIVE);
    FOR I IN 1 .. 255
    LOOP
    BEGIN
    DBMS_SQL.DEFINE_COLUMN (L_THECURSOR, I, L_COLUMNVALUE, 4000);
    L_COLCNT := I;
    EXCEPTION
    WHEN OTHERS
    THEN
    IF (SQLCODE = -1007)
    THEN
    EXIT;
    ELSE
    RAISE;
    END IF;
    END;
    END LOOP;
    DBMS_SQL.DEFINE_COLUMN (L_THECURSOR, 1, L_COLUMNVALUE, 4000);
    L_STATUS := DBMS_SQL.EXECUTE (L_THECURSOR);
    LOOP
    EXIT WHEN (DBMS_SQL.FETCH_ROWS (L_THECURSOR) <= 0);
    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 := P_SEPARATOR;
    UTL_FILE.FFLUSH (L_OUTPUT);
    END LOOP;
    UTL_FILE.FFLUSH (L_OUTPUT);
    L_CNT := L_CNT + 1;
    END LOOP;
    DBMS_SQL.CLOSE_CURSOR (L_THECURSOR);
    UTL_FILE.FCLOSE (L_OUTPUT);
    RETURN L_CNT;
    END CORP_IB_DUMP_FILE;
    /Check your logic very carefully. You are using UTL_FILE.PUT() which should not automatically put end-of-line characters i n your file but you are reassigning l_seperator with p_seprator after the first time.
    What value are you pasising in as p_seperator?
    UTL_FILE.PUT() should allow you to write a string of bytes without newlines as long as its arguments are less than 32K, and you can control when the newlines get written. If your arguments are > 32K can you split them up without writing the newlines until you need to do so? Try something like (untested)
    --         UTL_FILE.PUT (L_OUTPUT, L_SEPARATOR || L_COLUMNVALUE);
               UTL_FILE.PUT (L_OUTPUT, substr(L_SEPARATOR || L_COLUMNVALUE,1,32767));
               UTL_FILE.PUT (L_OUTPUT, substr(L_SEPARATOR || L_COLUMNVALUE),32767*2-1,32767));Edited by: riedelme on Sep 10, 2012 6:11 AM

  • Is therr any way to drag one line in ALV to a new postion in the ALV list?

    Dear All,
    Is there any way to drag one line of ALV and drop it to  a new position ?
    Woud you please show me some simple code?

    Hi Edwards,
    Drag and drop can be achived using the events in the class.
    TABLES:
      SSCRFIELDS.
    PARAMETERS:
      P_TABLE TYPE DD02L-TABNAME OBLIGATORY.
    DATA:
      W_DYNTABLE TYPE REF TO DATA,
      W_DYSTABLE TYPE REF TO DATA,
      W_STRUC    TYPE REF TO DATA.
    FIELD-SYMBOLS:
      <T_TABLE>  TYPE STANDARD TABLE,
      <FS_TABLE> TYPE ANY,
      <T_STABLE> TYPE STANDARD TABLE,
      <FS_STABLE> TYPE ANY.
    DATA:
      EFFECT TYPE I,
      HANDLE_ALV TYPE I.
    DATA:
      GRID TYPE REF TO CL_GUI_ALV_GRID,
      CONT TYPE REF TO CL_GUI_DOCKING_CONTAINER,
      C_DRAGDROPALV TYPE REF TO CL_DRAGDROP,
      T_STBL TYPE LVC_S_STBL,
      T_LAYO TYPE LVC_S_LAYO.
    AT SELECTION-SCREEN.
      SELECT TABNAME
        FROM DD02L
       UP TO 1 ROWS
        INTO P_TABLE
       WHERE TABNAME = P_TABLE AND TABCLASS = 'TRANSP'.
      ENDSELECT.
      IF SY-SUBRC NE 0.
        CLEAR SSCRFIELDS-UCOMM.
        MESSAGE 'Invalid Table Name'(001) TYPE 'E'.
      ENDIF.
    START-OF-SELECTION.
      CREATE DATA W_DYNTABLE TYPE STANDARD TABLE OF (P_TABLE)
                                          WITH NON-UNIQUE DEFAULT KEY.
      CREATE DATA W_DYSTABLE TYPE STANDARD TABLE OF (P_TABLE)
                                          WITH NON-UNIQUE DEFAULT KEY.
      CREATE DATA W_STRUC TYPE (P_TABLE).
      ASSIGN W_DYNTABLE->* TO <T_TABLE>.
      ASSIGN W_DYSTABLE->* TO <T_STABLE>.
      ASSIGN W_STRUC->* TO <FS_TABLE>.
      ASSIGN W_STRUC->* TO <FS_STABLE>.
      SELECT * FROM (P_TABLE) INTO CORRESPONDING FIELDS OF TABLE
      <T_TABLE>.
      CALL SCREEN 100.
          CLASS lcl_dataobject DEFINITION
    CLASS LCL_DATAOBJECT DEFINITION.
      PUBLIC SECTION.
        DATA:
            INDEX TYPE I.
    ENDCLASS.                    "lcl_dataobject DEFINITION
    DATA:
      L_OBJ TYPE REF TO LCL_DATAOBJECT.
          CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
              DRAG FOR EVENT
                           ONDRAG OF CL_GUI_ALV_GRID
                           IMPORTING ES_ROW_NO E_DRAGDROPOBJ E_ROW,
              DROP FOR EVENT
                           ONDROP OF CL_GUI_ALV_GRID
                           IMPORTING ES_ROW_NO E_DRAGDROPOBJ E_ROW.
    ENDCLASS.                    "lcl_event_handler DEFINITION
          CLASS lcl_event_handler  IMPLEMENTAION
    CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
      METHOD DRAG .
        CREATE OBJECT L_OBJ.
        READ TABLE <T_TABLE> INDEX ES_ROW_NO-ROW_ID ASSIGNING <FS_TABLE> .
        IF SY-SUBRC EQ 0.
          L_OBJ->INDEX = E_ROW-INDEX.
          ASSIGN <FS_TABLE> TO <FS_STABLE>.
          APPEND <FS_STABLE> TO <T_STABLE>.
          E_DRAGDROPOBJ->OBJECT = L_OBJ.
        ENDIF.
      ENDMETHOD.                    "lcl_event_handler
      METHOD DROP.
        DELETE <T_TABLE> INDEX L_OBJ->INDEX.
        LOOP AT <T_STABLE> ASSIGNING <FS_STABLE>.
          INSERT <FS_STABLE> INTO <T_TABLE> INDEX E_ROW-INDEX.
        ENDLOOP.
        PERFORM REFRESH_TABLE.
        CLEAR <FS_STABLE>.
        REFRESH <T_STABLE>.
      ENDMETHOD.                    "drop
    ENDCLASS.                    "lcl_event_handler  IMPLEMENTAION
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'ALV'.
      SET TITLEBAR 'TITLE' WITH P_TABLE.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  display  OUTPUT
          text
    MODULE DISPLAY OUTPUT.
      CREATE OBJECT CONT
         EXPORTING
           DYNNR             = '100'
           SIDE              = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP
           EXTENSION         = 350.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT GRID
        EXPORTING
          I_PARENT          = CONT.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT C_DRAGDROPALV.
      EFFECT = CL_DRAGDROP=>MOVE + CL_DRAGDROP=>COPY.
      CALL METHOD C_DRAGDROPALV->ADD
        EXPORTING
          FLAVOR     = 'Line'(002)
          DRAGSRC    = 'X'
          DROPTARGET = 'X'
          EFFECT     = EFFECT.
      CALL METHOD C_DRAGDROPALV->GET_HANDLE
        IMPORTING
          HANDLE = HANDLE_ALV.
      T_LAYO-S_DRAGDROP-ROW_DDID = HANDLE_ALV.
      CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          I_STRUCTURE_NAME = P_TABLE
          IS_LAYOUT        = T_LAYO
        CHANGING
          IT_OUTTAB        = <T_TABLE>.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      SET HANDLER LCL_EVENT_HANDLER=>DRAG FOR GRID.
      SET HANDLER LCL_EVENT_HANDLER=>DROP FOR GRID.
    ENDMODULE.                 " display  OUTPUT
    *&      Form  refresh_table
          text
    -->  p1        text
    <--  p2        text
    FORM REFRESH_TABLE .
      CALL METHOD GRID->REFRESH_TABLE_DISPLAY
        EXPORTING
          IS_STABLE      = T_STBL
          I_SOFT_REFRESH = 'X'
        EXCEPTIONS
          FINISHED       = 1
          OTHERS         = 2.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " refresh_table
    Edited by: Kumar M on Jun 29, 2009 8:02 AM

  • Write fields from two tables in one line??

    Hi friends,
    I want to write some fields from bkpf and bseg in one line...
    My report should like something like this:
    ****some text*****
    *for first document*******  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr     
    *for second document***  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr     
    *for third document******  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr  
    etc.
    What should I change in order to get this form in report output?? Can I put these fields in some table so that it looks like excel table??Could you please check out the code below?
      loop at it_bkpf into wa_bkpf.
      loop at it_bseg into wa_bseg.
      write: wa_bseg-gsber, wa_bseg-belnr, wa_bseg-wrbtr.
      endloop.
      write: wa_bkpf-bldat.
      read table it_bsid with key bukrs = wa_bkpf-bukrs
      belnr = wa_bkpf-belnr
      gjahr = wa_bkpf-gjahr
      cpudt = wa_bkpf-cpudt.
      if sy-subrc = 0.
      write: it_bsid-kunnr.
      endif.
      endloop.
    Thanks,
    Nihad

    hi nihad,
    define positions on where to write data like this.
    LOOP AT it_bkpf INTO wa_bkpf.
      LOOP AT it_bseg INTO wa_bseg WHERE belnr EQ wa_bkpf-belnr.
        WRITE: /5 wa_bkpf-bldat.
        READ TABLE it_bsid
        WITH KEY bukrs = wa_bkpf-bukrs
                         belnr = wa_bkpf-belnr
                         gjahr = wa_bkpf-gjahr
                         cpudt = wa_bkpf-cpudt.
        IF sy-subrc EQ 0.
           WRITE: 20 it_bsid-kunnr.
        ENDIF.
        WRITE: 35 it_bseg-belnr,
                    50 it_bseg-gsber,
                    60 it_bseg-wrbtr.
      ENDLOOP.
    ENDLOOP.
    regards,
    Peter

  • I want total in one line

    Hi All,
    I am creating one ALV grid report its working fine... output is:
    Total value    Cost Element
    100              644A65
    200              644A65
    300              644A65
    400              600100
                         1000
    I want total as per cost element in one line means 644A65 has 3 value so i want output like this........
    Total value    Cost Element
    600              644A65
    400              600100
    can you guide me how can i do?
    Thanks
    zeni

    >  Total value    Cost Element
    > 100              644A65
    > 200              644A65
    > 300              644A65
    > 400              600100
    >                     -
    >                      1000
    > Total value    Cost Element
    > 600              644A65
    > 400              600100
    I assume that first  Table is it_data, Change the field order , First Cost Element ,next Total value
    final data internal table is it_final .
    sort it_data by costelement.
    loop at it_data.
    at end of costelemt.
       sum.
      append it_data to it_final.
    endat.
    endloop.

Maybe you are looking for