Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Find the key in other file and replace by found value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Thu Feb 04, 2010 5:29 pm    Post subject: Find the key in other file and replace by found value
Reply with quote

How can i do this by dfsort/icetool ,
I have to edit a file A wherein a variable from File A has to be checked in File B (table ), If it is found in file B ..the variable has to be replaced by the value found in File B .

File A - FB , Reclength = 80
The variables are varying length , delimited by ( , or spaces )

File B - FB , Recl = 80

Code:

File A :

123456789101112131415161718
     ,var0,var1,var2   
             variable3,var4


File B :

123456789101112131415161718
var1              ws-A-variable1
variable3         ps-b-var3


Output :
 
123456789101112131415161718
     ,var0,ws-A-variable1,var2
             ps-b-var3,var4
Back to top
View user's profile Send private message

Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Feb 04, 2010 11:07 pm    Post subject:
Reply with quote

milind suman,

Does each key have 3 records? The replacing string is bigger than the search string. Do you truncate the record if it goes past 80?

What is the max number of records in file B?
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Thu Feb 04, 2010 11:49 pm    Post subject:
Reply with quote

Skolusu ,

Each record can have more than 3 keys ..Infact every string delimted by ( Comma or space ) has to be searched in File B .

File B has more than 500 entries .
Truncation chance are rare ..as replaced string will be of almost same length .
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Feb 04, 2010 11:52 pm    Post subject: Reply to: Find the key in other file and replace by found va
Reply with quote

is this some kind of data/variable naming normalization ?

the dataset to be changed is it a PS dataset or You have to change multiple members of a PDS?

in the first case a sort solution could be adequate,
in the second case a quick and dirty edit macro might yield better results
( more flexibility for line length overflow )
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Thu Feb 04, 2010 11:56 pm    Post subject:
Reply with quote

ya Enrico..its data variable normalization . The current data/variables defined in the program has to be replaced by a new name . The program has variables > 1000 . My second file (B) has two columns ( old name and new name of the variables ) ..

I need to check the variable from File(A) ..in B and replace with new one .

Data set is PS
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Feb 04, 2010 11:59 pm    Post subject: Reply to: Find the key in other file and replace by found va
Reply with quote

You did not answer the main question,
You want to update a single PS dataset or the members of a partitioned dataset...
the approach would be different!
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Fri Feb 05, 2010 12:00 am    Post subject:
Reply with quote

Data set to be updated is PS .
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Feb 05, 2010 3:59 am    Post subject:
Reply with quote

If the files are small enough that you could EDIT a concatenation of both files together, the following REXX Exec could be used to accomplish your goal. Mind you, it will essentially run two CHANGE ALL edit commands against the entire set of File-A records for EACH variable found in file-b. Note well that the macro makes two assumptions: 1) none of the variables to be replaced ( first column in fileB ) contain embedded spaces; and 2) IF the replacement string is longer than the search string, the data following the search string will be shifted to the right in order to accommodate the longer replacement string.

As always, make a backup copy of your file before you test any solution - just in case...

Code:

/* REXX */                                                             
   ADDRESS ISPEXEC                                                     
    "CONTROL ERRORS RETURN"                                           
    "ISREDIT MACRO"                                                   
    "ISREDIT (LA) = LINENUM .ZLAST"   /* LA = last line of File-A    */
    "ISREDIT COPY 'your.fileb.dsname' AFTER .ZLAST" /* Concat File-B */         
    "ISREDIT (LB) = LINENUM .ZLAST"   /* LB = last line of File-B    */
    IF CL = LL THEN                   /* If File-B was empty,        */
       DO                                                             
          SAY "FILE-B WAS EMPTY"      /* Display error message       */
          EXIT                        /*    and exit                 */
       END                                                             
    "ISREDIT LABEL " LA " = .LA"      /* .LA = last line of File-A   */
    CL = LA + 1                       /* CL (current line) = LA + 1  */
    FB = CL                           /* FB = first line of File-B   */
    DO UNTIL CL > LB                  /* Do until current line > last*/
       "ISREDIT (CLINE) = LINE " CL   /* CLINE = current line data   */
       LC = RC                                                         
       SVAR = WORD(CLINE,1)           /* SVAR = search string        */
       TVAR = WORD(CLINE,2)           /* TVAR = replacement string   */
       XVAR = WORD(CLINE,3)           /* XVAR = test for error       */
       IF XVAR ¬= "" THEN             /* if XVAR is not null,        */
          DO                          /*    display an error msg     */
             SAY "A STRING AT LINE " CL "CONTAINS EMBEDDED SPACE(S)"   
             SAY "DO NOT SAVE EDITED DATASET - FIX FILE-B AND RERUN"   
             EXIT                     /*    and exit                 */
          END                                                           
       IF SVAR = "" OR TVAR = "" THEN /* if either null, its an error*/
          DO                          /*    display an error msg     */
             SAY "SEARCH OR TARGET STRING MISSING AT LINE " CL         
             SAY "DO NOT SAVE EDITED DATASET - FIX FILE-B AND RERUN"   
             EXIT                     /*    and exit                 */
          END                                                         
       ELSE DO                                                         
          SVARC = SVAR || ","         /* SVARC = SVAR + COMMA        */
          SVARS = SVAR || " "         /* SVARS = SVAR + SPACE        */
          TVARC = TVAR || ","         /* TVARC = TVAR + COMMA        */
          TVARS = TVAR || " "         /* TVARC = TVAR + SPACE        */
    "ISREDIT CHANGE" "'"||SVARC||"'" "'"||TVARC||"'" ".ZFIRST .LA ALL"
    "ISREDIT CHANGE" "'"||SVARS||"'" "'"||TVARS||"'" ".ZFIRST .LA ALL"
          CL = CL + 1                 /* BUMP CL: POINT TO NEXT LINE */
       END                                                             
    END                                                               
    "ISREDIT DELETE ALL " FB ".ZLAST" /* DELETE THE FILE-B LINES     */
    EXIT                                                               
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Fri Feb 05, 2010 9:50 am    Post subject:
Reply with quote

