writing to file based on condition



IBM's Command List programming language & Restructured Extended Executor

writing to file based on condition

Postby ramu65 » Sun Oct 12, 2014 10:59 pm

Hi

I am a newbie in Rexx and I was trying this simple code to copy selected records from one file to another based on a condition.But once the condition fails , the other records are not getting written to the other file

The code snippet is as follows :

y = 1
Do while y < =  inrec.0
If substr (inrec.y, 5, 1) = 'x'
Then y = y + 1
If substr (inrec.i, 5, 1) = 'y'
Then do
Outrec.y = inrec.y
"Execio diskw outfile outfile (finis stem outrec."
Y= y + 1
End
End
"Free f (outfile)"
Exit


The moment the first condition becomes true the remaining records satisfying the second condition are not getting written to the second file. I am not able to trace the error.

Code'd, for what it was worth
ramu65
 
Posts: 29
Joined: Sat Feb 08, 2014 10:51 pm
Has thanked: 0 time
Been thanked: 0 time

Re: writing to file based on condition

Postby prino » Mon Oct 13, 2014 12:51 am

You are obviously totally unaware of how EXECIO works. Suggest you start reading the manuals before coming back here...
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: writing to file based on condition

Postby NicC » Mon Oct 13, 2014 5:39 pm

Also, how does the inrec stem get populated? Where do you get a value for i in your second IF. Why is your code not indented as per good proggramming practice?

Why not do a simple :
DO y = 1 TO inrec.0
   IF inrec.y is a record you want
   THEN DO
      whatever
   END
END
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: writing to file based on condition

Postby Pedro » Mon Oct 13, 2014 9:39 pm

re:
Outrec.y = inrec.y

You should use a different index value for each of the two stems. You want to increment the index of Outrec. only when you find value that meets your criteria.
Pedro Vera
User avatar
Pedro
 
Posts: 684
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 53 times

Re: writing to file based on condition

Postby PJAlarcon » Wed Oct 22, 2014 5:25 pm

