Monday, August 30, 2010

powerbuilder interview question _ part 3

1. Explain the difference between SetTrans() and SetTransObject()?
SetTransObject( ) works faster because it doesn’t perform Connect and Disconnect each
time we call it. When we specify SetTrans( ) system Does all transaction Automatically. When we specify SetTransObject( ) we have to manage all Transaction by ourselves. When we use SetTrans( ) in a script, the DataWindow uses its internal transaction object and automatically connects and disconnects as needed; any errors that occur cause an automatic rollback. Use SetTrans( ) when we want PowerBuilder to manage the database connections automatically because we have a limited number of available connections or will be used the application from a remote location. SetTrans( ) is appropriate when we are only retrieving data and do not need to hold database locks on records the user is modifying. However, for better performance, we should use SetTransObject( ).

2. When would you use SetTrans( )?
We use SetTrans() when only a limited No. of connections to the DB is allowed or we are only retrieving data and do not need to hold DB locks on records the user is modifying.

3. Explain SetActionCode(). Do DW events support this function?
The SetActionCode() function changes the action that follows a DW event. This function overrides the standard behavior of an event. Not all DW events have action codes, only those that can have different outcomes. In PB5 SetActionCode() became obsolete. We use key word “return” from 0 to 3 depending on the event. Default is (0). Return must be the last line in a script or statement.

4. How do you use ShareData() between two different DataWindows?
If we want to share the data between 2 DW controls we use dw_1.ShareData(dw_2).
Two DataWindows must have the same select but may have a different display.
In PB5 I use it with DataStore. The controls do not share formatting; only the data is shared, including data in the primary, delete, and filter buffers, and the sort order.
To turn off the sharing of data buffers for DataWindow controls we use the function dw_1.ShareDataOff(dw_2) .

5. What is the difference between TriggerEvent( ) and PostEvent( )?
TriggerEvent ( ) function makes the event occur immediately. This function does not return until the processing for the event is complete.
PostEvent( ) function makes the event occur when the current event is finished executing. In other words, it stands in the queue. The difference between them lies in timing.

6. What is the purpose of Yield( ) function?
We use YIELD( ) to allow the user to interrupt a tight loop in order to receive any messages there may be. We must call Yield( ) and check for an interruption each time we pass through the loop. We must also close the script when we close the window. Yield( ) checks the message queue and if there are message in the queue, it pulls them from the queue. Yields control to other graphic objects including objects that are not PowerBuilder. Include Yield( ) within a loop so that other processes can happen. E.g., use Yield( ) to allow end users to interrupt a loop. By yielding control, we give the user time to click on a cancel button in another window. We can also use Yield( ) in a loop in which we are waiting for something to finish so that other processing can take place, in either our or some other application.

7. What is the purpose of AcceptText( ) function?
The AcceptText( ) function validates the last item in the DataWindow control that a user worked on. Never call AcceptText( ) in the ItemChanged event. If a user enters the data and wants to close the window without pressing the tab or the update command button, we have to be responsible for saving the last modification: dwcontrol.AcceptText( )
When a user moves from item to item in a DW control, the control validates and accepts
data the user has edited. When a user modifies a DW item then immediately changes focus to another control in the window, the DW control does not accept the modified data—the data remains in the edit control. Use the AcceptText function in this situation to ensure that the DW object contains the data the user edited. A typical place to call AcceptText( ) is in a user event that is posted from the DataWindow's LoseFocus event.
(Applies the contents of the DataWindow's edit control to the current item in the buffer of a DataWindow control or DataStore. The data in the edit control must pass the validation rule for the column before it can be stored in the item.
Applies to DataWindow controls, DataStore objects, and child DataWindows
Syntax dwcontrol.AcceptText ( )
Argument Description
dwcontrol The name of the DataWindow control, DataStore, or child DataWindow in which you want to accept data entered in the edit control
Return value Integer. Returns 1 if it succeeds and -1 if it fails (for example, the data did not pass validation). If dwcontrol is NULL, AcceptText returns NULL.
Usage: When a user moves from item to item in a DataWindow control, the control validates and accepts data the user has edited. When a user modifies a DataWindow item then immediately changes focus to another control in the window, the DataWindow control does not accept the modified data—the data remains in the edit control. Use the AcceptText function in this situation to ensure that the DataWindow object contains the data the user edited. A typical place to call AcceptText is in a user event that is posted from the DataWindow's LoseFocus event.
AcceptText in the ItemChanged event
Calling AcceptText in the ItemChanged event has no effect.
Events: AcceptText may trigger an ItemChanged or an ItemError event.)


