Wednesday 29 January 2014

Oracle D2K form ( Block Detail )

Block is logical owner of items. It provides a mechanism for grouping related items into a functional unit for storing, displaying and manipulating records.

Types of Blocks

1. Data Blocks

Data blocks are associated with data (table columns) within a database.
By default, the association between a data block and the database allows operators to automatically query, update, insert, and delete rows within a database.

Data blocks can be based on database tables, views, procedures, or transactional
triggers.

2. Control Blocks

A control block is not associated with the database, and the items in a control block do not relate to table columns within a database.

All blocks are either single-record or multi-record blocks:

A single-record block displays one record at a time.
A multi-record block displays more than one record at a time.

In addition, a data block can also be a master or detail block:

Master block displays a master record associated with detail records displayed in a detail block.

A detail block displays detail records associated with a master record displayed in master block.

Block Built - ins
1. BLOCK_MENU built-in
Displays a list of values (LOV) containing the sequence number and names of valid blocks in your form. Form Builder sets the input focus to the first enterable item in the block you select from the LOV.

Example:
/*
** Built–in: BLOCK_MENU ** Example: Calls up the list of blocks in the form when the
** user clicks a button, and prints a message if ** the user chooses a new block out of the list
to ** which to navigate. */

DECLARE
prev_blk VARCHAR2(40) := :System.Cursor_Block;
BEGIN
BLOCK_MENU;
IF :System.Cursor_Block <> prev_blk THEN
Message(’You successfully navigated to a new block!’);
END IF;
END;

2. CLEAR_BLOCK built-in


Causes Form Builder to remove all records from, or "flush," the current block.

Clear_Block(No_Validate);


COMMIT_MODE
The optional action parameter takes the following possible constants as arguments:

ASK_COMMIT
Form Builder prompts the end user to commit the changes during CLEAR_BLOCK
processing.

DO_COMMIT
Form Builder validates the changes, performs a commit, and flushes the current block without prompting the end user.

NO_COMMIT
Form Builder validates the changes and flushes the current block without performing a commit or prompting the end user.

NO_VALIDATE
Form Builder flushes the current block without validating the changes, committing the changes, or prompting the end user.

3. FIND_BLOCK

Searches the list of valid blocks and returns a unique block ID. You must define an appropriately typed variable to accept the return value. Define the variable with a type of Block.

4. GET_BLOCK_PROPERTY

Returns information about a specified block. You must issue a call to the built-in once for each property value you want to retrieve.

Syntax:
GET_BLOCK_PROPERTY( block_id, property);
GET_BLOCK_PROPERTY( block_name, property);


** Determine the (1) Current Record the cursor is in,
** (2) Current Record which is visible at the
** first (top) line of the multirecord
** block.
*/
cur_rec := Get_Block_Property( bk_id, CURRENT_RECORD);
top_rec := Get_Block_Property( bk_id, TOP_RECORD);

5. GO_BLOCK

GO_BLOCK navigates to an indicated block. If the target block is non-enterable , an
error occurs.

6. ID_NULL

Returns a BOOLEAN value that indicates whether the object ID is available.

7. NEXT_BLOCK

Navigates to the first navigable item in the next enterable block in the navigation
sequence

8.PREVIOUS_BLOCK

Navigates to the first navigable item in the previous enterable block in the navigation
sequence

9.SET_BLOCK_PROPERTY

Sets the given block characteristic of the given block.

Syntax:
SET_BLOCK_PROPERTY( block_id, property, value);
SET_BLOCK_PROPERTY( block_name, property, value);


Example:
/* ** Built–in: SET_BLOCK_PROPERTY
** Example: Prevent future inserts, updates, and deletes to ** queried records in the block whose name is ** passed as an argument to this procedure. */

PROCEDURE Make_Block_Query_Only( blk_name IN VARCHAR2 )
IS
blk_id Block;
BEGIN
/* Lookup the block’s internal ID */

blk_id := Find_Block(blk_name);

/* ** If the block exists (ie the ID is Not NULL) then set ** the three properties for this block. Otherwise signal ** an error. */

IF NOT Id_Null(blk_id) THEN
Set_Block_Property(blk_id,INSERT_ALLOWED,PROPERTY_FALSE);
Set_Block_Property(blk_id,UPDATE_ALLOWED,PROPERTY_FALSE);
Set_Block_Property(blk_id,DELETE_ALLOWED,PROPERTY_FALSE);
ELSE
Message(’Block ’blk_name’ does not exist.’);
RAISE Form_Trigger_Failure;
END IF;
END;


Block - System Variables

1.SYSTEM.BLOCK_STATUS

SYSTEM.BLOCK_STATUS represents the status of a Data block where the cursor is located, or the current data block during trigger processing. The value can be one of three character strings:

CHANGED Indicates that the block contains at least one Changed record.
NEW Indicates that the block contains only New records.
QUERY Indicates that the block contains only Valid records that have been retrieved
from the database.

Example:
Assume that you want to create a trigger that performs a commit before clearing a block if there are changes to commit within that block.

The following Key–CLRBLK trigger performs this function.

IF :System.Block_Status = ’CHANGED’
THEN Commit_Form;
END IF;
Clear_Block;


2.SYSTEM.CURRENT_BLOCK

The value that the SYSTEM.CURRENT_BLOCK system variable represents depends on the
current navigation unit:

If the current navigation unit is the block, record, or item (as in the Pre- and Post- Item,
Record, and Block triggers), the value of SYSTEM.CURRENT_BLOCK is the name of the block
that Form Builder is processing or that the cursor is in.

If the current navigation unit is the form (as in the Pre- and Post-Form triggers), the value of
SYSTEM.CURRENT_BLOCK is NULL.

3.SYSTEM.CURSOR_BLOCK

The value that the SYSTEM.CURSOR_BLOCK system variable represents depends on the
current navigation unit:

If the current navigation unit is the block, record, or item (as in the Pre- and Post- Item,
Record, and Block triggers), the value of SYSTEM.CURSOR_BLOCK is the name of the block where the cursor is located. The value is always a character string.

If the current navigation unit is the form (as in the Pre- and Post-Form triggers), the value of
SYSTEM.CURSOR_BLOCK is NULL.

Example:

Assume that you want to create a Key–NXTBLK trigger at the form level that navigates depending on what the current block is. The following trigger performs this function, using
:SYSTEM.CURSOR_BLOCK stored in a local variable.

DECLARE
curblk VARCHAR2(30);
BEGIN
curblk := :System.Cursor_Block;

IF curblk = ’ORDERS’ THEN
Go_Block(’ITEMS’);
ELSIF curblk = ’ITEMS’ THEN
Go_Block(’CUSTOMERS’);
ELSIF curblk = ’CUSTOMERS’ THEN
Go_Block(’ORDERS’);
END IF;
END;

4. SYSTEM.MASTER_BLOCK

This system variable works with its companion SYSTEM.COORDINATION_OPERATION to help an On-Clear-Details trigger determine what type of coordination-causing operation fired the trigger, and on which master block of a master/detail relation.

5. SYSTEM.TRIGGER_BLOCK

SYSTEM.TRIGGER_BLOCK represents the name of the block where the cursor was located when the current trigger initially fired. The value is NULL if the current trigger is a Pre- or Post-Form trigger. The value is always a character string.


Example:

Assume that you want to write a form–level procedure that navigates to the block where the cursor was when the current trigger initially fired. The following statement performs this function.

Go_Block(Name_In(’System.Trigger_Block’));

Block – Based Triggers [Block Processing Trigger]

When-Create-Record, When-Clear-Block, When-Database-Record, When-Remove-Record

No comments:

Post a Comment