Wednesday, April 9, 2014

Drop Ship Sales Order



Drop Ship Sales Order
Drop shipping functionality enables you to take an order from your customer and fulfill it directly from your supplier's site. Order Management enables you to enter drop ship sales orders and lines for standard, model and kit, and configured items, although you currently cannot perform a drop shipment for Ship Model Complete (SMC) PTO's.
You can receive orders for items that you do not stock or for which you lack sufficient inventory, and have a supplier provide the items directly to your customer

The supply and demand details for drop ship orders are
not visible to Oracle Planning applications. Therefore, it is recommended that you associate a separate logical (dummy) organization for shipping drop ship orders; the logical organization should not be included in your planning processes.

When processing drop shipments for orders that contain models or kits, you can drop ship individual items within non SMC PTO configurations from different vendors or even ship several components from your own inventory.

In Oracle Order managementg we have Attribute Source Type, a value Source Type ='External' means it is Drop Ship. we can default Source Type from organizational item attribute,"Default SO Source Type", please note that If the value of this attribute is NULL, Order Management will default the value Internal.

Oracle Order Management seeded constraints will not enable you to perform changes to the Source Type value if the branch on source type workflow activity within the Create Supply - Line workflow subprocess has completed.


Features of Drop Ship Order lines -

Reservations
Once an order line has been specified as an External order, Order Management does notallow reservations to be placed against the order line.

Scheduling
When performing drop shipments of models or kits or standard items, the scheduled ship date is defaulted from the order line request date, and Oracle Global ATP calculations are ignored (demand for drop ship orders are not visible to Oracle Planning products).

Drop Shipment orders cannot consume forecast demand for standard items, ATO items, and models and their respective components.

Return
Use standard Order Management functionality to process return material authorizations (RMAs). Your customers can return drop shipped items to you or to your supplier. If you receive the return into your inventory, you can retain it or ship it to your supplier.

Mass Change and order line attribute Source Type
You can perform a Mass Change for the order line attribute Source Type. The order line attribute Source Type is available (as a field) within the Shipping Tab of the Mass Change window

Note: If the buyer makes changes to the requisition or purchase order in Oracle Purchasing after Purchase Release has been run, or modifies the sales order after the PO has been created, use the Order Management Sales Order and Purchase Order Discrepancy Report to note differences between the original sales order and its associated purchase order.

Confirmation of Shipment and Receipt
Standard Oracle Purchasing functionality confirms that your supplier has completed the drop shipment. Confirmation may be as simple as a phone call, or it may include Electronic Data Interchange (EDI) documents, such as an Advance Shipment Notice (ASN) and an Advance Shipping and Billing Notice (ASBN).
When you receive shipment confirmation, enter a receipt in Oracle Purchasing, even if the drop shipped item is not transactable. This creates inbound and outbound material transactions in your system for accounting purposes. Drop shipment orders can be processed across Ledgers, operating units, or legal entities.


 

Tuesday, April 8, 2014

Step by Step details about how to Create RMA in Oracle Order Management

In this blog I will explain how to create RMA in Oracle Order Management , I am taking the case of creation of Return Sales Order with Receipt and Credit Memo.

1.Create New Sales Order with Order Type = "Return Only . ( we can take Mixed or any other that allow return line)

2.Since Header Order Type is "Return Only", based on the transaction Type Setup ,  System will default Line Type .In transaction type set the Default RMA = "Return (Receipt)" , with this Setup system will populate the Line Type = "Return (Receipt)"  , enter other details like
Item #
Qty etc.

3.Go to Return tab ( Lines) and Enter Return Reason (There is LOV for Return Reason select any relevant value from LOV ).
4.Book the RMA.

5.Re-query the RMA , check the Line Status , It should be "Awaiting Return".

6.Select Receipt (Purchasing Responsibility)

7.Go to Customer Tab and Enter the RMA Number.

8.Press Find Button.

9.Ignore the receipt Header , and go to Receipts form

10.Select the line

11.Press Save,System will ask for the Sub Inventory.Best bet is enter "Stores" ( Here I am taking the case Routing = Direct Delivery)

12.Press Save Button. Save action will automatically submit the "Receiving Transaction Processor (RTP) concurrent Program.

13.Check Order line status , it should be "Returned".

14.Go to View > request . Submit Concurrent Program "Workflow background Process"
              with Item Type = OM Order Line
              Process Deferred = Yes
              Process Timeout = No.

Query Order line again , Status Should be "Closed"

15. Submit "Autoinvoice import program" concurrent Program.
16.Go to Transaction (Receivable Responsibility)

            Go to Find Window
             Enter Sales Order # in Sales Order Number Field
             Press Find
