Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Maintain-Write data in multi tables

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Maintain-Write data in multi tables
 Login/Join
 
Member
posted
I have a scenario like this:
There are two tables,table A and table B. A has three columns:ID,CardName,CardNum.B also has three columns:ID,UserName,Account. I create a form with five edit box and the user could type the value into it. I hope these values could be written in the database. The ID will be typed once but it will be written in two tables.How to do this?

WF 7702
Database Oracle 9i

This message has been edited. Last edited by: Kerry,
 
Posts: 22 | Registered: May 13, 2011Report This Post
Guru
posted Hide Post
Elaine

something like this:


MAINTAIN FILE table1 AND table2

Case Top
perform init;
perform disp_form;
EndCase

case init
infer table1.column1 into stk1;
infer table2.column1 into stk2;
endcase

case disp_form
Winform Show Form1;
endcase

END

You put a button on the screen and the onClick event handler would be:

Case OnButton1_Click
for 1 revise table1.some_column from stk1;
for 1 revise table2.some_column from stk2;
EndCase


WebFOCUS DS 8.0.06/08 DS/AS
WebFOCUS RS 8.0.08 (Linux/IBM i)
WebFOCUS Client 8.0.06 (Linux)
 
Posts: 319 | Location: Stockholm, Sweden | Registered: February 04, 2004Report This Post
Member
posted Hide Post
I tested it with your code, but it just could write in one table named info.
Here is my code:
MAINTAIN FILE info AND customer

$$Declarations

Case Top
init( );
disp_form( );
-* Replace the Winform Show command with the following code
-* when to display your form in a non-persistent state
-* Winform Show_And_Exit Form1;
EndCase

Case init
INFER info.INFO.SSN INTO AddInfoStk;
INFER customer.CUSTOMER.SSN INTO AddCustomerStk;
EndCase

Case disp_form
Winform Show Form1; 
EndCase

END  


The button on-click event is:
Case OnButton1_Click
For 1 revise info.INFO.SSN from AddInfoStk ;
For 1 revise customer.CUSTOMER.SSN from AddCustomerStk ;
EndCase
 
Posts: 22 | Registered: May 13, 2011Report This Post
Guru
posted Hide Post
Could it be that the ssn value already exist in the customer table? The revise command does an update or include depending on whether the row exist or not. Can you revise another column?


WebFOCUS DS 8.0.06/08 DS/AS
WebFOCUS RS 8.0.08 (Linux/IBM i)
WebFOCUS Client 8.0.06 (Linux)
 
Posts: 319 | Location: Stockholm, Sweden | Registered: February 04, 2004Report This Post
Member
posted Hide Post
FrownerThe SSN value I entered in display page isnn't exsit in customer table.
I don't quiet understand about this code:
 
For 1 revise customer.CUSTOMER.SSN from AddCustomerStk ; 

I don't input the customer.ssn value. How could the stack get it? And the from is as follows:

This message has been edited. Last edited by: Elaine,
 
Posts: 22 | Registered: May 13, 2011Report This Post
Virtuoso
posted Hide Post
Elaine

The form uses AddInfoStk for SSN, and I presume some of the elements are bound to that stack, others bound to AddCustomerStk.

Therefore there is no SSN in AddCustomerStk to be input.

You must compute the values in AddCustomerStk from the values in AddInfoStk.

Case OnButton1_Click
For 1 revise info.INFO.SSN from AddInfoStk ;
compute AddCustomerStk.SSN = AddInfoStk.SSN;
$$ repeat for all values required. 
For 1 revise customer.CUSTOMER.SSN from AddCustomerStk ;
EndCase


All of this is covered in the basic training course which I highly recommend you attend. Maintain is a powerful language, but not that easy to understand all the syntax and how it all fits together. The supervised workshops help put everything into perspective.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Member
posted Hide Post
Alan,
I add
 AddCustomerStk.SSN=AddInfoStk.SSN; 
