Purpose
Create progress bar in oracle forms
Step1:
Create New Form using scott user.
Step2:
Create 2 blocks
1.
Non-Database Block. Named as progress bar
2.
Non-Database Block. But same as EMP Table
Step3:
Create Package Specification with below mention Code:
PACKAGE progress_bar IS
----------------------------------------------- Public Variable
bar_id ITEM; -- id of the bar
view_id VIEWPORT ; -- id of the canvas
full_width NUMBER; -- full width
before modifying
return_item VARCHAR2(32); -- return
item
Initialized BOOLEAN;
---------------------------------------------
Public Procedures
PROCEDURE Initialize_progress_bar ;
PROCEDURE Show_progress_bar (percent
IN NUMBER := 0);
PROCEDURE Hide_progress_bar ;
END progress_bar;
Create Package Body with below mention Code:
----------Package
body-----------------------
PACKAGE BODY progress_bar IS
PROCEDURE Show_bar (percent IN NUMBER := 0) IS
bar_width NUMBER; IT_ID1 ITEM;
BEGIN
bar_width := ROUND((progress_bar.full_width)/ 100 * percent,2);
SET_ITEM_PROPERTY(progress_bar.bar_id,WIDTH, bar_width);
COPY(RTRIM(TO_CHAR(ROUND(percent,0)) || '%'),'progress_bar.percent');
SYNCHRONIZE;
/*IF percent >= 100 THEN -- job completed
progress_bar.Hide_progress_bar;
END IF;*/
END Show_bar;
PROCEDURE Initialize_progress_bar IS
it_id varchar2(200);IT_ID1 ITEM;
BEGIN
/*IF progress_bar.Initialized THEN
MESSAGE('A progress bar is already
initialized');
RAISE FORM_TRIGGER_FAILURE;
ELS*/IF progress_bar.full_width IS
NULL THEN
progress_bar.bar_id
:=FIND_ITEM('progress_bar.bar');
progress_bar.full_width :=
TO_NUMBER(GET_ITEM_PROPERTY(progress_bar.bar_id, WIDTH));
IT_ID1 :=
Find_Item('progress_bar.bar');
SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_TRUE);
IT_ID1 :=
Find_Item('progress_bar.PERCENT');
SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_TRUE);
END IF;
IF progress_bar.Return_item IS NULL THEN
it_id := :SYSTEM.TRIGGER_ITEM;
progress_bar.Return_item
:=NAME_IN('SYSTEM.TRIGGER_ITEM');
END IF;
progress_bar.Initialized := TRUE;
Show_bar(0);
END;
PROCEDURE Show_progress_bar (percent IN NUMBER := 0) IS
BEGIN
IF NOT progress_bar.Initialized
THEN
MESSAGE('No progress bar has
been initialized');
RAISE FORM_TRIGGER_FAILURE;
END IF;
Show_bar(percent);
END ;
PROCEDURE Hide_progress_bar IS
IT_ID1 ITEM;
BEGIN
IT_ID1 :=
Find_Item('progress_bar.bar');
SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_FALSE);
IT_ID1 := Find_Item('progress_bar.PERCENT');
SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_FALSE); --
SET_ITEM_PROPERTY(progress_bar.bar_id,WIDTH, 0);
progress_bar.full_width := NULL;
GO_ITEM(progress_bar.return_item);-- GO_ITEM(:SYSTEM.TRIGGER_ITEM);
progress_bar.Return_item := NULL;
progress_bar.Initialized :=
FALSE;--SET_WINDOW_PROPERTY('PROCESSING_bar',VISIBLE,PROPERTY_FALSE);
END Hide_progress_bar;
END;
----------End of Package
body-----------------------
Step4:
Create When-Button-Pressed Trigger on Button
“PB_POPULATE_Data” in Progress_Bar Block:
DECLARE
CURSOR C1 IS select * from emp e;
P_PERCENT NUMBER(3):=0;
C_DONE NUMBER:=1;
BEGIN
select count(*) INTO :GLOBAL.C_TOT from emp e;
PROGRESS_BAR.INITIALIZE_PROGRESS_BAR;
Go_Block('EMP');
First_Record;
FOR
CL_REC IN C1 LOOP
--
:global.c_totis the total number of records to be processed.
--c_done
total number of records processed.
:EMPNO := CL_REC.EMPNO;
:ENAME := CL_REC.ENAME;
:JOB := CL_REC.JOB;
:MGR := CL_REC.MGR;
:HIREDATE
:= CL_REC.HIREDATE;
:SAL := CL_REC.SAL;
:COMM := CL_REC.COMM;
:DEPTNO := CL_REC.DEPTNO;
Next_Record;
C_DONE:=C_DONE+1;
P_PERCENT
:= TRUNC(C_DONE*100/:GLOBAL.C_TOT);
IF
P_PERCENT >= 100 THEN
P_PERCENT
:= 100;
END
IF;
--commit;
PROGRESS_BAR.SHOW_PROGRESS_BAR(P_PERCENT);
END
LOOP;
First_Record;
message('Process has been completed successfully');
END;
Step5:
Compile all and run the form.