Thanks Much Ronald !! This is exactly what I was looking for .
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Fri Feb 05, 2010 5:12 pm    Post subject:
Reply with quote

Hi Ronald ,

While running this REXX I am getting an error :

[code]
14 +++ CL = LA + 1 /* CL (CURRENT LINE) = LA + 1 */
IRX0041I Error running ROUGH, line 14: Bad arithmetic conversion
***
[/code
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Fri Feb 05, 2010 5:31 pm    Post subject: Reply to: Find the key in other file and replace by found va
Reply with quote

what Ronal posted is a SAMPLE
If You choose to use it the assumption is that You have the basics skills to understand it
and do some basic debugging!
this is a help forum, not a do it for me!

the script is simple enough to run it with "trace on" and see what is happening!
no obligation on Ronald' s side to follow up with debugging
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Feb 05, 2010 6:47 pm    Post subject:
Reply with quote

Milind,
I TESTED the code before I posted it, using the sample file contents you provided, and it worked just fine. If you re-typed the code I provided, rather than doing a cut/paste, it is likely that you made an error during the process. There is also the possibility that you have numbering on and are getting an error because of superfluous data to the right of an exec stmt.
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Mon Feb 08, 2010 1:10 pm    Post subject:
Reply with quote

Hi Ronald ,

I am new to rexx and am not sure if i missed something . I copied the rexx code given by u as such and trying to run it thru jcl here is the jcl :
Code:

//STEP1    EXEC PGM=IRXJCL,             
//           PARM='ROUGH'               
//SYSEXEC  DD DSN=abc.rexlib,DISP=SHR   
//SYSTSPRT DD SYSOUT=A                 
//SYSTSIN  DD DUMMY                     


and here is the dump :

Code:

     3 *-* "CONTROL ERRORS RETURN"                                             
       +++ RC(-3) +++                                                           
     4 *-* "ISREDIT MACRO"                                                     
       +++ RC(-3) +++                                                           
     5 *-* "ISREDIT (LA) = LINENUM .ZLAST"   /* LA = LAST LINE OF FILE-A    */ 
       +++ RC(-3) +++                                                           
     6 *-* "ISREDIT COPY 'T6QJPNK.TEST.PGM3'  AFTER .ZLAST"                     
       +++ RC(-3) +++                                                           
     7 *-* "ISREDIT (LB) = LINENUM .ZLAST"   /* LB = LAST LINE OF FILE-B    */ 
       +++ RC(-3) +++                                                           
    13 *-* "ISREDIT LABEL " LA " = .LA"      /* .LA = LAST LINE OF FILE-A   */ 
       +++ RC(-3) +++                                                           
    14 +++ CL = LA + 1                       /* CL (CURRENT LINE) = LA + 1  */ 
IRX0041I Error running ROUGH, line 14: Bad arithmetic conversion     
           


could you please suggest me what could have possibly wrong in my jcl ?

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

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Mon Feb 08, 2010 1:25 pm    Post subject: Reply to: Find the key in other file and replace by found va
Reply with quote

Code:
//STEP1    EXEC PGM=IRXJCL,       


You are trying to run it as a pure REXX!

You need to run it as a BATCH ISPF application.

search the forums or ask Your support how to do it

but but but the sample as provide will run as an edit macro,
it means, open the dataset with ISPF EDIT and in the edit command line enter the name under which You have saved the script

to run it as a batch needs a bit of additional work!
Back to top
View user's profile Send private message
milind suman
Warnings : 1

New User


Joined: 19 Aug 2009
Posts: 55
Location: Pune

PostPosted: Mon Feb 08, 2010 1:41 pm    Post subject:
Reply with quote

I tried to execute with "tso exec 'dataset of rexx' on the (to edit) the file , but its failing ..it seems I am not able to execute any line of code ..as even deleting the FILEB gives the same error on line 14 ( bad arithmetic) ..I have cheked the possibilty of any junk data on right column as well .
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Feb 08, 2010 8:09 pm    Post subject:
Reply with quote

Hello,

Quote:
it seems I am not able to execute any line of code
Suggest you create a very simple rexx exec to show that you can actually execute something that you have created in your current setup.

You may need to work with your support people to use a different logon procedure when you sin on to tso/ispf. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us