Regarding loop statement

hi,
how to find whether a statement exists between loop and endloop.
for eg:
          loop at itab.
          clear.....
           endloop.
want check whether clear statement exists between loop.
Thanks

Take the report into one Internal table say t_source1 using below statement.
    Reading Report to delete the comments
      READ REPORT p_pgname INTO t_source1.
Get all the includes of the program into an internal table
      CALL FUNCTION 'GET_INCLUDETAB'
        EXPORTING
          progname = p_pgname
        TABLES
          incltab  = i_incl_tab.
      IF NOT i_incl_tab[] IS INITIAL.
      Loop at this internal table and append all the data to
      Main Report table
        LOOP AT i_incl_tab INTO wa_incl_tab.
          READ REPORT wa_incl_tab-line INTO t_source_tmp.
          APPEND LINES OF t_source_tmp TO t_source1.
          REFRESH t_source_tmp[].
          CLEAR wa_incl_tab.
        ENDLOOP.
      ENDIF.
Now LOOP AT t_source1 INTO wa_source1 ..... This t_source1 is an internal table with all the lines including all subroutines.....
You can read the table line by line with Key word LOOP and once find then you can find the required Statement ....
Include one more condition... If you find a Keywork ENDLOOP then it means your required statement does not exist in LOOP and ENDLOOP..... if found then you can set a Flag....
Thanks,
Amol
I think this will solve your purpose.

