Friday, June 19, 2015

Dynamic List Item

Create a Dynamic List Item




In the name of Allah, Most Gracious, Most Merciful
Praise be to Allah, blessing and peace be upon our prophet Mohammed, his family and his companions. After that,


Task Definition: Create a Dynamic List Item


Let's have a quite simple application, e.g. "Club Membership" application involved  two simple tables 'YEARS' and 'MEMBERS' with two abstract column contents; id and name column for each table individually. Now, we want to populate two list items dynamically for each individually.



Task Execution Idea:  You can follow the following logical steps to accomplish the task safely and properly...


Procedure


   ''ADD_LIST_ELEMENT''Using the following procedure 

        Syntax

       ADD_LIST_ELEMENT(list_id ITEM, list_index VARCHAR2, list_label VARCHAR2, list_value VARCHAR2);

o   Syntax Specifications

o   list_id: Specifies the unique ID that Oracle Forms assigns when it creates the list item.
o   Use the FIND_ITEM built-in to return the ID to an appropriately typed          variable.  The data type of the ID is ITEM.
          Example:  v_ stage  ITEM  := FIND_ITEM ('STAGE.st_id');
o   list_index:  Specifies the list index value.  The list index is 1 based.
o   list_label  Specifies: the VARCHAR2 string that you want displayed as the label of the list element.
o   list_value:  The actual list element value you intend to add to the list item.
o   Get_List_Element_Value: access the current index number for each loop independently. 

·        This procedure adds only a single element to a list item. 
·        This is not practical for multi-list values…

So it's more logical to think about looping through the whole database records stored in your 'List Item' table.
          Consequently, it's more appropriate use For…. Loop structure.
   
·      It's a dynamic procedure; it executes run-time. You have to free the memory from any old value to get actual and correct values result

·      built-ins used as needed:

o   CLEAR_LIST Built-in: Clears all elements from a list item. After Oracle Forms clears the list, the list will contain only one element the 'Null' value, regardless of the item's required property.
o   GET_LIST_ELEMENT_COUNT Built-in: Returns the the current index of the list item.

. 
Task Solution: 


Let's follow the above mentioned solution idea concerning…


 
ADD_LIST_ELEMENT(list_id ITEM, list_index VARCHAR2, list_label VARCHAR2, list_value VARCHAR2);


Pls. Follow the logic of the following steps to do the task safely and properly...



DECLARE

     v_count    NUMBER := 1 ;

     CURSOR  year_cur  IS SELECT year_id , year_name
                                          FROM  YEARS ORDER BY  year_id;

     v_ year  ITEM  := FIND_ITEM ('YEARS. year_id');


    CURSOR  member_cur IS SELECT member_name , member_id
                                           FROM  MEMBERS ORDER BY member_id ;

    v_ member ITEM  := FIND_ITEM ('STAGE. member_id');

BEGIN 
                   
     CLEAR_LIST (v_ year);

     FOR  m in year_cur LOOP

/** Get_List_Element_Value access the current index number for each loop independently.
This helps Determine the total number of list elements. **/

     ADD_LIST_ELEMENT t(v_ year  , GET_LIST_ELEMENT_COUNT(v_ year)+1,  m. year_name , TO_CHAR(m. year_id));

END LOOP;


/* The traditional technique */


  CLEAR_LIST (v_ member);
   
 FOR  z in member_cur LOOP

     ADD_LIST_ELEMENT (v_member, v_ member +1 , z. member_name , TO_CHAR (z. member_id ));

 END LOOP;

END;


Note:

o   You may face a Compilation error i.e.
  FRM-30351: No list elements defined for list item
  and a run time error i.e. unable to resolve reference to the item...
o   Although you fill your list item dynamically at runtime, but the 'Null' value always displays in the List Item.
      
           Key Reason: By default, the property of the list item 'Required' is set to 'YES'.
  
       Key Solution:

               *       Reset List item property: 'Required' value to 'NO'.
               *       You must provide 'dummy' values: let's say 0.


For more advanced techniques pls. read dependent drop down list

Hope this helps…

My success only comes from Allah, pls. note your comments and suggestions are great help for me in progress thanks in advance.


Wednesday, June 17, 2015


 Oracle Form Global Variable Recognition


In the name of Allah, Most Gracious, Most Merciful
Praise be to Allah, blessing and peace be upon our prophet Mohammed, his family and his companions. After that,


Global Variable
·        Global variables has a global scope; it is visible (accessible) throughout your application program.
·        Global variables are used extensively to pass information between forms.
·        Global variables can be initialized or declared in two different ways:

  •      DEFAULT_VALUE built-in.                                                  DEFAULT_VALUE ('Al-Emran', 'global.company_name');

  •        PL/SQL assignment statement                                                  Global.company_name := 'Al-Emran'; 
 

Global Variable Types
Oracle Forms Developer and PL/SQL support different types
  • Oracle Forms Global: a variable in the "global" pseudo-block of a form
  • PL/SQL Package Global: a global defined in the specification of a package
  • Oracle Forms Parameter: a variable created within the Oracle Forms Designer as a Parameter

