Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

REXX data manipulation

REXX data manipulation

REXX data manipulation

Hello everyone I have a small rexx data manipulation issue. I have a huge file with a lot of information and I want to only print / save the my necessary information from the file.

CODE --> rexx

file = "my.dsn.to.file"                
"ALLOC FI(file) DSN('"file"') SHR"       
"EXECIO * DISKR file(STEM file. FINIS"   
"FREE FI(file)"                              
DO x = 1 TO file.0                       
   JNAME = SUBSTR(file.x,2,9)            
   DATE  = SUBSTR(file.x,20,10)          
   RC    = SUBSTR(file.x,94,4)           
   SAY DATE JNAME RC                                   

With this I will receive my wanted information, but now especially in the date I have multiple entries with the same date. Now I am confused how can I merge /purge them together? I tried to make an easy counter but it didn’t work quite like I wanted.

Could someone give me an hint or a direction?bigsmile

RE: REXX data manipulation

post example of data: what is your output now and what you want to achieve

RE: REXX data manipulation

Is it that you only want one entry per date, or do you want to have all entries for a given date shown together?

If you can provide a more precise 'spec', there are several followers here who can provide direction.

Frank Clarke
--America's source for adverse opinions since 1943.

RE: REXX data manipulation

I tried this:



file = "firedotwater.txt"                

my_cmd = "cat" file
my_cmd_queue = my_cmd "| rxqueue"
do i=1 while queued() \= 0
  parse pull file.i
file.0 = i-1

say "Reading all records from file """||file||""":"
dates = ""
fruits = ""
/* initialize stem for counting fruits on a date */
date_fruit_count. = 0
do x = 1 to file.0                       
   my_fruit = strip(SUBSTR(file.x,2,9))            
   my_date  = strip(SUBSTR(file.x,20,10))          
   my_rcx   = SUBSTR(file.x,94,4)           
   say my_date my_fruit my_rcx
   if wordpos(my_date, dates) = 0 then do
     dates = dates my_date   

   if wordpos(my_fruit, fruits) = 0 then do
     fruits = fruits my_fruit
   if date_fruit_count.my_date.my_fruit = 0 then do
      date_fruit_count.my_date.my_fruit = 1
   else do
      date_fruit_count.my_date.my_fruit = date_fruit_count.my_date.my_fruit + 1
/* Report */
say "Report:"
say "======="
say "Dates found :" dates
say "Fruits found:" fruits
say "Fruits found on given dates:"
do i = 1 to words(dates)
  my_date = word(dates, i)
  out_line = my_date||":"
  do j = 1 to words(fruits)
    my_fruit = word(fruits, j)
    my_fruit_count = date_fruit_count.my_date.my_fruit
    if my_fruit_count <> 0 then do
      out_line = out_line my_fruit||"=" my_fruit_count
  say out_line

With this given data file


>apple             2022-10-01                                                                RC01
 pear              2022-10-02                                                                RC02
 pear              2022-10-02                                                                RC03
 apple             2022-10-01                                                                RC04
 pear              2022-10-03                                                                RC05
 apple             2022-10-03                                                                RC06
 apple             2022-10-03                                                                RC07
 pear              2022-10-03                                                                RC08
 pear              2022-10-03                                                                RC09
 banana            2022-10-04                                                                RC10
 apple             2022-10-04                                                                RC11
 apple             2022-10-05                                                                RC12
 apple             2022-10-05                                                                RC13
 apple             2022-10-05                                                                RC14 

it gives this result:


$ rexx firedotwater.rex
Reading all records from file "firedotwater.txt":
2022-10-01 apple RC01
2022-10-02 pear RC02
2022-10-02 pear RC03
2022-10-01 apple RC04
2022-10-03 pear RC05
2022-10-03 apple RC06
2022-10-03 apple RC07
2022-10-03 pear RC08
2022-10-03 pear RC09
2022-10-04 banana RC10
2022-10-04 apple RC11
2022-10-05 apple RC12
2022-10-05 apple RC13
2022-10-05 apple RC14

Dates found :  2022-10-01 2022-10-02 2022-10-03 2022-10-04 2022-10-05
Fruits found:  apple pear banana

Fruits found on given dates:
2022-10-01: apple= 2
2022-10-02: pear= 2
2022-10-03: apple= 2 pear= 3
2022-10-04: apple= 1 banana= 1
2022-10-05: apple= 3 

RE: REXX data manipulation

Holy moly, wow that's impressive. That's exactly what I wanted.
Perfect, many thanks @mikrom!


RE: REXX data manipulation

@firedotwater: and did you understand how it works ?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close