8. When do you use AcceptText()?
Sometimes if user changed the data and immediately changed the focus the data is not accepted yet. We have to use AcceptText() in the ItemChange event to accept the data.

9. You want to know how fast your code is being executed.
How do you time execution of your code?
use CPU( ) function
Long. Returns the number of milliseconds of CPU time elapsed since the start of your PowerBuilder application.
These statements determine the amount of CPU time that elapsed while a group of statements executed:
Long ll_start, ll_used // Declare start and used as long integers.
ll_start = CPU( ) // Set the start equal to the current CPU usage.
... // Executable statements being timed
// Set used to the number of CPU seconds
// that were used (current CPU time - start).
ll_used = CPU( ) - ll_start

10. What is the purpose of Describe( ), Modify( )?
Modify( ) and Describe( ) functions are DW object level functions. Describe( ) reads the attributes of a DW object at runtime. Modify( ) changes the attributes at runtime.
Typical uses for Modify () are:
• Changing colors, text settings, and other appearance settings of objects
• Changing the update status of different tables in the DW so that you can update more than one table
• Modifying the WHERE clause of the DataWindow object's SQL SELECT statement
• Turning on Query mode or Prompt For Criteria so users can specify the data they want
• Changing the status of Retrieve Only As Needed
• Changing the data source of the DataWindow object
• Controlling the Print Preview display
• Deleting and adding objects, for example, lines or bitmaps, in the DataWindow object
dw_customer.Modify("DataWindow.Color = 255")
where "DataWindow.Color = 255" is modstring.
Use Describe( ) to understand the structure of a DataWindow.
Typical uses for Describe () are:
• bands the DataWindow uses
• data types of the columns.
• to find out the current value of a property and use that value to make further modifications.
• to obtain the DataWindow's SELECT statement in order to modify it (for example, by adding a WHERE clause).
dw_1.Describe("salary.ColType")
where "salary.ColType" is attribute list

11. How can you find out what object is under the mouse pointer in a DataWindow?
Using ObjectAtPointer( ) function that finds out where the user clicked in a graph. ObjectAtPointer() reports the region of the graph under the pointer and stores the associated series and data point numbers in the designated variables. Applies to graph controls in windows and user objects, and in DataWindow controls.

13. What is the difference between GetText() and GetItem()? Get Text() gives you the content of the text control , when the data is not accepted yet and you can use it for example in ItemChanged Event to obtain the data that did not pass validation rule. GetItem() gives you value that accepted and is in the DW buffer already.
14. How can you copy data from one DW to another if they have the same structure?
We could use the function RowsCopy() The function copies a range of rows from one DataWindow control (or DataStore object) to another, or from one buffer to another within a single DataWindow control (or DataStore). Uses for RowsCopy() include:
n Making copies of 1 or more rows so that users can create new rows based on existing data.
n Printing a range of rows by copying selected rows to another DW and printing the second DW.
dw_1.RowsCopy(dw_1.GetRow(), dw_1.RowCount(), Primary!, dw_2, 1, Primary!)

15. What is the function of Find( ) ?
Finds the next row in a DW in which data meets a specified condition.
Find (expression, start, end). The search is case-sensitive. When you compare the text to the value in a column, the case must match.

16. What is the function of SetTabOrder( )?
Changes the tab sequence number of a column in a DW control to the specified value. E.g., dwcontrol.SetTabOrder (column, TabNumber)
Use SetTabOrder( ) to change a column in a DW object to read-only by changing the tab sequence number of the column to 0.

