IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need help in updating a dataset USING REXX


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Thu Apr 29, 2010 10:11 pm
Reply with quote

Hi All.

I am reading a dataset line by line, pulling the record in a variable "record" and checking record for various conditions.
If record passes all conditions I am to write "record" the whole line into a new dataset...

So if i just use this variable to write data using EXECIO command it says invalid EXEXIO function.. do i always have to use STEM ?

Actualy i already wrote a bigg code which only uses variables and repeatedly reads the same file and used Say command to sedn outut to terminal.. and now trying to put the data into a pds .. putting in STEM i am scared might pull an unknown string

following is my code.
Code:
member = IN
FILENAME="'"||'PRD.ME.('||MEMBER||')'||"'"                 
OUTNAME = "'PRD.ME.OUT'"                               
ADDRESS TSO                                                     
"ALLOC DA("FILENAME") F(INDD) SHR REUSE"                         
ADDRESS TSO                                                     
"ALLOC DA("OUTNAME") F(OUTDD) MOD REUSE"                         
DO WHILE DONE = 'NO'                                             
  "EXECIO 1 DISKR INDD"                                         
  IF RC = 0 THEN /* RECORD WAS READ */                           
    DO                                                           
      PULL RECORD                                               
      IF LENGTH(RECORD) > 1 THEN                                 
        DO                                                       
          "EXECIO 1 DISKW OUTDD (RECORD"                               
        END                                             
      ELSE                                             
        NOP                                             
    END                                                 
  ELSE                                                 
    DONE = 'YES'    /* IF RC \= 0 CLOSE PROCESSING */   
END                                                     
"EXECIO 0 DISKW OUTDD (FINIS"
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Apr 29, 2010 10:16 pm
Reply with quote

funny,
you used a PULL RECORD after the 1 record read with EXECIO
why don't you try a PUSH RECORD before the 1 record write with EXECIO

which would mean of course that this:
Code:
"EXECIO 1 DISKW OUTDD (RECORD" 

would become this:
Code:
"EXECIO 1 DISKW OUTDD"
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Thu Apr 29, 2010 10:25 pm
Reply with quote

Hello DBZ

ABove code that I pasted was only a sample thing I was trying. After pulling the record , i am to process the record , if it satisfies COND-1 , i am to read the next record and if next record satisfies COND-2 ... i am to write both these records into the OUT dataset.

So do you suggest I first do a pull twice as required and do push twice and then execio diskW operation

Something Like , taking length > somthing as a sample COND-1/-2

"EXECIO 1 DISKR INDD"
PULL RECORD
IF LENGTH (RECORD > 10)
DO
"EXECIO 1 DISKR INDD"
PULL RECORD
IF LENGTH (RECORD > 20)
PUSH RECORD
PUSH RECORD
"EXECIO 1 DISKW OUTDD (RECORD"
ELSE
NOP
END
ELSE
NOP
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Thu Apr 29, 2010 10:29 pm
Reply with quote

Also so just using a variable like I had initially used in EXECIO command doesn't work ?

The data has to be in memory STACK or some kind of STEM ?
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Thu Apr 29, 2010 10:30 pm
Reply with quote

The answers to these questions will help us help you:
Quote:

and now trying to put the data into a pds

Are you really trying to do that? If so, the allocate of that file with disp mod will not work. You can not mod to a pds.

How many records are you talking about here? 10, 1000, 100,000.

Are there and blank records (all spaces) mixed in your input file?

