Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to "diskw" with stem variable - VM/CMS...

Status
Not open for further replies.

tomsweb

Programmer
Jul 24, 2003
4
US
Fellow Programmers:

I have written a rexx exec to scan records in a dataset in vm/cms mainframe, and write certain records to an output file.

I am unable to succesfully write records to an output flat file (RECFM=F, LRECL=80). The problem is the output file contains the value "SLINE.1" on every line.

Can anyone help me straighten out the confusion over the "stem line.i" stuff? I think that is causing this mess.

Thanks!
TomsWeb

Here is the code...

SIGNAL ON ERROR
'EXECIO * DISKR TESTF FILE A (FINIS STEM IN.'
IF RC=2 THEN LEAVE
J = 0

LOOPA:
DO I = 1 TO IN.0
LINE = IN.I
PARSE VAR LINE V1 V2 .
LX=LINE.I
/* LZ = SUBSTR(LX,6,2)
SAY "LINE"LZ V2 . */
IF V2 = "CAR"
THEN OUT.J = V2
SAY OUT.J J
SIGNAL WRITEX
END
EXIT

WRITEX:
OUT=LABEL.J
'EXECIO 1 DISKW TOMMY FILE A 0 F 72 (FINIS STEM OUT.'
J = J + 1
I = I + 1
SIGNAL LOOPA
EXIT

RETURN 0
 
Probably the first thing I would suggest from looking at this is that you don't use EXECIO to write line-by-line. This will at least quadruple the execution time because of the excessive I/O. I recommend you create the whole stem and do 1 write.

Anyway, from reading this you want to read in file TESTF, and write it to file TOMMY if the second word is 'CAR'. As such there are a number of bugs in here (apart from the 'SIGNAL ON' to no-where, and the 'LEAVE' which should be 'EXIT');

* you do your SIGNAL to the WRITEX regardless of the IF - I think you want a 'THEN DO ... END'
* you set J to 0 then OUT.J so for the first record your OUT.0 will be a record not a number (stem.0 is supposed to be a record count like IN.0)
* you signal LOOPA from WRITEX which should put you into a permanant loop as you restart the DO I=1 every time you write a record
* you increment I in your WRITEX which means you skip the following input record when you do a write (which you may want to do)

Here's a suggestion;
SIGNAL ON ERROR
'EXECIO * DISKR TESTF FILE A (FINIS STEM IN.'
IF RC > 0 THEN do
say 'Read of file failed with return code 'rc
return rc
end
J = 0

DO I = 1 TO IN.0
LINE = IN.I
PARSE VAR LINE V1 V2 .
/* LX=LINE.I
LZ = SUBSTR(LX,6,2)
SAY "LINE"LZ V2 . */
IF V2 = "CAR" then do
call WRITEX
SAY OUT.J J
end
END
'EXECIO * DISKW TOMMY FILE A 0 F 72 (FINIS STEM OUT.'
Return 0

WRITEX:
J = J + 1
OUT.J = V2
Return

Error:
say 'Error on line 'sourceline()';'
say sourceline(sourceline())
Exit 8
 
This script seems to have errors. Control should go from loopa: to writex: as soon as it finds a match on:
'IF v2 = "CAR"'.

There it should write out the line that the match was found in.

As it is coded now, it will write a record to 'execio diskw'
regardless of a match.

What is the point of that, if I want to capture all records that contain the keyword "car"?

The issue is why I cannot write the matching records to
an ouput file using stem in 'EXECIO DISKW'?

Thanks,
Tom
 
KiwiRexx's code doesn't look like it will write the line regardless to me.

The STEM variable looks like it is only getting incremented on a match to me. Have you inadvertently omitted the DO from the IF THEN for the match criteria.

One of the things I was always taught to avoid was the use of SIGNAL. In your script it looks like you increment I and then loop back to the DO I = 1 TO IN.0...thereby resetting I to 1 every time. I am surprised this isn't looping like crazy. :)

HTH
 
Tom, the point I was trying to make is it is in-efficient to do an EXECIO everytime you write a single record. The EXECIO in my sample is outside the LOOPA: in order to do one bulk write rather than a write each time.

I too was told not to use SIGNAL, hence my use of CALL (to WRITEX:).

Maybe if I coloured the guts of the code around the IF's it would be easier for you to read;

J = 0
DO I = 1 TO IN.0
LINE = IN.I
PARSE VAR LINE V1 V2 .

IF V2 = "CAR" then do
call WRITEX
SAY OUT.J J
end

END
'EXECIO * DISKW TOMMY FILE A 0 F 72 (FINIS STEM OUT.'
Return 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top