Showing posts with label Forms Data Exchange. Show all posts
Showing posts with label Forms Data Exchange. Show all posts

Wednesday, June 10, 2015

Data Exchange "Parameter List"


Three Steps to Forms Data Exchange
"Parameter List"



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

One of the common tasks that most of Oracle developers are frequently used is passing data between form modules. It enhances more related  and integrated form modules. It also minimize user data input process.



Task Execution Idea: There are two different ways you can use regarding data forms exchanges:
  1.     Global variables.
2.     Parameter List.


Task Solution: The "Parameter List" solution technique is the target what we are concerned to recognize its practice solution.

  How it works?

Let's briefly summarize the life cycle of passing data between two forms into three logical steps to recognize the whole process it looks like a ping pong match between two players or two forms but with ONE way.

  ONE WAY  FORM'S PASSING DATA APPROACH


     The Form's text item data retrieved from database at (form'A')'s run-time  is desired  to pass it's current value to (form 'B')'s text item where a  form's parameter (pre-created at design time) helps in this process by receiving the value sent from form'A' and assigning it to it's appropriate text item( form 'B').



Now Let's  demonstrate a sample code for this approach




  Start Working in form 'A':

§  Create a new form module called form 'A'.
§  Create a data block based on "DEPARTMENTS" Table
§  Create a button, rename it call form 'B'.
§   Create When-Button-Pressed trigger.
§  Paste the following code in When-Button-Pressed trigger.

DECLARE

     Pl_Id PARAMLIST;

BEGIN


/* Let's Start the joy to simplify the Task Solution job*/

/* First you have to get your parameter list.
 It looks like getting (or buying) a container for filling it up with     expected future parameters retrieved from the database shop  */
  
     Pl_Id := GET_PARAMETER_LIST('tempdata');

/* Pls. Check if the container is full then you have empty it for future need of new data parameters */
  
     IF NOT ID_NULL(Pl_Id) THEN

          DESTROY_PARAMETER_LIST(Pl_Id);

     END IF;

 /* Now it's time to create data parameters according to your choice after creating a new & empty parameter list in your memory shop */

  
 Pl_Id := CREATE_PARAMETER_LIST('tempdata');


/*In this stage You can add one or more parameters as you need*/

ADD_PARAMETER
(Pl_Id, 'P_DEPT_NO', TEXT_PARAMETER, TO_CHAR(:DEPT.DEPT_NO));

ADD_PARAMETER(Pl_Id, 'parameter_name', TEXT_PARAMETER,:DEPT.DEPT_NAME);

--- Add parameters as much as needed ---

/* Now it's time to call the second form and pass the parameter list container with one or more data parameters as you previously determined in last step */


      Open_form('form_name', ACTIVATE, SESSION, Pl_Id);     


END;




    Now Let's Start Working in form 'B':


 §  Create a new form "form"  'B' based on any data block you specify.

   All you have to do is to  create WHEN-NEW-FORM-INSTANCE or PRE-FORM trigger, Form-Level and  Paste the following sample code.

   Never forget to Create the Parameter's form from Parameter's form's node in the Object Navigator and follow the guide lines listed below.

  
     IF :PARAMETER.P_DEPT_NO  IS NOT NULL THEN

      GO_BLOCK('DEPATMENTS');     
        
  :DEPATMENTS.DEPT_NO :=:PARAMETER.P_DEPT_NO;
  :DEPATMENTS.DEPT_NAME :=:PARAMETER.P_DEPT_NAME;

     END IF;

-- OPTIONAL WHERE CLAUSE to filter data