17. What is the function of DeleteRow( )?
Deletes a current row from a DW control or Child DataWindow.
dwcontrol.DeleteRow (row)
DeleteRow( ) deletes the row from the DataWindow's primary buffer.

18. How can you override a PB function, e.g., DeleteRow( ), for a DW control?
We need to create a User Object of the DataWindow type and declare the DeleteRow( ) function for this object having the same parameters as PowerBuilder’s DeleteRow( ). When we call the function, PB tries to find this function on the object level first, that’s why our function will be executed and not PowerBuilder’s. But we can still call PowerBuilder’s DeleteRow( ) by using Call Super :: DeleteRow( )

19. What is the function of DBErrorCode( )?
Reports the database-specific error code that triggered the DB Error event.
DBErrorCode() is obsolete. The DB error code is available as an argument SQLDBCode in the DB Error event: dwcontrol.DBErrorCode ( )
When a DB error occurs while a DW control is interacting with the DB, PB triggers the DB Error event. Since DBErrorCode is meaningful only if a DB error has occurred, we should call the function only in the DB Error event.

20. What is the function of DBErrorMessage( )?
Reports the database-specific error message that triggered the DB Error event.
DBErrorMessage( ) is obsolete. The DB error message is available as an argument SQLErrText in the DB Error event. dwcontrol.DBErrorMessage( )
When a DB error occurs while a DW control is interacting with the DB, PB triggers the DB Error event. Since DBErrorCode is meaningful only if a DB error has occurred, we should call the function only in the DB Error event.

21. What is the function of ScrollToRow( )?
Scrolls a DW control to the specified row. ScrollToRow( ) changes the current row. dwcontrol. ScrollToRow( row )
After we call ScrollToRow( ), the specified row becomes the new current row. If that row is already visible, the displayed rows do not change. If it is not visible, the displayed rows change to display the row. ScrollToRow( ) does not highlight the row. Use SelectRow( ) to let the user know what row is current. ScrollToRow( ) may trigger these events:
• ItemChanged
• ItemError
• ItemFocusChanged
• RowFocusChanged


23. What is the function of SetFilter( )?
Specifies filter criteria for a DW control.

24. What does the function ModifiedCount( ) do?
Reports the number of the rows that have been modified but not updated in a DW. dwcontrol.ModifiedCount ( )

25. What is the function of ShareData( )?
If we need to share data between a primary DW and more than one secondary DW control, we call ShareData( ) for each secondary DW control. When we call functions in either the primary or secondary DW that change the data, PB applies them to the primary DW control and all secondary DW controls are affected.
dw_primary.ShareData ( dw_secondary )
Shares data retrieved by one DW control, which is referred to as the primary DW, with another DW control, referred to as the secondary DW. The controls do not share formatting; only the data is shared, including data in the primary buffer, the delete buffer, the filter buffer, and the sort order.

26.What is the function of Create( ) ?
Creates a DW object using DW source code and puts that object in the specified DW control or DataStore object. This dynamic DW object does not become a permanent part of the application source library.
dwcontrol.Create ( syntax {, errorbuffer } )
The Create( ) function is used to associate the DW object syntax with an existing DW control. dw_1.Create( ls_syntax_str, ls_errmsg)

27. What does function SelectRow( ) do?
Highlights or dehighlights rows in a DW control. SelectRow( ) does not affect which row is current. dwcontrol.SelectRow(0, FALSE)
dwcontrol.SelectRow(row, TRUE)
If a row is already selected and we specify that it be selected (boolean is TRUE), it remains selected. If a row is not selected and we specify that it not be selected (boolean is FALSE), it remains unselected.

28. When do RetrieveAsNeeded( ) stop working?
If we use Filter( ) and Sort( ).

29. Give an example of a case sensitive functions?
Find( )

30. What will happened if we place AcceptText() in ItemChangeevent?
We get an error message

31. What functions used for creating DW dynamically?
Modify(),Describe()

2 comments:

Unknown said...

Nice collections of Questions. Thanks for sharing all about PowerBuilder and DB questions.

Vasu said...

How do I copy a folder from one drive to another drive using powerbuilder?

Custom Search