I'm currently stuck in creating two tasks inside of a procedure adding numbers of an array passed to the respective procedure.
My generic package looks like this:
generic
type Item_Type is private;
with function "+"(Left: Item_Type; Right: Item_Type) return Item_Type;
package Parallel_Algorithms is
type Array_Type is array(Natural range <>) of Item_Type;
type Array_Access_Type is access all Array_Type;
procedure Parallel_Sum(Input: Array_Access_Type; Result: out Item_Type);
end Parallel_Algorithms;
I implemented the Parallel_Sum Method the following way, being aware that the implementation is not perfect, nor thread safe.
procedure Parallel_Sum(Input: Array_Access_Type; Result: out Item_Type) is
Loop_Var: Integer:= 0;
task type T;
Task1, Task2 : T;
task body T is
begin
while Loop_Var < Input'Length loop
Result := Result + Input(Loop_Var);
Loop_Var := Loop_Var + 1;
end loop;
end T;
begin
-- Result := Temp;
end Parallel_Sum;
If I now run my main program the output of Result always ends up being something like 1918988326. Considering the elements inside of my array (1,2,3,4) that result is obviously wrong.
I read in another post that non altering an out type may result in undefined behaviour of the respective variable.
What would be the proper way to get the 'real' Result?
Upon looking at the problem more closely I see there are several issues to overcome. The tasks must accumulate their own totals, then those totals must be combined. Adding totals to an unprotected Result variable will produce a race condition which will result in undefined results.
Following is my approach to the problem.
------------------------------------------------------------------
-- Parallel Addition of Array Elements --
------------------------------------------------------------------
generic
type Element_Type is range <>;
package Parallel_Addition is
type Array_Type is array(Natural range <>) of Element_Type;
type Array_Access is access all Array_Type;
task type Adder is
Entry Set_Slice(Low, High : in Natural;
Item : in not null Array_Access);
end Adder;
protected Result is
procedure Accumulate(Item : in Element_Type);
function Report return Element_Type;
private
Sum : Integer := 0;
end Result;
end Parallel_Addition;
package body Parallel_Addition is
-----------
-- Adder --
-----------
task body Adder is
My_Array : Array_Access;
Id_Low, Id_High : Natural;
Sum : Integer := 0;
begin
accept Set_Slice(Low, High : in Natural;
Item : in not null Array_Access) do
Id_Low := Low;
Id_High := High;
My_Array := Item;
end Set_Slice;
for I in Id_Low..Id_High loop
Sum := Sum + Integer(My_Array(I));
end loop;
Result.Accumulate(Element_Type(Sum));
end Adder;
------------
-- Result --
------------
protected body Result is
----------------
-- Accumulate --
----------------
procedure Accumulate (Item : in Element_Type) is
begin
Sum := Sum + Integer(Item);
end Accumulate;
------------
-- Report --
------------
function Report return Element_Type is
begin
return Element_Type(Sum);
end Report;
end Result;
end Parallel_Addition;
------------------------------------------------------------------
-- Parallel_Addition Test --
------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Parallel_Addition;
procedure PA_Test is
package adders is new Parallel_Addition(Natural);
use adders;
Data : aliased Array_Type := (1,2,3,4,5,6,7,8,9,10);
T1, T2 : Adder;
begin
T1.Set_Slice(Low => 0, High => 4, Item => Data'Access);
T2.Set_Slice(Low => 5, High => 9, Item => Data'Access);
loop
if T1'Terminated and then T2'Terminated then
exit;
end if;
end loop;
put_Line("The sum is " & Integer'Image(Result.Report));
end PA_Test;
Related
I'm trying to read from a byte buffer in Ada, such as a file or via buffer for a network connection. The messages are variable in size with a common header, in C++ it'd look something like this:
enum class MessageType : uint16_t {
Foo = 0, Bar = 1
};
// Force the layout.
#pragma pack(push,1)
// 4 byte message header
struct MessageHeader {
uint16_t checksum;
uint16_t type;
};
// 4 byte header + 4 byte message
struct FooMessage {
MessageHeader header;
uint32_t tomatoes;
};
// 4 byte header + 8 byte message
struct BarMessage {
MessageHeader header;
uint32_t oranges;
uint32_t apples;
};
#pragma pack(pop)
// For simplicity, assume the buffer is complete and only holds full messages.
void read(char* buffer, uint32_t bytesLeft) {
while (bytesLeft > 0) {
MessageHeader* header = reinterpret_cast<MessageHeader*>(buffer);
switch (header->type) {
case FooType: {
FooMessage* foo = reinterpret_case<FooMessage*>(buffer);
// process as const FooMessage&
processFoo(*foo);
}
case BarType: {
BarMessage* bar = reinterpret_cast<BarMessage*>(buffer);
// process as const BarMessage&
processBar(*bar);
}
}
const auto size = (header->type == Foo ? sizeof(FooMessage) : sizeof(BarMessage));
buffer += size;
bytesLeft -= size;
}
}
I'm not sure of the idiomatic way of doing it. Note that in some formats, the message type might not be the leading data member in the header, as well. Should you be writing to and reading off an array of Character or something from Interfaces.C.char_array, or an address of memory from System.Address or something else? Or should this be an address to an array elsewhere here, or just an array with "Convention => C" to prevent the leading size from being included?
This is what I have so far in Ada:
type Message_Type is (Foo, Bar) with Size => 16;
for Message_Type use (Foo => 0, Bar => 1);
-- Assume these work correctly and I don't need to do bit layout directly.
type Message_Header is record
Checksum : Interfaces.Integer_16;
Msg_Type : Message_Type;
end record
with Convention => C, Size => 32;
type Foo_Message is record
Header : Message_Header;
Tomatoes : Interfaces.Integer_32;
end record
with Convention => C, Size => 64;
type Bar_Message is record
Header : Message_Header;
Oranges : Interfaces.Integer_32;
Apples : Interfaces.Integer_32;
end record
with Convention => C, Size => 96;
procedure Read(
-- System.Address seems really weird here
Buffer : in out System.Address;
Bytes_Left : in out Interfaces.Integer_64)
is
use type Interfaces.Integer_64;
use type System.Address;
function To_Address is new Ada.Unchecked_Conversion (Interfaces.Integer_64, System.Address);
function To_Integer is new Ada.Unchecked_Conversion (System.Address, Interfaces.Integer_64);
procedure Process_Bar (B : aliased Bar_Message) is null;
procedure Process_Foo (F : aliased Foo_Message) is null;
begin
while Bytes_Left > 0 loop
declare
-- I'm really lost here.
--
-- Do you use access types to access the buffer or
-- setting the address with "for Foo'Address use Buffer"??
--
Header : Message_Header;
for Header'Address use Buffer;
enter code here
-- I'm assuming this doesn't initialize Foo and Bar here?
Foo_Msg : aliased Foo_Message;
Bar_Msg : aliased Bar_Message;
for Foo_Msg'Address use Buffer;
for Bar_Msg'Address use Buffer;
-- I'm assuming this doesn't initialize Foo and Bar here?
Size : System.Address := To_Address(0);
begin
case Header.Msg_Type is
when Foo => Process_Foo (Foo_Msg);
when Bar => Process_Bar (Bar_Msg);
end case;
Size := To_Address (if Header.Msg_Type = Foo then Foo'Size else Bar'Size);
-- There's probably a better way to do this.
Buffer := To_Address(To_Integer (Buffer) + To_Integer (Size));
Bytes_Left := Bytes_Left - To_Integer (Size);
end;
end loop;
end Read;
What's the idiomatic way to march in a variable way across bytes in buffers and read the data in place?
I would keep it simple: just define a buffer array at the given address:
Buf : System.Storage_Elements.Storage_Array (0 .. Bytes_Left - 1)
with Address => Buffer;
and then parse the buffer, message-by-message. The example below provides a sketch of how I would solve this (disclaimer: did not test it).
message_reader.ads
with System;
with System.Storage_Elements;
with Interfaces;
package Message_Reader is
package SSE renames System.Storage_Elements;
-- NOTE: Not using an enum type eases the implementation of the parser (I think).
-- In particular for detecting unknown message types.
type Message_Type is new Interfaces.Unsigned_16;
Message_Type_Foo : constant Message_Type := 0;
Message_Type_Bar : constant Message_Type := 1;
-- Assume these work correctly and I don't need to do bit layout directly.
type Message_Header is record
Checksum : Interfaces.Integer_16;
Msg_Type : Message_Type;
end record
with Convention => C, Size => 32;
type Foo_Message is record
Header : Message_Header;
Tomatoes : Interfaces.Integer_32;
end record
with Convention => C, Size => 64;
type Bar_Message is record
Header : Message_Header;
Oranges : Interfaces.Integer_32;
Apples : Interfaces.Integer_32;
end record
with Convention => C, Size => 96;
Unknown_Message_Type : exception;
procedure Read
(Buffer : in System.Address;
Bytes_Left : in out SSE.Storage_Count);
private
use type SSE.Storage_Count;
pragma Compile_Time_Error
(System.Storage_Unit /= 8, "implementation expects a storage unit size of 8");
Foo_Msg_Size_Bytes : constant SSE.Storage_Count :=
Foo_Message'Size / System.Storage_Unit;
Bar_Msg_Size_Bytes : constant SSE.Storage_Count :=
Bar_Message'Size / System.Storage_Unit;
procedure Process_Bar (B : Bar_Message) is null;
procedure Process_Foo (F : Foo_Message) is null;
end Message_Reader;
message_reader.adb
with Ada.Unchecked_Conversion;
package body Message_Reader is
generic
type Chunk_Type is private;
procedure Read_Chunk
(Buffer : in SSE.Storage_Array;
Offset : in SSE.Storage_Offset;
Chunk : out Chunk_Type;
Success : out Boolean);
----------
-- Read --
----------
procedure Read
(Buffer : in System.Address;
Bytes_Left : in out SSE.Storage_Count)
is
Buf : SSE.Storage_Array (0 .. Bytes_Left - 1)
with Address => Buffer;
procedure Read_Header is new Read_Chunk (Message_Header);
procedure Read_Foo_Msg is new Read_Chunk (Foo_Message);
procedure Read_Bar_Msg is new Read_Chunk (Bar_Message);
Header : Message_Header;
Success : Boolean;
begin
loop
Read_Header (Buf, Buf'Last - Bytes_Left - 1, Header, Success);
if not Success then
exit; -- Not enough data left in buffer.
end if;
case Header.Msg_Type is
when Message_Type_Foo =>
declare
Foo : Foo_Message;
begin
Read_Foo_Msg (Buf, Buf'Last - Bytes_Left - 1, Foo, Success);
if not Success then
exit; -- Not enough data left in buffer.
end if;
Bytes_Left := Bytes_Left - Foo_Msg_Size_Bytes;
Process_Foo (Foo);
end;
when Message_Type_Bar =>
declare
Bar : Bar_Message;
begin
Read_Bar_Msg (Buf, Buf'Last - Bytes_Left - 1, Bar, Success);
if not Success then
exit; -- Not enough data left in buffer.
end if;
Bytes_Left := Bytes_Left - Bar_Msg_Size_Bytes;
Process_Bar (Bar);
end;
when others =>
raise Unknown_Message_Type;
end case;
end loop;
end Read;
----------------
-- Read_Chunk --
----------------
procedure Read_Chunk
(Buffer : in SSE.Storage_Array;
Offset : in SSE.Storage_Offset;
Chunk : out Chunk_Type;
Success : out Boolean)
is
Chunk_Type_Bytes : constant SSE.Storage_Count :=
Chunk_Type'Size / System.Storage_Unit;
subtype Chunk_Raw is SSE.Storage_Array (0 .. Chunk_Type_Bytes - 1);
function To_Chunk is new Ada.Unchecked_Conversion
(Source => Chunk_Raw, Target => Chunk_Type);
Slice_First : constant SSE.Storage_Offset := Offset;
Slice_Last : constant SSE.Storage_Offset := Offset + Chunk_Type_Bytes - 1;
begin
if Slice_Last <= Buffer'Last then
Chunk := To_Chunk (Buffer (Slice_First .. Slice_Last));
Success := True;
else
Success := False;
end if;
end Read_Chunk;
end Message_Reader;
Use can use a record with a Unchecked_Union aspect.
type Message (Msg_Type : Message_Type) is record
Header : Message_Header;
case Msg_Type is
when Foo =>
Tomatoes : Interfaces.Integer_16;
when Bar =>
Oranges : Interfaces.Integer_32;
Apples : Interfaces.Integer_32;
end case;
end record
with Unchecked_Union;
Please note the discriminant is not accessible when using Unchecked_Union.
Note : Tomatoes has not the same size in the C code and the Ada code you provided.
I am trying to develop a stored procedure within TERADATA to handle and manage exceptions.
The stored procedure should raise the error to the caller, which is an SSIS Package.
I am trying to illustrate this by creating a stored procedure for illustration only.
I have these tables:
Table_A:
- ID INT
- ITEM_NUM INT
- DESC VARCHAR(20)
- CREATE_DTTM VARCHAR(2O)
Table_B:
- ID INT
- ITEM_NUM INT
- DESC VARCHAR(20)
- CREATE_DTTM VARCHAR(2O)
I have two tables that will be inserting data from two SELECT statements.
REPLACE PROCEDURE csTest2()
SQL SECURITY OWNER
BEGIN
DECLARE varErrorMessage char(256);
DECLARE varSQLState char(5);
DECLARE varReturnCode char(5);
DECLARE varRollbackNeededInd char(1); /* transaction mgt */
SET varRollbackNeededInd = 'N';
SET varReturnCode = '00000';
SET varErrorMessage = '';
BEGIN TRANSACTION;
-- USING A SINGLE HANDLER WITH MULTIPLE STATEMENTS
-- PLANING TO CHANGE ERROR MESSAGE IN EACH STATEMENT.
ins6: BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
H99:Begin
set varSQLState = SQLSTATE;
set varErrorMessage= 'This message should not be displayed'; --
end H99;
-- IMAGINE THAT I AM GETTING THE VALUES AS INPUT PARAMERS IN THE PROCEDURE
INSERT INTO "Table_A"
(ID , ITEM_NUM, DESC, CREATE_DTTM)
SELECT 1, '222', 'SOME DESC',CURRENT_TIMESTAMP;
H98:Begin
set varSQLState = SQLSTATE;
set varErrorMessage= 'This message is displayed, ITEM_NUM invalid characters';
end H98;
-- NOW I AM DOING A SECOND INSERT TO table b WITH INVALID DATA
-- THE VALUE FOR THE ITEM NUMBER CONTAINS ALPHANUMERICE CHARACTERS
INSERT INTO "Table_b"
(ID , ITEM_NUM, DESC, CREATE_DTTM)
SELECT 1, '333F', 'SOME DESC',CURRENT_TIMESTAMP;
END ins6;
EndTrans: BEGIN
IF varSQLState <> '0' THEN
SET varRollbackNeededInd = 'Y';
SET varReturnCode = '9999';
END IF;
IF varRollbackNeededInd = 'Y' THEN
ROLLBACK; -- ROLLBACK AND SEND ERROR TO CALLER
SIGNAL SQLSTATE 'U0123' SET MESSAGE_TEXT = 'SQlState is - ' || varSQLSTATE || ' - and error is - ' || varErrorMessage;
ELSE
END TRANSACTION; -- COMMIT TRANSACTION
END IF;
END EndTrans;
END;
The problem that I am facing with the above stored procedure is that error message that I get is not the one that I am expecting. Since error is intentionally created in my second statement I am expecting to get: This message is displayed, ITEM_NUM invalid characters but I am getting This message should not be displayed
Now if I modify the PROCEDURE to have multiple handlers, one for each statement, I do get the correct error message, but now since I am intentionally generating the error in the first statement it does not terminate the procedure, it handles the error and sets the proper message but continues to process the next statement which I am not expecting to do this, so how can I terminate this procedure?
REPLACE PROCEDURE csTest2()
SQL SECURITY OWNER
BEGIN
DECLARE varErrorMessage char(256);
DECLARE varSQLState char(5);
DECLARE varReturnCode char(5);
DECLARE varRollbackNeededInd char(1); /* transaction mgt */
SET varRollbackNeededInd = 'N';
SET varReturnCode = '00000';
SET varErrorMessage = '';
BEGIN TRANSACTION;
ins6: BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
H99:Begin
set varSQLState = SQLSTATE;
set varErrorMessage= 'Error is displayed in this case because ITEM_NUM';
-- ERROR IS PRESENT IN THIS STATEMENT AND SHOULD TERMINATE THE PROCEDURE.
INSERT INTO "Table_A"
(ID , ITEM_NUM, DESC, CREATE_DTTM)
SELECT 1, '222F', 'SOME DESC',CURRENT_TIMESTAMP;
END ins6;
ins7: BEGIN
H98:Begin
set varSQLState = SQLSTATE;
set varErrorMessage= 'no error is displayed in this case';
end H98;
-- NO ERROR IS EXPECTED, BUT IT SHOULD NOT REACH HERE SINCE WE HAD ERROR ON FIRST STATEMENT.
INSERT INTO "Table_b"
(ID , ITEM_NUM, DESC, CREATE_DTTM)
SELECT 1, '333', 'SOME DESC',CURRENT_TIMESTAMP;
END ins7;
EndTrans: BEGIN
IF varSQLState <> '0' THEN
SET varRollbackNeededInd = 'Y';
SET varReturnCode = '9999';
END IF;
IF varRollbackNeededInd = 'Y' THEN
ROLLBACK; -- ROLLBACK AND SEND ERROR TO CALLER
SIGNAL SQLSTATE 'U0123' SET MESSAGE_TEXT = 'SQlState is - ' || varSQLSTATE || ' - and error is - ' || varErrorMessage;
ELSE
END TRANSACTION; -- COMMIT TRANSACTION
END IF;
END EndTrans;
END;
I'm new to Eiffel and I'm trying to use the LINKED_LIST class for organizing instances of other class "MONOMIO" I've made. I added a function for ordering this elements and I use the remove and the cursor movement features and when I try to execute the code it raises an exception saying that the objects contained should be readable and writable. I would like to know how to do it, this is my class:
class
MONOMIO
feature --Initialization
make (coef:INTEGER; expX:INTEGER; expY:INTEGER)
do
coeficiente := coef
exponenteX := expX
exponenteY := expY
end
feature
evaluar(valX: INTEGER; valY: INTEGER): REAL_64
do
Result := coeficiente*(valX^exponenteX)*(valY^exponenteY)
end;
coeficiente: INTEGER;
exponenteX: INTEGER;
exponenteY: INTEGER;
feature --setter
set_coeficiente(val: INTEGER)
do
coeficiente := val
end;
end
I think the exception raises because of this feature I've made for a class that has as a feature the LINKED_LIST[MONOMIO] and it's called "contenido":
simplificar
local
tamanio_polinomio: INTEGER -- NĂºmero de monomios que tiene el polinomio
contador: INTEGER
monomio_a_comparar: MONOMIO -- Auxiliar
coeficiente_total:INTEGER -- Auxiliar
indice_monomio_en_revision:INTEGER
do
from
contenido.start
indice_monomio_en_revision := 0
tamanio_polinomio := contenido.count
until
indice_monomio_en_revision = tamanio_polinomio
loop
contenido.start
contenido.move (indice_monomio_en_revision)
monomio_a_comparar := contenido.item
from
contador := indice_monomio_en_revision
coeficiente_total := monomio_a_comparar.coeficiente
contenido.forth
until
contador = tamanio_polinomio
loop
if
(monomio_a_comparar.exponentex = contenido.item.exponentex) and
(monomio_a_comparar.exponentey = contenido.item.exponentey)
then
coeficiente_total := coeficiente_total + contenido.item.coeficiente
contenido.remove -- Mueve el cursor a la derecha
tamanio_polinomio := tamanio_polinomio - 1
contador := contador - 1
else
if
not contenido.islast
then
contenido.forth
end
end
contador := contador + 1
end
contenido.start
contenido.move (indice_monomio_en_revision)
contenido.item.set_coeficiente (coeficiente_total)
indice_monomio_en_revision := indice_monomio_en_revision + 1
end
end;
I hope anyone can help me with this problem. Thanks.
Suppose you have a list with 1 element. Then we enter the outer loop and move to the first element. Then we execute contador := indice_monomio_en_revision that is still 0 at this point and do contenido.forth. Now we are beyond the list because there is only one element. However contador = tamanio_polinomio is false (0 = 1), so we enter the inner loop and try to retrieve the second (non-existing) item. BOOM!
Other issues include:
There are multiple calls like contenido.start followed by contenido.move. You could use a single call to go_i_th instead.
Instead of counting number of items in the list I would look at the feature after. It tells when you reach an end of the list. It would simplify the logic of your loop (e.g. the call to islast would be removed) and let you to remove some local variables.
Taking the last point into account I would write the inner loop condition as
contenido.after
At least this would avoid the crash you experience. As to the logic, you may need to check features start, after, forth and remove to see what effect they have. The usual way to write loops in such cases is like
from
l.start
until
l.after
loop
... -- Use l.item
l.forth
end
In case of remove probably you do not need to call forth.
I am using a stored procedure which returns multiple result sets and takes a lot of time to execute. I have to bind these result sets to the controls at the front end side. But it also takes a lot of time to display the results and there is no option of changing the stored procedures. So what else can I try?
Here is my stored proc,
ALTER PROCEDURE [dbo].[sp_getdata]
#Week int = 1,
#Year int = 2014
AS
BEGIN
declare #current_week int
set #current_week = datepart (week, getdate())
while #Week <= #current_week
begin
exec SP_GetResults_New #Week,#Year
set #Week = #Week + 1
end
END
Thanks.
Package
create or replace package PKG_PROJECT AS
type cur IS REF CURSOR;
procedure SP_PREPARESALARY(v_yr in number,v_mn in number);
END PKG_PROJECT;
PACKAGE BODY
PL/SQL statement ignored at line 29(just before the relevant insert query)
create or replace package body PKG_PROJECT AS
procedure SP_PREPARESALARY(v_yr in number,v_mn in number) AS
V_EMPNO INTEGER;
V_EMPNAME VARCHAR2(30);
V_BASICSALARY INTEGER;
V_DAYSPRESENT INTEGER;
V_YEAR INTEGER;
V_MONTH INTEGER;
V_PF INTEGER;
V_TAX INTEGER;
V_MON_SAL INTEGER;
V_NET_SAL INTEGER;
V_MAXDAYS INTEGER;
CURSOR EMP_VALUES IS
SELECT EMPNO, EMPNAME, BASICSALARY, YEAR, MONTH, DAYSPRESENT
FROM DELL_EMPLOYEE, DELL_ATTENDANCE
WHERE EMPNO=ENO AND YEAR = V_YR AND MONTH = V_MN;
BEGIN
OPEN EMP_VALUES;
LOOP
FETCH EMP_VALUES INTO V_EMPNO,V_EMPNAME,V_BASICSALARY,V_YEAR,V_MONTH,V_DAYSPRESENT;
EXIT WHEN EMP_VALUES%NOTFOUND;
V_YEAR := V_YR;
V_MONTH := V_MN;
V_MAXDAYS := FN_GETMAXDAYS(V_YEAR,V_MONTH);
V_MON_SAL:= FN_GETGROSSMONTHLYSALARY(V_BASICSALARY, V_DAYSPRESENT, V_MAXDAYS);
V_PF:= FN_GETPF(V_MON_SAL);
V_TAX:= FN_GETTAX(V_MON_SAL,V_PF);
V_NET_SAL:= FN_GETNETSALARY(V_MON_SAL, V_PF, V_TAX);
INSERT INTO DELL_SALARY (EMPNO, YEAR,MONTH,EMPNAME,DAYSPRESENT,BASICSALARY,MONTHSALARY,PF,TAX,NETSALARY)
VALUES (V_EMPNO,V_YEAR,V_MONTH,V_EMPNAME,V_DAYSPRESENT,V_BASICSALARY,V_MON_SAL,
V_PF,V_TAX, V_NET_SAL);
END LOOP;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
UPDATE DELL_SALARY
SET EMPNAME=V_EMPNAME,DAYSPRESENT=V_DAYSPRESENT,BASICSALARY=V_BASICSALARY,
MONTHSALARY=V_MON_SAL,PF=V_PF,TAX=V_TAX,NETSALARY=V_NET_SAL
WHERE EMPNO=V_EMPNO AND YEAR=V_YEAR AND MONTH=V_MONTH;
END SP_PREPARESALARY;
END PKG_PROJECT;
Created the DELL_EMPLOYEE, DELL_ATTENDANCE, DELL_SALARY tables. But I don't know why am kepp getting the unwanted error.
I do not have your functions,so I have commented or removed that part and created your package without any errors.
CREATE OR REPLACE PACKAGE BODY PKG_PROJECT
AS
PROCEDURE SP_PREPARESALARY (v_yr IN NUMBER, v_mn IN NUMBER)
AS
V_EMPNO VARCHAR2(30);
V_EMPNAME VARCHAR2(30);
V_BASICSALARY NUMBER;
V_DAYSPRESENT NUMBER;
V_YEAR NUMBER;
V_MONTH NUMBER;
V_PF NUMBER;
V_TAX NUMBER;
V_MON_SAL NUMBER;
V_NET_SAL NUMBER;
V_MAXDAYS NUMBER;
CURSOR EMP_VALUES
IS
SELECT E.EMPNO,
E.EMPNAME,
E.BASICSALARY,
E.YEAR,
E.MONTH,
E.DAYSPRESENT
FROM DELL_EMPLOYEE E, DELL_ATTENDANCE A
WHERE E.EMPNO = A.ENO AND E.YEAR = V_YR AND E.MONTH = V_MN;
BEGIN
OPEN EMP_VALUES;
LOOP
FETCH EMP_VALUES
INTO V_EMPNO,
V_EMPNAME,
V_BASICSALARY,
V_YEAR,
V_MONTH,
V_DAYSPRESENT;
EXIT WHEN EMP_VALUES%NOTFOUND;
V_YEAR := V_YR;
V_MONTH := V_MN;
V_MAXDAYS := 0;
-- V_MON_SAL :=
-- FN_GETGROSSMONTHLYSALARY (V_BASICSALARY,
-- V_DAYSPRESENT,
-- V_MAXDAYS);
V_PF := 0;
V_TAX := 0;
V_NET_SAL := 0;
-- INSERT INTO DELL_SALARY (EMPNO,
-- YEAR,
-- MONTH,
-- EMPNAME,
-- DAYSPRESENT,
-- BASICSALARY,
-- MONTHSALARY,
-- PF,
-- TAX,
-- NETSALARY)
-- VALUES (V_EMPNO,
-- V_YEAR,
-- V_MONTH,
-- V_EMPNAME,
-- V_DAYSPRESENT,
-- V_BASICSALARY,
-- V_MON_SAL,
-- V_PF,
-- V_TAX,
-- V_NET_SAL);
END LOOP;
EXCEPTION
WHEN DUP_VAL_ON_INDEX
THEN
null;
-- UPDATE DELL_SALARY
-- SET EMPNAME = V_EMPNAME,
-- DAYSPRESENT = V_DAYSPRESENT,
-- BASICSALARY = V_BASICSALARY,
-- MONTHSALARY = V_MON_SAL,
-- PF = V_PF,
-- TAX = V_TAX,
-- NETSALARY = V_NET_SAL
-- WHERE EMPNO = V_EMPNO AND YEAR = V_YEAR AND MONTH = V_MONTH;
END SP_PREPARESALARY;
END PKG_PROJECT;
Try commenting out part by part to identify where are the problems, that way you could easily find out the problem.