Search 800 + Posts

Feb 27, 2011

Samle Script to Delete Qualifiers Assocaited with Price List

This is a sample Script to Delete Qualifiers Associated with Price List .

NOTE  - This is a sample script that I have designed to delete the qualifiers associated with Price list.This is I designed to fulfill requirement for my customer.This is just a sample.

DECLARE
l_list_header_id  qp_list_headers_all.list_header_id%type :=&enter_list_header_id;
l_active_flag     qp_list_headers_all.active_flag%type;
l_name            qp_list_headers_all.name%type;
l_count_lines     NUMBER:=0;
l_count_quali     NUMBER:=0;
l_step            VARCHAR2(100);
qp_line_exists    EXCEPTION;
l_error           EXCEPTION;
BEGIN
  BEGIN
  l_step := 'Get List Details';
  SELECT active_flag,name
    INTO l_active_flag,l_name
    FROM qp_list_headers_all
  where list_header_id = l_list_header_ID;
  dbms_output.put_line('List Status - '||l_active_flag);
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      dbms_output.put_line('Error  - in Step '||l_step||'  '||sqlerrm);
      raise l_error;
    WHEN OTHERS THEN
      dbms_output.put_line('Error  - in Step '||l_step||'  '||sqlerrm);
      raise l_error;
  END ;
  --Check if lines Exists for Price List

    SELECT count(*)
      INTO l_count_lines
      FROM qp_list_lines
     WHERE list_header_id = l_list_header_id  ;
    IF l_count_lines > 0 THEN
        dbms_output.put_line('No. of Lines exists '||l_count_lines);
        raise qp_line_exists ;
    END IF;
    --Check if qualifiers exists for Price List
    SELECT count(*)
      INTO l_count_quali
      FROM qp_qualifiers
     WHERE list_header_id = l_list_header_id
       AND list_line_id  = -1;
    dbms_output.put_line('No. of Qualifier exists '||l_count_quali);  
    IF l_count_quali > 0 THEN
      DELETE from qp_qualifiers
       WHERE list_header_id = l_list_header_id
         AND list_line_id  = -1;
      dbms_output.put_line('No. of Qualifiers Delete for PList are '||sql%rowcount);
    ELSIF l_count_quali = 0 THEN
      dbms_output.put_line('NO Qualifiers exists for this Price List');
    END IF;  
EXCEPTION
  WHEN qp_line_exists THEN
     dbms_output.put_line('Error -  '||l_count_lines||' Lines Exists for Price List '||l_name);
   WHEN l_error THEN
     dbms_output.put_line('Exit');
  WHEN OTHERS THEN
    dbms_output.put_line('Error  - '||sqlerrm);
END;

No comments:

Post a Comment