Error While Sending record via Browse Widget.

Hello Everyone,

I took a single select browse widget associated with customer table having 3 fields which populates automatically when we execute that.

Requirement:- i wanted to send multiple records which i select from a browse one-by-one to a .text file and i can select n number of records from browse but one-by-one because its a single select browse.

These are the following steps that i have followed:-

1. When i use OUTPUT TO statement in VALUE-CHANGED trigger of browse-widget then in .text file it shows the data which i select latest from the browse(only one record is there) this could be because of frame flashing.
--------------------------------------------------------------------------------------------------------------
2. In case i use stream and define that stream in definition section and on VALUE-CHANGED trigger Ex:-
IF AVAILABLE customer THEN DO:
PUT STREAM c-strm
customer.name
customer.custnum
customer.balance
END.
Message i am getting while selecting a record from Browse-Widget:-
ERROR:-
attempt to write to a close stream.

--------------------------------------------------------------------------------------------------------------
3. In third step i define the stream in definition section but i associated the stream in VALUE-CHANGE trigger Ex code in VALUE-CHANGED trigger:-
OUTPUT STREAM c-strm to VALUE("c:\abc\111.txt").
IF AVAILABLE customer THEN DO:
PUT STREAM c-strm
customer.name
customer.custnum
customer.balance
END.

Message i am getting while selecting a record from Browse-Widget:-
ERROR:- c:\abc\111.txt is already in use.
------------------------------------------------------------------------------------------------------------
i am unable to understand why i getting these errors with streams. Please provide your inputs that how could i implement this.

THANKS!!!!
 
Last edited:

Osborne

Active Member
Firstly, make sure you close the stream when finishing the output:
Code:
OUTPUT STREAM c-strm CLOSE.
Regarding the error, this can happen if the stream is not closed and the file becomes locked until you quit the session and start again. Either restart the session or try writing to a different named file.
 
Hi Osborne, thanks for replying.

That comes to my mind also, as per my understanding that why stream is different from output to statement as instead of diverting a stream via output to we are creating new stream.
Ex:-
DEF STREAM c-strm.
OUTPUT STREAM c-strm TO VALUE("C:\DFG\111.TXT").
FOR EACH customer:
PUT STREAM c-strm
customer.name
customer.custnum
END.
According to this example for every iteration of for each block it writes data to stream and without closing the stream we are able to send all the data that customer table has, why?
 
Last edited:

Osborne

Active Member
The reason you are getting all the data from the customer table is after the OUTPUT statement you are reading each customer and have a PUT statement for each read which will write the fields to the file.

Are you trying to do something like this?:
Code:
DEF STREAM c-strm.

ON VALUE-CHANGED OF browse-widget DO:
   IF AVAILABLE customer THEN DO:
      OUTPUT STREAM c-strm TO VALUE("C:\DFG\111.TXT") APPEND.
      PUT STREAM c-strm customer.name customer.custnum SKIP.
      OUTPUT STREAM c-strm CLOSE.
   END.
END.
 
That's correct, this code works fine. but if i take output statement out of this code and define this into definition section then it will return me error message.

This is quite surprising because i am globally defining output statement same as for each example that i mentioned above, but in this case it is returning error message.
 

Osborne

Active Member
It sounds as though the OUTPUT STREAM statements may be in the wrong place and that is why you are getting errors. If you have the statements at the start and end of the program as similar to this very basic example does that work?:
Code:
DEFINE STREAM c-strm.

DEFINE QUERY q1 FOR Customer SCROLLING.

DEFINE BROWSE b1 QUERY q1 DISPLAY Customer.CustNum Customer.Name Customer.Balance
  WITH 10 DOWN TITLE "Customer Balances".

DEFINE FRAME f1 b1 WITH SIDE-LABELS ROW 2 CENTERED NO-BOX.

ON VALUE-CHANGED OF b1 DO:
   IF AVAILABLE Customer THEN
      PUT STREAM c-strm Customer.CustNum Customer.Name Customer.Balance SKIP.
END.

OUTPUT STREAM c-strm TO VALUE("C:\DFG\111.TXT").

OPEN QUERY q1 FOR EACH Customer NO-LOCK.
ENABLE ALL WITH FRAME f1.
WAIT-FOR END-ERROR, WINDOW-CLOSE OF CURRENT-WINDOW.

OUTPUT STREAM c-strm CLOSE.
 
Last edited:
Hi Osborne,

The above mentioned code doesn't work because we use output statement after VALUE-CHANGED trigger. if i little manipulate this code for ex:-

DEFINE STREAM c-strm.

DEFINE QUERY q1 FOR Customer SCROLLING.

OUTPUT STREAM c-strm TO VALUE("C:\DFG\111.TXT").

DEFINE BROWSE b1 QUERY q1 DISPLAY Customer.CustNum Customer.Name Customer.Balance
WITH 10 DOWN TITLE "Customer Balances".

DEFINE FRAME f1 b1 WITH SIDE-LABELS ROW 2 CENTERED NO-BOX.

ON VALUE-CHANGED OF b1 DO:
IF AVAILABLE Customer THEN
PUT STREAM c-strm Customer.CustNum Customer.Name Customer.Balance SKIP.
END.

OPEN QUERY q1 FOR EACH Customer NO-LOCK.
ENABLE ALL WITH FRAME f1.
WAIT-FOR END-ERROR, WINDOW-CLOSE OF CURRENT-WINDOW.

This code works fine without using close stream statement that is same as excepted, but i was trying the same scenario with static browse which i have created from AppBuilder and took three fields from customer table. In definition section i have defined the stream and output statement and in VALUE-CHANGED trigger section i wrote the same code as above and i got error which already discussed.

Perhaps it is AppBuilder/static browse property that it returns error message.

Thanks for your mentorship!!!
 

TomBascom

Curmudgeon
Just like "if you create it, you must delete it", "if you open it, you must close it".

Failing to close a stream is sloppy. It is not good practice -- even if you have managed to find an example where nothing bad has happened. Yet.
 
I got it Tom, i was trying to clarify some of my doubts. In the end i am able to send data from browse-widget. :)

Thanks!!!
 
Last edited:
Top