If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

If I was a betting man, I'd say the culprit isSELECT COUNT(*)
INTO bcount
FROM vam_ledger
WHERE party = tparty
AND vchtype IN('BA', 'CA')
AND vchno = c2.vchno;

Since you are only interested in whether there are zero rows or not, do a simple
SELECT count(*) INTO bcount
FROM DUAL WHERE EXISTS (SELECT 1 FROM vam_ledger
WHERE party = tparty
AND vchtype IN('BA', 'CA')
AND vchno = c2.vchno);
[There are other ways of writing that, but this has the smallest impact]

select opbal,STAT into op_bal1,CRDR from acc_mast where ac_code=TPARTY
IF OP_BAL1>0 THEN
IF CRDR='CR' then
op_bal1:=0-op_bal1;
select name into pname from acc_mast where ac_code=tparty;
insert into ledger_temp
(sno,party,NAME,bill_dt,narration,cramt,BAL_AMT,STAT)
values (sn,TPARTY,pname,BILL_DATE1,'/ OPENING BALANCE -----> ',abs(OP_BAL1),abs(OP_BAL1),'CR');
elsif crdr='DR' then
select name into pname from acc_mast where ac_code=tparty;
insert into ledger_temp
(sno,party,NAME,bill_dt,narration,dramt,bal_amt,STAT)
values (sn,TPARTY,pname,bill_date1,'/ OPENING BALANCE -----> ',ABS(OP_BAL1),abs(OP_BAL1),'DR');
end if;
sn:=2;
end if;