Update using a Function in select satement

Hi
Is it possible to do follwing .
i have tabele and a custom fucntion , the custome function will update the column(amount) in the table a based on the value pass through the function from the select statement .
select id, amount , outstanding from a where id=get_update(id) ;
Now
Get_update function will return the same id which i am passing and update the amount column to some value in the
table a .
when i execute the select satament i cannot see updated data in the amount column in my first executtion , but if run the same satement again i can see the changes reflected . is it possible to get the updated data in the first execution itself.
function is PRAGMA AUTONOMOUS_TRANSACTION type
Regards

Appreciate your response ,
i am using another tool where i can execute select statements . i know its not gud idea tio use PRAGMA AUTONOMUS , but i will be not havin much data which will be passing across , this is will be used on on deman basis.
i have table a
Id , amount
12 500
13 600
Function GET_ID( )
CREATE OR REPLACE FUNCTION GET_ID ( pid number) RETURN number IS
PRAGMA AUTONOMOUS_TRANSACTION ;
tmpVar1 number;
BEGIN
update a set amount =800 where id=pid;
commit;
select ID into tmpVar1 from a ;
RETURN tmpVar1;
END GET_ID;
select id, amount from a where id=GET_ID(13) ;
if i run above statement i dont get the updated amount , but fine in second time
Regards