System should display your Invoice (Credit memo)

Examine the Invoice and you are good to go.


Regular Expressions in 10g


This article briefly introduces Oracle’s support for regular expressions in 10g, considered by many developers to be long overdue. The new functions (available in both SQL and PL/SQL) are:
  • REGEXP_LIKE
  • REGEXP_INSTR
  • REGEXP_SUBSTR
  • REGEXP_REPLACE
Each of these functions are covered below. This article assumes that the reader has some knowledge of regular expressions and pattern matching. For further details, see the SQL Reference in the online Oracle documentation.

setup

To demonstrate regular expressions we’ll use a small set of arbitrary test data, created as follows.
SQL> CREATE TABLE t (x VARCHAR2(30));

Table created.

SQL> INSERT ALL
  2     INTO t VALUES ('XYZ123')
  3     INTO t VALUES ('XYZ 123')
  4     INTO t VALUES ('xyz 123')
  5     INTO t VALUES ('X1Y2Z3')
  6     INTO t VALUES ('123123')
  7     INTO t VALUES ('?/*.')
  8     INTO t VALUES ('\?.')
  9  SELECT * FROM dual;

7 rows created.

SQL> SELECT * FROM t;

X
------------
XYZ123
XYZ 123
xyz 123
X1Y2Z3
123123
?/*.
\?.

7 rows selected.

regexp_like

First we’ll look at REGEXP_LIKE and use this to introduce the basic means of specifying regular expressions. This function returns TRUE when it matches patterns using standard (or POSIX) notation. The pattern to match is passed as the second parameter to the function and is represented as a string using a combination of literal or meta characters. These can be quite sophisticated and flexible and it is worth reading the documentation for a full list of meta-characters, POSIX classes and references.
First we’ll look for data with a lower-case letter followed by a space and a number using standard pattern notation.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[a-z] [0-9]');

X
------------------------------
xyz 123
Next we look for data with a lower-case letter followed by any single character (represented by the “.”) then a number.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[a-z].[0-9]');

X
------------------------------
xyz 123
The question mark character in the following expression represents either zero or one occurrence of the previous pattern (in this example a lower-case letter). Hence this regular expression matches a wider range of records.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[a-z]?[0-9]');

X
------------------------------
XYZ123
XYZ 123
xyz 123
X1Y2Z3
123123
The “*” wildcard represents zero or more occurrences of the preceding expression, so it could be argued that the following pattern is simply looking for any data containing at least one number (zero or more lower-case characters followed by a digit).
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[a-z]*[0-9]');

X
------------------------------
XYZ123
XYZ 123
xyz 123
X1Y2Z3
123123
To search for a specific number of occurrences of an expression, it is followed by the number of occurrences in braces. The following expression is searching for data with three consecutive capital letters.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[A-Z]{3}');

X
------------------------------
XYZ123
XYZ 123
This time we search for three occurrences of a capital letter followed by a single digit. To ensure that we search for the entire pattern three times (and not just the digit), we need to wrap the combined expression in parentheses (this is known as a subexpression).
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '([A-Z][0-9]){3}');

X
------------------------------
X1Y2Z3
Note that to search for at least three occurrences of the subexpression, the number of occurrences would need to be followed by a comma, i.e. {3,}.
The following expression is one way of searching for all-numeric data. The caret (^) and dollar ($) denote start and end of line, respectively. The plus (+) after the digit class represents one or more occurrences.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '^[0-9]+$');

X
------------------------------
123123
We might sometimes need to match meta-characters, meaning that these must be “escaped”. For example, we’ve seen above that the question mark (?) is a special character meaning zero or one of the preceding pattern in the expression. To search explicitly for data containing this character, we must escape it using a backslash (\).
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '\?');

X
------------------------------
?/*.
\?.
To specify “not” in a regular expression, a caret (^) is used within the brackets to exclude the referenced characters. Note that outside of these brackets the caret denotes start of line. The following example searches for data that is not all digits, which in our dataset is all but one record. Note that this is not the same as searching for data without any digits at all (that would require a NOT REGEXP_LIKE() or a REGEXP_INSTR() = 0 expression).
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, '[^0-9]+');

X
------------
XYZ123
XYZ 123
xyz 123
X1Y2Z3
?/*.
\?.

6 rows selected.
Finally, we can also specify “either-or” using a pipe (|) meta-character. The following searches for all data containing either an ‘X’ or a ‘1’.
SQL> SELECT * FROM t WHERE REGEXP_LIKE(x, 'X|1');

X
------------
XYZ123
XYZ 123
xyz 123
X1Y2Z3
123123

5 rows selected.

regexp_instr

REGEXP_INSTR returns the position of a string that matches a given pattern. As with the INSTR function, we can specify a starting point within the string (default 1) and the nth occurrence to search for. There are additional parameters to REGEXP_INSTR that we shall briefly cover below. First, we’ll search for the position of a literal question mark in our test data.
SQL> SELECT x
  2  ,      REGEXP_INSTR(x, '\?') AS "POSITION_OF_?"
  3  FROM   t;

X                              POSITION_OF_?
------------------------------ -------------
XYZ123                                     0
XYZ 123                                    0
xyz 123                                    0
X1Y2Z3                                     0
123123                                     0
?/*.                                       1
\?.                                        2

7 rows selected.
As mentioned above, REGEXP_INSTR has additional (optional) parameters over and above those we use for standard INSTR-type operations. These additional parameters allow for offset and matching. Offset enables us to specify whether we want the position of the start of the expression match (0) or the position immediately after the end of the regex match (1). A match parameter enables us to request case sensitivity using flags (e.g. 'i' for ignore or 'c' for case sensitivity. Default is whatever is specified in NLS_SORT). The following demonstrates three variations while searching for three capital letters in our test data.
SQL> SELECT x
  2         --<>--
  3  ,      REGEXP_INSTR(
  4            x,
  5            '[A-Z]{3}', --expression
  6            1,          --start at
  7            1,          --nth occurrence
  8            0           --offset position
  9            ) AS regexp_offset_0
 10         --<>--
 11  ,      REGEXP_INSTR(
 12            x,
 13            '[A-Z]{3}',
 14            1,
 15            1,
 16            1
 17            ) AS regexp_offset_1
 18         --<>--
 19  ,      REGEXP_INSTR(
 20            x,
 21            '[A-Z]{3}',
 22            1,
 23            1,
 24            0,
 25            'i'        --match parameter
 26            ) AS regexp_case_insensitive
 27         --<>--
 28  FROM   t;

X            REGEXP_OFFSET_0 REGEXP_OFFSET_1 REGEXP_CASE_INSENSITIVE
------------ --------------- --------------- -----------------------
XYZ123                     1               4                       1
XYZ 123                    1               4                       1
xyz 123                    0               0                       1
X1Y2Z3                     0               0                       0
123123                     0               0                       0
?/*.                       0               0                       0
\?.                        0               0                       0

7 rows selected.

regexp_substr

REGEXP_SUBSTR is incredibly useful. It returns the part of the string that matches the pattern only. It follows the same convention as REGEXP_INSTR with respect to starting position, nth occurrence and match-parameter arguments. However, it doesn't work like the standard SUBSTR, for which you specify the length of string to return.
For a very simple demonstration of REGEXP_SUBSTR, we’ll look at the default behaviour when searching for a string of one or more digits. We’ll also try to strip a second occurrence of the same pattern by using the relevant parameter. Incidentally, I’ve deliberately introduced an alternative means of expressing “digits-only” by using the POSIX character class (there are quite a few of these classes described in the online documentation).
SQL> set null {null}

SQL> SELECT x
  2         --<>--
  3  ,      REGEXP_SUBSTR(
  4            x,
  5            '[[:digit:]]+' --note POSIX char-class
  6            ) AS first_occurrence
  7         --<>--
  8  ,      REGEXP_SUBSTR(
  9            x,
 10            '[[:digit:]]+',
 11            1,
 12            2
 13            ) AS second_occurrence
 14  FROM   t;

X            FIRST_OCCURRENCE     SECOND_OCCURRENCE
------------ -------------------- --------------------
XYZ123       123                  {null}
XYZ 123      123                  {null}
xyz 123      123                  {null}
X1Y2Z3       1                    2
123123       123123               {null}
?/*.         {null}               {null}
\?.          {null}               {null}

7 rows selected.

regexp_replace

Finally, we’ll take a brief look at REGEXP_REPLACE. As its name suggests, this function searches for a specified number of occurrences (default all) of a pattern and replaces it with a given string or NULL. As with REGEXP_INSTR and REGEXP_SUBSTR, we can supply starting position, nth occurrence and a match-parameter. In the following simple example, we’ll replace all digits with a hyphen (-).
SQL> SELECT x
  2  ,      REGEXP_REPLACE(x, '[[:digit:]]', '-') AS nums_to_hyphens
  3  FROM   t;

X            NUMS_TO_HYPHENS
------------ --------------------
XYZ123       XYZ---
XYZ 123      XYZ ---
xyz 123      xyz ---
X1Y2Z3       X-Y-Z-
123123       ------
?/*.         ?/*.
\?.          \?.

7 rows selected.
What if we need to replace a given pattern with the pattern itself plus some additional data? REGEXP_REPLACE enables us to back-reference the regular expression (up to 500 expressions in fact) and include it in our replacement. The following example shows how we can replace all digits with the digits themselves followed by an asterisk. We enclose the regular expression in parentheses and reference it in the replacement string using \n (in our case \1 as we only have one preceding expression).

SQL> SELECT x
  2  ,      REGEXP_REPLACE(
  3            x,
  4            '([0-9])', --note the parentheses
  5            '\1*'      --\1 means include 1st pattern
  6            ) AS search_pattern_included
  7  FROM   t;

X            SEARCH_PATTERN_INCLUDED
------------ -----------------------------------
XYZ123       XYZ1*2*3*
XYZ 123      XYZ 1*2*3*
xyz 123      xyz 1*2*3*
X1Y2Z3       X1*Y2*Z3*
123123       1*2*3*1*2*3*
?/*.         ?/*.
\?.          \?.

7 rows selected.

putting regular expressions to use

Once we become familiar with regular expressions in Oracle, we’ll find many uses for them, replacing older methods that used nested SUBSTR(INSTR,INSTR) and so on. The web is also awash with new solutions to old problems that are served by regular expressions in 10g. For example, postcode (zip) validation, telephone number validation, “IS_NUMBER”, email address validation and so on.


Add Unique key in a table that contains duplicate row

 
 
Requirement : A table contains some duplicate data. Now we want to add a unique constraint that skip existing duplicate values but check newly inserted duplicate values.

SQL> create table t2 (id number(10), t varchar2(20));

Table created.


SQL> insert into t2 values (1,'A');

1 row created.

SQL> insert into t2 values (1,'A');

1 row created.

SQL> insert into t2 values (1,'A');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table t2 add constraint uk_t2 unique(id) ENABLE NOVALIDATE;
alter table t2 add constraint uk_t2 unique(id) ENABLE NOVALIDATE
*
ERROR at line 1:
ORA-02299: cannot validate (HASAN.UK_T2) - duplicate keys found


SQL> select * from t2;

ID T
---------- ------------------------------------------------------------
1 A
1 A
1 A

So normal method does not work !



Case 1: New Table That means initially the table does not have any data

SQL> create table t3 (id number(10), t varchar2(20));

Table created.

SQL> alter table t3 add constraint gpu unique (id) deferrable initially deferred;

Table altered.

SQL> alter table t3 disable constraint gpu;

Table altered.


SQL> insert into t3 values(1,'A');

1 row created.

SQL> insert into t3 values(1,'A');

1 row created.

SQL> insert into t3 values(1,'A');

1 row created.

SQL> commit;

Commit complete.

SQL>
SQL>
SQL>
SQL> select * from t3;

ID T
---------- ------------------------------------------------------------
1 A
1 A
1 A



SQL> alter table t3 enable novalidate constraint gpu;

Table altered.

SQL> insert into t3 values(2,'A');

1 row created.

SQL> commit;

Commit complete.

SQL> insert into t3 values(2,'A');

1 row created.

SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-00001: unique constraint (HASAN.GPU) violated

SQL> alter table t3 modify constraint gpu INITIALLY IMMEDIATE;

Table altered.

SQL> insert into t3 values(1,'A');
insert into t3 values(1,'A')
*
ERROR at line 1:
ORA-00001: unique constraint (HASAN.GPU) violated



Case 2: Existing Table that contains duplicate data


SQL> create table t2 (id number(1),a varchar2(10));

Table created.


SQL> insert into t2 values(1,'A');

1 row created.

SQL> insert into t2 values(1,'A');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table t2 add constraint uk_t2 unique(id) DEFERRABLE INITIALLY DEFERRED disable;

Table altered.

SQL> alter table t2 enable novalidate constraint uk_t2;

Table altered.

SQL> insert into t2 values(1,'A');

1 row created.

SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-00001: unique constraint (HASAN.UK_T2) violated


SQL> alter table t2 modify constraint uk_t2 INITIALLY IMMEDIATE;

Table altered.

SQL> insert into t2 values(1,'A');
insert into t2 values(1,'A')
*
ERROR at line 1:
ORA-00001: unique constraint (HASAN.UK_T2) violated


OR


SQL> alter table t2 add constraint uk_t2 unique(id) disable;

Table altered.


SQL> alter table t2 enable novalidate constraint uk_t2;

Table altered.

SQL> insert into t2 values(1,'A');
insert into t2 values(1,'A')
*
ERROR at line 1:
ORA-00001: unique constraint (HASAN.UK_T2) violated



PL/SQL - Operator Precedence




In SQL or PL/SQL we use several operators. Some are mathematical, logical and comparison operators. Oracle follow a order of precedence when execute an expression that contains more than one operators. If operators with same precedence are occurred then it does not follow any order. Otherwise Oracle maintain the following order of precedence of operators.


Order |------------| Operator |------------| Operation
1 |------------| ** |------------| exponentiation
2 |------------| +, |------------| identity, negation
3 |------------| *, / |------------| multiplication, division
4 |------------| +, -, || |------------| addition, subtraction, concatenation
5 |------------| =, <, >, <=, >=, |------------| comparison
<>, !=, ~=, ^=, IS NULL, LIKE,
BETWEEN, IN
6 |------------| NOT |------------| logical negation
7 |------------| AND |------------| conjunction
8 |------------| OR |------------| inclusion


For example, when NOT, AND and OR operators are used in the same statement NOT is evaluated first, then AND and finally OR.


Analytical SQL functions


Oracle has introduced some exciting extensions to ANSI SQL to allow us to quickly compute aggregations and rollup. These new statements include:
  1. rollup
  2. cube
These simple SQL operators allow us to create easy aggregations directly inside the SQL without having to employ SQL*Plus break and compute statements. Let’s start by examining the ROLLUP syntax.

Tabular aggregates with ROLLUP



ROLLUP enables an SQL statement to calculate multiple levels of subtotals across a specified group of dimensions. It also calculates a grand total. ROLLUP is a simple extension to the GROUP BY clause, so its syntax is extremely easy to use.

SELECT deptno, job,count(*), sum(sal) FROM emp GROUP BY ROLLUP(deptno,job);


DEPTNO JOB COUNT(*) SUM(SAL)
--------- --------- --------- ---------
10 CLERK 1 1300
10 MANAGER 1 2450
10 PRESIDENT 1 5000
10 3 8750
20 ANALYST 2 6000
20 CLERK 2 1900
20 MANAGER 1 2975
20 5 10875


cross-tabular reports with CUBE



In multidimensional jargon, a “cube” is a cross-tabulated summary of detail rows. CUBE enables a SELECT statement to calculate subtotals for all possible combinations of a group of dimensions. It also calculates a grand total. This is the set of information typically needed for all cross-tabular reports, so CUBE can calculate a cross-tabular report with a single select statement.

Note in the example below that totals are calculated for each department, and also for each job category.

SELECT deptno,job,count(*),sum(sal) FROM emp GROUP BY CUBE(deptno,job);

DEPTNO JOB COUNT(*) SUM(SAL)
--------- --------- --------- ---------
10 CLERK 1 1300
10 MANAGER 1 2450
10 PRESIDENT 1 5000
10 3 8750
20 ANALYST 2 6000
20 CLERK 2 1900
20 MANAGER 1 2975
20 5 10875
30 CLERK 1 950
30 MANAGER 1 2850
30 SALESMAN 4 5600
30 6 9400
ANALYST 2 6000
CLERK 4 4150
MANAGER 3 8275
PRESIDENT 1 5000
SALESMAN 4 5600
14 29025


ALTER TABLE Option in Oracle.

ALTER TABLE

Specifications of 'ALTER TABLE' are as follows

Adding Foreign key

ALTER TABLE table_name
ADD CONSTRAINT constraint_name FOREIGN KEY (col1, col2)
REFERENCES table_2 (cola,colb);

Adding unique constraint

The following example adds a unique constraint on the column column_name in the table whose name is table_name. The name of the constraint is constraint_name.

ALTER TABLE table_name
add constraint constraint_name
unique (column_name)

Disabling constraints

Integrity constraints can be disabled with the ALTER TABLE command.

ALTER TABLE table-name disable constraint-specification;
ALTER TABLE table-name disable constraint constraint-name;

Adding new Column

ALTER TABLE foo_table add bar_column char(1);
ALTER TABLE foo_table add (bar_column1 char(1),bar_column2 char(1));

Modifying a column

Renaming a column name

ALTER TABLE some_table rename column column_name to new_column_name;

Changing a column's type

A column's type can be changed if the column is empty within the entire table, otherwise Oracle gives an ORA-01440: column to be modified must be empty to decrease precision or scale.

ALTER TABLE some_table modify (column_name number);

Changing null to not null or vice versa

ALTER TABLE some_table modify (column_name not null);

ALTER TABLE some_table modify col_not_null number null;


Specifying tablespace for index

ALTER TABLE tbl add constraint pk_tbl
primary key (col_1, col_2)
using index tablespace ts_idx

Removing a constraint

ALTER TABLE table_name drop constraint constraint_name;