View previous topic :: View next topic
|
Author |
Message |
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
I got a requirement as below
I need to change(comment the line with comp-3 and add a line with comp-5) all the strings 'PIC S9(3) COMP-3' with 'PIC S9(4) COMP-5'
but this may not present in the same column.The value may present in different columns as below.
01 J PIC S9(3) COMP-3 VALUE ZEROS.
01 C PIC S9(3)COMP-3 VALUE ZEROS.
01 I-GR PIC S9(3) COMP-3 VALUE ZEROS.
01 I-HJ PIC S9(3) COMP-3 VALUE ZEROS.
01 X-T2 PIC S9(3) COMP-3 VALUE ZEROS.
01 kk PIC S9(6) COMP-3 VALUE ZEROS.
How to acheive this in an easiest way? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
I think that I would probably start with a search of the forum as this has been asked and answered quite a few times.
Quote: |
How to acheive this in an easiest way? |
That is all relative as I would go for a REXX/ISPF solution where someone else might consider a COBOL solution the easiest.
As you have posted in the REXX forum, what is your experience of REXX, are you a novice or accomplished, or expert. |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
I have developed few REXX tools. Could you please provide me the link in the forum where it's already discussed. So that I can get an idea to develop this tool. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi Kevin,
Please find below the source code i have developed in rexx for thie requirement.
Code: |
/* REXX */
SAY 'ENTER THE PDS NAME : '
PULL SRCPDS
SRCPDS = STRIP(SRCPDS)
TRGTPDS = SRCPDS
SAY 'ENTER THE ORIGINAL STRING: '
PULL SRCSTRNG
SAY 'ENTER THE REPLACEMENT STRING: '
PULL TRGSTRNG
IF SYSDSN("'"SRCPDS"'") /= "OK" THEN
DO
SAY "UNABLE TO FIND DATASET '"SRCPDS"'. PLEASE VERIFY."
EXIT
END
X = OUTTRAP("MEMLST.")
"LISTDS '"SRCPDS"' MEMBERS"
X = OUTTRAP("OFF")
SHOWLIST = 0
DO I = 1 TO MEMLST.0
IF MEMLST.I = "--MEMBERS--" THEN
DO
I = I + 1
LEAVE
END
END
CHANGED = 0
SKIPED = 0
DO INDX = I TO MEMLST.0
MEMBER = STRIP(MEMLST.INDX)
INPUTDAT = SRCPDS"("MEMBER")"
INP. = ""
OUT. = ""
"ALLOC DA('"INPUTDAT"') F(INPF) SHR REU"
"EXECIO * DISKR INPF (STEM INP. FINIS"
"FREE F(INPF)"
TRACE ?IR
STRFLAG = 0
DO I = 1 TO INP.0
SRCPOS = 1
DO WHILE SRCPOS > 0
SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
IF SRCPOS > 0 THEN
DO
SAY "INP.I:" INP.I
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
STRFLAG = 1
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
END
END
END
IF STRFLAG = 1 THEN
DO
OUTPUTDAT = TRGTPDS"("MEMBER")"
"ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"
"EXECIO * DISKW OUTF (STEM INP. FINIS"
"FREE F(OUTF)"
SAY "CHANGED " INPUTDAT
CHANGED = CHANGED + 1
END
ELSE
DO
SKIPED = SKIPED + 1
END
END
SAY ' TOTAL NO. OF MEMBERS CHANGED : ' CHANGED
SAY ' TOTAL NO. OF MEMBERS SKIPED : ' SKIPED |
The strings which I want to change is perfectly changed. But If the string which I'm searching is found then I need to write it in the file as commented line(* in column 7) and the next line with the changed string.
So the record where the searched string is found have to written twice. One with old string and commented. Second with changed string without commented.
Please let me know how to proceed on this?
Thanks in advance. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
instead of 'reading' the member,
i would invoke an EDIT session with an EDIT MACRO for the member.
usage of ISPF EDIT Macro Commands would easily enable the insert of additional lines,
whereas dealing with a stem, as in your current logic, is more cumbersome. |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
Could you please explain me in detail or posting the sample code for acheiving this requirement using ISPF EDIT Macro Commands |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
Read the ISPF Edit manual and study the FIND, LINE, and LINE_AFTER macro instructions. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
In the rexx program that you have already done, I would:
1. make a subroutine to process the reading, stem processing, inserting lines.
2. Call that subroutine from the loop that does the member names
3. In the subroutine, make a new stem... check each line at a time and if string is no is not found, copy from input stem to output stem. If it is found, do your comment / change logic for that line. |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
I have include one more stem and tryed to write the record in the file as bleo.But only the changed record is written in to the file and the other one is not writing.
IF SRCPOS > 0 THEN
DO
SAY "INP.I:" INP.I
INTER.I = INP.I
OUTPUTINT = TRGTPDS"("MEMBER")"
"ALLOC DA('"OUTPUTINT"') F(OUTE) SHR REU"
"EXECIO * DISKW OUTE (STEM INTER. FINIS"
"FREE F(OUTE)"
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
STRFLAG = 1
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
OUTPUTDAT = TRGTPDS"("MEMBER")"
"ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"
"EXECIO * DISKW OUTF (STEM INP. FINIS"
"FREE F(OUTF)"
END |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
You do not show the value of I, but likely you are not incrementing it.
Get a trace and analyze it. If you cannot figure it out, post the trace here. |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
I have modified my code as below ,but now i am hitting the below error .Please let me know what's wrong with the code.
24 +++ SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
Error running SRCHBKP1, line 24: Incorrect call to routine
***
source code:
SRCPOS = 0
DO I = 1 TO INP.0
"EXECIO * DISKW OUTF (STEM INP. "
SAY 'SRCSTRNG:'SRCSTRNG
SAY 'INP.I:'INP.I
SAY 'SRCPOS:' SRCPOS
SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
IF SRCPOS > 0 THEN
DO
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
OUT.J =INP.I
SAY 'OUT.J' OUT.J
"EXECIO * DISKW OUTF (STEM OUT. "
J = J + 1
END
END
"FREE F(OUTF)"
. . . . . . . . . . . . . . . . . . . . . |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Huh ....................... how can you specify a starting position of zero
No wonder you get an error. This is a true position not an offset. |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi,
I solved the problem.The offset(srcpos) must be a positive whole number. A syntax error will be raised if the offset is 0 |
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
SOURCE CODE:
Code: |
/* REXX */
SRCPDS = 'Z000089.GPI.OPT(OPT1)'
TRGTPDS = 'Z000089.GPI.OPT(OP2)'
SRCSTRNG = 'COMP-4'
TRGSTRNG = 'COMP-3'
INPUTDAT = SRCPDS
OUTPUTDAT = TRGTPDS
INP. = ""
OUT. = ""
J = 1
"ALLOC DA('"INPUTDAT"') F(INPF) SHR REU"
"EXECIO * DISKR INPF (STEM INP. FINIS"
"FREE F(INPF)"
"ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"
TRACE ?IR
SRCPOS = 1
DO I = 1 TO INP.0
"EXECIO * DISKW OUTF (STEM INP. "
SAY 'SRCSTRNG:'SRCSTRNG
SAY 'INP.I:'INP.I
SAY 'SRCPOS:' SRCPOS
SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
IF SRCPOS > 0 THEN
DO
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
OUT.J =INP.I
SAY 'OUT.J' OUT.J
"EXECIO * DISKW OUTF (STEM OUT. "
J = J + 1
END
END
"FREE F(OUTF)"
|
INPUT:
Z000089.GPI.OPT(OPT1)
----+----1----+----2----+-
**************************
RAJAN BOSE COMP-4
AISHWARYA COMP-4
Expected Output:
Z000089.GPI.OPT(OP2)
----+----1----+----2---
***********************
RAJAN BOSE COMP-4
RAJAN BOSE COMP-3
AISHWARYA COMP-4
AISHWARYA COMP-3
Current Output:
----+----1----+----2----+----
*****************************
RAJAN BOSE COMP-4
AISHWARYA COMP-4
RAJAN BOSE COMP-3
RAJAN BOSE COMP-3
AISHWARYA COMP-4
But Hitting RC=12 in trace as below
35 *-* END
19 *-* DO I = 1 TO INP.0
36 *-* "FREE F(OUTF)"
>L> "FREE F(OUTF)"
FILE OUTF NOT FREED, DATA SET IS OPEN
+++ RC(12) +++
Please help me out to overcome this issue. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
"EXECIO * DISKW OUTF (STEM INP. "
Would be better coded as ......................
"EXECIO * DISKW OUTF (STEM INP. FINIS" |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
You need to close the file before freeing it. Look at the syntax for the EXECIO command. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
I had the same thought as Expat, but a quick look at the program showed that you were doing EXECIO in a loop.
I believe you have a logic problem in your program. It appears you are writing the output file for each line of the input file, which I do not think you want to do. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
I thought you wanted to do an update-in-place, finding the string, commenting it out, and then adding the changed string. If that's still what you want, here's something a bit simplified:
Code: |
/* REXX */
THEPDS = 'Z000089.GPI.OPT(OPT1)'
SRCSTRNG = 'COMP-4'
TRGSTRNG = 'COMP-3'
"ALLOC DA('"THEPDS"') F(IO) SHR REU"
"EXECIO * DISKR IO (STEM INP. FINIS"
J = 0
DO I = 1 TO INP.0
PARSE VAR INP.I LFT (SRCSTRNG) RGT
IF LENGTH(RGT) = 0 THEN
DO
J = J + 1
OUT.J = INP.I
OUT.0 = J
END
ELSE
DO
J = J + 1
OUT.J = INP.I
OUT.J = OVERLAY('*',OUT.J,7,1)
J = J + 1
OUT.J = LFT||TRGSTRNG||RGT
OUT.0 = J
END
END
"EXECIO * DISKW IO (STEM OUT. FINIS"
"FREE F(IO)"
EXIT 0
|
|
|
Back to top |
|
|
srajanbose
New User
Joined: 11 Oct 2004 Posts: 69 Location: chennai
|
|
|
|
Hi Superk,
Thanks a Lot.It worked fine for me.If anyone want me to post the source code please let me know.
Again Thanks Superk |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Good to hear it is working - thank you for letting us know
If you used the code Kevin provided it would be good to mention this. Tf the code you used is different and you post the code you created explaining why your requirement changed the posted code it will help someone else some day. . . |
|
Back to top |
|
|
|