Similar Messages

  • 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!

  • 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

  • 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.

  • 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

  • Dynamic where clause with loop statement

    Hi all,
    is it possible to use a dynamic where clause with a loop statement?
    Can you please advise me, how the syntax needs to be?
    Thanks for your suggestions,
    kind regards, Kathrin!

    Hi Kathrin,
               If u are in ECC 6.0, please go through the code...
              REPORT  zdynamic_select.
    TYPES:
      BEGIN OF ty_sales,
        vbeln  TYPE vbak-vbeln,            " Sales document
        posnr  TYPE vbap-posnr,            " Sales document item
        matnr  TYPE vbap-matnr,            " Material number
        arktx  TYPE vbap-arktx,            " Short text for sales order item
        kwmeng TYPE vbap-kwmeng,           " Order quantity
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
      END OF ty_sales.
    DATA :
      gt_sales TYPE STANDARD TABLE OF ty_sales,
      wa_sales TYPE ty_sales.
    DATA: ob_select TYPE REF TO cl_rs_where.
    DATA: ob_from   TYPE REF TO cl_rs_where.
    DATA: ob_where  TYPE REF TO cl_rs_where,
          gv_source TYPE abapsource.
    START-OF-SELECTION.
    *Step 1 : Prepare the select fields.
      PERFORM zf_build_select.
    *Step 2 : Build the from clause for the select
      PERFORM zf_build_from.
    *Step 3 : Build the where clause for the select
      PERFORM zf_build_where.
    *Step 4 : Execute the dynamic select
      SELECT (ob_select->n_t_where)
          FROM (ob_from->n_t_where)
            INTO CORRESPONDING FIELDS OF TABLE gt_sales
            WHERE (ob_where->n_t_where).
      LOOP AT gt_sales INTO wa_sales.
        WRITE :   /5 wa_sales-vbeln,
                  15 wa_sales-vkorg,
                  20 wa_sales-kunnr,
                  40 wa_sales-netwr,
                  50 wa_sales-posnr,
                  60 wa_sales-matnr,
                  70 wa_sales-arktx,
                  90 wa_sales-kwmeng.
      ENDLOOP.
    *&      Form  zf_build_select
    FORM zf_build_select .
      CREATE OBJECT ob_select.
    *Build the table name/field name combination
    *Add Sales order header fields
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VBELN'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VKORG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'KUNNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'NETWR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    *Add Sales order item fields
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'POSNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'MATNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'ARKTX'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'KWMENG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    ENDFORM.                    " zf_build_select
    *&      Form  zf_build_from
    FORM zf_build_from .
      CREATE OBJECT ob_from.
    *Add opening bracket
      CALL METHOD ob_from->add_opening_bracket
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'VBAK AS VBAK INNER JOIN VBAP AS VBAP'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'ON VBAKVBELN = VBAPVBELN'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
    *Add the closing bracket
      CALL METHOD ob_from->add_closing_bracket
    ENDFORM.                    " zf_build_from
    *&      Form  zf_build_where
    FORM zf_build_where .
      DATA :
      lv_field TYPE REF TO data,
      lv_field_low TYPE REF TO data,
      lv_field_high TYPE REF TO data.
      CREATE OBJECT ob_where.
    *Add the field VBELN : Sales Document
    *Use this method if you want to assign a single value to a field
    *Set the value for VBELN : Sales Document Number
    CALL METHOD ob_where->add_field
       EXPORTING
         i_fieldnm  = 'VBAK~VBELN'
         i_operator = '='
         i_intlen   = 10
         i_datatp   = 'CHAR'
       IMPORTING
         e_r_field  = lv_field.
    CALL METHOD ob_where->set_value_for_field
       EXPORTING
         i_fieldnm = 'VBAK~VBELN'
         i_value   = '0000120020'.
    *Use this method if you want to assign a range of values
    *Set a range for the Sales Document number
      CALL METHOD ob_where->add_field_between_2values
        EXPORTING
          i_fieldnm      = 'VBAK~VBELN'
          i_intlen       = 10
          i_datatp       = 'CHAR'
        IMPORTING
          e_r_field_low  = lv_field_low
          e_r_field_high = lv_field_high.
      CALL METHOD ob_where->set_2values_for_field
        EXPORTING
          i_fieldnm    = 'VBAK~VBELN'
          i_value_low  = '0000120020'
          i_value_high = '0000120067'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and.
    *Add the field MATNR : Material
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'MATNR'
          i_operator = '='
          i_intlen   = 18
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for the Material field
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'MATNR'
          i_value   = '000000000050111000'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and
    *Add the field VKORG
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'VKORG'
          i_operator = '='
          i_intlen   = 4
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for VKORG : Sales Organization
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'VKORG'
          i_value   = 'GMUS'.
    ENDFORM.                    " zf_build_where

  • 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?

  • Regarding case statement and decode function

    Hi Experts,
    I have question.....regarding case statement and decode statement....
    Can you please explain me that which one will be efficient,to place in insert statement...
    insert statement(
    (case when ........then
                         case when ....then
                         else
                         end)
      else
    end)
    or
    insert statement(
    case when.....then
    decode(....)
    else
    end)
    Can you people explain me which one is more efficient method?
    Thanks in advance.......

    The are major differences to talk about in case of CASE vs DECODE, but performance wise both are pretty much the same.
    Have a look at Tom's thread
    Ask Tom &amp;quot;better performance - case or decode&amp;quot;
    I would suggest to use CASE whenever possible. Don't worry about the performance part.

  • 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

  • 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.

  • Looping statements

    I am trying to set up a loop statement for the calculation of a mortgage amortization table. The formula I am using came from http://www.interest.com/hugh/calc/formula.html
    Here is what I have so far. It calculates the monthly payment given an array of interest rates and terms in years.
    public void monthlyPaymentCalc()
    Double P = new Double(amtLoan.getText()); // principal borrowed
    double X = P.doubleValue(); // variable X to represent the double value P
    double L = loan[0][0]; // array term years = 7 years
    double I = loan[0][1]; // array APR interest 0f 5.35
    double J = (I)/(12*100); // APR interest converted to monthly decimal
    double N = (L)*12; // convert years to payments per year (months)
    double D = (1+J); // simplify denominator for Math.pow
    double M = Math.abs(X * (J / (1 - ( Math.pow(D,-N)))));
    monthlyPayment.setText(" " + M);
    The calculations to be used in the loop are:     
    double H = X * J;           //current monthly interest
    double C = M - H;           //monthly payment minus monthly interest (principal paid)
    double Q = X - C;           //new principal balance
    X = Q;           //reset P to the new principal balance and start loop again
    I am very new at this, and have no clue how to set up a loop.. can anyone help me out with this?
    Thanks!
    visa798

    This should be very simple!
    //I am assuming that you want your loop to go round 12 times.
    for( int loopCount = 0 ; loopCount < 12 ; loopCount++ )
      //Put all that code which you want looped over here...
    }Hope this helps.
    Plutaurian

  • AW scripting question...loop statements

    Hello again Steve- everyone- I am trying to remember all the scripting options for looping statements. I know you can use a repeat/end repeat statement, but doesn't AW recognize a "while variable is true, do this"? Or a repeat while statement? Or repeat until a condition is true? I would appreciate a quick list of all the possible options for these looping statements that AW recognizes to get the dust off my brain.
    Thank you in advance for any input everyone, I always appreciate everyone's time!!
    Terry

    Authorware does support all of these, but they are named a little
    different, perhaps, than you are expecting.
    Open up the Functions window, and select the Language section. If you
    have a calc icon too, you can paste the right syntax into your calc by
    selecting the open calc, then double-clicking the appropriate language
    option.
    HTH
    Steve

  • Regarding SUBMIT statement - to process a program in background

    Hi All,
    I have issue of submitting a program in background and also i need to process the no of records come from program by splitting them by 1000(n).
    First of all i have program whose code is like following:
    <b>REPORT  z_update_material_master.</b>
    TYPES: BEGIN OF t_marc,
              matnr LIKE marc-matnr,   "Material Number
              werks LIKE marc-werks,   "Plant
              beskz LIKE marc-beskz,   "Procurement Type
              sobsl LIKE marc-sobsl,   "Special procurement type
              fhori LIKE marc-fhori,   "Scheduling Margin Key for Floats
              dzeit LIKE marc-dzeit,   "In-house production time
              plifz LIKE marc-plifz,   "Planned delivery time in days
              webaz LIKE marc-webaz,   "Goods rcpt processing time
              pwwrk LIKE t460a-wrk02,  "Production plant in planned order
              erhor LIKE t436a-erhor,  "Opening periodr
              zlt   TYPE p DECIMALS 3, "Total replenishment lead time
              ztlt  TYPE p DECIMALS 3, "Total replenishment lead time
              wzeit TYPE p DECIMALS 3, "Total replenishment lead time
              upd(1) TYPE c,            "UPDATE INDICATER
              ind    TYPE c,
         END OF t_marc.
    DATA: i_marc  TYPE SORTED TABLE OF t_marc INITIAL SIZE 0
                   WITH HEADER LINE
                   WITH NON-UNIQUE KEY matnr werks,
          i_marc_rpt LIKE i_marc OCCURS 0 WITH HEADER LINE.
    DATA: l_plantdata  LIKE bapi_marc,
          l_headdata   LIKE bapimathead,
          l_plantdatax LIKE bapi_marcx,
          l_tabix      LIKE sy-tabix.
    CONSTANTS: c_s TYPE c VALUE 'S',
               c_x TYPE c VALUE 'X'.
    DATA i_temp_bapi_return LIKE bapi_matreturn2
                            OCCURS 0 WITH HEADER LINE.
    DATA BEGIN OF i_temp_zppe0091_01 OCCURS 0.
            INCLUDE STRUCTURE zppe0091_01.
    DATA: END OF i_temp_zppe0091_01.
    DATA: l_tab_nam LIKE rstable-tabname VALUE 'ZPPE0091_01'.
    SELECT * FROM zppe0091_01
             INTO CORRESPONDING FIELDS OF TABLE i_temp_zppe0091_01.
    IF sy-subrc EQ 0.
      LOOP AT i_temp_zppe0091_01 WHERE upd = c_x.
        l_tabix = sy-tabix.
        l_headdata-material     = i_temp_zppe0091_01-matnr.
        l_plantdata-plant       = i_temp_zppe0091_01-werks.
        l_plantdata-replentime  = i_temp_zppe0091_01-wzeit.
        l_plantdatax-replentime = c_x.
        CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
          EXPORTING
            headdata       = l_headdata
            plantdata      = l_plantdata
            plantdatax     = l_plantdatax
          TABLES
            returnmessages = i_temp_bapi_return.
        IF NOT i_temp_bapi_return[] IS INITIAL.
          READ TABLE i_temp_bapi_return WITH KEY type = c_s.
          IF sy-subrc EQ 0.
            i_marc_rpt-matnr = i_temp_zppe0091_01-matnr.
            i_marc_rpt-werks = i_temp_zppe0091_01-werks.
            APPEND i_marc_rpt. CLEAR i_marc_rpt.
          ELSE.
            i_temp_zppe0091_01-upd = space.
            MODIFY i_temp_zppe0091_01 INDEX l_tabix TRANSPORTING upd.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.
    Now i want to call this program from another program that is already exists by using <b>SUBMIT</b>
    statement in background and i need to process this program by dividing records by <b>1000</b> into seperate session.
    how can i do it. Can any body tell me the solution with syntax.
    I might get lot of records from above program so i want to split them into diffrent sessions based on number of records(1000).
    can any body give me the solution.
    Thanks in advance.
    Thanks & Regards,
    Rayeez.

    Try implementing the following code. Use the code accordingly...
      MOVE 100 TO c_recs_b4_split.
      IF num_src_trans > c_recs_b4_split.
        target_break = num_src_trans / p_thread.
      ELSE.
        target_break = num_src_trans + 1.
      ENDIF.
      wa_subbch  = 1.
      last_index = 1.
    No batch split required if total recrods less than 100
      IF num_src_trans < c_recs_b4_split.
        CLEAR  : range_btch.
        REFRESH: range_btch.
        IF wa_subbch = p_thread.
          target_break = num_src_trans.
        ENDIF.
        MOVE 'S_SRCTRN' TO range_wa-selname.
        MOVE 'S'        TO range_wa-kind   .
        MOVE 'I'        TO range_wa-sign   .
        MOVE 'EQ'       TO range_wa-option .
        LOOP AT itab_src_trans INTO st_src_trans.
          MOVE st_src_trans-src_tran_id TO range_wa-low.
          APPEND range_wa TO range_btch.
        ENDLOOP.
    Step 3 Submit the batch.
        v_job_no = v_job_no + 1.
        PERFORM submit_tp_jobs.
      ELSE.
        DO.
    Step 1 Collect data for the target count
          CLEAR  : range_btch.
          REFRESH: range_btch.
         IF wa_subbch = p_thread.
           target_break = num_src_trans.
         ENDIF.
          MOVE 'S_SRCTRN' TO range_wa-selname.
          MOVE 'S'        TO range_wa-kind   .
          MOVE 'I'        TO range_wa-sign   .
          MOVE 'EQ'       TO range_wa-option .
          IF wa_subbch = p_thread.
            target_break = num_src_trans - v_cnt .
          ENDIF.
          LOOP AT itab_src_trans INTO st_src_trans FROM last_index.
            last_index = sy-tabix.
            batch_total = batch_total + 1.
            IF batch_total <= target_break.
              MOVE st_src_trans-src_tran_id TO range_wa-low.
              APPEND range_wa TO range_btch.
            ELSE.
              EXIT.
            ENDIF.
            v_cnt = v_cnt + 1.
          ENDLOOP.
          CLEAR batch_total.
    Step 2 Submit the batch.
          v_job_no = v_job_no + 1.
          PERFORM submit_tp_jobs.
          ADD 1 TO wa_subbch.
          IF wa_subbch > p_thread.
            EXIT.
          ENDIF.
        ENDDO.
      ENDIF.
    FORM submit_tp_jobs .
      DATA : l_jobcount LIKE tbtcjob-jobcount,
             l_jobrelease LIKE btch0000-char1,
             w_job_flag VALUE 'X',
             w_process_mode,
             w_user_print_params  LIKE pri_params.
      l_jobname = p_batch.
      CONCATENATE 'TP_'  l_jobname '_' v_job_no INTO l_jobname.
      CONDENSE l_jobname NO-GAPS.
      w_process_mode = ' '.
      IF NOT range_btch[] IS INITIAL.
        PERFORM create_post_ctrl.
        CALL FUNCTION 'JOB_OPEN'
          EXPORTING
            jobname  = l_jobname
          IMPORTING
            jobcount = l_jobcount.
        SUBMIT zfi_pc_tran_proc
          AND RETURN
               WITH p_batch  = p_batch
               WITH p_jobid  = p_jobid
               WITH p_mode   = w_process_mode
               WITH p_subbch = wa_subbch
               WITH p_jobq   = p_jobid
               WITH p_cntlmt = p_cntlmt
               WITH p_tpiop  = p_iop
               WITH SELECTION-TABLE range_btch
               USER sy-uname
               VIA JOB l_jobname NUMBER l_jobcount
               TO SAP-SPOOL
               SPOOL PARAMETERS w_user_print_params
               WITHOUT SPOOL DYNPRO.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount             = l_jobcount
            jobname              = l_jobname
            strtimmed            = 'X'
          IMPORTING
            job_was_released     = l_jobrelease
          EXCEPTIONS
            cant_start_immediate = 1
            invalid_startdate    = 2
            jobname_missing      = 3
            job_close_failed     = 4
            job_nosteps          = 5
            job_notex            = 6
            lock_failed          = 7
            invalid_target       = 8
            OTHERS               = 9.
      ENDIF.
    ENDFORM.                    " submit_tp_jobs
    Pl. add the points....

Maybe you are looking for