SET_BLOCK_PROPERTY('DEPATMENTS', DEFAULT_WHERE,
          ' DEPATMENTS.DEPT_NO = ''' || :PARAMETER.DEPT_NO || '''' || 'AND '  || ' DEPATMENTS.DEPT_NAME = ''' || :PARAMETER.P_DEPT_NAME || ''''  );

  




§  Guide Lines to Oracle form parameter Data types:


   §  Form Parameters data type in both forms 'Must be the same' 
   (Text items created in data block in form 'B' Must be the same name and data type of text parameters' names created in form  'A' 's at memory run-time).

 §   TO_CHAR ()  function 'Must be  used'  in ADD_PARAMETER statement     if and only if required to CAST the Numbers and Date Data Types.

   §  Maximum Length of the parameter property 'Must be the same'; You have       to specify the Maximum Length of each form parameter and each item  in     a data block form item according to your needs.
     
§  Naming convention rules is recommended to use for parameters as:
"P_DEPT_NAME"  or "P_HIRE_DATE".


 Any expressive parameter name explains its contents.


Functional Steps To Test 

  1.           Compile, generate and Save form 'A' and form 'B'.
  2.           Run form 'A'.
  3.           Retrieve the department name value as in the example.
  4.          Press "call form 'B' " button.
  5.          Form 'B' will be opened with the department name value passed from Form 'A'.

Hence, the Form parameter technique is the best solution you can ever rely on concerning passing data between forms. It is strongly recommended choice rather than the Global Variables Solution.


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 8, 2015

Oracle Forms Data Exchange
"Global Variable"


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

   One of the essential tasks that an Oracle developer is commonly used is passing data  between two forms

 There are Four different ways for forms data exchanges

1.     Global variables.
2.      Parameter Lists.
3.     Global Record Groups.
4.     PL/SQL variables in shared libraries.

 All above methods can pass data between two forms by one way data pass from form A to form B But, in such cases, you may need to pass data two ways data exchanges; meaning you can pass a value from form A to Form B and the vice versa form B to 
form A.

Only Global variables can accomplish this task if they are correctly recognize how to use them correctly. 


ask Definition:T

Passing data exchange between two forms. 

Assuming we have a Student Reservation System, the system user is currently opening a reservation form. Let's assume the following scenario:

1.     A new student is coming to reserve a specific course. 
2.     The user will need to register the new student's personal data in the students form. 
3.     Then, the system user will need to call the reservation form with the new registered student's id and name, with no need to rewrite them once again, in the reservation form to complete other related student reservation data.

Task Solution Idea: 

  Global variables is the task solution for such a requirement. 

Global Variable Limitations :

·        Can contain a maximum of 255 characters datatype.
·        Each Global variable Must has the same name to each form session.
·        Global variables can be created by a PL/SQL assignment, or by the DEFAULT_VALUE built-in.

The following Solution Algorithm has two stages for passing data between two forms a reservation form and Students form to show you how it works... 

 Stage 1: The following steps are one way data pass.(reservation to students)

1.     Call the students form From Reservation form. 
2.     In the students form, initialize two Global variables with the  student_id  and student_name. 
3.     In the students form, assign the student_id to and student_name to two Global variables.
4.     In the reservation form, Assign the two Global variables storing the student_id and student_name value to the two form items student_id and student_name
5.     Then, Erase the two Global variables to avoid repeating displaying old data.

 But perhaps you want to edit or update the address or telephone number of the current reserved student for emergency cases. In this case you have to reverse the rudder
How...? Repeat the same previous steps as follow:

 Stage 2: The following steps are one way data pass.(reservation to students)

1.     In the reservation form, initialize two Global variables with the  student_id  and student_name. 
2.     In the reservation form, assign the student_id and student_name to the two Global variables.
3.     Call the students form for editing. 
4.     In the students form, Assign the two Global variables storing the student_id and student_name value to the two form items student_id and student_name
5.     Then, Erase the two Global variables to avoid repeating displaying old data.

First, we have to recognize how Global variable works according to a specific characteristics and limitations as  follow:


Task Solution: 

     Stage 1one way data pass (reservation to students)       
  1. Call the students form From Reservation form. Using "The Parameter List" 
  2. In the students form, initialize two Global variables with the student_id  and student_name. I would suggest:
    •       Form-Level: when-new-form-instance trigger or Pre-Form  trigger.
    •       Block-Level:  when-new-block-instance trigger    
               
  :GLOBAL.student_id := TO_CHAR(:students.student_id ); 

   :GLOBAL.student_name := :students.student_name 


  ·        You can either initialize a Global variable to Null value

DEFAULT_VALUE(NULL, 'GLOBAL.variable_name'); 
    
  ·        Or You can initialize a Global variable to a blank value.

 DEFAULT_VALUE(' ', 'GLOBAL.variable_name'); 

Note: Null or blank value is almost One, the same as null. It's just two different syntax to initiate a null value.
  
 ·        You can  also initialize a Global variable to a character value.

DEFAULT_VALUE('Egypt', 'GLOBAL.variable_name'); 

·        You can initialize it externally to a Number using a character format mask.


 ;(GLOBAL.variable_name := TO_CHAR(33:

·        You can initialize it to a Number but with  a single quote.

;'GLOBAL.variable_name := '33:

 ·        You can also rely on form implicit conversion.
     
   :GLOBAL.variable_name := 33 ;

         
       3. In the students form, assign the student_id to and student_name to two Global variablesChoosing the trigger depends upon your business logic or your requirements. I would suggest using:
      
    •        Form-Level:  when-new-form-instance trigger or Pre-Form  trigger.
    •       Block-Level:  when-new-block-instance trigger        

 BEGIN
   :GLOBAL.student_id       := TO_CHAR(:students.student_id ); 
     :GLOBAL.student_name := :students.student_name 
 END; 

      Note: Global variables accepts ONLY character data types.
       
       4. In the reservation form, Assign the two Global variables storing the student_id and student_name value to the two reservation form items student_id and student_name


 BEGIN
   TO_CHAR(:reservation.student_id ):=   :GLOBAL.student_id 
    :reservation.student_name  := :GLOBAL.student_name 
 END; 
         

  Note: Since Global variables are always char datatype then, you will need to cast it's stored values back to its initial data type e.g. student_id of NUMBER data type should be converted to number datatype using  TO_NUMBER() built-in function. 
 Oracle recommends explicit conversions, rather than rely on implicit or automatic conversions for these reasons:
  

         5. Then, Erase the two Global variables to avoid repeating displaying old data.


     ERASE ('GLOBAL.student_id ');
     ERASE ('GLOBAL.student_name ');

    •     Once the Global variable value is assigned to a form parameter or a form item it MUST BE DESTROYED. 

Stage 2two ways data exchanges (students to reservation )    

  1. In the reservation form, initialize two Global variables with the  student_id  and student_name. 
  :GLOBAL.student_id := TO_CHAR(:reservation.student_id ); 

   :GLOBAL.student_name := :reservation.student_name ; -- display item

     2.  In the reservation form, assign the student_id and student_name to the two Global variables. Same as previous step.

    3. Call the students form for editing "The Parameter List" . 

    4. In the students form, Assign the two Global variables storing student_id and student_name value to the two form items student_id and student_name

 BEGIN
   TO_CHAR(:students.student_id :=   :GLOBAL.student_id 
    :students.student_name           := :GLOBAL.student_name 
        Go_block('students');
       Execute_query;
 END; 
       
Now you can make the changes you want to the student's address or mobile number.
         5. Then, Erase the two Global variables to avoid repeating displaying old data.

          ERASE ('GLOBAL.student_id ');
          ERASE ('GLOBAL.student_name ');

          Honestly, "Global Variable"  is essential in this task, it looks easy and require few lines of code but generally, it has few drawbacks that makes you think twice before taking the decision to use. Still  the charms of "The Parameter List"   is the best reliable technique to choose when passing data between forms.  


    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.