Using a recordset in a loop statement

Hello all,
I am (still) trying to get an Excel spreadsheet for a dynamically created table. A crucial parameter of the problem is that I do not know the column names for my table at runtime, as it is created by a pivot query.
I was very excited to find Tom Kyte's post on "Using a recordset in a loop statement:
http://asktom.oracle.com/pls/ask/f?p=4950:8:4768329722850645393::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:464820324673,
This is precisely the solution I need. Unfortunately for me, when I create my stored procedure, it doesn't compile. As suggested I systematically renamed EXEC_SQL to DBMS_SQL, then I made some minor tweaks to integrate with HTMLDB:
create or replace procedure export_tsv as
connection_id DBMS_SQL.CONNTYPE
default DBMS_SQL.default_connection;
cursorID DBMS_SQL.CURSTYPE;
nIgn number;
columnValue varchar2(4000);
ncols number;
sep varchar2(1);
colName varchar2(40);
colLen number;
coltype number;
BEGIN
IF DBMS_SQL.is_connected = FALSE THEN
Message('No primary connection. Please connect.');
RETURN;
END IF;
-- set up for excel spreadsheet
htp.init;
owa_util.mime_header ('application/vnd.ms-excel',false);
htmldb_application.g_page_text_generated := true;
htp.p('Content-Disposition: attachment;
filename=myexport.txt');
owa_util.http_header_close;
-- end excel spreadsheet setup
cursorID := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursorID, 'select * from exp_data', DBMS_SQL.V7);
nIgn := DBMS_SQL.EXECUTE(cursorID);
for i in 1 .. 1000 loop
begin
DBMS_SQL.describe_column( connection_id, cursorId, i,
colName, colLen, colType );
DBMS_SQL.define_column(cursorID, i, columnValue,
4000 );
exception
when DBMS_SQL.invalid_column_number then
ncols := i-1;
exit;
end;
end loop;
while (DBMS_SQL.fetch_rows(cursorID) > 0)
loop
sep := '';
for i in 1 .. ncols loop
DBMS_SQL.COLUMN_VALUE(cursorID, i, columnValue);
-- print the column value
htp.p( sep || columnValue);
sep := chr(9);
end loop;
-- print the end of line CRLF
htp.p(chr(13)|| chr(10));
END LOOP;
DBMS_SQL.CLOSE_CURSOR(cursorID);
DBMS_SQL.CLOSE_CONNECTION;
END;
When I try to run this in the HTMLDB SQL Command Processor, I see the following error:
ERROR at line 2: PLS-00302: component 'CONNTYPE' must be declared
Can someone provide me with the correct translation of Tom Kyte's approach into the HTMLDB idiom?
Thanks in advance,
susan

