Output in a comma list

Hi all,
i am need the change the output of the below query.
SQL> select department_id,employee_id from employees order by department_id;
DEPARTMENT_ID EMPLOYEE_ID
           10         200
           20         201
           20         202
           30         114
           30         119
           30         115
           30         116
           30         117
           30         118
           40         203
           50         198
DEPARTMENT_ID EMPLOYEE_ID
           50         199
           50         120
           50         121
           50         122
           50         123
           50         124
           50         125
           50         126
           50         127
           50         128
           50         129
DEPARTMENT_ID EMPLOYEE_ID
           50         130
           50         131
           50         132
           50         133
           50         134
           50         135
           50         136
           50         137
           50         138
           50         139
           50         140
DEPARTMENT_ID EMPLOYEE_ID
           50         141
           50         142
           50         143
           50         144
           50         180
           50         181
           50         182
           50         183
           50         184
           50         185
           50         186
DEPARTMENT_ID EMPLOYEE_ID
           50         187
           50         188
           50         189
           50         190
           50         191
           50         192
           50         193
           50         194
           50         195
           50         196
           50         197
DEPARTMENT_ID EMPLOYEE_ID
           60         104
           60         103
           60         107
           60         106
           60         105
           70         204
           80         176
           80         177
           80         179
           80         175
           80         174
DEPARTMENT_ID EMPLOYEE_ID
           80         173
           80         172
           80         171
           80         170
           80         169
           80         168
           80         145
           80         146
           80         147
           80         148
           80         149
DEPARTMENT_ID EMPLOYEE_ID
           80         150
           80         151
           80         152
           80         153
           80         154
           80         155
           80         156
           80         157
           80         158
           80         159
           80         160
DEPARTMENT_ID EMPLOYEE_ID
           80         161
           80         162
           80         163
           80         164
           80         165
           80         166
           80         167
           90         101
           90         100
           90         102
          100         110
DEPARTMENT_ID EMPLOYEE_ID
          100         108
          100         111
          100         112
          100         113
          100         109
          110         206
          110         205
                      178
107 rows selected.Now i need to change this output in the floowing manner.
DEPARTMENT_ID EMPLOYEE_ID
           10         200
           20         201,202
           30         114,119,115,116,117,118
           30         119
           40         203
the employee id should be in a comma separated list instead of a single row.

rajavu1 wrote:
You can use Sys_Connect_By_path also as given below.
SQL> SELECT DEPTNO,
2 LTRIM(MAX(SYS_CONNECT_BY_PATH(EMPNO,',')),',')  AS EMPNOLIST
3 FROM   (SELECT deptno,
4                         EMPNO,
5                         ROW_NUMBER() OVER (PARTITION BY DEPTNO ORDER BY EMPNO) AS CURR,
6                         ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY empno) -1 AS prev
7               FROM   emp)
8  GROUP BY deptno
9  CONNECT BY PREV = PRIOR CURR AND DEPTNO = PRIOR DEPTNO
10  START WITH curr = 1;
DEPTNO EMPNOLIST
30 7499,7521,7654,7698,7844,7900
20 7369,7566,7876,7902
10 7782,7839
SQL>
Urgh! Misuse of MAX and GROUP BY in a hierarchical query, and an unnecessary extra row_number calculation.
SQL> ed
Wrote file afiedt.buf
  1  select deptno
  2        ,trim(',' from sys_connect_by_path(empno,',')) as empnolist
  3  from  (select deptno
  4               ,empno
  5               ,row_number() over (partition by deptno order by empno) as rn
  6         from emp)
  7  where connect_by_isleaf = 1
  8  connect by deptno = prior deptno and rn = prior rn + 1
  9* start with rn = 1
SQL> /
    DEPTNO EMPNOLIST
        10 7782,7839,7934
        20 7369,7566,7788,7876,7902
        30 7499,7521,7654,7698,7844,7900In 10g you can use CONNECT_BY_ISLEAF to give only the leaf nodes of the hierarchy, and when comparing row numbers it's easier to just "+1" to the prior in the connect by clause rather than calculating an extra row_number value.

