Odd Error with decode function in Order By Clause

I am trying to compile a procedure and can't get around an error with a dynamic order by that doesn't make much sense to me. I can repoduce the error with a plain select statment in sql plus so I can rule out a declaration error. Here is an example with 2 numeric columns and a date column.
select task_id, display_date, remark_id from task_list
where task_id > 1000
order by decode('Task_ID', 'Task_ID',Task_ID, 'Display_Date', Display_Date, 'Remark_ID',Remark_ID)
returns the error:
select task_id, display_date, remark_id from task_list
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE
I'm not sure why this error is occuring, because it doesn't even hit the Display_Date field in the Decode statment. If I take the Display_date out of the statement, it runs properly. If I change Display_Date to To_Char(Display_Date) it also runs fine, but the sorting is incorrect. Also I'm running 9.2, and do not want to use dynamic sql to build my query. Any Ideas out there as to the cause of this error?

I did find a workaround to this issue by breaking the decode statment into three separate statement, but I still think that the way it is written above should work, and may be a bug, or an error that I don't understand fully.
The Order by was rewritten like this:
order by decode(pSort, 'Task_ID',Task_ID), decode(pSort, 'Display_Date', Display_Date),
decode(pSort, 'Remark_ID',Remark_ID);
Thanks

Similar Messages

  • Decode function in order by clause

    Hi,
    I need a help from you..
    SELECT 'ALTER ' || object_type || ' '|| object_name ||' COMPILE;' FROM user_objects WHERE object_type IN ('FUNCTION', 'PACKAGE', 'PROCEDURE', 'TRIGGER', 'VIEW') ORDER BY DECODE(object_type, 'VIEW','A', 'FUNCTION','B', 'PROCEDURE', 'C', 'PACKAGE','D', 'Z');
    Explanation: This will sort by type of an object, in the decode assigned value A to VIEW, B FUNCTION, C PROCEDURE, D to PACKAGE and Z to OTHERS. so all the views will be at the top and then functions, then procedures, then packages and finally the rest of the object.
    Please let me know how this query will be executed.
    Cheers,
    bell.

    Hi,
    Try this:
    FOR obj_cur IN (
    SELECT 'ALTER ' || object_type || ' '|| object_name ||' COMPILE;'  exc_cmd FROM user_objects WHERE object_type IN ('FUNCTION', 'PACKAGE', 'PROCEDURE', 'TRIGGER', 'VIEW') ORDER BY DECODE(object_type, 'VIEW','A', 'FUNCTION','B', 'PROCEDURE', 'C', 'PACKAGE','D', 'Z')
    LOOP
    BEGIN
      EXECUTE IMMEDIATE obj_cur.exc_cmd ;
    EXCEPTION
        WHEN OTHERS THEN
         dbms_output.put_line(obj_cur.exc_cmd || SQLERRM);
    END;
    END LOOP;
    Regards

  • Error while replacing IF statements with DECODE function in procedure

    Hi All,
    I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
    Procedure:
    IF (var_int_sev = '0')
    THEN
    var_sev := '2';
    ELSE
    SELECT sev
    INTO var_int_sev
    FROM errorconfig
    WHERE errorcode = var_errorcode;
    var_sev := var_int_sev;
    END IF;
    I converted the above IF statement into DECODE function as mentioned below:
    var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
    But it throws below error at the select statement used inside DECODE.
    Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
    Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.

    instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
    read this:
    When your query takes too long ...

  • OWB3i - Validate with DECODE function

    Hi,
    in OWB 3i when I validate an expression defined inside an expression operator with DECODE() function (which is not include in default transformation) come this error:
    Line 1, Col 1:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
    but it seems only a warning because when i generate the scripts and run no other error happen and all works fine.
    Regards

    Hi,
    Welcome to the forum!
    When you use a default value, the last argument to DECODE is the actual value you want as a default.
    For example:
    SELECT       ename
    ,       deptno
    ,       DECODE ( deptno
                 , 30     , 'Sales'
                      , 'All others'     -- Default value
                  )                 AS dname
    FROM      scott.emp
    ORDER BY  ename
    ;Output:
    ENAME          DEPTNO DNAME
    ADAMS              20 All others
    ALLEN              30 Sales
    BLAKE              30 Sales
    CLARK              10 All others
    FORD               20 All others
    JAMES              30 Sales
    JONES              20 All others
    KING               10 All others
    MARTIN             30 Sales
    MILLER             10 All others
    SCOTT              20 All others
    SMITH              20 All others
    TURNER             30 Sales
    WARD               30 Sales 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • OBIEE: Incorrect SQL - with count function uses ORDER BY instead GROUP BY

    I made a basic report that is a client count; I want to know how many clients the company have.
    But, when I run this report, OBIEE generates a ORDER BY sentence, instead a GROUP BY. Remember that I'm using count function, that is a agregation.
    The SQL generated was:
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    order by c1
    The error that I receive is:
    "Query Status: Query Failed: [nQSError: 16001] ODBC error state: S1000 code: -1005018 message: [Sybase][ODBC Driver][Adaptive Server Anywhere]Illegal ORDER BY item Order Item: 'N0',
    -- (opt_OrderBy.cxx 429) .
    [nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement."
    If I substitute ORDER BY with GROUP BY and test it in Sybase, Ithe query runs without any problem.
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    group by c1
    Do you know why OBIEE generates this SQL??? Why uses, with a aggregation function, a ORDER BY and not a GROUP BY? How can I resolve this problem???
    Regards,
    Susana Figueiredo

    Verify your repository design and make sure that you have defined count aggregate on fact column. You would also need to define the content level of each dimension in fact table.

  • Error adding new function in order template

    Hi,
    When i am trying to add a new function to order Template under /contolData/Functions/ form data dictonary
    I am getting error :
    Element with same name exist.The following nodes can not be added to the order.
    (no namespace):/ControlData/Functions/MyNewFunction
    (no namespace):/ControlData/Functions/MyNewFunction/componentKey
    Thanks
    Harman

    Hi Harman,
    You might need to be more specific before I can help you. What have you done, and which step you run into the error? I supopse you have created a new "function" Order Component, and created the required Control Data nodes in Data Dictionary (what have you added?), right? So, when you go into the Order Template tab of the new Order Component (which would be empty since it was newly created), and you try to "select from Dictionary" the corresponding ControlData for the function (e.g. /ControlData/Functions/MyNewFunction), that such an error occurs?
    Have you assigned a process for this Order Component? Studio does not allow adding control data to it unless a process is assigned.
    Btw, you should define a namespace for your Order Components (and other orchestration entities). The OSM server uses namespace to locate these entities among cartridges.
    Cheers,
    Daniel Ho
    Product Management -- OSM

  • Prob with decode function

    hi iam having prob with the following decode function
    declare
    c varchar2(20);
    begin
    select decode(deptno,
    10, 'accounting',
    20,'Research',
    30 ,'sales',
    40,'operations','UNKNOWN') into c from dept where loc='DALLAS';
    dbms_output.put_line('DEPARTMENT in DALLAS'||c);
    select decode(deptno,
    10, 'accounting',
    20,'Research',
    30 ,'sales',
    40,'operations','UNKNOWN') into c from dept where loc='INDIA';
    dbms_output.put_line('DEPARTMENT IN INDIA'||c);
    end;
    iam getting no_data_found exception which is reasonable..but what happened to 'unknown' clause in decode function.
    thank u
    rajiv

    Please see the responses to your prob in decode function
    John

  • Problem with decode function.

    Hi,
    Can anyone of you help me out in solving this?
    It is like i wish to give different select statements according to the value of a parameter entered by user USING DECODE FUNCTION.The select statement contains some other select statements inside it.So when i execute it,it is giving error like 'ORA-00913-too many values(even when i enclose select statements within brackets).

    ORA-00913 too many values
    Cause: The SQL statement requires two sets of values equal in number. This error occurs when the second set contains more items than the first set. For example, the subquery in a WHERE or HAVING clause may return too many columns, or a VALUES or SELECT clause may return more columns than are listed in the INSERT.
    Action: Check the number of items in each set and change the SQL statement to make them equal.
    the above is from oracle documentation. the brackets is not the problem, u must be using multiple items in the integrated decode queries. If the problem still exists post ur DML for further analysis.
    zaibi.

  • How to convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • Need help with DECODE function

    Hello,
    I am trying to use default within the decode function and every time I get a missing expression. I have searched everywhere and cant figure out what I'm doing wrong. Thanks
    select decode (request_id,0,'No files found', DEFAULT)

    Hi,
    Welcome to the forum!
    When you use a default value, the last argument to DECODE is the actual value you want as a default.
    For example:
    SELECT       ename
    ,       deptno
    ,       DECODE ( deptno
                 , 30     , 'Sales'
                      , 'All others'     -- Default value
                  )                 AS dname
    FROM      scott.emp
    ORDER BY  ename
    ;Output:
    ENAME          DEPTNO DNAME
    ADAMS              20 All others
    ALLEN              30 Sales
    BLAKE              30 Sales
    CLARK              10 All others
    FORD               20 All others
    JAMES              30 Sales
    JONES              20 All others
    KING               10 All others
    MARTIN             30 Sales
    MILLER             10 All others
    SCOTT              20 All others
    SMITH              20 All others
    TURNER             30 Sales
    WARD               30 Sales 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Q: Error with TimestampAdd function

    Hi Gurus,
    In the rpd file referenced by my Siebel demo instance I have following error [NQError: 22025] Function TimestampAdd is called with an incompatible type
    Expression 1 is: " TIMESTAMPADD( SQL_TSI_DAY , CEILING("S_MKT_OLAP (MyConsumer Master)".""."MyConsumersMasterPhysicalSchema"."MyConsumers"."CU_DAYS_AS_CUSTOMER") * -(1), NOW())"
    Expression 2 is: " TIMESTAMPADD( SQL_TSI_DAY , CEILING("S_MKT_OLAP (MyConsumer Master)".""."MyConsumersMasterPhysicalSchema"."MyConsumers"."CU_AGE" * 365) * -(1), NOW())"
    Expression 3 is: " TIMESTAMPADD( SQL_TSI_DAY , CEILING("S_MKT_OLAP (MyConsumer Master)".""."MyConsumersMasterPhysicalSchema"."MyConsumers"."CU_DAYS_SINCE_LAST_PAYMENT") * -(1), NOW())"
    This is resulting in that the related presentation catalog is showing empty in the Marketing Segment Designer which is nothing but Answers.
    Could that be the source of my problem? How to resolve it?
    PS: I have very limited OBIEE and PLSQL knowledge, and I'm not a member of this DL so kindly keep me on copy.
    Many thanks in advance and regards,
    Jad

    Hi,
    Kindly refer the below link
    http://obieeelegant.blogspot.com/2011/06/obiee-date-expressions-reference.html
    First Date of Week:
    TIMESTAMPADD(SQL_TSI_DAY, (DAYOFWEEK(Current_date)*-1)+1, Current_date)
    Lat Date of Week:
    TIMESTAMPADD(SQL_TSI_DAY,DAYOFWEEK(Current_Date)*-1,TIMESTAMPADD(SQL_TSI_WEEK, 1, Current_date))
    First Date of Year:
    TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)
    Last Date of Year:
    TIMESTAMPADD(SQL_TSI_YEAR, 1, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)))
    Thanks
    Deva

  • Error with intersects function

    I've an error I don't understand the cause.(it worked before the SDK update)
    Here is my code :
         * Permet de vérifier que l'évênement passé en paramètre n'en chavauche aucun autre
        function detectCollision(guiEvent: DayEvent) {
            // On sélectionne tous les évênements affichés sauf celui pour lequel on test les limites
            for (e in app_events.displayedEvents.content[p | p.id != guiEvent.id]) {
                if (e.intersects(guiEvent.boundsInLocal.minX, guiEvent.boundsInLocal.minY+5, guiEvent.boundsInLocal.width, guiEvent.boundsInLocal.height-10) == true) {
                    guiEvent.guiEvent.stroke = Color.RED;
                    collisionsDetected = true;
                    break;
                } else {
                    guiEvent.guiEvent.stroke = Color.rgb(77,130,178);
                    collisionsDetected = false;
        }"DayEvent" is a Group...("e" too)
    The error is:
    "An internal error has occurred in the OpenJFX compiler."

    This is helpful... :-)
    I can reproduce the error with the simple code:
    var app_events: Node[];
    var collisionsDetected: Boolean;
    function detectCollision(guiEvent: Group) {
      for (e in app_events[p | p.visible]) {
        if (e.intersects(guiEvent.boundsInLocal.minX, guiEvent.boundsInLocal.minY+5, guiEvent.boundsInLocal.width, guiEvent.boundsInLocal.height-10) == true) {
          collisionsDetected = true;
          break;
        } else {
          collisionsDetected = false;
    }I suggest you report the bug to Jira / Kenai with the above code. If you don't want or cannot, just tell, I will do.
    *[EDIT]* I went ahead, since I could reproduce it, and made the bug [http://javafx-jira.kenai.com/browse/JFXC-3283]
    As guessed from the cryptic error, the problem comes from the break instruction. So a workaround is not to use it! :-) Or to change the instructions. Maybe the compiler thinks that break is supposed to be a value (implicit return).
    A possible solution is:
    function detectCollision(guiEvent: Group) {
      for (e in app_events[p | p.visible]) {
        collisionsDetected = e.intersects(
            guiEvent.boundsInLocal.minX, guiEvent.boundsInLocal.minY+5,
            guiEvent.boundsInLocal.width, guiEvent.boundsInLocal.height-10);
        if (collisionsDetected) break;
    }Simple, elegant (in my eye!) and compiling...
    A less breaking solution (ie. with minimal change to your code) is to say your function returns nothing: function detectCollision(guiEvent: DayEvent): Void
    Another, perhaps better, is to return true or false instead of changing some global variable.
    The compiler tries hard to guess the types, but sometime it fails and behaves badly or even crashes...
    Edited by: PhiLho on Jun 18, 2009 3:45 PM

  • Between clause with DECODE function.

    Hi All,
    I have one table which has object, date and quantity columns, Now based on date range I can find out the objects and quantity but the question is: I want a query which returns all the objects and should show quantity 0(zero or null) for those objects which don't falls under that date range. So I thought to use a decode function but it only uses the relational operation, I thought something like this but it's wrong,
    select object,decode(created_date,BETWEEN '01/01/2008' TO '08/01/2008',quantity,0) from table;
    Does anyone have any idea how can I make this work in single sql statement?
    Thanks for your help.

    select object,decode(created_date,BETWEEN '01/01/2008' TO '08/01/2008',quantity,0) from table;
    Does anyone have any idea how can I make this work in single sql statement?If you're still interested in using DECODE over Case when, please try this.
    Check for employees hired between 6/17/1987 and 9/30/1987
    SQL> select first_name||' '||last_name as emp_name, hire_date,
      2         decode(sign((to_date('06/17/1987','MM/DD/YYYY')-1)-hire_date)
      3           + sign((to_date('09/30/1987','MM/DD/YYYY')+1)-hire_date)
      4                   ,0,'Between','Not between') as IsBetween
      5    from employees
      6   where hire_date <to_date('01/01/1991','MM/DD/YYYY')
      7  /
    EMP_NAME                                       HIRE_DATE ISBETWEEN
    Steven King                                    17-JUN-87 Between
    Neena Kochhar                                  21-SEP-89 Not between
    Alexander Hunold                               03-JAN-90 Not between
    Jennifer Whalen                                17-SEP-87 BetweenMessage was edited by:
    Bobbydj

  • Sql count function in order by clause

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Hi Guys
    Can i ask a quick question. I am trying to retrieve data remotely from a SQL Server via crystal reports.
    Within the Database Expert I have entered a SQL query to retrive the number of (call center) support calls raised by our customers:-
    Select `Primary_Company`, COUNT(`Calls`)From  `SPRT_Issue` GROUP BY  `Primary_Company`ORDER BY  COUNT(`Calls`) desc
    The customer's column is called 'Primary Company' and the calls they raise are in the 'Calls' column. the above is a normal sql query.
    However Crystal fails to run the query and generates an error message :-
    Failed to open a rowset. Details: 420: Driver&#93; Expected lexical element not found: <identifier>
    I dont understand why it wont run. In the ORDER BY clause if i replace field 'Calls' by the field 'Primary Company' then it works.
    I think the problem is that it wont accept the count function in the order by clause. which is what i want it to do i.e display the calls in descending order by each customer.
    Could someone tell me if there is a way around it.
    Thanks
    Krypton

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Thanks Lynn
    I tried your suggestion. But there is one probelm.
    When i sort the data in descending order using the count(calls) field, the data is returned but the customer's name appears multiple times along with their calls raised.
    E.g, if customer Mark raised multiple calls i.e. 2, 5, and 10 calls, then the report will show
    Mark   2
    Mark  5
    Mark 10
    But is there a way to aggregate all the calls for mark and show them only once:
    such as Mark   17
    Thanks

  • 'Missing parameter with PERFORM' error with a function IN BACKGROUND TASK

    I am getting this error when calling a custom function in MIGO user exit ZXMBCU01.  When I remove the 'IN BACKGROUND TASK' the function works fine and there are no error messages.  When using 'IN BACK...' you can't debug within it to see where the message comes from.  I see the message with SM58.  I am working in an sap 4.7 environment.  I have not found any solutions from google searches.
    Here is the statement within ZXMBCU01:
        CALL FUNCTION 'Z_UPDATE_MATERIAL_AVAIL_STATUS' IN BACKGROUND TASK
          EXPORTING
            work_order = xmseg-aufnr.
    Here is the code for the function:
    FUNCTION Z_UPDATE_MATERIAL_AVAIL_STATUS.
    ""Update function module:
    ""Local interface:
    *"  IMPORTING
    *"     VALUE(WORK_ORDER) LIKE  AUFK-AUFNR DEFAULT '0000000000'
    TABLES: eban, resb, aufk.
    -Global Types----
    TYPES: BEGIN OF t_data,
           rsnum TYPE resb-rsnum,
           rspos TYPE resb-rspos,
           aufnr TYPE resb-aufnr,          "Order Number
           bdmng TYPE resb-bdmng,          "Requirement Quantity
           enmng TYPE resb-enmng,          "Quantity withdrawn
           bsmng TYPE eban-bsmng,          "Quantity ordered against this purchase requisition
           END OF t_data.
    DATA:  gt_data TYPE t_data OCCURS 0,
           ga_data TYPE t_data.
    -Global Variables----
    DATA: gv_refused TYPE BAPIFLAG-BAPIFLAG,
          gs_caufvd  TYPE caufvd,
          g_text TYPE t100-text,
          gv_objnr LIKE aufk-objnr,
          gv_status LIKE  bsvx-sttxt,
          gv_trig_stat TYPE c.
    TABLES RETURNED FROM BAPI
    DATA:  BEGIN OF xreturn OCCURS 0.
            INCLUDE STRUCTURE bapiret2.
    DATA:  END OF xreturn.
      SELECT SINGLE objnr FROM aufk
         INTO gv_objnr
         WHERE  aufnr = work_order.
      CALL FUNCTION 'STATUS_TEXT_EDIT'
        EXPORTING
          flg_user_stat = 'X'
          objnr         = gv_objnr
          only_active   = 'X'
          spras         = sy-langu
        IMPORTING
          line          = gv_status.
      IF ( gv_status CS 'REL' ) AND
         ( gv_status NS 'NMAT' AND gv_status NS 'CNF' AND gv_status NS 'CLSD' AND
           gv_status NS 'TECO' AND gv_status NS 'DLFL' ).
        SELECT SINGLE *
          FROM AUFK
         WHERE aufnr = work_order AND
               ( auart = 'PM01' OR
                 auart = 'PM02' OR
                 auart = 'PM03' OR
                 auart = 'PM99' ).
        IF sy-subrc = 0.
          SELECT resbrsnum resbrspos resbaufnr resbbdmng resbenmng ebanbsmng
            INTO CORRESPONDING FIELDS OF ga_data
            FROM resb LEFT JOIN eban
              ON resbrsnum = ebanarsnr AND
                 resbrspos = ebanarsps
           WHERE resb~aufnr = work_order AND
                 resb~bdmng > 0.
        SELECT rsnum rspos aufnr bdmng enmng
          INTO CORRESPONDING FIELDS OF ga_data
          FROM resb
         WHERE aufnr = work_order
           AND bdmng > 0.
              SELECT SINGLE bsmng
                INTO ga_data-bsmng
                FROM eban
               WHERE arsnr = ga_data-rsnum
                 AND arsps = ga_data-rspos.
              IF sy-subrc <> 0.
                CLEAR ga_data-bsmng.
              ENDIF.
               IF ga_data-bdmng = ga_data-enmng OR
                  ga_data-bdmng = ga_data-bsmng.
                 "update status - but all items must pass
               ELSE.
                 gv_trig_stat = 'N'.
                 EXIT. "status won't change so get out now
               ENDIF.
         ENDSELECT.
       IF ga_data~bdmng > 0.
           IF ga_data-bdmng = ga_data-enmng OR
              ga_data-bdmng = ga_data-bsmng.
         IF gv_trig_stat <> 'N'.
              CALL FUNCTION 'CO_IH_USERSTATUS_SET'
                EXPORTING
                  I_AUFNR              = ga_data-aufnr    "'000005000263'
                  I_USR_STAT_INT       = 'E0002'
      I_USR_STAT_EXT       =
      I_SET_INACTIVE       =
      I_BUF_READ           =
                  I_SPRAS              = sy-langu
                IMPORTING
                  E_CHNG_REFUSED       = gv_refused
                  E_CAUFVD             = gs_caufvd
                TABLES
                  RETURN               = xreturn.
              LOOP AT xreturn
               WHERE type = 'E'.
              ENDLOOP.
              IF sy-subrc <> 0.
                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
                RETURN.
              ELSE.
                READ TABLE xreturn INDEX 1.
                CALL FUNCTION 'PI_BP_GET_MESSAGE_TEXT'
                  EXPORTING
                    iv_message_id     = xreturn-id
                    iv_message_type   = xreturn-type
                    iv_message_number = xreturn-number
                    iv_message_v1     = xreturn-message_v1
                    iv_message_v2     = xreturn-message_v2
                    iv_message_v3     = xreturn-message_v3
                    iv_message_v4     = xreturn-message_v4
                  IMPORTING
                    ev_message_text   = g_text.
              ENDIF.
         ENDIF.
         ENDIF.
           ENDIF.
         ENDSELECT.
        ENDIF.
      ENDIF.
    ENDFUNCTION.
    Does anyone have any ideas?  Thank you very much in advance.
    Glenn Allen
    Software Architect (specializing in SAP)

    I'd be starting a process of elimination... perhaps start with an "exit." right after
    SELECT SINGLE objnr
      FROM aufk
      INTO gv_objnr
      WHERE aufnr = work_order.
    exit.  "leave FM NOW
    and if that doesn't crash, work down the code down the code in the function e.g. comment out the BAPI_commit call... and / or build a little test harness report to call the Z function in background task... btw, does the ST22 dump point to anything more specific...?

Maybe you are looking for