Similar Messages

  • Using java function in select statement

    Hi,
    I am trying to use java function in select statement.
    public class ClassA{
         private static String MyConst = "foo";
         public static String functionA(){
              return MyConst;
    in my query I have:
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    ClassA is part of the application (no need to import).
    I get and error of Invalid Expression on ClassA.functionA().
    I also tried to declare the function in the processor element:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    <wlevs:processor>
    but then I get a different error in the processor XML file:  "An InvocationTargetException was encoutered while attemting to register the user defind function A. The message was null"
    What am I missing here?

    Hi,
    From the above description, you have tried two manners to call method functionA() in the user defined  class ClassA. One uses java cartridge manner directly and the other try to use user defined function manner.
    For the java cartridge manner, the following CQL query should work if the ClassA is really included in the OEP app. I have done similar test before, it works.
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    For user defined function manner, I think two things you need to change:
    1. Need to declare the function in the EPN assembly file(under META-INF/spring/), not component configuration file(under META-INF/wlevs/). The following is an example:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    </wlevs:processor>
    2. Call the user defined function in the CQL query in the component configuration file under processor. For example:
    select A() from myChannel
    Regards,
    XiYing

  • Orcl:query-database gives error when using to_char function in select stmt

    hi
    Use Case : We get a csv file ("bank_import_<MMDDYYYYY>.csv") from the bank containing the transactions occured for the month. The date in the filename is retrieved into string and i need to convert this string to the format "MON-DD-YYYY". This is the required format for an header table which takes this string as primary key.
    Code:
    statement_name = '11302206'.........
    <copy>
    <from expression="concat("'select to_char(to_date('",bpws:getVariableData('statement_name') ,"','MMDDYYYY'),'MON-DD-YYYY') from dual'")"/>
    <to variable="xpath"/>
    </copy>
    <copy>
    <from expression="orcl:query-database(bpws:getVariableData('xpath'),false(),false(),'jdbc:oracle:thin:apps/apps@croaker:1529:RSICMI')"/>
    <to variable="statement_name"/>
    </copy>
    Error:
    [2006/12/06 19:13:04] Updated variable "xpath" less
    <xpath>'select to_char(to_date('10302006','MMDDYYYY'),'MON-DD-YYYY') from dual'</xpath>
    [2006/12/06 19:13:04] "XPathException" has been thrown. less
    XPath expression failed to execute.
    Error while processing xpath expression, the expression is "orcl:query-database(bpws:getVariableData("xpath"), false(), false(), "jdbc:oracle:thin:apps/apps@croaker:1529:RSICMI")", the reason is .
    Please verify the xpath query.
    Log Message:
    <2006-12-06 19:13:04,595> <DEBUG> <UAT.collaxa.cube.xml> <XPathUtil::evaluate> XPathQuery[concat("'select to_char(to_date('", bpws:getVariableData("statement_name"), "','MMDDYYYY'),'MON-DD-YYYY') from dual'")], XPath Result: class=java.lang.String value='select to_char(to_date('10302006','MMDDYYYY'),'MON-DD-YYYY') from dual'
    <2006-12-06 19:13:04,595> <DEBUG> <UAT.collaxa.cube.xml> <XPathUtil::initXPath> namespaceMapping is: rootMap: {bpws=http://schemas.xmlsoap.org/ws/2003/03/business-process/, xp20=http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20, ns4=http://xmlns.oracle.com/pcbpel/adapter/db/top/BAIBankUpload, ldap=http://schemas.oracle.com/xpath/extension/ldap, xsd=http://www.w3.org/2001/XMLSchema, ns5=http://xmlns.oracle.com/pcbpel/adapter/file/, client=http://xmlns.oracle.com/BAI_BankUpload, ora=http://schemas.oracle.com/xpath/extension, ns1=http://xmlns.oracle.com/pcbpel/adapter/file/readBAIBankImportCSV/, ns3=http://TargetNamespace.com/readBAIBankImportCSV, ns2=http://xmlns.oracle.com/pcbpel/adapter/db/Insert_SI_CE_STATEMENT_LINES_INT/, bpelx=http://schemas.oracle.com/bpel/extension, orcl=http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc, =http://schemas.xmlsoap.org/ws/2003/03/business-process/}
    scopedMap: {}
    <2006-12-06 19:13:04,751> <DEBUG> <UAT.collaxa.cube.xml> <XPathUtil::evaluate> XPathQuery :orcl:query-database(bpws:getVariableData("xpath"), false(), false(), "jdbc:oracle:thin:apps/apps@croakercom:1529:RSICMI")
    org.collaxa.thirdparty.jaxen.FunctionCallException
         at org.collaxa.thirdparty.jaxen.FunctionCallException.fillInStackTrace(FunctionCallException.java:124)
         at java.lang.Throwable.<init>(Throwable.java:195)
         at java.lang.Exception.<init>(Exception.java:41)
         at org.collaxa.thirdparty.jaxen.saxpath.SAXPathException.<init>(SAXPathException.java:83)
         at org.collaxa.thirdparty.jaxen.JaxenException.<init>(JaxenException.java:82)
         at org.collaxa.thirdparty.jaxen.FunctionCallException.<init>(FunctionCallException.java:86)
         at oracle.tip.pc.services.functions.ExtFuncFunction$QueryDatabaseFunction.call(ExtFuncFunction.java:190)
         at org.collaxa.thirdparty.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:184)
         at org.collaxa.thirdparty.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:107)
         at org.collaxa.thirdparty.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:724)
         at org.collaxa.thirdparty.jaxen.BaseXPath.selectNodes(BaseXPath.java:253)
         at org.collaxa.thirdparty.jaxen.BaseXPath.evaluate(BaseXPath.java:210)
         at com.collaxa.cube.xml.xpath.XPathUtil.evaluate(XPathUtil.java:93)
         at com.collaxa.cube.engine.ext.wmp.BPELAssignWMP.evalFromValue(BPELAssignWMP.java:501)
         at com.collaxa.cube.engine.ext.wmp.BPELAssignWMP.__executeStatements(BPELAssignWMP.java:122)
         at com.collaxa.cube.engine.ext.wmp.BPELActivityWMP.perform(BPELActivityWMP.java:188)
         at com.collaxa.cube.engine.CubeEngine.performActivity(CubeEngine.java:3408)
         at com.collaxa.cube.engine.CubeEngine.handleWorkItem(CubeEngine.java:1836)
         at com.collaxa.cube.engine.dispatch.message.instance.PerformMessageHandler.handleLocal(PerformMessageHandler.java:75)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleLocalMessage(DispatchHelper.java:166)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.sendMemory(DispatchHelper.java:252)
         at com.collaxa.cube.engine.CubeEngine.endRequest(CubeEngine.java:5438)
         at com.collaxa.cube.engine.CubeEngine.createAndInvoke(CubeEngine.java:1217)
         at com.collaxa.cube.engine.delivery.DeliveryService.handleInvoke(DeliveryService.java:511)
         at com.collaxa.cube.engine.ejb.impl.CubeDeliveryBean.handleInvoke(CubeDeliveryBean.java:335)
         at ICubeDeliveryLocalBean_StatelessSessionBeanWrapper16.handleInvoke(ICubeDeliveryLocalBean_StatelessSessionBeanWrapper16.java:1796)
         at com.collaxa.cube.engine.dispatch.message.invoke.InvokeInstanceMessageHandler.handle(InvokeInstanceMessageHandler.java:37)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleMessage(DispatchHelper.java:125)
         at com.collaxa.cube.engine.dispatch.BaseScheduledWorker.process(BaseScheduledWorker.java:70)
         at com.collaxa.cube.engine.ejb.impl.WorkerBean.onMessage(WorkerBean.java:86)
         at com.evermind.server.ejb.MessageDrivenBeanInvocation.run(MessageDrivenBeanInvocation.java:123)
         at com.evermind.server.ejb.MessageDrivenHome.onMessage(MessageDrivenHome.java:755)
         at com.evermind.server.ejb.MessageDrivenHome.run(MessageDrivenHome.java:928)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    Root cause:
    java.lang.ClassCastException
         at oracle.tip.pc.services.functions.ExtFuncFunction$QueryDatabaseFunction.call(ExtFuncFunction.java:158)
         at org.collaxa.thirdparty.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:184)
         at org.collaxa.thirdparty.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:107)
         at org.collaxa.thirdparty.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:724)
         at org.collaxa.thirdparty.jaxen.BaseXPath.selectNodes(BaseXPath.java:253)
         at org.collaxa.thirdparty.jaxen.BaseXPath.evaluate(BaseXPath.java:210)
         at com.collaxa.cube.xml.xpath.XPathUtil.evaluate(XPathUtil.java:93)
         at com.collaxa.cube.engine.ext.wmp.BPELAssignWMP.evalFromValue(BPELAssignWMP.java:501)
         at com.collaxa.cube.engine.ext.wmp.BPELAssignWMP.__executeStatements(BPELAssignWMP.java:122)
         at com.collaxa.cube.engine.ext.wmp.BPELActivityWMP.perform(BPELActivityWMP.java:188)
         at com.collaxa.cube.engine.CubeEngine.performActivity(CubeEngine.java:3408)
         at com.collaxa.cube.engine.CubeEngine.handleWorkItem(CubeEngine.java:1836)
         at com.collaxa.cube.engine.dispatch.message.instance.PerformMessageHandler.handleLocal(PerformMessageHandler.java:75)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleLocalMessage(DispatchHelper.java:166)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.sendMemory(DispatchHelper.java:252)
         at com.collaxa.cube.engine.CubeEngine.endRequest(CubeEngine.java:5438)
         at com.collaxa.cube.engine.CubeEngine.createAndInvoke(CubeEngine.java:1217)
         at com.collaxa.cube.engine.delivery.DeliveryService.handleInvoke(DeliveryService.java:511)
         at com.collaxa.cube.engine.ejb.impl.CubeDeliveryBean.handleInvoke(CubeDeliveryBean.java:335)
         at ICubeDeliveryLocalBean_StatelessSessionBeanWrapper16.handleInvoke(ICubeDeliveryLocalBean_StatelessSessionBeanWrapper16.java:1796)
         at com.collaxa.cube.engine.dispatch.message.invoke.InvokeInstanceMessageHandler.handle(InvokeInstanceMessageHandler.java:37)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleMessage(DispatchHelper.java:125)
         at com.collaxa.cube.engine.dispatch.BaseScheduledWorker.process(BaseScheduledWorker.java:70)
         at com.collaxa.cube.engine.ejb.impl.WorkerBean.onMessage(WorkerBean.java:86)
         at com.evermind.server.ejb.MessageDrivenBeanInvocation.run(MessageDrivenBeanInvocation.java:123)
         at com.evermind.server.ejb.MessageDrivenHome.onMessage(MessageDrivenHome.java:755)
         at com.evermind.server.ejb.MessageDrivenHome.run(MessageDrivenHome.java:928)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    <2006-12-06 19:13:04,751> <ERROR> <UAT.collaxa.cube.xml> ORABPEL-09500
    XPath expression failed to execute.
    Error while processing xpath expression, the expression is "orcl:query-database(bpws:getVariableData("xpath"), false(), false(), "jdbc:oracle:thin:apps/apps@croaker:1529:RSICMI")", the reason is .
    Please verify the xpath query.

    Hi,
    QAbdul wrote:
    when I tried to execute the followingin XMLQuery by calling TO_CHAR() whithin this query I am getting this error"ORA-19237: XP0017 - unable to resolve call to function - fn:TO_CHARTO_CHAR is a SQL function, XQuery is unaware of it.
    XPath 2.0 specifications define a fn:format-date function but Oracle has not included yet in its XQuery implementation.
    Easiest way to go is A_Non's solution, but if you need to format at multiple places in the query, you can declare a local XQuery function.
    For example, to format to "DD/MM/YYYY" from the canonical xs:date format "YYYY-MM-DD" :
    {code}
    declare function local:format-date($d as xs:date) as xs:string
    let $s := xs:string($d)
    return concat(
    substring($s, 10, 2), "/",
    substring($s, 7, 2), "/",
    substring($s, 2, 4)
    {code}
    and an example of use :
    {code}
    SQL> CREATE TABLE test_xqdate AS SELECT sysdate dt FROM dual;
    Table created
    SQL> SELECT *
    2 FROM XMLTable(
    3 'declare function local:format-date($d as xs:date) as xs:string
    4 {
    5 let $s := xs:string($d)
    6 return concat(
    7 substring($s, 10, 2), "/",
    8 substring($s, 7, 2), "/",
    9 substring($s, 2, 4)
    10 )
    11 }; (: :)
    12 for $i in ora:view("TEST_XQDATE")/ROW/DT
    13 return element e {
    14 attribute xs_date_format { $i/text() },
    15 attribute local_format { local:format-date($i) }
    16 }'
    17 COLUMNS
    18 xs_date_format VARCHAR2(10) PATH '@xs_date_format',
    19 local_format VARCHAR2(10) PATH '@local_format'
    20 )
    21 ;
    XS_DATE_FORMAT LOCAL_FORMAT
    2010-10-28 28/10/2010
    {code}

  • ORA-01407 with UPDATE using COALESCE function

    Hi
    We're trying to run the following query as part of an upgrade:
    UPDATE LAWSON.NATBALANCE
    SET STATEMENT_REQ=(SELECT COALESCE(acm.STATEMENT_REQ,' ')
    FROM LAWSON.ARCUSTOMER acm
    WHERE acm.NAT_FLAG='N'
    AND LAWSON.NATBALANCE.NAT_COMPANY=acm.COMPANY AND
    LAWSON.NATBALANCE.NAT_CUSTOMER=acm.CUSTOMER)
    But we're getting the following error:
    ORA-01407: cannot update ("LAWSON"."NATBALANCE"."STATEMENT_REQ") to null.
    I’m confused by this for a couple of reasons. First, the STATEMENT_REQ field in LAWSON.ARCUSTOMER contains no NULLS, and second I thought the whole purpose of the COALESCE function was to return the first non-null result. What am I missing here?
    Edited by: ltzwoman on Dec 4, 2012 10:48 AM

    Hi,
    Welcome to the forum!
    Instead of UPDATE, you might prefer to do this with MERGE:
    MERGE INTO  lawson.netbalance     dst
    USING   (
             SELECT  company
             ,         customer
             ,         COALESCE ( statement_req
                        ) AS statement_req_not_null
             FROM    lawson.arcustomer
         )               src
    ON     (   src.company          = dst.nat_company
         AND src.customer     = dst.customer
    WHEN MATCHED THEN UPDATE
    SET     dst.statement_req     = src.statement_req_not_null
    WHERE     dst.statement_req      != src.statement_req_not_null
    ;You may find this easier to debug and maintain, since in an UPDATE statement, such as the one suggested by Solomon, the sub-query in the SET clause has to be repeated in the WHERE clause.
    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.
    If you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • How to use a function in select clause

    hi gems...good evening...
    I want to write a select clause from a function. The scenario is like below:
    function parameters
    CREATE OR REPLACE FUNCTION FUNCTION_DEMO(p_pid IN NUMBER,
    p_bankerNum IN NUMBER,
    p_banker_name IN VARCHAR2,
    p_business_num IN NUMBER,
    p_businesses IN table_typ_businesses)
    return table_typ_bankers
    as .......
    global object and table types
    CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER);
    CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses;
    CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,0));
    CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers;
    The select query
    select * from
    table(cast(FUNCTION_DEMO(1,
    2,
    'ALEX',
    2,
    table(cast(select businesses_id from reference_businesses) as table_typ_businesses) as table_typ_bankers)But it is giving error with Missing expression.
    My function is compiled successfully. I just want to make the select query to view the output given by the function i.e the table type "table_typ_bankers".
    Please help...thanks in advance..

    Hi ,
    You can check this and change your code by taking this as an example. I just noted down with simple one input and return as collection type
    and how to use/call it in select statement.
    SQL> CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,2))
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers
      2  /
    Type created.
    /* Now creating a demo function and just focusing on your one input as collection type  */
    SQL> create or replace function f11 ( tab_rec  IN table_typ_businesses)
      2  return table_typ_bankers
      3  is
      4  t_val table_typ_bankers:= table_typ_bankers();
      5  begin
      6        dbms_output.put_line('tab_rec count -'||tab_rec.count);
      7
      8  for i in 1..tab_rec.count
      9              loop
    10               dbms_output.put_line ('tab_rec value ('||i||')'||tab_rec(i).businesses);
    11                       t_val.EXTEND;
    12                    t_val(i) := obj_typ_bankers(tab_rec(i).businesses * 12.50);
    13              end loop;
    14              return t_val;
    15  end;
    16  /
    Function created.
    /* To run your function by a select statement */
    SQL> SELECT * FROM TABLE(f11(table_typ_businesses(obj_typ_businesses(5),
      2                          obj_typ_businesses(12),
      3                                         obj_typ_businesses(18))
      4                                             ) )
      5  /
    BANKER_NUM
          62.5
           150
           225
    tab_rec count -3
    tab_rec value (1)5
    tab_rec value (2)12
    tab_rec value (3)18Hope this will help you... :)
    Thanks!
    Ashutosh

  • BOM Update using a function module - 'CSAP_MAT_BOM_MAINTAIN'

    Hi,
    I have problem in updating the item status for a BOM using a function module - 'CSAP_MAT_BOM_MAINTAIN'.
    My goal is reset the Checkbox for 'Indicator: item relevant to production'. When i pass the value ' '[Space] to the structure field 'T_STPO-REL_PROD' it doen't work.
    Do let me know if you come across such problem & what needs to passed as input to reste the checkbox in the BOM.
    Thanks & Regards,
    Bhargava

    PLM wants to manipulate the Indicators u2013 u201CBulk Materialu201D & u201CCost Relevancyu201D in BOM.
    Note: The 2 indicators [u201CBulk Materialu201D & u201CCost Relevancyu201D] are interlinked with each other for a business functionlity given by SAP. So, if we try to set both indicators we get the below SAP standard error.
    E 29127 Bulk material not allowed for items relevant to costing
    SAP Field Name                             RFC Tag       SAP values    PLM values  Meaning for SAP field
    Indicator: bulk material                   BULK_MAT   Space             !                   No
    Indicator: bulk material                   BULK_MAT    X                   X                  Yes
    Indicator: item relevant to costing  REL_COST    Space            !                    Not relevant to costing
    Indicator: item relevant to costing  REL_COST     1                   1                   Not relevant to costing
    Indicator: item relevant to costing  REL_COST     2                   2                   Packaging operation
    Indicator: item relevant to costing  REL_COST     3                   3                   Packaging material
    Indicator: item relevant to costing  REL_COST     X                   X                  Relevant to costing
    To achieve the clear/reset/set value for 2 indicators [u201CBulk Materialu201D & u201CCost Relevancyu201D] from PLM, only eitheir of indicators status needs to sent [i.e 1 indicator status @ a time].

  • Using TRIM function in select statement

    Hi All,
    I'm using the TRIM function in my select statement to eliminate the white spaces.
    But while using in select the TRIM function is not working in SQL*PLUS client(The query returns the white spaces also)
    Kindly provide some pointers regarding the issue.........
    I want to get only the data without the spaces in select statement
    Regards,
    Mohan

    Hi, Mohan,
    SQL*Plus always pads columns to make them line up nicely.
    If you have a column declared as VARCHAR2 (20), then SQL*Plus will normally display 20 characters for that column, even in the maximum actual length is, say, 5 (or even if the column always happens to be NULL).
    If you want the output to include only the actual data, without the padding that SQL*Plus adds, then concatenate all the columns into one big string column.
    People often do something like the following to generate a CSV file, with no exta spaces:
    SELECT       TO_CHAR (empno)
    || ',' || ename
    || ',' || job
    || ',' || TO_CHAR (deptno)
    || ',' || TO_CHAR (hiredate, 'DD-Mon-YYYY')     AS all_data
    FROM          scott.emp;

  • How to use xpath function to select some particular  nodes

    Dear experts:
    does abap supports  xpath  to sellect particular  nodes  according some node value or condition, i know other  programe language  supports the function selectNode(xpath expression)  , does abap or have the api to support it?
    and i know there is a class support  the xpath but it's not work., the class this:cl_xslt_processor
    to clarify my point. i take a ex.
    the xml doc is follow:
    <?xml version="1.0" encoding="utf-8" ?>
    - <n0:MT_CRM_Req xmlns:n0="http://gome.com/CRM/CRM/Outbound" xmlns:prx="urn:sap.com:proxy:DC0:/1SAI/TAS05C79364B9D0DC5F6738:701:2010/02/19">
    <company name="hp">
    <dep name="gds">
    <empolyeeid>123</empolyeeid>
    </dep>
    <dep name="its">
    <empolyeeid>148</empolyeeid>
    </dep>
    </company>
    <company name="foxconn">
    <dep name="fih">
    <empolyeeid>569</empolyeeid>
    </dep>
    </company>
      </n0:MT_CRM_Req>
    i  want to  select the employee 's company name who empolyee id is 123
    i use the method  ,and the code is :
    l_xslt->set_expression(
    expression = '/n0:MT_CRM_Req/n0:company[n0:dep/n0:empolyeeid=123]'
    nsdeclarations = 'n0 http://gome.com/CRM/CRM/Outbound'
    l_xslt->run('').
    nodes = l_xslt->get_nodes( ).
    LEN = nodes->GET_LENGTH( ) .
    WRITE LEN.
    but no nodes return.
    is anybody knows what's wrong with it? or there is some other api to manipulate the xml dom.
    best regrds!

    Hello Kevin ,
    i think you can get those details , have a look at program BCCIIXMLT1, i think this program will give you some idea to handle * manage xml docs.
    along with that program ...you need to put filter
    *---creating filers.
      filter   = document->create_filter_name( name = 'Company' ).
      iterator = document->create_iterator_filtered( filter ).
      main_node =  document.
    *---processing document.
      perform print_node using main_node p_flag.
    let me know if you need anymore help.
    regards
    Prabhu

  • Using function in select statement

    Hi,
    CREATE FUNCTION [dbo].[udf_testFunction] 
    @value int
    RETURNS int
    AS
    BEGIN
    -- Declare the return variable here
    declare @returnValue int
    set @returnValue = @value*2;
    return @returnValue;
    END
    GO
    create table #Temp
        EmpID int, 
        EmpName Varchar(50)
    insert into #Temp(EmpID,EmpName) values(1,'Name1');
    insert into #Temp(EmpID,EmpName) values(2,'Name2');
    insert into #Temp(EmpID,EmpName) values(3,'Name3');
    insert into #Temp(EmpID,EmpName) values(4,'Name4');
    insert into #Temp(EmpID,EmpName) values(5,'Name5');
    select EmpID,EmpName, [dbo].[udf_testFunction](EmpID), [dbo].[udf_testFunction](EmpID)*EmpID,[dbo].[udf_testFunction](EmpID)+2 from #Temp
    In the above select statement i used [dbo].[udf_testFunction]() function 3 times. But i want to use only once and reuse it.
    Something like 
    select EmpID,EmpName, testfunctionvalue,testfunctionvalue*EmpID,testfunctionvalue+2 from #Temp
    Please advise me.... Thanks in Advance...

    You can use this code: 
    WITH cte
    AS ( SELECT EmpID ,
    EmpName ,
    [dbo].[udf_testFunction](EmpID) AS testfunctionvalue
    FROM #Temp
    SELECT EmpID ,
    EmpName ,
    testfunctionvalue ,
    testfunctionvalue * EmpID ,
    testfunctionvalue + 2
    FROM cte
    But using scalar functions in select clause can hurt the performance. Please see this link: 
    SQL Server Scalar User Defined Function Performance
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • Using packaged functions in Apex

    Hi,
    I'm fairly new to apex and I am about to write an app which needs to access a SQL server database. My local dba has set up the transparent gateway and I can select from and update the SQLServer database no problem via a db link. What I need to decide is whether to code the sql for reports etc directly into the apex page or to call a pl/sql function returning a select statement. I would like to have all the code in packages as a lot of it will be used by multiple apps in future but is there any extra overhead in doing this:
    declare
    l_sql varchar2(4000);
    begin
    select package.function into l_sql from dual;
    return l_sql;
    end;
    rather than coding the SQL directly in the page? Also is there a more efficient way of using packaged functions to select data rather that just have it returning sql statements.
    Thanks in advance.
    Dave

    Hi
    I only use function returning select when I have a strong reason to do so, because it is so much more difficult to test and maintain. Not sure about performance, but I think it is not that much worse.
    If you simply want to reuse SELECT statements, you could use views instead.
    Anyway, if you decide to use the package solution, at least you can make it much simpler -- just code like this in the page:
    return package.function;
    I hope this helps.
    Luis

  • How can i use SUM aggregate in select query?

    HI,
    GURUS,
    How can i use SUM function in Select Query and i want to store that value into itab.
    for ex:
    TABLES: vbap.
    types: begin of ty_vbap,
           incluse type vbap,
           sum type string,
          end of ty_vbap.
    data: i_vbap type TABLE OF ty_vbap,
          w_vbap type ty_vbap.
    SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
                            (or)
    SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
      loop at i_vbap into w_vbap
    " which variable have to use to display summed value.
      endloop.
    if above code is not understandable pleas give ome sample code on  above query.
    Thank u,
    shabeer ahmed.

    Hi,
    Check this sample code.
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Regards,
    Sravanthi

  • Parameterized function in select

    Hi Folks,
    How can i pass parameterized function in a select statement.
    The function has four parameters, those are : NUMBER, NUMBER, VARCHAR2, Collection of Varchar2.
    The return type of the function is Collection of Numbers.
    i am trying like this :
    select banker_id from table(cast(FETCH_BANKERS(:PID,:bankerId,:bankerName,:businessId,cast(:businessIds as tt_varchar))as tab_typ_bankers))It is failing with error : ORA-00932: inconsistent datatypes: expected - got CHAR

    See the answers in your other thread
    how to use a function in select clause

  • Help to write using anlytical functions or singe count instead of many

    HI,
    Could you some one help to write as single count instead of many (.Or) Is there any way to write below query using analytical functions?
    SELECT paper_code,paper_code_description, numCandidates, cast(numAwaitingApproval as varchar2(10)) as numAwaitingApproval, (numawaitingtrans + numawaitingibtran) as numAwaitingSubmission, (numibsub + numsub) as numSubmittedForMarking
           FROM(
             SELECT e.paper_code,
      translate_paper(e.paper_code,:v_year,:v_month,:v_iblanguage,:v_paper_type) AS paper_code_description,
      COUNT(e.candidate)                                                     AS numcandidates,
      COUNT(DECODE(status, 'AWAITING AUTHENTICATION',1))                     AS numAwaitingApproval,
      COUNT(DECODE(status, 'AWAITING TRANSFER',1))                           AS numawaitingtrans,
      COUNT(DECODE(status, 'AWAITING IB TRANSFER',1))                        AS numawaitingibtran,
      COUNT(DECODE(status, 'SUBMITTED',1))                                   AS numsub,
      COUNT(DECODE(status, 'IB SUBMITTED',1))                                AS numibsub
    FROM e_assessment_cands e,
      candidate_component_reg ccr,
      person_subject_session pss
    WHERE e.year                = :v_year
    AND e.month                 = :v_month
    AND e.e_coursework          = :v_e_coursework
    AND e.school_code           = :v_school_code
    AND ccr.split_session_year  = e.year
    AND ccr.split_session_month = e.month
    AND ccr.candidate           = e.candidate
    AND ccr.paper_code          = e.paper_code
    AND ccr.subject             =:v_subject
    AND ccr.subject_option      =COALESCE(:v_subject_option,ccr.subject_option)
    AND ccr.lvl                 =COALESCE(:v_lvl,ccr.lvl)
    AND ccr.language            =COALESCE(:v_language,ccr.language)
    AND ccr.component           =COALESCE(:v_component,ccr.component)
    AND pss.year                = ccr.split_session_year
    AND pss.month               = ccr.split_session_month
    AND pss.subject             = ccr.subject
    AND pss.lvl                 = ccr.lvl
    AND pss.subject_option      = ccr.subject_option
    AND pss.language            = ccr.language
    AND pss.role                = :v_role
    AND pss.person_code         = :v_person_code
    GROUP BY e.paper_code)

    Hi,
    user575115 wrote:
    HI,
    Could you some one help to write as single count instead of many (.Or) If you're using Oracle 11, look at SELECT ... PIVOT.
    If you'd like help. post CREATE TABLE and INSERT statements for some sample data, and the results you want from that data.
    Always say which version of Oracle you're using.
    Given that you need numCnadidates and numAwaitingApproval, using COUNT twice seems to be the simplest and most efficient way to do it.
    If you don't need the other COUNTs, such as numawaitingtrans, then don't compute them.
    Is there any way to write below query using analytical functions?Analytic functions can give you a COUNT without reducing the result set to one row per group. It lookw like you do want to reduce the result set to one row per group, however, so I don't see how analytic functions would help in this problem.

  • Subquery removal using window functions

    Hi,
    DB is 9.2.0.8 EE .
    select * from FROM bt_osoby osoby , bt_osoby_firmy osf1
    WHERE osoby.osb_audyt_st = '1'
      AND osf1.osf_audyt_st = '1'
      AND osoby.osb_id = osf1.osf_osb_id
      AND osoby.osb_nzm_id != 4140963  
      AND osoby.osb_id = ( SELECT MAX (osoby2.osb_id)
                             FROM bt_osoby osoby2
                             WHERE osoby2.osb_audyt_st = '1'
                             AND osoby2.osb_nzm_id = osoby.osb_nzm_id) I'm trying to rewrite above with subquery removal using window functions trick.
    select * from bt_osoby osoby , (
      SELECT first_value(osoby2.osb_id) over (partition by osoby2.osb_nzm_id order by osoby2.osb_id desc nulls last) max_osb_id ,osoby2.osb_nzm_id o2_osb_nzm_id
                             FROM bt_osoby osoby2
                             WHERE osoby2.osb_audyt_st = '1') v
                             ,bt_osoby_firmy osf1
                             where
                             osoby.osb_audyt_st = '1'
      AND osf1.osf_audyt_st = '1'
      AND osoby.osb_id = osf1.osf_osb_id
      AND osoby.osb_nzm_id != 4140963
      AND   v.max_osb_id = osoby.osb_id
      AND osoby.osb_nzm_id = v.o2_osb_nzm_idbut rewritten query plan involves huge FTS on BT_OSOBY (much worst then NL over sub query before), how to
    benefit from 'subquery removal using window functions' then?
    Regards.
    GG

    Hi,
    As you discovered, a query with a sub-query can be more efficient that one without a sub-query.
    I would do this using the analytic RANK function (or, depending on your needes, maybe ROW_NUMBER).
    WITH     bt_osoby_with_rnum     AS
         select  bt_osoby.*
         ,     RANK () OVER ( PARTITION BY  osb_nzm_id
                               ORDER BY          osb_id     DESC
                        ) AS rnum
         FROM      bt_osoby
         WHERE     osb_audyt_st     = '1'
         AND     osb_nzm_id      != 4140963  
    SELECT     *     -- or list all columns except rnum
    FROM     bt_osoby_wtih_rnum             osoby
    ,      bt_osoby_firmy                 osf1
    WHERE      osf1.osf_audyt_st  = '1'
    AND      osoby.osb_id = osf1.osf_osb_id
    ;Of course, without versions of your tables, I can't test this.
    Note that this does use a sub-query.

  • Partner function update using CRM_PARTNER_MAINTAIN_SINGLE_OW

    Hi Experts,
    Can some one pls help me with some working code/sample to update a partner function value in CRM Order. I tried the below code but it doesnt seems to be working.
    Appreciate your help on this.
        call function 'CRM_ORDER_READ'
          exporting
            it_header_guid       = lt_guid
            iv_mode              = 'C'
          importing
            et_orderadm_h        = it_orderadm_h
          et_sales             = it_sales
          et_orderadm_i        = it_orderadm_i
          et_orgman            = it_orgman
          et_shipping          = it_shipping
          et_partner           = it_partner
          exceptions
            document_not_found   = 1
            error_occurred       = 2
            document_locked      = 3
            no_change_authority  = 4
            no_display_authority = 5
            no_change_allowed    = 6
            others               = 7.
        if sy-subrc <> 0.
    Implement suitable error handling here
        endif.
          clear wa_orderadm_h.
          read table it_orderadm_h into wa_orderadm_h index 1.
         lv_ref_guid = it_orderadm_h-guid.
          call function 'CRM_PARTNER_GET_CONTROL_INF_OW'
            exporting
              iv_ref_guid          = wa_orderadm_h-guid
              iv_ref_kind          = 'A'
            importing
              es_partner_control   = ls_partner_control
            exceptions
              determination_failed = 1
              others               = 2.
          if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          endif.
          move-corresponding ls_partner_control to es_partner_control.
    Common fields for both create and change *****
          import lv_qplant to lv_werks2 from memory id 'QUOTA_PLANT'.
          select single partner_no
            from crmm_locmap
            into w_partner
           where ext_locno = lv_werks2. "wa_quota_so_items_return-werks2.
    Partner_com parameter
          ls_partner_com-ref_guid = wa_orderadm_h-guid.
          ls_partner_com-ref_kind = 'A'.
          ls_partner_com-partner_no = w_partner.
          ls_partner_com-display_type = 'BP'.
          ls_partner_com-no_type = 'BP'.
    Find whether create or change is required
          read table gt_partner into wa_partner with key partner_fct = '00000035' ref_kind ='A'.
          if sy-subrc eq 0.
            ls_partner_com-kind_of_entry = 'C'.
            ls_partner_com-partner_fct = '00000035'.
            ls_ip_fields-fieldname = 'DISPLAY_TYPE'.
            append ls_ip_fields to lt_ip_fields.
            ls_ip_fields-fieldname = 'KIND_OF_ENTRY'.
            append ls_ip_fields to lt_ip_fields.
            ls_ip_fields-fieldname = 'NO_TYPE'.
            append ls_ip_fields to lt_ip_fields.
            ls_ip_fields-fieldname = 'PARTNER_FCT'.
            append ls_ip_fields to lt_ip_fields.
            ls_ip_fields-fieldname = 'PARTNER_NO'.
            append ls_ip_fields to lt_ip_fields.
            call function 'CRM_PARTNER_MAINTAIN_SINGLE_OW'
              exporting
                iv_ref_guid           = wa_orderadm_h-guid
                iv_ref_kind           = 'A'
                is_partner_com        = ls_partner_com
                iv_populate_mode      = 'X'
                iv_check_partner_only = ' '
                is_partner_control    = es_partner_control
                iv_external_call      = 'X'
              changing
                ct_input_field_names  = lt_ip_fields
              exceptions
                error_occurred        = 1
                others                = 2.
            if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            endif.

    Reply to an old post but still can be helpful to someone in need
    *& Report  ZUPDATE_TRANSACTION_PF
    REPORT  zupdate_transaction_pf.
    *======================================================================*
    *  Variable declaration for ALV                                        *
    *======================================================================*
    TYPE-POOLS: slis.     " Type pool required for ALV
    TYPES: BEGIN OF gs_output,
              extid             TYPE ib_extid,
              prodid            TYPE comt_product_id,
              msg_type          TYPE bapi_mtype,
              message           TYPE bapi_msg,
              layout            TYPE slis_t_specialcol_alv,
           END OF gs_output.
    DATA: gt_output             TYPE TABLE OF gs_output,
          gs_output             TYPE gs_output,
          gt_fieldcat           TYPE slis_t_fieldcat_alv,
          gt_color_green        TYPE slis_t_specialcol_alv,
          gt_color_red          TYPE slis_t_specialcol_alv,
          gt_color_yellow       TYPE slis_t_specialcol_alv,
          gt_layout             TYPE slis_layout_alv,
          lt_header_guid        TYPE crmt_object_guid_tab,
          ls_header_guid        TYPE crmt_object_guid,
          lt_partner            TYPE crmt_partner_external_wrkt,
          ls_partner            TYPE crmt_partner_external_wrk,
          lt_guid               TYPE crmt_object_guid_tab,
          lt_guid_single        TYPE crmt_object_guid_tab,
          lt_req_obj            TYPE crmt_object_name_tab,
          ls_req_obj            TYPE crmt_object_name,
          lt_partner_update     TYPE crmt_partner_comt,
          lt_partner_com        TYPE crmt_partner_comt,
          ls_partner_com        TYPE crmt_partner_com,
          lt_input_fields       TYPE crmt_input_field_names_tab,
          ls_input_fields       TYPE crmt_input_field_names,
          lv_partner_fct        TYPE crmt_partner_fct,
          lv_partner_no         TYPE bu_partner,
          lv_trans_no           TYPE crmt_object_id_db,
          lt_return             TYPE STANDARD TABLE OF ddshretval,
          ls_return             LIKE LINE OF lt_return,
          lv_guid               TYPE crmt_object_guid.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE block1.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (36) forpf.
    PARAMETERS: p_pf TYPE comt_partner_fct OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (36) frombp.
    PARAMETERS: p_frombp TYPE but000-partner  OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (36) tobp.
    PARAMETERS: p_tobp TYPE but000-partner OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (36) fortrans.
    SELECT-OPTIONS: p_trans FOR lv_trans_no MATCHCODE OBJECT crm_order_object_id.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE block2.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (36) fortest.
    PARAMETERS: p_test AS CHECKBOX.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b2.
    INITIALIZATION.
      fortrans = 'Transaction Number'.
      forpf = 'Partner Function'.
      frombp = 'From Business Partner'.
      tobp = 'To Business Partner'.
      fortest = 'Test Run, Check Only'.
    *======================================================================*
    *  AT SELECTION-SCREEN                                                 *
    *======================================================================*
    AT SELECTION-SCREEN.
      FIELD-SYMBOLS:
        <sscrfields> TYPE sscrfields.
      DATA:
      lv_answer   TYPE char1,
      lt_options  TYPE TABLE OF rfc_db_opt,
      lt_fields   TYPE TABLE OF rfc_db_fld,
      lt_func_det TYPE TABLE OF tab512.
      CHECK sy-ucomm EQ 'ONLI'.
    AT SELECTION-SCREEN ON p_trans.
      CHECK sy-ucomm EQ 'ONLI' OR sy-ucomm EQ 'SJOB'.
      IF p_trans IS INITIAL.
        MESSAGE e398(00) WITH 'Please enter the transaction numbers'.
      ENDIF.
    AT SELECTION-SCREEN ON p_pf.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pf.
      CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
        EXPORTING
          tabname           = 'CRMC_PARTNER_FT'
          fieldname         = 'PARTNER_FCT'
        TABLES
          return_tab        = lt_return[]
        EXCEPTIONS
          field_not_found   = 1
          no_help_for_field = 2
          inconsistent_help = 3
          no_values_found   = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF lt_return[] IS NOT INITIAL.
        READ TABLE lt_return[] INTO ls_return INDEX 1.
        p_pf = ls_return-fieldval.
      ENDIF.
      CHECK sy-ucomm EQ 'ONLI' OR sy-ucomm EQ 'SJOB'.
      IF p_pf IS INITIAL.
        MESSAGE e398(00) WITH 'Please enter the partner function'.
      ENDIF.
    AT SELECTION-SCREEN ON p_frombp.
      CHECK sy-ucomm EQ 'ONLI' OR sy-ucomm EQ 'SJOB'.
      IF p_frombp IS INITIAL.
        MESSAGE e398(00) WITH 'Please enter the business partner id to be changed'.
      ENDIF.
    AT SELECTION-SCREEN ON p_tobp.
      CHECK sy-ucomm EQ 'ONLI' OR sy-ucomm EQ 'SJOB'.
      IF p_tobp IS INITIAL.
        MESSAGE e398(00) WITH 'Please enter the new business partner id'.
      ENDIF.
    *======================================================================*
    *  START-OF-SELECTION                                                  *
    *======================================================================*
    START-OF-SELECTION.
      PERFORM init_alv_col_color.
      PERFORM update_transactions.
    END-OF-SELECTION.
      PERFORM create_report.
    *&      Form  create_fieldcat
    *       text
    FORM create_fieldcat.
      PERFORM add_fld USING: 'EXTID'     'Order ID'        '20' 1,
                             'PRODID'    'Product ID'         '20' 2,
                             'MSG_TYPE'  'MSG Type'            '8'  9,
                             'MESSAGE'   'Message Description' '100' 10.
    ENDFORM.                    "CREATE_FIELDCAT
    *&      Form  add_fld
    *       text
    *      -->P_FIELDNAME  text
    *      -->P_SELTEXT_M  text
    *      -->P_OUTPUTLEN  text
    *      -->P_COL_POS    text
    FORM add_fld USING p_fieldname
                       p_seltext_m
                       p_outputlen
                       p_col_pos.
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = p_fieldname.
      ls_fieldcat-ref_fieldname = p_fieldname.
      ls_fieldcat-seltext_m     = p_seltext_m.
      ls_fieldcat-outputlen     = p_outputlen.
      ls_fieldcat-col_pos       = p_col_pos.
      APPEND ls_fieldcat TO gt_fieldcat.
    ENDFORM.                    "add_fld
    *&      Form  create_report
    *       text
    FORM create_report.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          text = 'Creating output ...'.
    * Get the field headers into an internal table
      PERFORM create_fieldcat.
      gt_layout-coltab_fieldname = 'LAYOUT'.
      gt_layout-colwidth_optimize = 'X'.
      gt_layout-zebra = ' '.
    * Call ABAP/4 Grid Viewer
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_top_of_page = 'TOP-OF-PAGE'
          i_callback_program     = sy-repid
          it_fieldcat            = gt_fieldcat[]
          is_layout              = gt_layout
        TABLES
          t_outtab               = gt_output  " it_sort = gt_sort
        EXCEPTIONS
          program_error          = 1
          OTHERS                 = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " create_report
    *&      Form  init_alv_col_color
    *       text
    FORM init_alv_col_color.
    * Red ALV column
      PERFORM add_field_color USING gt_color_red 'MSG_TYPE' '6' '1' '1'.
      PERFORM add_field_color USING gt_color_red 'MESSAGE' '6' '1' '1'.
    * Green ALV column
      PERFORM add_field_color USING gt_color_green 'MSG_TYPE' '5' '1' '1'.
      PERFORM add_field_color USING gt_color_green 'MESSAGE' '5' '1' '1'.
    * Yellow ALV column
      PERFORM add_field_color USING gt_color_yellow 'MSG_TYPE' '3' '1' '1'.
      PERFORM add_field_color USING gt_color_yellow 'MESSAGE' '3' '1' '1'.
    ENDFORM.                    "init_alv_col_color
    *&      Form  add_field_color
    *       text
    *      -->PT_COLOR   text
    *      -->FIELDNAME  text
    *      -->COL        text
    *      -->INT        text
    *      -->INV        text
    FORM add_field_color USING pt_color TYPE slis_t_specialcol_alv
                               fieldname col int inv.
      DATA: ls_color TYPE slis_specialcol_alv.
      ls_color-fieldname = fieldname.
      ls_color-color-col = col.
      ls_color-color-int = int.
      ls_color-color-inv = inv.
      APPEND ls_color TO pt_color.
    ENDFORM.                    "add_field_color
    * Form  TOP-OF-PAGE                                                 *
    * ALV Report Header                                                 *
    FORM top-of-page.
    *ALV Header declarations
      DATA: t_header TYPE slis_t_listheader,
            wa_header TYPE slis_listheader,
            t_line LIKE wa_header-info,
            ld_lines TYPE i,
            ld_linesc(10) TYPE c.
    * Title
      wa_header-typ  = 'H'.
      wa_header-info = 'Data Migration'.
      APPEND wa_header TO t_header.
      CLEAR wa_header.
    * Date
      wa_header-typ  = 'S'.
      wa_header-key = 'Date: '.
      CONCATENATE  sy-datum+6(2) '.'
                   sy-datum+4(2) '.'
                   sy-datum(4) INTO wa_header-info.   "todays date
      APPEND wa_header TO t_header.
      CLEAR: wa_header.
    * Time
      wa_header-typ  = 'S'.
      wa_header-key  = 'Time: '.
      CONCATENATE  sy-uzeit(2) ':'
                   sy-uzeit+2(2) ':'
                   sy-uzeit+4(2) INTO wa_header-info.   "time
      APPEND wa_header TO t_header.
      CLEAR: wa_header.
    * File Path
      wa_header-typ  = 'S'.
      wa_header-key  = 'File Path: '.
      wa_header-info = ''.
      APPEND wa_header TO t_header.
      CLEAR: wa_header.
    * Test Mode
      wa_header-typ  = 'S'.
      wa_header-key  = 'Test Mode: '.
      IF p_test = 'X'.
        wa_header-info = 'Yes'.
      ENDIF.
      APPEND wa_header TO t_header.
      CLEAR: wa_header.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_header.
    ENDFORM.                    "top-of-page
    *&      Form  UPDATE_TRANSACTIONS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM update_transactions .
      SELECT guid INTO TABLE lt_header_guid FROM crmd_orderadm_h WHERE object_id IN p_trans.
      IF sy-subrc EQ 0.
        LOOP AT lt_header_guid INTO ls_header_guid.
          CLEAR: lt_guid, lt_req_obj, lt_partner, lt_input_fields.
          ls_req_obj = 'PARTNER'.
          APPEND ls_req_obj TO lt_req_obj.
          APPEND ls_header_guid TO lt_guid.
          CALL FUNCTION 'CRM_ORDER_READ'
            EXPORTING
              it_header_guid       = lt_guid
              it_requested_objects = lt_req_obj
            IMPORTING
              et_partner           = lt_partner
            EXCEPTIONS
              document_not_found   = 1
              error_occurred       = 2
              document_locked      = 3
              no_change_authority  = 4
              no_display_authority = 5
              no_change_allowed    = 6
              OTHERS               = 7.
          lv_partner_fct = p_pf.
          lv_partner_no = p_frombp.
          SHIFT p_frombp LEFT DELETING LEADING '0'.
          READ TABLE lt_partner INTO ls_partner WITH KEY partner_fct = p_pf partner_no = p_frombp.
          IF sy-subrc EQ 0.
            LOOP AT lt_partner INTO ls_partner WHERE partner_fct = p_pf AND partner_no = p_frombp.
              lv_partner_no = p_tobp.
              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  input  = lv_partner_no
                IMPORTING
                  output = lv_partner_no.
              REFRESH lt_input_fields.
              CLEAR   ls_partner_com.
              ls_partner_com-ref_guid     = ls_partner-ref_guid.
              ls_partner_com-ref_kind     = ls_partner-ref_kind.
              ls_partner_com-ref_partner_handle = ls_partner-ref_partner_handle.
              ls_partner_com-kind_of_entry = 'C'.
              ls_partner_com-partner_fct  = ls_partner-partner_fct.
              ls_partner_com-partner_no   = lv_partner_no.
              ls_partner_com-display_type = 'BP'.
              ls_partner_com-no_type      = 'BP'.
              ls_partner_com-ref_partner_no = ls_partner-ref_partner_no.
              ls_partner_com-ref_partner_fct = ls_partner-ref_partner_fct.
              ls_partner_com-ref_no_type     

Maybe you are looking for