Dynamic IF statement

Hi all @SAPForums,
I need to manage an IF statement whose conditional expression depends on certain parameters. I wonder if there's an easy way to do as follows:
IF parameter 1 is not set (EQ SPACE), then the condition must be:  IF it_po_items-delete_ind <> 'L'.
IF parameter 2 is not set (EQ SPACE), then the condition must be:  IF it_po_items-delete_ind <> 'S'.
IF both parameters are not set, the condition must be the concatenation of the two above:
IF it_po_items-delete_ind <> 'L' AND it_po_items-delete_ind <> 'S'.
IF both params are set (EQ 'X', they are flags), then there's no condition at all. (IF true?).
Sounds like a thing I could manage using dynamic conditional statements, I did once time ago on a WHERE clause in a SELECT statement, but I'm not able to redo it in this case... maybe because isn't possible in an IF statement?
Thanks for any help you would give me

Hi,
You can use ranges...for this..
Ex..
DATA: r_range TYPE RANGE OF loekz,
          s_range LIKE LINE OF r_range.
s_range-sign = 'I'.
s_range-option = 'EQ'.
*IF parameter 1 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind 'L'.
IF parameter1 = SPACE.
  s_range-low = 'L'.
  APPEND s_range TO r_range.
ENDIF.
*IF parameter 2 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind 'S'.
IF parameter2 = SPACE.
  s_range-low = 'S'.
  APPEND s_range TO r_range.
ENDIF.
IF it_po_items-delete_ind IN r_range. " Only one IF condition should be enough..
**Condition satisfied. 
ENDIF.
Hope this is clear.
Thanks
Naren