Pls. see the Oracle Forms Reference Manual for a complete description of these variable types.
 The following table lists the characteristics of each type of variable, and enables you to select the type most appropriate for your code.
Behavior
Oracle Forms Global
PL/SQL Package Global
Oracle Forms Parameter
Can be created at Design time

Y
Y
Can be created at runtime
Y


Accessible across all forms
Y


Accessible from attached libraries
Y
(1)
Y
Support specific data types
(2)
Y
Y
Have declarative defaults


Y
Can be referenced indirectly
Y

Y
Can be specified on command line


Y
Must be erased to recover memory
Y


Can be used in any Oracle Forms code
Y

Y



Global Variable Limitations  

·        Global variables do not generate any compilation errors during development stage but only run-time errors.

·        Global variables are always characters. If you are not familiar with this fact, your expected output will not work; no effect.

       Now Current situation

§    On development stage, at design-time, you will not face any compilation error.
§   On test stage, at run-time you will not face any run-time error.
        You will have  just silent failure with no explanation and sucked helpless. It's                 better to know this case before wasting effort and time.

·     A significant drawback of Global variables; it consumes high memory resources:
§  Memory is an important resource for your application so it’s wise to consider choosing other alternatives for Global variables.
§   Form Parameters are recommended alternative instead of using Global variables.

·     Global variables usage is recommended Not to use them if un-necessary.

·     Global variables persist in memory until you remove it externally with the ERASE () built-in procedure.

·     Global variables must be declared, if Not initialize before execution, it will generate run-time error.

FRM-40815 GLOBAL. does not exist.

              Warning Avoid above error by assigning the appropriate value to                                             the global variable before opening the new form.

·        In fact, they are usually considered bad practice precisely because of their non-locality.


·     Each Global variable Must has the same name to each form session.



          Warning: Oracle recommends explicit conversions, rather than rely on                                         implicit or automatic conversions for these reasons:

·        You will need   using a NUMBER using the TO_NUMBER() function or using TO_DATE() functions. 

   

  For more related detailed Global variables usage pls read 



Hope this helps…


My success only comes from Allah, pls. note your comments and suggestions are great help for me in progress thanks in advance.



Monday, June 15, 2015

'Globals' Vs 'GET_APPLICATION_PROPERTY'


'Globals'  Vs  'GET_APPLICATION_PROPERTY' 


      In the name of Allah, Most Gracious, Most Merciful
Praise be to Allah, blessing and peace be upon our prophet Mohammed, his family and his companions. After that,


     In spite of  'Global variable's downsides,  in some cases, it is still a good    alternative  solution  

       'Global variables'  are initialized once to hold e.g. user's name value and it persists or lasts  with you till the form's  end of  session

   No  'Global variable' downloads can exist that may affect your  application in terms of  system efficiency and resources. 


      On the other hand, you should also recognize alternatives e.g. getting user names, has another alternative you can use as follow: 

GET_APPLICATION_PROPERTY (USERNAME) built-in 

   You can assign the return value of Get_Application_Property(USERNAME) built- function to a variable or a form item to get the current user name.


       Two methods with one output:


          If  you know there are two ways to get your out put then you should learn why you have to choose then decide what to choose. This depends upon specific system criteria as follow:

       why to choose vs. what to choose...?


o   If your application is Not Large so it is more efficient to use  GET_APPLICATION_PROPERTY (USERNAME) built-in, it does not make sense to think about  'Global variable' to hold the current data base user name whereas it is already stored and can be easily retrieved from the database.

o   If your application is Large and/or you do expect to build different integrated systems supported by a security application system then  'Global variables'  is the best choice. This logically leads us to understand how  'Global variables'  lives and dies.
     The main LOGIN  form in all applications almost have buttons that holds both one single value of each Global variables and one single call to other sub-main forms for each module system.

          Intialization:

     The question is...  where to initialize it...?  
         In your main application login-form.
         Globals are usually intialized in One main form that holds valuable and popular data that are commonly used,  e.g. user names,  financial year and the company's branch or the location_id.  
   
          The question is...  when to initialize it...?  
       It is recommended to use either PRE-FORM or WHEN-NEW-FORM-INSTANCE form level triggers.

         The question is...  how to initialize it...?    
       U can use any technique to initialize 'Global variables' .


            The login form is the main form application where user inputs data into it's text items. The text items's data values are assigned internally to  'Global variables'  to be passed to any sub-main form application system the user choose upon his request with one button click or what so ever...
     
       Passing Globals from main login form to other applications

         Each sub-main form can receive the Globals from the main application  login form either by assigning the Globals to the local parameters form or by directly reference to Globals by Global's names. 
     
       Erase Globals

             it is strongly recommended to  destroy 'Global variables'  at the moment you don't need anymore.


  The question is...  where to erase it...?  
     In your main application login-form.
   
      The question is...  when to erase it...?  
    U can use key-exit or when-window closed form-level triggers.
  
      The question is...  how to erase it...?    
    U can use  Erase built-in.


     

Hope it helps…

My success only comes from Allah, pls. note your comments and suggestions are great help for me in progress thanks in advance.