Struggling with the Sybase pseudo code as it only accomplishes half of the intended task

I’ve created a pseudo code in my Sybase database to store bulk transactions in the table. However, it’s only saving half of them before stopping.
Upon rerunning it, I encounter truncating errors as half of the transactions are already stored. Despite implementing BEGIN ATOMIC to revert changes, the halting problem persists.

The code is as below:

ALTER PROCEDURE "DBA"."CW_UpdateNegCharges" (IN @ReferenceDate DATE) 
BEGIN 
    DECLARE @InvoiceConfigHeader Entity_No;
    DECLARE @LocalSiteNo Entity_No;
    DECLARE @AuditDescription VARCHAR(1000);
    DECLARE @JobList VARCHAR(900);
    DECLARE @CustList VARCHAR(900);
    DECLARE @GotDate DATETIME;
    DECLARE @ComputerName Windows_Computer_Name;

  SET @ComputerName = PROPERTY('MachineName');

  SET @GotDate = current utc timestamp;

  SELECT SM2_GetLocalSiteNo() INTO @LocalSiteNo;

  SET @AuditDescription = STRING('Started Job and Customer Negotiated Charge Update for Date ', @ReferenceDate, ' On ', @GotDate);

    INSERT INTO SM2_Audit_Log(Site_No, Application_Name, Originator, 
    Event_ID, Event_Class, Event_Severity, Event_Description, Operator_Code, Replication_Group_ID, Windows_Computer_Name)
    VALUES(@LocalSiteNo, 'Database', 'Negotiated Charge Effective Date',
    7302, 0, 10, @AuditDescription, CURRENT USER, RTRIM(CAST(@LocalSiteNo AS CHAR)), @ComputerName);

    

    --Gets list of Jobs updated
    WHILE EXISTS(SELECT 1 FROM SM2_Job_Product_Auth_Tran
    WHERE New_Charge_Start_Date <= @ReferenceDate
    AND New_Charge_Start_Date IS NOT NULL) LOOP

        UPDATE SM2_Job_Product_Auth_Tran 
        SET Neg_Unit_Cost_Override = Neg_Unit_Cost_Override_New, 
        Neg_Min_Charge_Override = Neg_Min_Charge_Override_New,
        Neg_Unit_Cost_Override_Cost = Neg_Unit_Cost_Override_Cost_New, 
        Neg_Min_Charge_Override_Cost = Neg_Min_Charge_Override_Cost_New
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        AND Job_No = (SELECT TOP 1 Job_No FROM SM2_Job_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Job_No);

        SELECT TOP 1 STRING(COALESCE(@JobList + ',', ''), Job_No) INTO @JobList
        FROM SM2_Job_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Job_No;
    
        UPDATE SM2_Job_Product_Auth_Tran
        SET Neg_Unit_Cost_Override_New = NULL,
        Neg_Min_Charge_Override_New = NULL,
        Neg_Unit_Cost_Override_Cost_New = NULL,
        Neg_Min_Charge_Override_Cost_New = NULL,
        New_Charge_Start_Date = NULL
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        AND Job_No = (SELECT TOP 1 Job_No FROM SM2_Job_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Job_No);
    END LOOP;

    --Gets list of Customers updated
    WHILE EXISTS(SELECT 1 FROM SM2_Customer_Product_Auth_Tran
    WHERE New_Charge_Start_Date <= @ReferenceDate
    AND New_Charge_Start_Date IS NOT NULL) LOOP

        UPDATE SM2_Customer_Product_Auth_Tran 
        SET Neg_Unit_Cost_Override = Neg_Unit_Cost_Override_New, 
        Neg_Min_Charge_Override = Neg_Min_Charge_Override_New
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        AND Customer_No = (SELECT TOP 1 Customer_No FROM SM2_Customer_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Customer_No);
    
        SELECT TOP 1 STRING(COALESCE(@CustList + ',', ''), Customer_No) INTO @CustList
        FROM SM2_Customer_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Customer_No;
    
        UPDATE SM2_Customer_Product_Auth_Tran
        SET Neg_Unit_Cost_Override_New = NULL,
        Neg_Min_Charge_Override_New = NULL,
        New_Charge_Start_Date = NULL
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        AND Customer_No = (SELECT TOP 1 Customer_No FROM SM2_Customer_Product_Auth_Tran
        WHERE New_Charge_Start_Date <= @ReferenceDate
        AND New_Charge_Start_Date IS NOT NULL
        ORDER BY Customer_No);

    END LOOP;

    SET @AuditDescription = STRING('Negotiated Charge Update for ',@ReferenceDate, ' complete.');
    
    IF @JobList IS NULL THEN
        SET @AuditDescription = STRING(@AuditDescription,' No Jobs updated.');
    ELSE
        SET @AuditDescription = STRING(@AuditDescription,' Jobs Updated: ', @JobList);
    END IF;

    IF @CustList IS NULL THEN
        SET @AuditDescription = STRING(@AuditDescription,' No Customers updated.');
    ELSE
        SET @AuditDescription = STRING(@AuditDescription,' Customers Updated: ', @CustList);
    END IF;

    INSERT INTO SM2_Audit_Log(Site_No, Application_Name, Originator, 
    Event_ID, Event_Class, Event_Severity, Event_Description, Operator_Code, Replication_Group_ID, Windows_Computer_Name)
    VALUES(@LocalSiteNo, 'Database', 'Negotiated Charge Effective Date',
    7302, 0, 10, @AuditDescription, CURRENT USER, RTRIM(CAST(@LocalSiteNo AS CHAR)), @ComputerName);

END

How can I adjust it to execute all transactions or resume from the last saved one upon restarting?

New contributor

syed Ali is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật