src-db/database/model/functions/AD_IMPFORMAT_COPY.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 6701 690d2af86089
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION AD_IMPFORMAT_COPY">
adrian@94
     3
    <function name="AD_IMPFORMAT_COPY" type="NULL">
juanpablo@1605
     4
      <parameter name="pinstance_id" type="VARCHAR" 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: AD_ImpFormat_Copy.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
carlos@0
    28
  ***
carlos@0
    29
  * Title: Copy Import Format content (i.e. Rows) to another
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):='';
juanpablo@1605
    35
  v_Record_ID VARCHAR2(32);
carlos@0
    36
  -- Parameter
carlos@0
    37
  TYPE RECORD IS REF CURSOR;
carlos@0
    38
    Cur_Parameter RECORD;
carlos@0
    39
    -- Parameter Variables
juanpablo@1605
    40
    v_AD_ImpFormat_ID VARCHAR2(32);
carlos@0
    41
    v_NoOfFields NUMBER:=0;
juanpablo@1605
    42
    v_NextNo VARCHAR2(32);
carlos@0
    43
    Cur_Rows RECORD;
carlos@0
    44
  BEGIN
carlos@0
    45
    --  Update AD_PInstance
carlos@0
    46
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID) ;
carlos@0
    47
    v_ResultStr:='PInstanceNotFound';
carlos@0
    48
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    49
  BEGIN --BODY
carlos@0
    50
    -- Get Parameters
carlos@0
    51
    v_ResultStr:='ReadingParameters';
carlos@0
    52
    FOR Cur_Parameter IN
carlos@0
    53
      (SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
carlos@0
    54
      FROM AD_PInstance i
carlos@0
    55
      LEFT JOIN AD_PInstance_Para p
carlos@0
    56
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    57
      WHERE i.AD_PInstance_ID=PInstance_ID
carlos@0
    58
      ORDER BY p.SeqNo
carlos@0
    59
      )
carlos@0
    60
    LOOP
carlos@0
    61
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    62
      IF(Cur_Parameter.ParameterName='AD_ImpFormat_ID') THEN
juanpablo@1605
    63
        v_AD_ImpFormat_ID:=Cur_Parameter.P_String;
carlos@0
    64
        DBMS_OUTPUT.PUT_LINE('  AD_ImpFormat_ID=' || v_AD_ImpFormat_ID) ;
carlos@0
    65
      ELSE
carlos@0
    66
        DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
carlos@0
    67
      END IF;
carlos@0
    68
    END LOOP; -- Get Parameter
carlos@0
    69
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    70
    -- Record_ID is the ImpFormat_ID to copy to
carlos@0
    71
    FOR Cur_Rows IN
carlos@0
    72
      (SELECT *  FROM AD_ImpFormat_Row  WHERE AD_ImpFormat_ID=v_AD_ImpFormat_ID)
carlos@0
    73
    LOOP
carlos@0
    74
      -- Get next no
carlos@0
    75
      AD_Sequence_Next('AD_ImpFormat_Row', Cur_Rows.AD_Client_ID, v_NextNo) ;
carlos@0
    76
      -- Insert
carlos@0
    77
      INSERT
carlos@0
    78
      INTO AD_ImpFormat_Row
carlos@0
    79
        (
carlos@0
    80
          AD_ImpFormat_Row_ID, AD_ImpFormat_ID, AD_Client_ID, AD_Org_ID,
carlos@0
    81
          IsActive, Created, CreatedBy, Updated,
carlos@0
    82
          UpdatedBy, Name, SeqNo, AD_Column_ID,
carlos@0
    83
          StartNo, EndNo, DataType, DataFormat,
carlos@0
    84
          DecimalPoint, DivideBy100, ConstantValue, Callout
carlos@0
    85
        )
carlos@0
    86
        VALUES
carlos@0
    87
        (v_NextNo, v_Record_ID, Cur_Rows.AD_Client_ID, Cur_Rows.AD_Org_ID,
juanpablo@1605
    88
        Cur_Rows.IsActive, now(), '0', now(),
juanpablo@1605
    89
        '0', Cur_Rows.Name, Cur_Rows.SeqNo, Cur_Rows.AD_Column_ID,
carlos@0
    90
        Cur_Rows.StartNo, Cur_Rows.EndNo, Cur_Rows.DataType, Cur_Rows.DataFormat,
carlos@0
    91
        Cur_Rows.DecimalPoint, Cur_Rows.DivideBy100, Cur_Rows.ConstantValue, Cur_Rows.Callout) ;
carlos@0
    92
      --
carlos@0
    93
      v_NoOfFields:=v_NoOfFields + 1;
carlos@0
    94
    END LOOP;
carlos@0
    95
    v_Message:='@Copied@=' || v_NoOfFields;
gorkaion@239
    96
    --<<FINISH_PROCESS>>
carlos@0
    97
    --  Update AD_PInstance
carlos@0
    98
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
    99
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
   100
    RETURN;
carlos@0
   101
  END; --BODY
carlos@0
   102
EXCEPTION
carlos@0
   103
WHEN OTHERS THEN
carlos@0
   104
 v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   105
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   106
  AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   107
  RETURN;
antonio@735
   108
END AD_IMPFORMAT_COPY
gorkaion@239
   109
]]></body>
adrian@94
   110
    </function>
adrian@94
   111
  </database>