Questions about opening multiple worksheets on the web:
I have this link that submits the page and my process calls a PL/SQL procedure that prints out an excel spreadsheet. When I hit the link again, the spreadsheet does not update. I can make the spreadsheet update from ASP or a java servlet, but never from the PL/SQL procedure. Even if I use the procedure to print out XML in XMLSS format, so that I can change worksheet name, it still does not update on successive calls.
My code:
PROCEDURE SQL_TO_EXCEL(p_sql in varchar2)
as
l_cursor integer default dbms_sql.open_cursor;
l_status PLS_INTEGER;
l_desc dbms_sql.desc_tab;
l_col_cnt number;
l_columnValue varchar2(4000);
l_row varchar2(4000);
l_frow PLS_INTEGER;
l_lrow PLS_INTEGER;
l_cols varchar2(4000);
l_date date;
begin
--set mime type to Excel
htp.init;
owa_util.mime_header('application/vnd.ms-excel',true);
--htp.p('Pragma: no-cache');
--htp.p('Cache-Control: no-cache');
--owa_util.http_header_close;
htmldb_application.g_page_text_generated := true;
--htp.htmlOpen;
--htp.headOpen;
--htp.title('SQL to Excel Export');
--htp.headCLose;
--htp.bodyOpen;
execute immediate 'alter session set nls_date_format=''dd-mon-yyyy'''; -- hh24:mi:ss''';
DBMS_SQL Calls
dbms_sql.parse(l_cursor,rtrim(p_sql,';'),dbms_sql.native);
l_status := dbms_sql.execute(l_cursor);
dbms_sql.describe_columns(l_cursor,l_col_cnt,l_desc);
l_frow := l_desc.FIRST;
l_lrow := l_desc.LAST;
if l_col_cnt > 0 then
FOR colind IN l_frow..l_lrow LOOP
l_cols := l_cols||chr(9)||l_desc(colind).col_name;
END LOOP;
htp.p(ltrim(l_cols,chr(9)));
end if;
for i in 1 .. l_col_cnt loop
if l_desc(i).col_type = 12 then
dbms_sql.define_column(l_cursor,i,l_date);
else
dbms_sql.define_column(l_cursor,i,l_columnValue,4000);
end if;
end loop;
--l_status := dbms_sql.execute(l_cursor);
while (dbms_sql.fetch_rows(l_cursor) > 0) loop
for i in 1 .. l_col_cnt loop
if l_desc(i).col_type = 12 then
dbms_sql.column_value(l_cursor,i,l_date);
l_row := l_row||chr(9)||to_char(l_date,'DD-MON-YYYY HH24:MI:SS');
else
dbms_sql.column_value(l_cursor,i,l_columnValue);
l_row := l_row||chr(9)||l_columnValue;
end if;
end loop;
htp.p(ltrim(l_row,chr(9)));
l_row := '';
end loop;
--htp.bodyclose;
--htp.htmlclose;
dbms_sql.close_cursor(l_cursor);
exception
when others then
dbms_sql.close_cursor(l_cursor);
htp.p(SQLERRM||chr(10)||p_sql);
end SQL_TO_EXCEL;
Any ideas on how I can get the spreadsheet to update from repeated calls to the PL/SQL?

Similar Messages

  • [SOLVED] problem using variable in "for do" loop statement

    As 'm fairly new to scripting in linux there are still many things I don't know about the regular syntax. So I've made a script where in a variable $nb I retain the number of lines from the result of a series of commands. I have to use a variable as the number of lines from the output is not the same all the time.
    To finish my script I need to use a for loop something like this
    for i in {1..$nb}
    do
    echo "bla bla bla $i"
    done
    the thing is if $nb, for example, has the value 29 it outputs
    bla bla bla {1..29}
    without doing any loop.
    So how can I use a variable, to define the edge of an interval in a for statement ?
    Last edited by I'mGeorge (2011-06-18 16:19:16)

    The sanctioned method in Bash is using a C style for loop:
    for ((i=0; i<nb;i++)); do
    done
    Because brace expansion is performed before parameter expansion, a range like {1..$nb} will fail.

  • Loop statement in ABAP OO

    Hi,
    I am trying to change a BADI interface and since BADIs use ABAP OO, a simple loop statement fails to work.
    I need to loop through an internal table and for each record in the internal table I need to read another db table which has a field in common with the internal table.
    Ideally,
    Loop at lt_selections
    select logsys from /bic/mzcs_unit where /bic/zcs_unit = lt_selections-cs_unit
    endloop.
    But this piece of code fails to work in BADI because of OO concepts.
    Can anyone help me out here?
    THank you

    As Alejandro said, if you are getting a syntax error, it is probably because <b>header lines are not allow in OO</b>.
    data: wa_selections like line of lt_selections.
    Loop at lt_selections into wa_wa_selections.
    select logsys from /bic/mzcs_unit
         where /bic/zcs_unit = wa_selections-cs_unit.
    endloop.
    Regards,
    Rich Heilman
    Message was edited by: Rich Heilman

  • Delete internal table rows without using loop statement

    i have an internal table which consists of 100 records.
    i need to keep only first 5 records.
    without using the loop statement i need to delete the rest of the records. how can we achieve this result.
    i.e.  delete itab1 where  "recordno"  > 5.
    regards.
    ZG

    Hi,
    Delete itab [FROM idx1] [TO idx2] {Where (log_exp)]
    To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.
    Delete itab [FROM idx1]
    If you specify FROM, all the table rows from the table index idx1 onwards are included.
    Delete itab [TO idx2]
    If you specify TO, all the table rows from the table index idx2 onwards are included.
    PARAMETERS: p_carrid TYPE sflight-carrid,
                p_connid TYPE sflight-connid.
    DATA: BEGIN OF seats,
            fldate    TYPE sflight-fldate,
            seatsocc  TYPE sflight-seatsocc,
            seatsmax  TYPE sflight-seatsmax,
            seatsfree TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE STANDARD TABLE OF seats.
    SELECT fldate seatsocc seatsmax
           FROM sflight
           INTO TABLE seats_tab
           WHERE carrid = p_carrid AND
                 connid = p_connid.
    LOOP AT seats_tab INTO seats.
      seats-seatsfree = seats-seatsmax - seats-seatsocc.
      MODIFY seats_tab INDEX sy-tabix FROM seats.
    ENDLOOP.
    ENDLOOP.
    SORT seats_tab BY seatsfree DESCENDING.
    DELETE seats_tab FROM 5.
    Thanks & Regards,
    ShreeMohan
    Edited by: ShreeMohan Pugalia on Jul 21, 2009 4:28 PM

  • Using Looping statements to loop images

    Hi Guys i posted a similar question to this before but i couldn't get anywhere using the method that was described to me. Im currently creating a Puyo Puyo game and im nearly done ive been working on this for about 2 months im still new to java. Anyway my question is, is that after my first two puyo images reach the bottom how would i go about having my next images load and then drop and then have that loop. I understand how to create a loop statement but i just don't understand what parameters i would need to put into it and what kind of loop statement i would need i.e. for loop, do loop etc... I really could use some help ive tried and gotten this far but im pretty stuck. I appreciate any help you can provide. Here is my code so far
    public class Puyo {
        public int x, y, color;
        public Puyo(int c, int x2, int y2) {
            color = c;
            x = x2;
            y = y2;
    import javax.swing.*;
    import java.awt.*; 
    public class DemoTest extends JPanel {
        public static void main(String[] args) { {
        JFrame frame = new JFrame("Puyo Puyo");
        frame.setContentPane(new PuyoAnimation()); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setSize(200,453);
        frame.setResizable(false);
        frame.setVisible(true);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*; 
    import javax.swing.event.*;
    import java.util.Random;
    public class PuyoLogic extends JPanel {
       public static final int puyoEmpty=0;
      final int board_height = 12;
      final int board_width = 6;
      final int image_height= 32;
      final int image_width = 32;
      final int MAX_X = board_width*image_width;
      final int MAX_Y = board_height*image_height;
      private static final int DELTA_Y = 2;
      private static final int TIMER_DELAY = 20;
      Image images[];
      Puyo puyolist[][];
      Puyo current[];
      Puyo droppingBalls[];
      Timer pptimer;
      Random myRand= new Random();
      boolean keyRight,keyLeft,keyUp;
         public PuyoLogic() {
         super();
            puyolist = new Puyo[board_width][board_height];
            current = new Puyo[2];
            current[0] = new Puyo(myRand.nextInt(4), (board_width * image_width /2), 0);
            current[1] = new Puyo(myRand.nextInt(4), (board_width * image_width /2)+image_width, 0);
        // current[2] = new Puyo(myRand.nextInt(4), (board_width * image_width /2), 0);
       //     current[3] = new Puyo(myRand.nextInt(4), (board_width * image_width /2)+image_width, 0);
         images = new Image[4];
         images[0] = Toolkit.getDefaultToolkit().getImage("puyo_yellow.png");
         images[1] = Toolkit.getDefaultToolkit().getImage("puyo_blue.png");
         images[2] = Toolkit.getDefaultToolkit().getImage("puyo_green.png");
         images[3] = Toolkit.getDefaultToolkit().getImage("puyo_red.png");
         setFocusable(true);
         PuyoMove puyo_move = new PuyoMove(); // Make a new video game KeyListener
         addKeyListener(puyo_move);
         setBackground(Color.BLACK);
          pptimer = new Timer(TIMER_DELAY, new TimerAction());
          pptimer.start();
         public void setAnimation(boolean OnandOff){
            if (OnandOff) {
                pptimer.start(); 
            } else {
                pptimer.stop(); 
        public void NewBlock() {
        int newblock;
        int i,j;
        for(i=0; i<4; i++)
            for(j=0; j<4; j++)
            //puyolist[i][j] = new Puyo[2];
        current[0].x=board_width/2-2;
        current[0].y=0;
        public void puyoBoundsRight(Puyo[] current){
        if ((current[0].x + image_width <= MAX_X - image_width) && (current[1].x + image_width <= MAX_X - image_width)){
        current[0].x += image_width;
        current[1].x += image_width;
        public void puyoBoundsLeft(Puyo[] current){
        if ((current[0].x - image_width >= 0) && (current[1].x - image_width >= 0)){
        current[0].x -= image_width;
        current[1].x -= image_width;
       private class PuyoMove implements KeyListener {
         public void keyTyped(KeyEvent k){}
         public void keyReleased(KeyEvent k){}
         public void keyPressed(KeyEvent k){
            switch (k.getKeyCode()){
             case KeyEvent.VK_LEFT:
                 keyLeft = true;
                 break;
             case KeyEvent.VK_RIGHT:
                 keyRight = true;
                 break;
            public void paintComponent(Graphics g){
            super.paintComponent(g); 
            g.drawImage(images[current[0].color],current[0].x,current[0].y,this);
            g.drawImage(images[current[1].color],current[1].x,current[1].y,this);
           // g.drawImage(images[current[2].color],current[2].x,current[2].y,this);
            //g.drawImage(images[current[3].color],current[3].x,current[3].y,this);
            class TimerAction implements ActionListener {
            public void actionPerformed(ActionEvent e) {
              if (keyLeft){
                puyoBoundsLeft(current);
                keyLeft = false;
              else if (keyRight) { 
                puyoBoundsRight(current);
                keyRight = false;
              if (current[0].y + image_height <= MAX_Y && current[1].y + image_height  <= MAX_Y)
                 current[0].y += DELTA_Y;
                 current[1].y += DELTA_Y;
            else {
                   setAnimation(false);
               repaint();   
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class PuyoAnimation extends JPanel {
       PuyoLogic pl;   
      public PuyoAnimation() {
           pl = new PuyoLogic();       
           JButton startButton = new JButton("Start");       
           JButton stopButton  = new JButton("Stop");
           startButton.addActionListener(new Start());
           stopButton.addActionListener(new Stop());
           JPanel button = new JPanel();
           button.setLayout(new FlowLayout());
            button.add(startButton);
            button.add(stopButton);
           this.setLayout(new BorderLayout());
           this.add(button, BorderLayout.SOUTH);
            this.add(pl,BorderLayout.CENTER);
        class Start implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pl.setAnimation(true);
        class Stop implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pl.setAnimation(false);
    }//endclass Edited by: Riz01 on Oct 14, 2009 1:35 PM

    Don't use a loop to do graphics, it will make your game unresponsive and possibly draw enough resources from your machine to make the entire system unresponsive. You make a javax.swing.Timer object and using the timing there to drive your animations.

  • How can i use multiple row subquery in update statement

    Hai All
    I using group function in my update statement.. and i need to update more rows so i need to use multiple row
    subquery pls tell me how to use multiple row subquery in update statement
    For example
    while i am using this like this i got an error
    update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
    barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
    Pls tell me how to use with example
    Thanks & regards
    Srikkanth.M

    Hai Man
    Thanks for ur response Let me clear what i need
    First step Fetch the records as text file and stores into table T1
    and the next step is i have seperated the text using substring and stores in different columns of a table
    There are two shifts 0815 to 1645 and 1200 and 2000
    Here I rep IN and O rep OUT
    Empno date time inout
    001 01-01-10 0815 I
    002 01-01-10 0815 I
    003 01-01-10 0818 I
    001 01-01-10 1100 0
    001 01-01-10 1130 I
    002 01-01-10 1145 0
    002 01-01-10 1215 I
    004 01-01-10 1200 I
    005 01-01-10 1215 I
    004 01-01-10 1315 O
    004 01-01-10 1345 I
    001 01-01-10 1645 0
    002 01-01-10 1715 0
    003 01-01-10 1718 0
    004 01-01-10 2010 0
    005 01-01-10 2015 0
    This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
    T2 contains like this
    Empno Intime Intrin Introut Outtime Date
    001 0815 1100 1130 1645 01-01-10
    002 0815 1145 1215 1715 01-01-10
    003 0818 1718 01-01-10
    004 1200 1315 1345 2010 01-01-10
    005 1215 2015 01-01-10
    This what i am trying to do man but i have little bit problems Pls give some solution with good example
    And my coding is
    declare
         emp_code varchar2(25);
    in_time varchar2(25);
    out_time varchar2(25);
    Cursor P1 is
    Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    From temp_att
    group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    ORDER BY enpno,pdate,ptime;
    begin
         for r2 in p1 loop
    declare
    bar_code varchar2(25);
    begin
    select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
    For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
    if r2.inout ='O' then
    update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
    end if;
    end loop;     
    exception
         when no_data_found then
         if r2.inout ='I' then
                   insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
         end if;
    end;
    end loop;
    commit;     
         end;
    Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
    and how can i use it in the update statement
    Thanks In Advance
    Srikkanth.M

  • Problem using local variable in event loop

    I have a state machine from which I want to monitor various controls, including "Start" and "Stop" buttons.  Not every state needs to monitor the controls.  At present, most states run timed loops.  In the first state that reads the front panel, I have an Event structure (inside a While loop) that monitors the various controls' Change Value events.  For numeric controls, I update variables (in shift registers) as needed.  The "Start" button is used to end the While loop controlling the Event structure, allowing the State to exit to the next state.
    My problem comes in subsequent states that employ this same idea.  Here, I put a Local Variable bound to the Start button and use the same code, but it frequently happens that when I enter this particular state, I cannot "turn on" the control -- I push the button, but it stays off.  Curiously, if it was On when I enter, I can turn it off, but then I'm stuck not being able to turn it on.
    I mocked up a very simply routine that illustrates this.  There are two sequences (corresponding to the two states).  Both use an Event loop with a local variable bound to my Stop button (really this is an LED control with custom colors).  I've deliberately moved the "initialization" (the declaration of the control in the block diagram) out of the Event loops -- putting it inside the first loop modifies the behavior in another strange way.
    Here's my thinking on how I would expect this to work:  The code outside Event Loop 1 should have little effect.  Assume the Stop button is initially Off.  You will "sit" in Event Loop 1 until you push the Stop button, changing its value to True; this value will be passed out of the Event case and cause the first While loop to exit.  You now enter the second sequence.  As I understand the Exit tunnel, it defaults to "False", so I'd expect to stay in the second Event loop until I turn the Stop button from On to Off, which will pass out a False, and keep me in the While for one more button push.  However, this doesn't happen -- I immediately exit, as though the "True" value of the Stop local variable is being seen and recognized by the Event loop (even though it hasn't changed, at least not in the context of this second loop).
    An even more curious thing occurs if I start this routine with the Stop button turned on.  Now I start in my Event loop waiting for a change, but this time the change will be from On to Off, which won't cause an exit from the frame.  This will be reflected by having the While loop count increment.  We should now be in the state of the example above, i.e. in an Event loop waiting for the control to be pushed again, and turned On.  However, clicking the control has no effect -- I cannot get it to "turn on".
    Where am I going astray in my thinking?  What is it about this method of doing things that violates the Labview paradigm?  As far as I can tell, what I'm doing is "legal", and I don't see the flaw in my reasoning, above (of course not -- otherwise I'd have fixed it myself!).  Note that because I'm using local variables inside Event loops (and I'm doing this because there are two places in my code where I want to do such testing), the Stop control is not latching (as required).  Is there something that gets triggered/set when one reads a latched control?  Do I need to do this "manually" using my local variable?
    I'll try to attach the simple VI that illustrates this behavior.
    Bob Schor
    Attachments:
    Simple Stop Conundrum.vi ‏14 KB

    altenbach wrote:
    Ravens Fan wrote:
    NEVER have multiple event structures that share the same events. 
    Actually, that's OK.  NOT OK is having multiple event structures in the same sequence structure.
    See also: http://forums.ni.com/ni/board/message?board.id=170&message.id=278981#M278981
    That's interesting.  I had always thought I read more messages discouraging such a thing rather than saying it was okay.  Your link lead me to another thread with this message. http://forums.ni.com/ni/board/message?board.id=170&message.id=245793#M245793.  Now that thread was mainly concentrating on registered user events which would be a different, but related animal. 
    So if you have 2 event structures they each have their own event queue?  So if you have a common event, one structure pulls it off its event queue and it does not affect the other structure's event queue?  I guess the inherent problem with this particular VI was that the second event structure locked the front panel.  Since the code never got to that 2nd event structure because the  first loop never stopped because the change was from true to false.  After reading your post and the others, I did some experimentation and turned off the Lock front panel on the 2nd structure, and that prevented the lockup of the program.
    Overall, the example VI still shows problems with the architecture and I think your answer should put the original poster on the right track.  I think as a rule I would probably never put the same event in multiple structures, I feel there are better ways to communicate the same event between different parts of a program,  but I learned something by reading your reply and about how the event structures work in the background.  Thanks.

  • Script Logic: Using a property in MDX *REC statement (BPC NW)

    Hi,
    Is it possible to use a Property in an MDX statement without using  *LOOKUP() function? I have script successfully working but it takes 15 minutes to execute and would like to speed it up.
    I understand that [DIMENSION].[MEMBER].Property is not valid syntax, and do not believe NW has any other functions to resolve the issue, except *LOOKUP which takes a long time.
    Specific Example is below:
    I have a piece of script that successfully splits JV Expense by customers. A Profit Share planning driver determines the percentage that each customer is entitled to. Typically this will be 100%, but could be 50% between two customers.
    The PROFIT SHARE planning drivers records, and PARTNER_INCOME transactional records are below:
    ACCOUNT
    ENTITY
    PARTNER
    SIGNED DATA
    PROFIT_SHARE
    UK_001
    PARTNER_A
    0.5
    PROFIT_SHARE
    UK_001
    PARTNER_B
    0.5
    PROFIT_SHARE
    UK_002_PLANNING_DRIVERS
    PARTNER_B
    1.00
    PARTNER_INCOME
    UK_001
    NO_PARTNER
    $5,000
    PARTNER_INCOME
    UK_002
    NO_PARTNER
    $5,000
    UK_001 has two partners that are each entitled to 50% of the $5,000 NET PROFIT.
    For UK_002, one one single Partner is entitled to 100% of the $5,000 NET PROFIT.
    Using script logic, you can scope the Profit Share account (PROFIT_SHARE) - , and use a *REC statement to multiply this by the driver. It would look like:
    *XDIM_MEMBERSET ACCOUNT = PROFIT_SHARE
    *WHEN ACCOUNT
    IS *
    *REC (EXPRESSION = %VALUE% * ([ACCOUNT].[PROFIT_SHARE],[PARTNER].[NO_PARTNER]), ACCOUNT = PARTNER_PROFIT_SHARE)
    *ENDWHEN
    This wouldn't be a problem if the Planning Driver is always stored on the same Entity that the Income is stored on, but for UK_002, the planning driver is stored on another Entity - which is stored in a the PLAN_DRIVER_REF property of the entity. It should use UK_002_PLAN_DRIVERS
    ID (Entity)
    PLAN_DRIVER_REF
    UK_001
    UK_002
    UK_002_PLAN_DRIVERS
    UK_002_PLANNING_DRIVERS
    In this scenario, we need to switch out the Entity used in the MDX, however I do not believe you can use a property in MDX - can anyone confirm?
    I have currently implemented the *LOOKUP functionality to loop through, changing each *LOOKUP partner for each loop.
    Lookup:
    *LOOKUP PLANNING_JV_US
    *FOR %LOOP_ASLS% = %ASL_LOOKUP_LOOP_VARIABLE%        
      *DIM LOOK_%LOOP_PARTNERS%:ACCOUNT = "PROFIT_SHARE"
      *DIM LOOK_%LOOP_PARTNERS%:PARTNER= %LOOP_PARTNERS%
    *NEXT
    *DIM ENTITY = ENTITY.PLAN_DRIVER_REF                   //   Use PLAN_DRIVER_REF Property of Entity
    *ENDLOOKUP
    Scope and *REC:
    *XDIM_MEMBERSET ACCOUNT = PROFIT_SHARE
    *WHEN ACCOUNT
    IS *
    *FOR %LOOP_PARTNERS% = %PARTNER_LOOKUP_LOOP_VARIABLE%      // 1000 Partners
    *REC(EXPRESSION = %VALUE% * LOOKUP(LOOK_%LOOP_PARTNERS%), PARTNER= %LOOP_PARTNERS%, ACCOUNT = TCOJVSHAR_CALC, AUDIT_ID = PP_EXPENSE_BY_PARTNER)
    *NEXT
    *ENDWHEN
    The problem with the above, is that because the Lookup is being generated for every single Partner, there are significant numbers of loops.
    Does anyone know of another way this can be implemented in Script Logic? Otherwise we'll need to explore BAdI route.
    Thanks,
    Nick

    Hi Nick,
    Use property in LOOKUP - will dramatically speed up the calculation without FOR/NEXT.
    Vadim

  • Regarding LOOP Statement in ABAP

    Hi,
    I have small question regarding <b>LOOP ..... ENDLOOP</b> statement against <b>SY-SUBRC</b> Check.
    I have a loop as below:
    <b> LOOP AT i_vbap WHERE vbeln = i_vbak-vbeln.
        Some Code
        ENDLOOP.
        IF sy-subrc <> 0.
          APPEND i_sdata.
          CLEAR i_sdata.
        ENDIF.</b>
    Is the above <b>Code/Syntax</b> is correct one.
    Can we use <b>SY-SUBRC</b> Check against <b>LOOP ...  ENDLOOP</b> statement.
    Is this the right way of writing the code as per standards.
    Can anybody give sujjestions regarding the same.
    Thanks in advance.
    Thanks & Regards,
    Prasad.

    Hi Prasad,
    Yes, you could use sy-subrc after the endloop. For example:
    loop at itab1 where kunnr = itab2-kunnr.
    some conditions...
    endloop.
    if sy-subrc = 0.
    write: 'Success!'.
    else.
    leave program.
    endif.
    if you press F1 while highlighting the LOOP statement here are the meaning of sy-subrc in loop...endloop.
    SY-SUBRC = 0:
    At least one loop pass was processed.
    SY-SUBRC = 4:
    The loop was not processed because the table contains no entries or no entries satisfied the conditions.
    Regards!

  • Delete statement that uses a sub-select with the statement in the cursor

    Hi all,
    How to write write a delete statement that uses a sub-select with the statement in the cursor?
    CURSOR excluded_dates IS         
           SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
          INTO my_current_date_time
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE';
    OPEN excluded_dates;
      LOOP
        FETCH excluded_dates INTO my_excluded_date;
        EXIT WHEN excluded_dates%NOTFOUND;
        DELETE FROM edr_rpt_tmp_inclusion_table
        WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
      END LOOP;
      CLOSE excluded_dates;Thanks

    Hi,
    In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
    View created
    SQL> select * from v_employees;
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE   JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
            110 John                 Chen                      JCHEN                     515.124.4269         28/09/1997  FI_ACCOUNT    8200,00                       108           100
            112 Jose Manuel          Urman                     JMURMAN                   515.124.4469         07/03/1998  FI_ACCOUNT    7800,00                       108           100
            125 Julia                Nayer                     JNAYER                    650.124.1214         16/07/1997  ST_CLERK      3200,00                       120            50
            127 James                Landry                    JLANDRY                   650.124.1334         14/01/1999  ST_CLERK      2400,00                       120            50
            131 James                Marlow                    JAMRLOW                   650.124.7234         16/02/1997  ST_CLERK      2500,00                       121            50
            133 Jason                Mallin                    JMALLIN                   650.127.1934         14/06/1996  ST_CLERK      3300,00                       122            50
            139 John                 Seo                       JSEO                      650.121.2019         12/02/1998  ST_CLERK      2700,00                       123            50
            140 Joshua               Patel                     JPATEL                    650.121.1834         06/04/1998  ST_CLERK      2500,00                       123            50
            145 John                 Russell                   JRUSSEL                   011.44.1344.429268   01/10/1996  SA_MAN       14000,00           0,40        100            80
            156 Janette              King                      JKING                     011.44.1345.429268   30/01/1996  SA_REP       10000,00           0,35        146            80
            176 Jonathon             Taylor                    JTAYLOR                   011.44.1644.429265   24/03/1998  SA_REP        8600,00           0,20        149            80
            177 Jack                 Livingston                JLIVINGS                  011.44.1644.429264   23/04/1998  SA_REP        8400,00           0,20        149            80
            181 Jean                 Fleaur                    JFLEAUR                   650.507.9877         23/02/1998  SH_CLERK      3100,00                       120            50
            186 Julia                Dellinger                 JDELLING                  650.509.3876         24/06/1998  SH_CLERK      3400,00                       121            50
            189 Jennifer             Dilly                     JDILLY                    650.505.2876         13/08/1997  SH_CLERK      3600,00                       122            50
            200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17/09/1987  AD_ASST       4400,00                       101            10
    16 rows selected
    SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
    2 rows deleted
    SQL> regards,

  • My loop statement in smartforms seems not to be working...

    Hello Experts,
    I am currently practicing smartforms and I am trying to display the records of my internal table.
    What I did was in my table under MAIN window I have put the statement:
    it_spfli into wa_spfli and also in my main area of my table I have a loop statement. Now, in one of my text
    i put wa_spfli-carrid, wa_spfli-countryfr, etc. But it still does not show any data.Help would be greatly appreciated.

    u will be getting a function module name for the smartform then
    goto se37-->enter the FM name -->search for the ITAB you r using then put a break point.
    come back to u r program the run.. controle will stops over there then check whether the data is populating or not.
    INPUT and OUTPUT patameters are for program line and INITIALIZATION tabs.. when you want to modify some data in these you need to give the veriable or ITABs u r using inside. so that system will determine the global declarations(veriable or ITAbs).
    for more info refer these links
    http://www.sap-img.com/smartforms/sap-smart-forms.htm
    http://www.sap-img.com/smartforms/smartform-tutorial.htm
    http://www.sapgenie.com/abap/smartforms.htm

  • Loop statement in oracle

    SOurce Table
    ID ADDRESS1 ADDRESS2
    11 12 QA ST. 16 SELI ST.
    12 455 LANE 3222 ROGER LANE
    Target Table:
    ID TYPE ADDRESS1 ADDRESS2
    11 NORMAL XYZ st.
    11 HIGH ABC st.
    12 NORMAL TYU st.
    12 HIGH XCV st.
    Description of Problem:
    I have a source table in which ADDRESS1 pertains to Address1 column in target table where type= 'NORMAL' and ADDRESS2 pertains to Address 2 column in target table where type = 'HIGH'
    I want to update the target table using source table on ID so that Address column in target table is updated corresponding to the ADDRESS 1 AND ADDRESS 2 columns from source table.
    I am using the following code:
    MERGE
    INTO TARGET tgt
    USING SOURCE src
    ON (src.ID = tgt.ID)
    WHEN MATCHED
    THEN
    UPDATE
    SET tgt.address1 = src.address1
    where TGT.type = '=NORMAL'
    How can i update the address2 column in the target table where type = 'HIGH'
    in one shot.
    I dont want to write two seprate queries.
    I think i can use loop statement.
    Please Advice as how to use loop, else any other suggestion.
    Thanks

    user11018028 wrote:
    SOurce Table
    ID ADDRESS1 ADDRESS2
    11 12 QA ST. 16 SELI ST.
    12 455 LANE 3222 ROGER LANE
    Target Table:
    ID TYPE ADDRESS1 ADDRESS2
    11 NORMAL XYZ st.
    11 HIGH ABC st.
    12 NORMAL TYU st.
    12 HIGH XCV st.
    Description of Problem:
    I have a source table in which ADDRESS1 pertains to Address1 column in target table where type= 'NORMAL' and ADDRESS2 pertains to Address 2 column in target table where type = 'HIGH'
    I want to update the target table using source table on ID so that Address column in target table is updated corresponding to the ADDRESS 1 AND ADDRESS 2 columns from source table.
    I am using the following code:
    MERGE
    INTO TARGET tgt
    USING SOURCE src
    ON (src.ID = tgt.ID)
    WHEN MATCHED
    THEN
    UPDATE
    SET tgt.address1 = src.address1
    where TGT.type = '=NORMAL'
    How can i update the address2 column in the target table where type = 'HIGH'
    in one shot.
    I dont want to write two seprate queries.
    I think i can use loop statement.
    Please Advice as how to use loop, else any other suggestion.
    ThanksMaybe this? If you provide scripts for create tables and sample data this wouldn't be a guess :)
    MERGE
    INTO TARGET tgt
    USING SOURCE src
    ON (src.ID = tgt.ID)
    WHEN MATCHED
    THEN
    UPDATE
    SET tgt.address1 = case when TGT.type  = 'NORMAL' then src.address1 else tgt.address1 end
    ,   tgt.address2 = case when TGT.type != 'NORMAL' then src.address2 else tgt.address2 end

  • Loop statement logic required!!!

    Dear Gurus,
    The following is used now. Need to change into Loop statement.
    Read the internal table t_ABC INTO w_ABC WITH KEY ....       "ABC is to collect all Successful Insertion
      IF sy-subrc NE 0.
        CLEAR w_ABC.
        Read the internal table t_XYZ INTO w_ABC WITH KEY ....
        IF sy-subrc EQ 0.
          PERFORM locktable.
          INSERT ABC FROM w_ABC.
          IF sy-subrc NE 0.
            w_failure = c_x.
          ENDIF.
          PERFORM unlocktable.
          APPEND w_ABC TO t_ABC.   "Here t_ABC will hv only all Successful Insertion records
          CLEAR w_ABC.
        ENDIF.
      ENDIF.
    Since there will be more than one record, I can't use READ Statement.
    How to use Loop? But it should not affect performance.
    My worry is that, if i use "Locking the table" and "Insert" inside Loop, then it will affect performance.
    Can any one please help me out?
    It's pretty urgent.
    Points will be rewarded immediately.
    Thanks & Regards,
    Neeraj

    Hi,
    Loop at t_abc INTO w_ABC .
    Read table t_XYZ INTO w_ABC WITH KEY ....
    IF sy-subrc EQ 0.
    PERFORM locktable.
    INSERT ABC FROM w_ABC.
    IF sy-subrc NE 0.
    w_failure = c_x.
    ENDIF.
    PERFORM unlocktable.
    APPEND w_ABC TO t_ABC. "Here t_ABC will hv only all Successful Insertion records
    CLEAR w_ABC.
    ENDIF.
    ENDIF.

  • Use of cursors insted of select statements

    could any one please explain what is the advantage of using cursors instead of simple select statements
    thanks
    siby

    A benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
    if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
    declare
    v_var varchar2(1);
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin <<main>>
    do_something('x');
    begin <<selectblock>>
    select dummy
    into v_var
    from dual
    where dummy = 'a';
    do_something(v_var);
    exception
    when no_data_found then
    log_error;
    end selectblock;
    do_something (v_var||'abc');
    end main;
    if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
    BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
    declare
    v_var varchar2(1);
    cursor my_cur is
    select dummy
    from dual
    where dummy = 'a';
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin << main>>
    for cur_rec in my_cur loop
    dbms_output.put_line('inside');
    begin <<loop_block>>
    if nvl(my_cur%rowcount,0) > 1 then
    do_something(cur_rec.dummy);
    else
    log_error;
    end if;
    end loop_block;
    end loop;
    end main;
    /

  • Performance issue in Loop statement.

    Hi experts,
    I got an issue regarding performance in the loop statement. (IT_OUT_FINAL has huge amount of data.)
    LOOP AT it_out_final INTO wa_out_final.
    READ TABLE it_prdline_txt
    WITH KEY ydprodln = wa_out_final-prdline.
    IF sy-subrc = 0.
    wa_out_final-prdline = it_prdline_txt-ydvtext.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING prdline.
    CLEAR: wa_out_final.
    ENDIF.
    read table i_sokna with key kunnr = wa_out_final-kunnr.
    if sy-subrc eq 0.
    wa_out_final-soreg = i_sokna-regio.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING soreg.
    endif.
    read table i_sokna with key kunnr = wa_out_final-kunwe.
    if sy-subrc eq 0.
    wa_out_final-shreg = i_sokna-regio.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING shreg.
    endif.
    clear : i_sokna,wa_out_final.
    ENDLOOP.
    Can you please help me , how to improve the performance in the above loop statement.
    Thanks,
    Revanth Kumar
    Moderator message: duplicate post locked.
    Edited by: Thomas Zloch on Jun 20, 2011 1:22 PM

    Hi,
    This one helped me in understanding the basics clearly. But I would like to further give you one example by which my question will be more clear to you and hence your further answer to it will help me in getting the idea about WHERE clause clarified.
    I was required to develop a report of all held docs by the SAP USER that were created through transaction FB60, the input obtained from user should be SAP USERNAME(obligatory).
    So the straight approach by me was that writing a SELECT-OPTIONS asking SAP USERNAME, and such username obtained from USER executing a report will be compared with the USERNAME stored in the column of table RFDT which stores all such held docs by a SAP USER that used transaction FB60 to temporarily hold it.
    So the approach used by me was using the select statement fetch all records from the column storing the SAP USERNAMES that have held docs using FB60 transaction and where clause is used to filter out only values matching the values obtained from user i.e. using SELECT-OPTIONS.
    So I was under the impression that WHERE clause can only be used in SELECT STATEMENT and not in LOOP AT...ENDLOOP.
    Now I hope my question is more clear to you. If I am not wrong, there can be two approaches,
    1) Using a SELECT statement containing the WHERE clause, fetch a resultset and then using LOOP...ENDLOOP. statement, display the output of the report using WRITE statement.
    i.e. SELECT...WHERE...ENDSELECT and then LOOP AT...ENDLOOP.
    2) Using SELECT statement, fetch all possible records and using LOOP...ENDLOOP. statement filter out the records using WHERE to match the resultset and display values in that resultset using WRITE statement
    i.e. SELECT...ENDSELECT and then LOOP AT...WHERE...ENDLOOP.
    Hope you will now be able to guide me better.
    Regards
    Ameet

Maybe you are looking for