src-db/database/model/functions/TEMPLATE.xml
author Asier Lostalé <asier.lostale@openbravo.com>
Mon, 05 May 2008 06:59:24 +0000
changeset 799 fef2c5e2feb7
parent 785 8dba91261590
child 1027 2e9052d7de0e
permissions -rw-r--r--
Merged cleanup branch (r3931) with trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION TEMPLATE">
adrian@94
     3
    <function name="TEMPLATE" type="NULL">
antonio@735
     4
      <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
juanpablo@771
     8
  * The contents of this file are subject to the Compiere Public
juanpablo@771
     9
  * License 1.1 ("License"); You may not use this file except in
juanpablo@771
    10
  * compliance with the License. You may obtain a copy of the License in
juanpablo@771
    11
  * the legal folder of your Openbravo installation.
carlos@0
    12
  * Software distributed under the License is distributed on an
carlos@0
    13
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    14
  * implied. See the License for the specific language governing rights
carlos@0
    15
  * and limitations under the License.
juanpablo@778
    16
  * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    17
  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
carlos@0
    18
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    19
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    20
  * All Rights Reserved.
carlos@0
    21
  * Contributor(s): Openbravo SL
juanpablo@785
    22
  * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    23
  *
juanpablo@771
    24
  * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    25
  * file and version.
carlos@0
    26
  *************************************************************************
carlos@0
    27
  * $Id: Template.sql,v 1.9 2003/02/18 03:33:22 jjanke Exp $
carlos@0
    28
  ***
carlos@0
    29
  * Title:
carlos@0
    30
  * Description:
carlos@0
    31
  ************************************************************************/
carlos@0
    32
  -- Logistice
carlos@0
    33
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    34
  v_Message VARCHAR2(2000):='';
carlos@0
    35
  v_Result NUMBER:=1; -- 0=failure
carlos@0
    36
  v_Record_ID NUMBER;
carlos@0
    37
  v_AD_User_ID NUMBER;
asier@799
    38
  v_PInstance_Log_ID NUMBER;
asier@799
    39
  v_Client_ID NUMBER;
carlos@0
    40
  -- Parameter
carlos@0
    41
  TYPE RECORD IS REF CURSOR;
carlos@0
    42
    Cur_Parameter RECORD;
carlos@0
    43
    -- Parameter Variables
carlos@0
    44
    rowcount NUMBER;
carlos@0
    45
  BEGIN
carlos@0
    46
    --  Update AD_PInstance
carlos@0
    47
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    48
    v_ResultStr:='PInstanceNotFound';
carlos@0
    49
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    50
  BEGIN --BODY
carlos@0
    51
    -- Get Parameters
carlos@0
    52
    v_ResultStr:='ReadingParameters';
carlos@0
    53
    FOR Cur_Parameter IN
carlos@0
    54
      (SELECT i.Record_ID,
carlos@0
    55
        i.AD_User_ID,
carlos@0
    56
        p.ParameterName,
carlos@0
    57
        p.P_String,
carlos@0
    58
        p.P_Number,
asier@799
    59
        p.P_Date,
asier@799
    60
        p.AD_CLIENT_ID
carlos@0
    61
      FROM AD_PInstance i
carlos@0
    62
      LEFT JOIN AD_PInstance_Para p
carlos@0
    63
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    64
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    65
      ORDER BY p.SeqNo
carlos@0
    66
      )
carlos@0
    67
    LOOP
carlos@0
    68
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    69
      v_AD_User_ID:=Cur_Parameter.AD_User_ID;
asier@799
    70
      v_Client_ID:=Cur_Parameter.AD_CLIENT_ID;
carlos@0
    71
      -- IF (p.ParameterName = 'xx') THEN
carlos@0
    72
      --  p_xx := p.P_String;
carlos@0
    73
      --  DBMS_OUTPUT.PUT_LINE('  xx=' || p_xx);
carlos@0
    74
      -- ELSE
carlos@0
    75
      --  DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
carlos@0
    76
      --  END IF;
carlos@0
    77
    END LOOP; -- Get Parameter
carlos@0
    78
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    79
    -- Log info - Log_ID must be unique in instance
carlos@0
    80
    --  P_Date/P_ID/P_Number/P_Msg are optional.
asier@799
    81
    AD_SEQUENCE_NEXT('AD_PInstance_Log', v_Client_ID, v_PInstance_Log_ID);
carlos@0
    82
    INSERT
carlos@0
    83
    INTO AD_PInstance_Log
carlos@0
    84
      (
carlos@0
    85
        AD_PInstance_ID,
carlos@0
    86
        Log_ID,
carlos@0
    87
        P_Msg
carlos@0
    88
      )
carlos@0
    89
      VALUES
carlos@0
    90
      (
carlos@0
    91
        p_PInstance_ID,
asier@799
    92
        v_PInstance_Log_ID,
carlos@0
    93
         '@Created@'
carlos@0
    94
      )
carlos@0
    95
      ;
carlos@0
    96
    -- Summary info rowcount
carlos@0
    97
    rowcount:=SQL%ROWCOUNT;
carlos@0
    98
    DBMS_OUTPUT.PUT_LINE('  Count=' || rowcount);
carlos@0
    99
    v_Message:='@Totals@ @Created@ @Updated@';
gorkaion@239
   100
    --<<FINISH_PROCESS>>
carlos@0
   101
    --  Update AD_PInstance
carlos@0
   102
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
   103
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
carlos@0
   104
    RETURN;
carlos@0
   105
  END; --BODY
carlos@0
   106
EXCEPTION
carlos@0
   107
WHEN OTHERS THEN
carlos@0
   108
   v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   109
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   110
  ROLLBACK;
carlos@0
   111
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   112
  RETURN;
antonio@735
   113
END TEMPLATE
gorkaion@239
   114
]]></body>
adrian@94
   115
    </function>
adrian@94
   116
  </database>