In general it is more efficient to read all your data with a single EXECIO, either into the stack, or a stem variable (don't be afraid). You can then process from the stack (pull) or from the input stem (increment a counter).

What I like to do is to move my 'good' data into an output stem valiable, then write all of them at the end with a single EXECIO.

If you answer the questions, an example will be forth coming.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Apr 29, 2010 10:34 pm
Reply with quote

Please,

RECORD is a variable. only one. so, if you do a

read
PULL RECORD /* populate with first read */
read
PULL RECORD /* populate with second read */

which means you have lost the first record.

if you insist on not using stem operations,
suggest that you at least use two variables,
like FIRST_RECORD and SECOND_RECORD
at least you will know which is which and
will not lose one.

if you would spend some time reading about the data stack,
you would find that you could
PUSH var2
PUSH var1

since the PUSH is LIFO.

also, suggest you look at the syntax diagram for EXECIO
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Thu Apr 29, 2010 10:53 pm
Reply with quote

Hello DBZ
yeah too silly of me on the point u mentioned.. overlaying values.. damm

hello Dave

I have to be able to use this dataset repetetivey so in that sense i just want to append data to it always so used MOD.. inserting a *** for every fresh iteratio maybe

Number of records I scan in each file should be around 10000 and i am to scan 1700 such files... Selected records in each file should be b/w 0 -50 lines of code. and yes the pds members I would be scanning would have blank records too

I started reading REXX like 4 days back and I am do finish my code max by tomm .. REXX was my own choice else I would have ended up seacrhing each module manually .. so I guess i am too short of time to rewrite the code using STEM..

What I like to do is to move my 'good' data into an output stem valiable, then write all of them at the end with a single EXECIO. ---- thats a good choice .. How can i do that plS ?
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Thu Apr 29, 2010 11:03 pm
Reply with quote

Your structure appears very complicated to me.

If it were me, based on your sample code, I would do it like this.

Code:

/* INITIALIZE STEM AND COUNTER */
OUT. = ''
OUT_CTR = 0
/* READ ALL DATA INTO STACK */
"EXECIO * DISKR INDD"
LINES = QUEUED()
/* LOOP THRU STACK */
DO IN_CTR = 1 TO LINES
  PULL DATA
  /* STRIP OFF TRAILING BLANKS TO GET 'TRUE' LENGTH */
  DATA = STRIP(DATA)
  /* PUT 'GOOD' DATA INTO OUTPUT STEM */
  IF LENGTH(DATA) > 1 THEN DO
    OUT_CTR = OUT_CTR +1
    OUT.OUT_CTR = DATA
  END
END
/* WRITE OUTPUT STEM WITH ONE STATEMENT */
"EXECIO * DISKW OUTDD (STEM OUT. FINIS"
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Thu Apr 29, 2010 11:15 pm
Reply with quote

sunn_io,

My guess is that what I provided, will not work based on your latest requirement.

It would be best if you provided your ACTUAL requirement, not a 'sample'.

A subset of 'real' data would also help.

What if the first record doesn't pass the test? Is the next record another first record, or is a second record to be discarded?

What if the first record passes the test and the second fails? Are they both to be discarded?

Do you see why showing data and real requirements would help?
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Thu Apr 29, 2010 11:57 pm
Reply with quote

Hi Dave,

I guess trying would be a must, I'll try once more cause I think i have an idea now..
and post it back.

Thanks
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Fri Apr 30, 2010 12:03 am
Reply with quote

good to hear.... let us know how it goes.....
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Fri Apr 30, 2010 2:36 am
Reply with quote

Hi Dave..

I followed the following algo and it works well. Essentially after satisfying my condition, moved data into an STEM and used the STEM at last to put data into a PDS file.
Just for the record, if my 1st record satisfies COND-1 and record 2 doesn't satisfies COND-2 , processing should continue from record 3 and record 1 and 2 be ignored.
Thank you.

Code:
FLAG1 = NO
DO WHILE FLAG = 'NO'
  "EXECIO 1 DISKR INDD"
  IF RC = 0 THEN
    DO
      PULL RECORD
      IF LENGTH (RECORD > 10) THEN
        DO
           RECORD1 = RECORD
          "EXECIO 1 DISKR INDD"
           IF RC = 0 THEN
             DO
               PULL RECORD
               IF LENGTH (RECORD > 20) THEN
                 DO
                     OUT_CTR = OUT_CTR + 1
                     OUT.OUT_CTR = RECORD1
                     OUT_CTR = OUT_CTR + 1
                     OUT.OUT_CTR = RECORD
                 END
               ELSE
                   NOP
             END   
           ELSE
               FLAG1 = 'YES'
        END         
      ELSE
         NOP
    END
  ELSE
    FLAG1 = 'YES'
END
"EXECIO * DISKW OUTDD (STEM OUT. FINIS"
"Code'd"
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Fri Apr 30, 2010 2:39 am
Reply with quote

Hi All..
I had formatted the code in this window.. starting next line after leaving 2 spaces , after an IF or Do statement .. but after postig .. ALL IZZ SAME..
Poor me !
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Apr 30, 2010 2:41 am
Reply with quote

Hello,

Suggest you practice with the "Code" tag - it will do what you want icon_smile.gif

Notice your last reply that contains code. . .
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri Apr 30, 2010 2:43 am
Reply with quote

Here are a few remarks (based on 1st post):

  1. Code:
    member = IN
    FILENAME="'"||'PRD.ME.('||MEMBER||')'||"'"
    Keep your code simple. This will give the same result (i assume the extra point is just a typo):
    Code:
    FILENAME = "'PRD.ME("IN")'"


  2. Code:
    OUTNAME = "'PRD.ME.OUT'"
    If you want "to put the data into a pds", then you should have a member name.

  3. Code:
    ADDRESS TSO
    "ALLOC DA("FILENAME") F(INDD) SHR REUSE"
    ADDRESS TSO
    "ALLOC DA("OUTNAME") F(OUTDD) MOD REUSE"
    The first ADDRESS TSO tells rexx "from now on, all commands unknown to rexx will be passed to TSO".
    The second ADDRESS TSO is redundant and useless (and most likely the first one is useless too, because that's the default).
    If OUTNAME is a PDS then you cannot have a MOD disposition.

  4. Code:
    DO WHILE DONE = 'NO'
      "EXECIO 1 DISKR INDD"
      IF RC = 0 THEN /* RECORD WAS READ */
      ... (your code here)
      ELSE
        DONE = 'YES'    /* IF RC \= 0 CLOSE PROCESSING */
    This is very complicated. If variable DONE is not assigned (and you didn't show us when and how you assign it) then you will do nothing.
    Again, Keep It Simple. This will give the same result (but faster):
    Code:
    Do Forever
       "EXECIO 1 DISKR INDD"
       If RC <> 0 Then Leave
       ... (your code here)
    End
    No need for a DONE flag. No need for ELSE sentence.
    You just have a unconditional loop, and once you've finished to read the file then you stop looping.

  5. Code:
    "EXECIO 1 DISKW OUTDD (RECORD"
    Does this means you are learning rexx all by yourself without opening the rexx reference book???

  6. Code:
    ELSE
            NOP
    Useless. Just remove that please.

  7. Code:
    "EXECIO 0 DISKW OUTDD (FINIS"
    If you take th time to close the output file, then do the same for the input file too:
    Code:
    "EXECIO 0 DISKR INDD (FINIS"


  8. Quote:
    putting in STEM i am scared might pull an unknown string
    If you use STEM then you don't use the stack (unless you are pulling my leg). Using STEM is easier than using the stack, specially if you try to use it (the stack) both for reading and writing.

  9. Quote:
    What I like to do is to move my 'good' data into an output stem variable, then write all of them at the end with a single EXECIO. ---- thats a good choice .. How can i do that plS ?
    you're lucky today, I'm in a good mood for some rexx! Here it comes:
    Code:
    /* Before the loop */
    outlines. = ''    /* empty output buffer */
    outcount = 0      /* currently 0 lines in output buffer */

    /* inside the loop, if the "record" is "good" */
    outcount = outcount + 1
    outlines.outcount = RECORD

    /* once the loop is finished */
    "EXECIO "outcount" DISKW OUTDD (STEM outlines. FINIS"


Seriously, it's your lucky day today. Do you know how much I usually charge for a session like this ?
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Apr 30, 2010 2:52 am
Reply with quote

What concerns me if I swear I've seen this almost exact same code before. I remember asking that member if he could tell me where he got that code from, which of course he never did. I hope this isn't coming from some publication or a text book.
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Fri Apr 30, 2010 2:55 am
Reply with quote

Hey Marso

Well, I must thank you for taking out time to correctly point out my mistakes. Appreciate it..

I take the charge part in light mode especially cause i got no personal message with an account number in it .. icon_lol.gif

And All this while I was using PDS and dataset words interchangeably. I am updating a dataset after reading a PDS member.

Thank you again.

I was bit in a hurry so manual printouts + the forum is what my domain is for now.. Next week, I'll dwell more into the manual.

Cheers
Sunny
Back to top
View user's profile Send private message
sunny_io

New User


Joined: 11 Jul 2007
Posts: 68
Location: noida

PostPosted: Fri Apr 30, 2010 2:59 am
Reply with quote

Hi superk

The code I pasted, is my own sweat .. no wonder it will smell salty icon_smile.gif
its also basic in approach as i feel. I used ELSE and NOP for every IF just like the manual says to do.. most publications avoid that in my view.

Regards
Sunny
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Run rexx with JCL Job CLIST & REXX 1
No new posts Run rexx in batch job CLIST & REXX 7
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
No new posts REXX/CMS How to place command console... CLIST & REXX 4
Search our Forums:

Back to Top