Similar Messages

  • Dynamic IF statement in PL/SQL on-insert trigger in Forms 6.0

    I would like to build a dynamic IF statement for the on-insert trigger in a form... Users are restricted to which "projects" they are allowed to enter into the database. These restrictions are based on a security table. The same restrictions are used to build the dynamic where clause that limits which previously inserted records the users can see when they are in the form. Since the restrictions are identical, I want to use the same logic that I use to build a where clause to build a dynamic If statement instead... If the statement is true, the user can insert the record. If its false, they can't.
    I'm trying to this as follows:
    declare
    big_if varchar2(10000) :=' ';
    begin
    if :global.admin='YES'
    then
    insert_record;
    else
    declare
    cursor cur1 is
    select paren1, field, comparison_operator, value, paren2, and_or
    from rcdb.user_project_assign2
    where user_id = user;
    c1_rec cur1%ROWTYPE;
    begin
    for c1_rec in cur1 loop
    big_if:= big_if &#0124; &#0124; c1_rec.paren1 &#0124; &#0124; ':tbl_main_data.' &#0124; &#0124;c1_rec.field &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    end loop;
    end;
    if big_if
    then
    insert_record;
    else message('You are not allowed to insert this record');
    end if;
    end if;
    end;
    The problem is in the line
    IF big_if
    big_if is the variable that holds the text to my if statement (hense dynamic If statement) but I can't get the code to allow me to use that variable.
    Can anyone do this?
    null

    That code was great, but forms isn't allowing me to use the dbms_sql so I have to make a procedure out of forms and call it from the form. Both my form code and the procedure are compiling, but I"m still getting an error when the result is coming back to the form...
    the code in the form is:
    declare
    big_if varchar2(10000) :=' ';
    result varchar2(5) :=' ';
    check_state varchar2(2):=:tbl_main_data.state_abr;
    check_region varchar2(3):=:tbl_main_data.region_abr;
    check_program varchar2(25):=:tbl_main_data.program;
    begin
    if :global.admin='YES'
    then
    insert_record;
    else
    declare
    cursor cur1 is
    select paren1, field, comparison_operator, value, paren2, and_or
    from rcdb.user_project_assign2
    where user_id = user;
    c1_rec cur1%ROWTYPE;
    begin
    for c1_rec in cur1 loop
    big_if:= big_if &#0124; &#0124; c1_rec.paren1;
    if c1_rec.field = 'state_abr' then
    big_if:=big_if &#0124; &#0124; 'check_state' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    elsif c1_rec.field = 'region_abr' then
    big_if:=big_if &#0124; &#0124; 'check_region' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    elsif c1_rec.field = 'program' then
    big_if:=big_if &#0124; &#0124; 'check_program' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    end if;
    end loop;
    end;
    message(big_if); pause;
    message(check_state); pause;
    message(check_region); pause;
    message(check_program); pause;
    rcdb.check_if(big_if,result,check_state,check_region,check_program);
    message('resulte = &#0124; &#0124;result&#0124; &#0124;');
    if result = 'TRUE' then insert_record;
    else
    message ('you cant enter');
    end if;
    end if;
    end;
    AND THE CODE IN THE PROCEDURE IS....
    create or replace procedure check_if (
    big_if in varchar2,
    result out varchar2,
    check_state in varchar2,
    check_region in varchar2,
    check_program in varchar2
    IS
    v_indx binary_integer := 0;
    v_sql_syntax varchar2(32767);
    root_cursor number;
    ignore integer;
    your_if_statement VARCHAR2(32767);
    v_check VARCHAR2(5);
    BEGIN
    your_if_statement := ' if '&#0124; &#0124;big_if&#0124; &#0124;' then :v_check := ''TRUE''; end if;';
    v_sql_syntax := 'begin '&#0124; &#0124;your_if_statement&#0124; &#0124;' end;';
    root_cursor := dbms_sql.open_cursor;
    v_sql_syntax := replace(replace(REPLACE(v_sql_syntax,chr(10),' '),chr(13),' '),chr(9),' ');
    dbms_sql.parse(root_cursor,v_sql_syntax,dbms_sql.v7);
    dbms_sql.bind_variable( root_cursor, ':v_check',v_check,5);
    ignore := dbms_sql.execute(root_cursor);
    dbms_sql.variable_value(root_cursor, ':v_check', v_check);
    if v_check = 'TRUE' then result:='TRUE';
    else
    result:='FALSE';
    end if;
    dbms_sql.close_cursor(root_cursor);
    END check_if;
    DO YOU KNOW WHATS WRONG?

  • Dynamic SELECT statement causing CX_SY_DYNAMIC_OSQL_SEMANTICS error.

    Hello Gurus,
    We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
              SELECT (lt_select_flds)
                FROM (lf_tab_name)
                INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
                FOR ALL ENTRIES IN <lt_source_data>
                WHERE (lf_where).
    In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
    WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
    This code was working fine till yesterday when we encountered serious performance problems and the Basis team had to do some changes at the DB level [Oracle]. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS.
    Is setting changes at the Oracle level cause issues with how the data is being read at the DB. If yes, can you suggest what can we do to this code to get is working correctly [in case Basis can't revert back their changes]?
    Would appreciate any help we can get here.

    You don't understand - this error comes up when we run specific BEx queries.  It was working yesterday, but today it is not.  Our support package did not change from yesterday.  We did not apply any OSSnotes.
    We are however doing pre-prepare on our Prod system.
    The temporary table is used to store SIDs for use in the join.  the table exists in the dictionary, but not at an Oracle level.

  • DYnamic select statement in JDBC adapter?

    Hi guys,
                 Is it possible so send dynamic select statement in jdbc adapter?
    XIer

    Aamir,
    The poster did not specify whether this was sender or receiver channel, but it would only make sense that a "dynamic query" must be on the receiver communication channel since if it was on the sender channel, the channel would have to intelligently determine how to do dynamic queries.
    Also, the poster asked if there was a way to "send a dynamic query" to the channel.  This seems to imply that the channel is receiving information from somewhere to determine the query, which could only mean it is a receiver channel.
    If you would like more information on the JDBC sender communication channel, please open a new thread.

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Dynamic TSQL Statement with Dynamic Parameters

    I'm trying to utilize a dynamic TSQL Statement where I can have various parameters passed of differing kinds, e.g. In some cases parameter 1 would be an int, other cases it may be a datetime, or varchar, etc.
    I'm going to keep  a table of with certain key SQL Statements, and then parameters in another column so this can be resusable.
    Here is my code:
    Case 1
    Declare @FromDate as DATE='2013-10-01'
    Declare @ToDate as DATE='2013-10-31'
    Declare @FamilyMember as nvarchar(2)='20'
    DECLARE @retval int
    DECLARE @sSQL nvarchar(500);
    DECLARE @ParmDefinition nvarchar(500);
    DECLARE @tablename nvarchar(50)
    --Select Convert(nvarchar(15), @FromDate,126)
    SELECT @sSQL = N'select count(distinct id) as AggregateCount from [Table] where familyMember = @FamilyMember
    and DateStamp between @FromDate and @ToDate';
    SET @ParmDefinition = N'@retvalOUT int OUTPUT';
    EXEC sp_executesql @sSQL, @ParmDefinition, @retvalOUT=@retval OUTPUT;
    Case 2
    Declare @FromDate as DATE='2013-10-01'
    Declare @ToDate as DATE='2013-10-31'
    Declare @Id as int=3510021
    DECLARE @retval int
    DECLARE @sSQL nvarchar(500);
    DECLARE @ParmDefinition nvarchar(500);
    DECLARE @tablename nvarchar(50)
    --Select Convert(nvarchar(15), @FromDate,126)
    SELECT @sSQL = N'select count(distinct id) as AggregateCount from [Table] where Id=@Id
    and DateStamp between @FromDate and @ToDate';
    SET @ParmDefinition = N'@retvalOUT int OUTPUT';
    EXEC sp_executesql @sSQL, @ParmDefinition, @retvalOUT=@retval OUTPUT;
    John

    The following is an example I found, but I am receiving a Message "Must declare the scalar variable @StudentNumber"
    Alter Procedure [dbo].[spInsertStudentDoc2]
    @StudentNumber integer
    AS
    Begin
    DECLARE @P_StudentNumber integer
    DECLARE @ParameterList nvarchar(max)
    DECLARE @SQLSnippit as nvarchar(max)
    SET @ParameterList = N'@P_StudentNumber integer'
    SET @SQLSnippit = N'Select Count(*) from dbo.student where patid=@StudentNumber'
    PRINT @SqlSnippit -- debug & test
    Exec SP_EXECUTESQL @SqlSnippit, @ParameterList, @P_StudentNumber=@StudentNumber
    End
    John

  • Getting result of dynamic select statement into variable

    I have a function that builds a dynamic sql statement. I then want to take the result of that statement and insert it into a variable. I have tried this
    execute immediate strSQL USING OUT intCounter;but that is giving me an error on that line of code. The SQL is a select count(*) and works fine. It is just how to get it into the variable that is tripping me up.
    Thanks,
    Eva

    Sure. Version 11g. The complete procedure reads as follows:
    CREATE OR REPLACE FUNCTION VALIDATIONQUESTIONRESULT
        p_ShortName VARCHAR2,
        p_SiteID    VARCHAR2
    RETURN NUMBER IS
        strSQL VARCHAR2(5000);
        strTableName VARCHAR2(200);
        strPatIDFieldName VARCHAR2(200);
        intCounter NUMBER;
    BEGIN
        select VALIDATIONSQL into strSQL from vwvalidationquestions where upper(shortname) = upper(p_ShortName);
        select
                case UPPER(DBTABLENAME)
                    when 'CPTICODES' then 'CPTIPATID'
                    when 'CPTIICODES' then 'CPTIIPATID'
                    when 'DEMOGRAPHICS' then 'PATID'
                    when 'FAMILYHISTORY' then 'FHPATID'
                    when 'GCODES' then 'GCODEPATID'
                    when 'HOSPITALIZATION' then 'HPATID'
                    when 'MEDICALHISTORY' then 'MHPATID'
                    when 'MEDICATIONS' then 'MPATID'
                    when 'PROCEDURES' then 'PPATID'
                    when 'VISITS' then 'VPATID' end into strPatIDFieldName
        from DATASPECIFICATIONS where UPPER(SHORTNAME) = UPPER(p_ShortName);
        strSQL := strSQL||' and '||strPatIDFieldName||' in (select PATID from DEMOGRAPHICS where PARTICID = '||p_SiteID||');';
        execute immediate strSQL into intCounter;
        return intCounter;
    END VALIDATIONQUESTIONRESULT; strSQL when checked builds perfectly. I get 100% what I expect from it. An example of what I am getting from strSQL is:
    select count(*) from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);I am getting the number I would expect from this. I just need to put that number into intCounter. I tried altering strSQL so it looked like this:
    select count(*) into intCounter from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);but that gave me an error on the execute immediate line as well.
    Sorry, I thought it would be simple so that was why I only put that bit of info. I guess it is more complicated than it at first appeared!
    Eva

  • Help With SUBSTR in dynamic SQL statement

    Following is the dynamic SQL statement.
    EXECUTE IMMEDIATE 'UPDATE table_name pml
    SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
    (SELECT pml1.'||con_fields.field||'
    FROM table_name pml1
    WHERE pml1.grp_id = '||los_concats.grp_id ||'
    AND pml1.row_id = '||los_concats.row_id||'
    AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
    WHERE pml.grp_id = '||los_concats.grp_id ||'
    AND pml.loser_flg IS NULL ';
    what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
    My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
    ORA-00907: missing right parenthesis.
    Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
    Appreciate it.

    The other alternative I thought about was to do this first
    EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
    FROM table_name pml
    WHERE pml.grp_id = '||los_concats.grp_id||'
    AND pml.row_id = '||los_concats.row_id||'
    AND pml.loser_flg = ''Y''
    ' INTO v_concat_field;
    write into the variable v_concat_field and then use it into the previous script.
    But on this I get SQL Command not properly terminated, I don't get it Why?
    Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
    Thanks

  • Preparing Dynamic SQL statement for inserting in Pro*C

    Hi Friends,
    From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
    Can somebody go through my code and suggest me the rigth way of doing.
    Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
    Please help me.
    Girish.
    int main()
    EXEC SQL BEGIN DECLARE SECTION;
    char *uid ="scott/tiger";
    static char sqlstmt[129];
    struct /* DEPT record */
    int dept_num;
    char dept_name[15];
    char location[14];
    } dept_rec;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL CONNECT :uid;
    dept_rec.dept_num = 50;
    strcpy(dept_rec.dept_name,"ADMIN");
    strcpy(dept_rec.location,"IN");
    strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
    EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
    EXEC SQL COMMIT;
    exit(0);
    void sql_error()
    printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL ROLLBACK;
    }

    A bit rusty here but this is how I see it.
    Think of it this way ..
    all Oracle is going to see is:
    UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
    Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
    it doesnt go back and fill in those values.
    You need something like
    strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
    strcat(sqlstmt,dept_rec.dept_name);
    strcat(sqlstmt,"\" where DEPTNO = ");
    strcat(sqlstmt,dept_rec.dept_num);
    printf(sqlsmt); # Just to be sure the update statement look right during testing.

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • Creating a Dynamic Update Statement based on Select

    hi,
    i'm trying to create a dynamic update statement based on select statement
    my requirment is to query a joint tables and get the results then based on the results i need to copy all the data and create an update statement for each row
    for ex
    the update statement should look like this
    update iadvyy set SO_SWEEP_CNT = '1' where inst_no = '003' and memb_cust_no = 'aaaaaaaaaaaaaaaa';
    and the select statement like the following
    select substr(key_1,11,9) account_no,sord_mast SO_SWEEP_CNT from
    select acct_no,count(*) sord_mast from
    (select from_acct_no acct_no,update_mast
    from sord where FROM_SYS in ('DEP','INV') and TERM_DATE > 40460
    union all
    select to_acct_no acct_no,update_mast
    from sord where TO_SYS in ('DEP','INV') and TERM_DATE > 40460)
    group by Acct_no)
    right outer join
    invm
    on
    key_1 = '003'||acct_no
    where sord_mast > 0;
    so taking the above two columns from the above select statement and substitue the values as separate update statement.
    is that doable , please share your knowledge with me if poosible
    thanks in advanced

    is that doable , please share your knowledge with me if poosibleyes
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the SQL before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • CX_SY_DYNAMIC_OSQL_SEMANTICS error with dynamic SELECT statement

    Hello Gurus,
    We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
              SELECT (lt_select_flds)
                FROM (lf_tab_name)
                INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
                FOR ALL ENTRIES IN <lt_source_data>
                WHERE (lf_where).
    In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
    WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
    This code was working fine till we were in BW 3.5 and is causing issues after we moved to BW 7.31 recently. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS. THE ERROR TEXT SAYS 'Unable to interpret '<LT_SOURCE_data>-DOC_NUMBER'.
    Can you pleasesuggest what can we do to this code to get is working correctly ? What has changed in ABAP Objects that has been introduced from BI 7.0 that could be causing this issue?
    Would appreciate any help we can get here.
    Thanks
    Arvind

    Hi,
    Please try this.
    data: lv_where type string.
    concatenate 'vbeln' 'in' 'r_vbeln' into lv_where separated by space.
    select *from table into itab where (lv_where).
    Also please check this sample code.
    REPORT ZDYNAMIC_WHERE .
    TABLES: VBAK.
    DATA: CONDITION TYPE STRING.
    DATA: BEGIN OF ITAB OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    END OF ITAB.
    SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
    CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
    INTO CONDITION SEPARATED BY SPACE.
    SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
    WHERE (CONDITION).
    LOOP AT ITAB.
    WRITE 'hello'.
    ENDLOOP.
    Regards,
    Ferry Lianto

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • Autonumbers through dynamic SELECT statement

    Trying to get an autonumber from an order table. The order_id I need from the table is only uniquely identified by the customer_id and the date/time. I've been advised that you cannot get an autonumber back from access without going via a select statement.
    I've tried to do a dynamic select statement by getting the date (short i.e.DD/MM/YY) from the server using a JSP custom tag and then putting this value into a hidden form field on the previous web page.
    However, when I load the next page the data gets input into the order table okay but the web page displayed is blank i.e. it doesn't display the order_id or the form to input credit card details. There are no error messages
    Code below, any ideas?
    <%@ page language="java" contentType="text/html"
    import="ShoppingBasket,Product,java.util.*"
    errorPage="errorpage.jsp"%>
    <jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
    <html>
    <head>
    <title>Your Order Has Been Received</title>
    </head>
    <body>
    <%
    String customer_id = request.getParameter("customer_id");
    String total_value = request.getParameter("total_value");
    String order_date = request.getParameter("order_date");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
    java.sql.Statement Stmt = connection.createStatement();
    String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
    Stmt.executeUpdate(query);
    java.sql.Statement Stmt2 = connection.createStatement();
    java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );
    while(RS.next())
    String order_id = RS.getString("order_id");
    %>
    your order id is <%=order_id %>. Please input your credit card details in the form below:
    <form name="form1" method="post" action="shop-postorder4.jsp">
    <table width="90%" border="0" cellspacing="1" cellpadding="5">
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
    Card Type</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <select name="card_type">
    <option value="AMERICAN EXPRESS">American Express</option>
    <option value="MASTER CARD">Master Card</option>
    <option value="SWITCH">Switch</option>
    <option value="VISA">Visa</option>
    </select>
    *</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
    Card No.</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="card_number" size=18 maxlength="18">
    *</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Issue
    No. <font size="1"><br>
    (Switch card holders<br>
    only)</font></font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="issue_no" size="2" maxlength="2">
    </font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Valid
    From</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="valid_from" size="4" maxlength="4">
    e.g. 0502</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Validy
    To</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="valid_to" size="4" maxlength="4">
    * e.g. 0105</font></td>
    </tr>
    </table>
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="order_id" value="<%=order_id %>">
    </form>
    <a href=" <%= response.encodeURL(shop-products.jsp") %">">
    <img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>
    <%
    RS.close();
    Stmt.close();
    Stmt2.close();
    connection.close();
    %>
    </body>
    </html>
    </a>

    String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
    the data gets input into the order table okay
    java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );It is a field name as <B>time_date </B>in Orders table? And should you insert some value ?
    It seems your select return nothing.
    When your RS.next() is false, so you get blank. Add some HTNL code or just <HR> after while {} block so your would see it.

  • Dynamic PL statements

    Does anyone know how to execute a dynamic PL statement? For example, I'm concatenating a statement based on user input and then trying to run it. Is there a command I can use to run the concatenated statement?
    I'm having the user enter a package name into a field. I'm appending the package name string with a known procedure within the packaged. Once the string is built, I need to execute the package procedure.
    Sample code fragment:
    vcPackageName :='CASE_MGMT_PK';
    vcProcName :=vcPackageName&#0124; &#0124;'.'&#0124; &#0124;'getVersion';
    How do I execute the statement in the vcProcName variable.

    EXECUTE IMMEDIATE vcProcName;
    I believe that should work on Oracle 8i.
    On 8.0.5 that doesn't work this way.
    Still, you may use
    forms_ddl(vcProcName);
    This will work even with Oracle 7.x.
    Of course, this goes for Oracle Forms.
    For dynamic sql in Oracle 7.x and 8.0.5, use the dbms_sql package facilities.
    null

  • Dynamic data statements

    Hi,
    I need help regarding a dynamic data statement. I'm selecting data from a table like this:-
    DATA: lv_table(20) type c.
    lv_table = e_s_odstabname-c_log.
    SELECT * FROM (LV_TABLE)
    INTO lv_wa UP TO 1 ROWS
    WHERE PARAM1 = p_parm1
    AND   PARAM2 = p_parm2.
    ENDSELECT.
    I need to declare the lv_wa the same as the value contained in lv_table but I don't know how to do this.
    Any help would be great.
    KR,
    C

    hi C,
    declare it as
    data :  lv_wa like lv_table occurs 0 with header line.
    or
    data :  lv_wa like lv_table occurs 0.
    Regards,
    santosh

Maybe you are looking for