Create a Dynamic List Item in Oracle Form

Procedure :-

“ADD_LIST_ELEMENT” Using the following procedure 

Syntax

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

 Syntax Specifications

  • list_id: Specifies the unique ID that Oracle Forms assigns when it creates the list item.
  • 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’);

  • list_index:  Specifies the list index value.  The list index is 1 based.
  • list_label  Specifies: the VARCHAR2 string that you want displayed as the label of the list element.   
  • list_value:  The actual list element value you intend to add to the list item. 
  • 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 current index of the list item.

 

How do we solve:

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 (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;

Recent Posts