View previous topic :: View next topic
|
Author |
Message |
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
Data set to be updated is PS . |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
Thanks Much Ronald !! This is exactly what I was looking for . |
|
Back to top |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
milind suman Warnings : 1 New User
Joined: 19 Aug 2009 Posts: 55 Location: Pune
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|