Similar Messages

  • Reading text file and output (to stdout) a list of the unique words in the

    Hi,
    I have a main method as
    main.java
    package se.tmp;
    public class Main
    public static void main( String[] args )
    WordAnalyzer.parse( args[0] );
    and text file as
    words.txt
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the requirement is like
    I need create this WordAnalyzer class, implement the parse method, and then commit the file. This method takes a single parameter, the filename of the file to parse. The method should read this file and output (to stdout) a list of the unique words in the file along with the number of times each appears in the file.
    Can anyone please help me on this?
    Thanks.

    Where are you having problems?

  • Is it Possible to display the output of the ALV list as POP-UP

    Hi Experts,
                     Is it Possible to display the output of the ALV list as POP-UP, if yes then provide some ideas on it.
    thanking in advance,
    Samad.

    Hi samad, it is possible to display alv list as pop-up by using the FM " REUSE_ALV_POPUP_TO_SELECT"
    try this sample code
    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
          EXPORTING
       I_TITLE                       =  P1_TITLE
           I_SELECTION                   = 'X'
           I_ZEBRA                       = 'X'
      I_CHECKBOX_FIELDNAME          =
      I_LINEMARK_FIELDNAME          =
      I_SCROLL_TO_SEL_LINE          = 'X'
            I_TABNAME                     = 'T_VBAP'
           I_STRUCTURE_NAME              =  'T_VBAP'
           IT_FIELDCAT                   =  T_FCAT2
           I_CALLBACK_PROGRAM            = 'ZTEST_ALV_POPUP'
       IMPORTING
           ES_SELFIELD                   = I_SELFIELD
           E_EXIT                        = W_EXIT
          TABLES
            T_OUTTAB                      = T_VBAP.
    i think it will solve your problem
    Regards,
    Vijay

  • Output in a seperate list when we click a button

    hi experts,
                when we click a button in alv list it should display the output in a seperate list
    thanks
    harish

    Hi,
    It can be handled in user command event...
    Regards,
    Kumar.

  • 9iJSP Report output to a comma seperated file

    Hi,
    Is it possible to create a comma seperated file with output data from a 9iJSP report. If yes, can anyone tell me how ??
    thanks in advance
    Unmesh

    Hello Unmesh,
    If your JSP report has a paper layout, then you can use Reports Builder or the client/servlet/runtime executables to generate the paper layout to CSV formatted output with the DESFORMAT=DELIMITEDDATA and DELIMITER=, command-line options. If you have only a web layout , it will generate its output only in HTML format.
    You can add a paper/web layout to your JSP report, if it already doesn't have one, by opening it in Reports Builder, and inserting a report block in the paper layout view/web source view. This JSP report can then be used both to generate to CSV format using rwservlet, and to the web when deployed as a JSP.
    Thanks,
    The Oracle Reports Team.

  • How to change the ColumnName in the output of an ALV List

    ello Experts,
    Can you please let me know how can I change the column name of a field in an ALV List. For eg: I want to see the 'I_FIELDCAT-MATNR' field's name as 'ITEM NUMBER' in the output.
    Thanks for the help

    Hi Raj,
    Have a look at this file.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/eac1fa0b-0e01-0010-0990-8530de4908a6
    Reward if useful.
    Thanks
    Aneesh.

  • Output determination for picking list

    Dear friends,
    Where to assign procedure of o/p determination of Picking list.Give me path. Which procedure shall i assign.Pls give me immidiate solution.

    Use transaction code NACE for using the o/p determination
    Then select V2 for shipping as you are creating o/p for delivery
    Create table, maintain access sequence, maintain output type and assign o/p to procedure. Then create the master record in VV21. In o/p you have std functionality to use EDI, email, Print, Fax, ALE
    if you are having problem using NACE transaction, use this flow:
    SPRO>Logistics Execution>Shipping>Basic Functions>Output Control>Outpur determination>maintain o/p determination for outbound deliveries.
    reward points if helpful
    Message was edited by:
            Comes Naturally

  • Smartform for output type CHKL (count list ) as Inbound Delivery(E1)

    At this moment, I know the Sapscript form RT_CHECK_LIST & program RTCHECKL for count list (output type CHKL) as inbound delivery (E1), but I need  the PROGRAM and SMARTFORM for this output?!
    Thanks in advanced

    I don't think we have a similar print program and smartform available, if you want to use it in Smartfrom.. copy SAPscript and migrate to smartform using SF_migrate and copy the print program of SAPscript and make necessary changes.
    Regards,
    SaiRam

  • Output device for MB51 List

    Hello Experts!
    Does anybody know how can I find to which output device a user sends the list he gets from MB51?
    Regards,
    Ileana

    Hi,
    The user says the documents are not printed there, and once the user clicks 'print', everything is printed automatocally, she doesn't do any input... Is theresomething like an output device for program / for user????
    Regards,
    Ileana

  • Dedupe a comma list

    I have a string of values in a comma delimited list. Is there
    a quick and easy way to find exact duplicated and remove all but
    one?
    I am sure I could sit down and come up with CFLOOP/IF-fest
    but wondered if there was already something out there.

    Jonathan,
    Everything I've seen and used involved loops, structs and the
    like. I did find this UDF on CFlib.org:
    http://www.cflib.org/udf.cfm?ID=1275
    It's pretty straightforward and might save you a little
    typing!
    Cheers,
    Craig

  • How to generate oracle report output in a comma separated format in reports

    Pls any one can help in generation of oracle report in comma separated format in reports 10g.....
    thanks,
    prasad.
    1,Chennai,Nokiasiemen,Convent junction,5535

    Use desformat=delimited.
    http://download.oracle.com/docs/cd/E15523_01/bi.1111/b32122/orbr_howto007.htm#i1040102

  • Output the record in list

    ■        Create a work area with the following fields
    o        EMPNO
    o        EMPNA
    o        EMPID
    o        EMPDA (Joining Date)
    o        EMPSA (Salary)
    ■        Initialize the EMPDA to 30/01/2008 and EMPSA to   1000
    ■        Populate 10 records in a ‘DO LOOP’
    ■        Everytime you fill up the record increment the Month and Year by one for the field EMPDA and EMPSA by 1000
    ■        Output the record

    I don't know what is your exact requirement ..
    data : begin of itab occurs 0,
       EMPNO(10),
       EMPNA(40),
       EMPID(10),
       EMPDA like sy-datum,
       EMPSA type ANSAL_15,
    end of itab.
    itab-EMPDA = '20080130'.
    itab-EMPSA = 1000.
    do 10 times.
      itab-pernr = <value>.
    *populate all other values ...
      append itab.
      clear itab.
      itab-EMPDA0(4) = itab-EMPDA0(4) + 1.
      itab-EMPDA4(2) = itab-EMPDA4(2) + 1.
      itab-EMPDA+6(2) = '30'.
    (write logic for FEB ... )
      itab-EMPSA = itab-EMPSA + 1000.
    enddo.
    loop at itab.
      write :/ itab-empno , itab-empna ...
    endloop.

  • Output type EK00 pickng list error

    hi all,
    while issuing a delivery doc to o/p in vl02n. i get a message 'output cud not be issued'. i have chckd all cond recodrds and config is in place. we are using SAP script for this purpose.  the processng status is also 2 tht is 'incorreclty processed'.
    plz guide.
    thnx in advance
    saurabh

    hi manoj,
    thnx for the reply. i need some more clarifications. wen i go to vg01 and choose the grp 'k' for picking and assign Ek00 to it, i got a message that ek00 is not defined in application v5- grps. i created a new o/p type ek00 for v5. i have assigned the delivery number to the grp too. but am still getting the same issue. on analysing the issue futher i get a mssg ' An error occurred in the message processing program'. how do i proceed.
    saurabh

  • Output of two ALV lists in background

    HI ALV experts,
    [Soory I just saw that I posted this yesterday with a wrong subject]
    I'm currently working with an existing reports which is quite complex. The report creates an ALV grid and uses a couple of write statements to create some statistics.
    Running the report, we get the ALV grid. Then using BACK/F3 we leave the grid and get the list showing statistics.
    I would like to create an ALV for the statistics. This works fine online: After leaving the grid the statistics ALV is started. But in background, I got just one list.
    I tried this sample:
    FORM batchtest .
      DATA:
        lr_data TYPE REF TO data,
        lo_salv TYPE REF TO cl_salv_table.
      FIELD-SYMBOLS:
        <table>  TYPE table.
    * dynamic table fpr T000
      CREATE DATA lr_data TYPE TABLE OF t000.
      ASSIGN lr_data->* TO <table>.
      SELECT * INTO TABLE <table> FROM t000.
    * show table in grid
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_structure_name = 'T000'
        TABLES
          t_outtab         = <table>
        EXCEPTIONS
          program_error    = 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.
    * create another table
      TRY.
          CREATE DATA lr_data TYPE TABLE OF t100.
          ASSIGN lr_data->* TO <table>.
          SELECT * INTO TABLE <table> FROM t100 UP TO 100 ROWS.
          cl_salv_table=>factory(
            EXPORTING
              list_display   = if_salv_c_bool_sap=>true
            IMPORTING
              r_salv_table   = lo_salv
            CHANGING
              t_table        = <table> ).
    * display list
          lo_salv->display( ).
        CATCH cx_salv_msg .
          ASSERT 1 = 2.
      ENDTRY.
    ENDFORM.                    " BATCHTEST
    Online, it works fine. In batch, I get only the second table as list. If I exit after calling FUNCTION 'REUSE_ALV_GRID_DISPLAY', I get the first list only. How to get both lists printed in sequence? I will not use ALV block list display, because this would mean major restructuring of the program and no grid online. SUBMIT ist no good idea as well.
    Thanks in advance
    Regards
    Clemens

    Hi
    The option is in layout structure adn has to be set in the next ALV function called, so if the program works in background mode it can call REUSE_ALV_LIST_DISPLAY instaed of CL_SALV_TABLE.
    The call can be place in the END_OF_LIST event of ALV:
    TYPE-POOLS: SLIS.
    PERFORM BATCHTEST.
    FORM BATCHTEST .
      DATA:
        LR_DATA TYPE REF TO DATA,
        LO_SALV TYPE REF TO CL_SALV_TABLE.
      FIELD-SYMBOLS:
        <TABLE>  TYPE TABLE.
      DATA: T_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.
      DATA: L_PRINT  TYPE SLIS_PRINT_ALV.
      DATA: L_REPORT TYPE SY-REPID.
    * dynamic table fpr T000
      CREATE DATA LR_DATA TYPE TABLE OF T000.
      ASSIGN LR_DATA->* TO <TABLE>.
      SELECT * INTO TABLE <TABLE> FROM T000.
      IF SY-BATCH = 'X'.
    * In background only
        L_PRINT-PRINT              = 'X'. "Print ALV
        L_PRINT-NO_PRINT_LISTINFOS = 'X'.
        T_EVENTS-NAME = 'END_OF_LIST'.    "Call event
        T_EVENTS-FORM = 'END_OF_LIST'.
        APPEND T_EVENTS.
      ENDIF.
      L_REPORT = SY-REPID.
    * show table in grid
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = L_REPORT
          I_STRUCTURE_NAME   = 'T000'
          IT_EVENTS          = T_EVENTS[]
          IS_PRINT           = L_PRINT
        TABLES
          T_OUTTAB           = <TABLE>
        EXCEPTIONS
          PROGRAM_ERROR      = 1
          OTHERS             = 2.
      IF SY-SUBRC  NE 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CHECK SY-BATCH IS INITIAL.
    * The form for the nex ALV is called by event END_OF_LIST if the
    * program works in background   
      PERFORM NEXT_LIST.
    ENDFORM.                    " BATCHTEST
    FORM NEXT_LIST .
      DATA:
        LR_DATA TYPE REF TO DATA,
        LO_SALV TYPE REF TO CL_SALV_TABLE.
      FIELD-SYMBOLS:
        <TABLE>  TYPE TABLE.
      DATA: LT_LAYOUT TYPE SLIS_LAYOUT_ALV.
    * create another table
      TRY.
          CREATE DATA LR_DATA TYPE TABLE OF T100.
          ASSIGN LR_DATA->* TO <TABLE>.
          SELECT * INTO TABLE <TABLE> FROM T100 UP TO 100 ROWS.
          IF SY-BATCH IS INITIAL. "Online
            CL_SALV_TABLE=>FACTORY(
              EXPORTING
                LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>TRUE
              IMPORTING
                R_SALV_TABLE   = LO_SALV
              CHANGING
                T_TABLE        = <TABLE> ).
    * display list
            LO_SALV->DISPLAY( ).
          ELSE.                   "In background
            LT_LAYOUT-LIST_APPEND = 'X'. "Append new ALV list
            CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
              EXPORTING
                I_STRUCTURE_NAME = 'T100'
                IS_LAYOUT        = LT_LAYOUT
              TABLES
                T_OUTTAB         = <TABLE>
              EXCEPTIONS
                PROGRAM_ERROR    = 1
                OTHERS           = 2.
            IF SY-SUBRC  NE 0.
              MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
          ENDIF.
        CATCH CX_SALV_MSG .
          ASSERT 1 = 2.
      ENDTRY.
    ENDFORM.                    " NEXT_LIST
    FORM END_OF_LIST.
      PERFORM NEXT_LIST.
    ENDFORM.                    "END_OF_LIST
    Max

  • Output number with comma separator

    I have the value 1250 as an amount in a smartform.  And I want to output this as 1,250.  How do I do this?

    Hi...
    Use this function module.....
    it will satify your requirements...
    pass that changing parameter to the smartform..
    DATA: v_cur like TCURX-CURRKEY,
            c_cur(10) type c VALUE '1250'..
      CALL FUNCTION 'SD_CONVERT_CURRENCY_FORMAT'
        EXPORTING
          i_currency                  = v_cur
    *   IMPORTING
    *     E_CURRENCY_INT_FORMAT       =
        changing
          c_currency_ext_format       = c_cur
       EXCEPTIONS
         WRONG_FORMAT                = 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.
      WRITE: C_CUR.
    I believe this will greatly help you.
    Thanks and regards
    Bhuvana

Maybe you are looking for

  • Sales Orders Report which are invoiced

    Hi gurus, I want to take a report of Sales orders which are invoiced. Its order related invoice. Eg. from 01.04.2008 to 30.04.2008 I created 120 Sales orders, out of 120 i created invoices for 80 Sales orders. Now i want the report of the Sales order

  • IOS Calendar not showing correct day of the Week. Anyone having this same issue?

    Hello! I live in Brazil and this is what I am seing today for my calendar.  Today is Thursday not Friday. The horizontal weekdays is showing that 31 is a 'Sexta' which is Friday.  Apparently, someone told me this is happening only in Brazil.  Started

  • Capture problem

    I am having trouble capturing from my Sony HVR -HD1000U to Final Cut Express since I changed to Lion from Snow Leopard. Any suggestions

  • My computer can not be muted

    My computer can't be muted. In the past few days, the sound will automatically go to the highest level. If I push mute (after rebooting) it will stay off for perhaps 5 minutes. As long as my computer is on, it stays at the highest level. The sound ic

  • How do I download Framemaker 11. My copy was wiped out by Acronis True Image.

    I tried to clone my program disk with Acronis True Image. Through my fault, or through a program mis-step, the program wiped out my Framemaker 11. How do I download a new copy?