ramu65:
I'm not a REXXX expert, but have walked a few miles on REXX's shoes.
Basically (there's more into it) the stem variables works like a buffer array. You just keep writing to it, increasing the 'subscript' by one each time, if you skip one the output will be truncated.
Once you've finished writing all the lines you need, THEN use the EXECIO command.

prino: there's no need to be rude. I've been in a similar situation before and it seems members keep forgetting this is a forum for "Begginers and Students". If you need to send someone to read books, do it nicely, just MHO.
PJAlarcon
 
Posts: 8
Joined: Mon Mar 14, 2011 6:28 pm
Has thanked: 3 times
Been thanked: 0 time

Re: writing to file based on condition

Postby enrico-sorichetti » Wed Oct 22, 2014 6:20 pm

if you skip one the output will be truncated.


things are a bit more complicated ...

that' s why it is IMPROPER to use EXECIO * DISKW
always use the count when writing from a STEM
and use the * only when writing from the stack

run this and see Yourself why
( just allocate a fb 80 sequential file and use that instead of ENRICO.TEST.EXECIO )

 ****** ***************************** Top of Data ******************************
 000001 /* REXX */
 000002
 000003 Trace "O"
 000004 Signal on novalue name novalue
 000005
 000006 do i = 1 to 10
 000007    stem.i = "xyz" || right(i,2,"0")
 000008 end
 000009
 000010 Address TSO
 000011 "ALLOC FI(OUT) DS('ENRICO.TEST.EXECIO') SHR REUS"
 000012
 000013 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000014 head.2 = "EXECIO   * DISKW OUT (STEM STEM. "
 000015 head.3 = "- with stem.5 = 'xyz05' "
 000016 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000017 "EXECIO   * DISKW OUT (STEM STEM. "
 000018 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000019 head.2 = "EXECIO  10 DISKW OUT (STEM STEM. "
 000020 head.3 = "- with stem.5 = 'xyz05' "
 000021 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000022 "EXECIO  10 DISKW OUT (STEM STEM. "
 000023
 000024 stem.5 = ""
 000025 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000026 head.2 = "EXECIO   * DISKW OUT (STEM STEM. "
 000027 head.3 = "- with stem.5 = '' "
 000028 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000029 "EXECIO   * DISKW OUT (STEM STEM. "
 000030 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000031 head.2 = "EXECIO  10 DISKW OUT (STEM STEM. "
 000032 head.3 = "- with stem.5 = '' "
 000033 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000034 "EXECIO  10 DISKW OUT (STEM STEM. "
 000035
 000036 drop stem.5
 000037 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000038 head.2 = "EXECIO   * DISKW OUT (STEM STEM. "
 000039 head.3 = "- with drop.5  "
 000040 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000041 "EXECIO   * DISKW OUT (STEM STEM. "
 000042 head.1 = "- - - - - - - - - - - - - - - - - - - "
 000043 head.2 = "EXECIO  10 DISKW OUT (STEM STEM. "
 000044 head.3 = "- with drop.5  "
 000045 "EXECIO   3 DISKW OUT (STEM HEAD. "
 000046 "EXECIO  10 DISKW OUT (STEM STEM. FINIS"
 000047
 000048 exit
 000049
 000050 novalue:
 000051 say  "** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 000052 say  "** "
 000053 say  "** novalue trapped at line" right(sigl,5)
 000054 say  "** "
 000055 say  "** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 000056 exit
 000057
 000058 /* */
 000059 logic_error:
 000060 say  "** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 000061 say  "** "
 000062 say  "** logic error at line    " right(sigl,5)
 000063 say  "** "
 000064 say  "** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 000065 exit
 ****** **************************** Bottom of Data ****************************


if You cannot run the sample Yourself here is the result

 EDIT       ENRICO.TEST.EXECIO                              Columns 00001 00072
 Command ===>                                                  Scroll ===> CSR
 ****** ***************************** Top of Data ******************************
 000001 - - - - - - - - - - - - - - - - - - -
 000002 EXECIO   * DISKW OUT (STEM STEM.
 000003 - with stem.5 = 'xyz05'
 000004 xyz01
 000005 xyz02
 000006 xyz03
 000007 xyz04
 000008 xyz05
 000009 xyz06
 000010 xyz07
 000011 xyz08
 000012 xyz09
 000013 xyz10
 000014 - - - - - - - - - - - - - - - - - - -
 000015 EXECIO  10 DISKW OUT (STEM STEM.
 000016 - with stem.5 = 'xyz05'
 000017 xyz01
 000018 xyz02
 000019 xyz03
 000020 xyz04
 000021 xyz05
 000022 xyz06
 000023 xyz07
 000024 xyz08
 000025 xyz09
 000026 xyz10
 000027 - - - - - - - - - - - - - - - - - - -
 000028 EXECIO   * DISKW OUT (STEM STEM.
 000029 - with stem.5 = ''
 000030 xyz01
 000031 xyz02
 000032 xyz03
 000033 xyz04
 000034 - - - - - - - - - - - - - - - - - - -
 000035 EXECIO  10 DISKW OUT (STEM STEM.
 000036 - with stem.5 = ''
 000037 xyz01
 000038 xyz02
 000039 xyz03
 000040 xyz04
 000041
 000042 xyz06
 000043 xyz07
 000044 xyz08
 000045 xyz09
 000046 xyz10
 000047 - - - - - - - - - - - - - - - - - - -
 000048 EXECIO   * DISKW OUT (STEM STEM.
 000049 - with drop.5
 000050 xyz01
 000051 xyz02
 000052 xyz03
 000053 xyz04
 000054 - - - - - - - - - - - - - - - - - - -
 000055 EXECIO  10 DISKW OUT (STEM STEM.
 000056 - with drop.5
 000057 xyz01
 000058 xyz02
 000059 xyz03
 000060 xyz04
 000061 STEM.5
 000062 xyz06
 000063 xyz07
 000064 xyz08
 000065 xyz09
 000066 xyz10
 ****** **************************** Bottom of Data ****************************


anyway dropping a stem entry without changing stem.0
or/and losing track of the valid stem entries is IMO a logic/coding error
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
PJAlarcon (Sat Apr 22, 2017 12:02 am)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post