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

Processing stem with some 1000 entries.


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

New User


Joined: 19 May 2007
Posts: 25
Location: Chicago

PostPosted: Thu Dec 04, 2008 7:49 am
Reply with quote

Hello folks.

I have problem to solve and would like your input please.

I have a stem with some 1000 entries. Each entry is only 8 bytes each. Its a list of applids from CL/Stupersession.

Anyway. What I want to do is create a target stem which has only unique applids and a second stem that has a count of the applid from the original.

like so.

Source stem
a.1 = TSO
a.2 = NDM
a.3 = TSO

Target stems
b.1 = TSO
b.2 = NDM

c.1 = 2 (two tsos in source stem)
c.2 = 1

any suggestions would be greatly appreciated.

thanks in advance
rp
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Dec 04, 2008 9:31 am
Reply with quote

Cigar,

Quote:
I have a stem with some 1000 entries.


How was this stem populated? If it was populated by reading an input file then

- Invoke DFSORT from REXX to eliminate the duplicates and to get the count.

AFAIK coding logic in REXX is difficult for this requirement.
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 400
Location: Mumbai

PostPosted: Thu Dec 04, 2008 9:33 am
Reply with quote

use the facts that you can set a default stem's default value and that the tails of rexx stems do not need to be numbers. No comments in the code because figuring it out is a good exercise. For example, it uses stems to contain indices into other stems. If you use these techniques in code others will maintain, add GOOD comments though because at first glance, it is indecipherable.
Code:
/* make some test data  */

a.0 = 4000
do i = 1 to a.0
  if random(100) < 30 then
    a.i = 'TSO'
  else
    a.i = 'NDM'
end

cindex = 0

/* create the stems. b is unique values, c is counts  */

knownvalues. = "not set"
knownvaluecount = 0
c. = 0
b. = 0

do i = 1 to a.0
  val = a.i
  if knownvalues.val == "not set" then
    do
      knownvaluecount = knownvaluecount + 1
      knownvalues.val = knownvaluecount
      b.knownvaluecount = val
      b.0 = knownvaluecount
      cindex = knownvaluecount
    end
  else
    cindex = knownvalues.val
  c.cindex = c.cindex + 1
end
c.0 = knownvaluecount

/* print the results  */

do i=1 to b.0
  say "b." || i || "=" || b.i
end
do i=1 to c.0
  say "c." || i || "=" || c.i
end

do i = 1 to b.0
  count = c.i
  say "there are "c.i" instances of "b.i
end

example output
Code:
b.1=NDM
b.2=TSO
c.1=2831
c.2=1169
there are 2831 instances of NDM
there are 1169 instances of TSO
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Dec 04, 2008 9:53 am
Reply with quote

Mbabu,

Thanks for the code. It would be great if you can explain us the logic in few words.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 04, 2008 10:09 am
Reply with quote

Hello,

Please read the words above the code. . .

Quote:
No comments in the code because figuring it out is a good exercise.
Part of the contribution was the opportunity for some to learn, not just grab and run icon_wink.gif
Back to top
View user's profile Send private message
cigarman

New User


Joined: 19 May 2007
Posts: 25
Location: Chicago

PostPosted: Thu Dec 04, 2008 10:36 am
Reply with quote

Arau: Thanks for the comment. I will keep DFSORT in mind for future code.

Mbabu: This is really good stuff. I will dig into it tomorrow, but I think its exactly what I'm looking for. At a quick glance, it looks cool. I will have to go through it line by line to understand.

Thanks to both or you.

rp
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu Dec 04, 2008 11:16 am
Reply with quote

a quick and dirt google with "rexx stem sort" gave..

www.markcrocker.com/rexxtipsntricks/rxtt28.2.0475.html
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Dec 04, 2008 3:28 pm
Reply with quote

Dick,

Quote:
Part of the contribution was the opportunity for some to learn, not just grab and run


Had i just wanted to Grab and run i would not have asked for an explanation icon_biggrin.gif . I would have executed it as such.

Anyways as per your suggestion let me take a look at it.
Back to top
View user's profile Send private message
cigarman

New User


Joined: 19 May 2007
Posts: 25
Location: Chicago

PostPosted: Fri Dec 05, 2008 7:25 am
Reply with quote

Mbabu:

This is perfect. Does exactly what I need. I went through it line by line. Desktop debugging shows me where the vars are going, but I still really don't know how its working. What would be a the term for what is going on here so I may look it up.

Thanks

rp
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 400
Location: Mumbai

PostPosted: Sat Dec 06, 2008 7:58 am
Reply with quote

Here are comments on the relevant lines. I moved one line out of the loop for efficiency and clarity.
Code:
cindex = 0

/* Create the stems. B is unique values, C is counts.               */
 
/* Known values will contain a running list of values read from stem
   a.  We will check to see if a value is known by using the value as
   a tail named v Knownvalues.Val will return the tail, Of the
   corresponding stems b and c.  If The string "Not set" Will be
   returned and a new slot (Tail) Will be allocated
                                                                    */
knownvalues. = "not set"
/* Known value count is the index or tail number for b and c used
   for the last new value  found in a.                              */
knownvaluecount = 0
/* B is the list of values and c the number of entries for that value*/
c. = 0
b. = 0
   /* Read stem values of a                                         */
Do i = 1 to a.0
  val = a.i          /* We'll use the value as a tail in other stems */
   /* See if the value is known already                             */
  If knownvalues.val == "not set" Then /* Value is not known        */
    Do
      /* Get a new index for stems b and c to hold info on value    */
      knownvaluecount = knownvaluecount + 1
      /* Save value as next entry in knownvalues                    */
      knownvalues.val = knownvaluecount
      /* Save actual value in stem b at next index                  */
      b.knownvaluecount = val
      /* Set cindex to new index value                              */
      cindex = knownvaluecount
    End
  Else                         /* Value is already known            */
    cindex = knownvalues.val
  /* Update the count using the existing tale for this value cindex */
  c.cindex = c.cindex + 1
End
   /* Since knownvalue count is the value of the last used stem,
      We can use it to set the zero tail of b and c for future
      reference                                                     */
b.0 = knownvaluecount
c.0 = knownvaluecount
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sat Dec 06, 2008 8:17 am
Reply with quote

Thank you icon_cool.gif

d
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 STEM usage in REXX CLIST & REXX 14
No new posts Fault Analyzer not producing entries ... IBM Tools 19
No new posts passing stem variable with VPUT/VGET ... CLIST & REXX 6
No new posts icetool empty file and not empty file... DFSORT/ICETOOL 5
This topic is locked: you cannot edit posts or make replies. Parsing more than 1000 columns in a s... SYNCSORT 10
Search our Forums:

Back to Top