Question How Pass Stream As Parameter

Progress Version: 11.x
Progress Platform: Linux, character based
Windows: Windows 8

I am using character based ABL. I have 2 branches of the company, I need to create 10 outputs for each branch for data in the past 10 years with 1 file for 1 year's data.

I thus need to output files to 20 separate streams. i grouped all the output logic into a procedure. My question is how will I be able to pass the stream to this procedure to output to the various streams.

Moreover, this program is run in a special environment which a .I is not allowed. That is, all the codes must be in a single .P program.

Thanks in advance.
 
I got it resolved somehow. Thanks guys.

The file size is about 100 MB to 200 MB each.

solution:
Code:
define stream sBranchA.
define stream sBranchB.
define var cFile as char extent 20 no-undo.
define var cName as char extent 2 no-undo.
define var i as int no-undo.
define var j as int no-undo.

/* I calculate and switch the output stream to different files */

do i = 5 to 15:
     j = (i - 5) * 2.
     vFile[1 + j]  = "BranchA_20" + string(i,"99") + ".txt".   /* file name will be as BranchA_2005.txt */
     vFile[2 + j] = "BranchB_20" + string(i,"99") + ".txt".
end.

/* now loop through data */
data_loop:
for each ....:
     /* now calculate the output file name for data */
     j = if branchA then 1 else 2.
     i = (year(record_date) - 2005) * 2 + j.

     if vFile[i] <> vName[j] then do: /* switch output file, as data is indexed by date so the switch only occur once for each year */
           if branch = "A" then do:
                  output stream sBranchA close.
                  output stream sBranchA to value (vFile[i])
           end.
           else do: /* do the same for branch B */
                  output stream sBranchB close.
                  output stream sBranchB to value (vFile[i])
           end.

          vName[j] = vFile[i]
     end.

end. /* data loop */
 

GregTomkins

Active Member
For the record, this seems to work and seems to meet the original requirement:

def stream x.
output stream x to /tmp/gt1.
run p(stream x:handle).
output stream x close.
output stream x to /tmp/gt2.
run p(stream x:handle).
output stream x close.

procedure p:
def input param s as handle. /* Voila! */
put stream x "hello".
end.
 

GregTomkins

Active Member
Oops! Not quite. The 'put stream x', DUH, is just referencing the procedure-visible stream defined previously. A good example of why I'd like a 'make procedure-level names invisible inside internal procedures' compiler option. Anyway. I don't have a compiler in front of me, but it's probably possible to rearrange this code slightly to make it work. Apologies for the overly hasty earlier reply.

http://documentation.progress.com/o...ABL/ABL Reference/20dvref-Handles.034.45.html
 

Cringer

ProgressTalk.com Moderator
Staff member
My question about file sizes was that if they weren't too big it would be much more interesting to build them as a LONGCHAR and then just COPY-LOB. No need for streams. :)
 

tamhas

ProgressTalk.com Sponsor
Also note that passing a stream as a parameter is a strong hint that you should be moving the stream processing into a persistent procedure or object so that the stream handling all happens in one place.
 

davidvilla

Member
this should work:

Code:
define stream str1.
define variable hstr as handle no-undo.
hstr = stream str1:handle.
output stream str1 to "teststream.txt".
export stream str1 "in main 1".
run teststream.p(input hstr ).
export stream str1 "in main 2".
output stream str1 close.

teststream.p:
define input parameter iphstr as handle no-undo.
export stream-handle iphstr " in sub 1".
 
Top