DBA Data[Home] [Help]

PACKAGE BODY: APPS.AD_CORE

Source


1 package body ad_core as
2 /* $Header: aducoreb.pls 115.3 2004/06/04 14:31:53 sallamse noship $ */
3 
4 
5 --
6 -- Private program units
7 --
8 
9 --
10 --
11 -- Debug utils START
12 --
13 G_DEBUG constant boolean := FALSE;  --%%set to FALSE in production code
14 
15 procedure put_line
16            (msg varchar2, len number default 80)
17 is
18   n number := 1;
19   nmax number;
20 begin
21   nmax := nvl(length(msg), 0);
22   if not G_DEBUG then
23     return;
24   end if;
25 
26   loop
27 --  dbms_output.put_line(substr(msg, n, len)); --%%comment out in prodn code
28     n := n + len;
29     exit when n > nmax;
30   end loop;
31 end put_line;
32 --
33 -- Debug utils END
34 --
35 --
36 
37 
38 --
39 -- Public program units
40 --
41 
42 
43 -- Given an elapsed time in days (such as that returned by subtracting 2
44 -- dates in SQL), return the formatted value in Hrs/Mins/Secs.
45 --   Supported format_modes: 1, 2
46 --     1 => Always display hrs, min, secs
47 --       eg: 0.00030093 days is displayed as 0 Hrs, 0 Mins, 26 Secs
48 --     2 => Only display applicable units
49 --       eg: 0.00030093 days is displayed as 26 Secs
50 
51 function get_formatted_elapsed_time
52 (
53   p_ela_days number,
54   p_format_mode number
55 ) return varchar2 is
56 
57   l_hrs    number := 0;
58   l_mins   number := 0;
59   l_secs   number := 0;
60 
61   l_days_i number := 0;   -- integral # of days
62   l_hrs_i  number := 0;   -- integral # of total hrs
63   l_mins_i number := 0;   -- integral # of mins within the hour
64   l_secs_i number := 0;   -- integral # of secs within the min
65 
66   l_fmt_val varchar2(80) := null;  -- formatted value
67 
68 begin
69   if p_ela_days  is  NULL then  -- This is to check the value of p_ela_days, in case of SerialmodeAutopatchoptions and NoExecuted Actions where the value of p_ela_days will be null
70  l_fmt_val := null;
71  else
72 
73   l_days_i := floor(p_ela_days);
74 
75   l_hrs  := p_ela_days * 24; -- Total hrs. eg: 1 day, 1 hr, 1 min, 1 sec equals
76                              -- 25.0169 hrs
77 
78   l_hrs_i  := floor(l_hrs);  -- Integral hrs: 25 hrs in the above eg.
79 
80   l_mins := (l_hrs - l_hrs_i) * 60;  -- Total mins within the hr: 1.014 mins in
81                                      -- the above eg.
82 
83   l_mins_i := floor(l_mins);  -- Integral mins: 1 min in the above eg.
84 
85   l_secs := (l_mins - l_mins_i) * 60;  -- Total secs within the min: 0.84 secs
86                                        -- in the eg.
87 
88   l_secs_i := round(l_secs);  -- Integral secs (rounded): 1 sec in the above eg
89 
90 
91   if p_format_mode = 1 then
92 
93     -- Here the interest is in showing all components, even if 0. So it
94     -- is assumed that we want the components aligned. Hence lpad the min
95     -- and sec components to 2 places with 0's. Hr component is intentionally
96     -- not lpadded, since we'd like that to stand out unaligned if >= 10 hrs
97     -- (atleast thats what we'd like for the current sole consumer, viz. OAM
98     -- patch history UI's)
99 
100     l_fmt_val := to_char(l_hrs_i)                || ' hr, '  ||
101                  lpad(to_char(l_mins_i), 2, '0') || ' min, ' ||
102                  lpad(to_char(l_secs_i), 2, '0') || ' sec';
103 
104   elsif p_format_mode = 2 then
105 
106     -- Here the interest is in showing only applicable components. So it
107     -- is assumed that alignment is not needed. So DONT lpad.
108 
109     if l_hrs_i > 0 then
110       l_fmt_val := to_char(l_hrs_i)  || ' hr, '  ||
111                    to_char(l_mins_i) || ' min ';
112                    --to_char(l_secs_i) || ' sec'; -- Decided not to show sec
113     elsif l_mins_i > 0 then
114       l_fmt_val := to_char(l_mins_i) || ' min, ' ||
115                    to_char(l_secs_i) || ' sec';
116     else
117       l_fmt_val := to_char(l_secs_i) || ' sec';
118 
119 
120     end if;
121 
122   else
123     raise_application_error(-20000, 'Invalid format_mode: '||
124                                     to_char(p_format_mode));
125  end if;
126 end if;
127   return l_fmt_val;
128 
129 end get_formatted_elapsed_time;
130 
131 
132 end ad_core;