Pages

Wednesday, December 4, 2013

How to validate previous record's properties when user tries to enter new record in to the same data block without entering and saving the previous record and it's properties(data for child blocks)

Hi fellas,

This is just for new guys to oracle.

                                           I got an oracle form which has 6 data blocks based on 6 separate tables and form has 3 tabs. From first data block to last block, there is a connection between the particular block and it's previous block. Its like second block has a relation with first block, third block has a relation with second block, fourth block has a relation with third block and like wise. Since all these blocks based on database tables when tab pages changes changes will be inserted into the relevant tables.
                                           
                                           The form i had has data enter process like below.

First block has the master record. This is only one record per one round.
Second block is tabular one and can have multiple records per round. Record can be a item which should have serial numbers or may be a item which shouldn't have serial numbers. Third block based on this concept.
If the second block has serialized item then the third block should have relevant serial numbers accordingly.
Since the data blocks based on tables when tab pages changed relevant input data will get inserted in to tables.
The problem i had was when user create the first record on the second block, user used serialized item and  without entering relevant serial numbers in to third block, he tries to add a second record in to the second block. I have restrict the user in this scenario and navigate him / her to enter serial numbers when tries to enter the  second record in the second block without entering serial numbers for the first record.
                                     all the input data will get inserted in to the tables when tab pages changed but wont get committed until press the save button in the end of the process. Therefore i couldn't check for the serial numbers from the database table. What i did for this situation was i maintain a variable to hold the value of :system.cursor_value. When ever user tries to create a new record in the second block ( :system.cursor_value null because user tries to create a new record. ) i navigate to the previous record, checked whether the previous record is a serialized item and if so i checked the third block's values. If the third block doesn't have any data then i just redirect the user to the third block and forced him / her to enter the serial numbers. If the previous record has the relevant serial numbers in the third block or the previous record is a non serialized item then navigate to the second block and create a new record by using create_record built in.
I just put my code here and you can get the idea by going through that. Leave the additional conditions here  which are unique to my form and it's functionality. Just concentrate on the codings in red color...


DECLARE

    
    ml_new_cursor_rec NUMBER;   
    ml_value VARCHAR2(50);
    
BEGIN
    
    ml_new_cursor_rec := :system.cursor_record;
    ml_value := :system.cursor_value;
    
    IF ml_value IS NULL THEN 
        previous_record;
    
        IF FU_SERIAL_NO_ITEM THEN
        
            IF :stl_adjust_qty != 0 AND :stl_adjust_qty IS NOT NULL AND :SVS_SERIAL_NO IS NULL THEN
                err_msg(3620,2);
            
                set_tab_page_property('ADJUSTED_DETAILS',enabled,property_true);
                set_tab_page_property('APPROVEL_INFORMATION',enabled,property_true);
            
                IF NVL(:ic_stk_take_lines.stl_adjust_qty,0) > 0 THEN 
                    :IC_STK_VARIANCE_LINES.SVL_VARIANCE_TYPE := 'R';
                ELSIF NVL(:ic_stk_take_lines.stl_adjust_qty,0) < 0 THEN
                    :IC_STK_VARIANCE_LINES.SVL_VARIANCE_TYPE := 'I';
                END IF;
            
                :ic_stk_variances.stv_date            := sysdate; 
                :ic_stk_variance_lines.svl_item_code  := :ic_stk_take_lines.stl_item_code;
                :ic_stk_variance_lines.fc_item_desc   := :ic_stk_take_lines.fc_item_desc;
                :ic_stk_variance_lines.svl_adjust_qty := NVL(:ic_stk_take_lines.stl_adjust_qty,0);
                :ic_stk_variance_lines.svl_rack_no    := :ic_stk_take_lines.stl_rack_no;
                :ic_stk_variance_lines.svl_bin_no     := :ic_stk_take_lines.stl_bin_no;
                        
                :FC_SUPPESS_VALIDATE_FLAG := 'Y';
                SELECT SYSDATE INTO :IC_STK_VARIANCES.STV_DATE FROM DUAL; 
                go_item('ic_stk_variance_serials.svs_serial_no');
                first_record;
        
                IF :ic_stk_variance_serials.svs_serial_no IS NULL THEN
     
                    LOOP
        
                        EXIT WHEN :ic_stk_variance_serials.svs_serial_no IS NULL;
            
                        DELETE FROM ic_stk_variance_serials
                        WHERE svs_voucher_no = :ic_stk_variances.stv_voucher_no
                        AND svs_item_code  = :ic_stk_take_lines.stl_item_code
                        AND svs_serial_no  = :ic_stk_variance_serials.svs_serial_no;
                 
                        EXIT WHEN :system.last_record = 'TRUE'; 
                 
                        next_record;
                 
                    END LOOP;
            
                ELSE  
                    go_block('IC_STK_TAKE_LINES');  
                    create_record;  
        
                END IF;  
        
            ELSE
                go_block('IC_STK_TAKE_LINES');  
                create_record;  
        
            END IF;
        
        ELSE
            go_block('IC_STK_TAKE_LINES');  
            create_record;
        
        END IF;
        
    END IF;
    
END;

Happy coding.....:)