and it works.
But I found that if I don't close the display page,there are always three locks in my database and if I close the page the value would be inserted into the tables immediately.How could this happen? What should I do if I want to insert the value immediately after I click the add-button.
 
Posts: 22 | Registered: May 13, 2011Report This Post
Virtuoso
posted Hide Post
Changes need to be committed to your database to release the locks and see the changes immediately.

I know nothing about Maintain but I believe there has to be a command/statement equivalent to a COMMIT TRANSACTION, no?



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Guru
posted Hide Post
You have to issue a COMMIT statement after the insert. There is also a ROLLBACK statement in Maintain.


WebFOCUS DS 8.0.06/08 DS/AS
WebFOCUS RS 8.0.08 (Linux/IBM i)
WebFOCUS Client 8.0.06 (Linux)
 
Posts: 319 | Location: Stockholm, Sweden | Registered: February 04, 2004Report This Post
Virtuoso
posted Hide Post
Elaine

Structure is very important to the maintainability(!) of the Maintain code, and to ensuring that you can develop easily and control what happens.

May I suggest the following structure:
MAINTAIN FILE info AND customer

$$Declarations

Case Top
$$ The top case is the controlling case, keep the infers and initial winforms up here
$$ If you are retrieving data, make a case call though

  Infer info.info.ssn into addinfostk;
  Infer customer.customer.ssn into addcustomerstk;

  Winform Show Form1; 

EndCase

Case update
declare error/i8;
        errorFile/a20;
        errorMsg/a0;

  AddCustomerStk.SSN = AddInfoStk.SSN;

$$ Using a dummy repeat lets you control the commits and rollbacks quite easily
  repeat 1

    For 1 revise info.INFO.SSN from AddInfoStk ;

$$ Check error, and if gt 0 rollback and exit dummy repeat
      if FocError ne 0 then begin
        error = FocError;
        errorFile = 'info';
$$ The errorMsg can be displayed back to the user, and/or other action taken
        errorMsg = 'Error ' | error | ' in file ' | errorFile || '. Data not updated';
        rollback
        goto exitrepeat;
      endbegin

    For 1 revise customer.CUSTOMER.SSN from AddCustomerStk ;

      if FocError ne 0 then begin
        error = FocError;
        errorFile = 'customer';
        errorMsg = 'Error ' | error | ' in file ' | errorFile || '. Data not updated';
        rollback
        goto exitrepeat;
      endbegin

$$ commit only if no errors
    commit

  endrepeat
  
EndCase

END  


and for the handler. (Oh and please name the form objects, don't use the default name like button1, edit1 etc.)
Case OnButton1_Click
$$ Keep as much code out of the handlers as possible.  It is easier to develop and maintain.
update();
EndCase

I know that this is personal, but after 12 years of WebFOCUS maintain, this is the structure I have settled on, and it works.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Guru
posted Hide Post
Alan, I second that. Though I stick to only put the main logic in the top case, and make the declarations of stacks etc in a separate case like this:

Case Top
init();
show_form();
etc.
EndCase

Case init
infer etc
EndCase

Case show_form
Winform Show Form1;
EndCase

END

and of course, all Maintain code should be called from an event handler, no inline code, except for javascript or vbscript.


WebFOCUS DS 8.0.06/08 DS/AS
WebFOCUS RS 8.0.08 (Linux/IBM i)
WebFOCUS Client 8.0.06 (Linux)
 
Posts: 319 | Location: Stockholm, Sweden | Registered: February 04, 2004Report This Post
Member
posted Hide Post
Alan,
Yes,you're right.
I saw the same structure with yours in WF help documentation and I will modify my structure.
Thank you for your suggestion!
Smiler
 
Posts: 22 | Registered: May 13, 2011Report This Post
Virtuoso
posted Hide Post
Håkan

It is a personal preference, we are all different. I would move the Winform call separate if running with multiple forms rather than a single form though.

However, training is still important, there is a huge amount that can be achieved in the Maintain, but also techniques for controlling Winforms etc.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Maintain-Write data in multi tables

Copyright © 1996-2020 Information Builders