View previous topic :: View next topic
|
Author |
Message |
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
Hi All,
Can someone please help me writing a edit macro to replace a value in a file at particular column in a line ?
If I am not clear above...
I need to put a 4 digit value in a line at particular postion in a flatfile. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
What have you got so far? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
for a flat file, a better term would be PS, the best approach would be to use
Your sort product
if You search the forums You will find lots of examples on how to do it |
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
i have found a INSERT function..but that may give what i want..OVERYLAY did not help..so thought of going to macro.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If you need to put a value in the same place in some file, you might consider using your sort product rather than a macro. . .
Possibly, i misunderstand. . . |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
A good place to start is to figure out what the EDIT command or commands are that you issue manually to do what you want. I'm thinking that you need to look at the CHANGE command ... |
|
Back to top |
|
|
MBabu
Active User
Joined: 03 Aug 2008 Posts: 400 Location: Mumbai
|
|
|
|
Just curious... why is using SORT the "best approach"? What possible criteria could make that statement true?
The file might be small, it might be a 1 time thing, it could be that there are thousands of replacements that need an algorithm to determine (poorly defined requirements such as this one are often much more involved than the original question lets on). From the description, a single edit command (" C XXXX YYYY 5") might be all that is needed. No macro, no cryptic control cards, no programming and it would take about 0.05 seconds to run.
Sorry -- pet peeve. I know that SORT is frequently given as an answer here, but that does not make it the "best approach", only the most familiar to the posters (as edit macros are most familiar to me). |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
Quote: |
Just curious... why is using SORT the "best approach"? What possible criteria could make that statement true? |
the PS organization
asking for an edit macro without telling anything more
( my assumption was for a repetitive requirement)
but I agree, depending on the requirement the alternative would be different
1) one shot and forget about it ==> sequence of ISPF commands
2) repetitive task
-- a sort approach .. because of better support and possible skill availability in the organization
-- a RYO approach ( EDIT macro in this case ) has to be written, tested, documented, deployed, mantained
-- pet peeve if somebody has chosen a tool it means that he has the competence for having
evaluated all the alternatives ( skill availabilty included ) and should not need to ask anybody on how to do it
-- too many times REXX scripts have been provided and the TS was not able to carry on without further help
-- many samples of the solution of the same problem on the sort forums
by the way I tend to use edit macros too, faster to write an edit macro than to look at the sort manuals! |
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
MBabu wrote: |
Just curious... why is using SORT the "best approach"? What possible criteria could make that statement true?
The file might be small, it might be a 1 time thing, it could be that there are thousands of replacements that need an algorithm to determine (poorly defined requirements such as this one are often much more involved than the original question lets on). From the description, a single edit command (" C XXXX YYYY 5") might be all that is needed. No macro, no cryptic control cards, no programming and it would take about 0.05 seconds to run.
Sorry -- pet peeve. I know that SORT is frequently given as an answer here, but that does not make it the "best approach", only the most familiar to the posters (as edit macros are most familiar to me). |
Hi Babu,
Thanks for your help..edit command (" C XXXX YYYY 5") will help if I know what is there in the file in that position..however i donot have that data. I just need to open the file and put( replace) my data in that position.
Regards |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
Thanks enrico,
This served my purpose. Thanks a lot.
regards |
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
I am facing another hurdle in edit macro..dont know i can continue with the last topic.
Here is my macro..
/* REXX */
ADDRESS ISPEXEC
"VGET (XXX) PROFILE"
ADDRESS ISREDIT
"MACRO"
"CHANGE P'====' '"XXX"' 4 7"
"SAVE"
"END"
"SET XXX = XXX + 1"
EXIT
I need to increment the value of XXX variable everytime at the end of the macro. XXX value is captured from a panel initially. I used SET command which I know. however I am getting error message " MAC1 MACRO ERROR".
Please someone throw some light on this.
Thanks in advance |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
XXX = XXX + 1
XXX = 0
XXX = 'a literal string' |
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
expat, I am really sorry i could not understand your suggestion. are you asking me to try xxx = xxx + 1 ? I have tried that..but no luck. I got a the same error..
please explain how I can use XXX = 0 and XXX = 'a literal string' for my requirement |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Have you run the macro using trace to see what is happening.
Use TRACE I to get the maximum details. |
|
Back to top |
|
|
sparrow
New User
Joined: 26 Mar 2007 Posts: 57 Location: Pune
|
|
|
|
expat, I used TRACE I ..
It opened my file in edit mode, CHANGE command is executed and it stopped there. " SAVE" and " END" is not executed and when use PF3 to close the file, the next step executes. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
/good mood on!
here is a macro I wrote some time ago ,
I called if XRENUM ( eXtended RENUMber )
the invocation format is ...
Code: |
XRENUM <string> / <the usual find replace parms>
XRENUM <string> <from>/ <the usual find replace parms>
XRENUM <string> <from> <incr> / <the usual find replace parms> |
here ids the shebang
Code: |
/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
Trace "O"
Parse Source _system _called _commnd .
parse upper arg zparms
_parms = 1
_endms = 1
_ispex = 1
_macro = 1
_inner = 0
_errmsg = ""
zretc = 0
zerrsm = ""
zerrlm = ""
zerralrm = "YES"
zerrhm = "ISR2MACR"
call $init
parse upper var zparms tokn from incr "/" zparms
if incr = "" then ,
incr = 1
if from = "" then ,
from = 1
leng = length(tokn)
from = right(from,leng,"0")
if ( 0 /= $isred("SEEK '"tokn"' FIRST " zparms ) ) then do
zerrsm = "- Not Found"
zerrlm = left(_commnd,8)"- No Occurrences of '"tokn"' Found"
zretc = 4
call $term
exit 1
end
coun = 0
do while ( 0 = $isred("CHANGE '"tokn"' '"from"' NEXT " zparms ) )
from = from + incr
from = right(from,leng,"0")
coun = coun + 1
end
zerrsm = "Renum("coun") "
zerrlm = left(_commnd,8)"- "coun "Occurrences of '"mask"' Changed"
zretc = 0
call $term
Exit
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Standard %Include Start */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*%incdone $init */
/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
$init:
trace "O"
if _macro then ,
_ispex = 1
if _ispex then do
If Sysvar(SYSISPF) /= "ACTIVE" Then Do
Say left(_commnd,8)"- Ispf is not active"
Exit 4
End
call $ispex "CONTROL ERRORS RETURN"
if $isred("MACRO (ZPARMS) NOPROCESS ") = 0 then do
if _inner then ,
call $ispex "VGET (ZPARMS) "
zparms = translate(strip(zparms))
_macro = 1
end
else do
if _macro then do
zerrsm = left(_commnd,8)"- Invocation ERROR"
zerrlm = left(_commnd,8)"- Must be invoked as edit macro"
call $ispex "SETMSG MSG(ISRZ002) "
Exit 1
end
end
zparms = strip(zparms)
If _parms & ,
zparms = "" Then do
zerrsm = left(_commnd,8)"- Missing Parameter"
zerrlm = left(_commnd,8)"- 'H' For Help, Or .........."
call $ispex "SETMSG MSG(ISRZ002) "
Exit 1
end
if zparms = "?" | ,
zparms = "H" | zparms = "HELP" Then do
z_rc = $ispex("DISPLAY PANEL("zerrhm") ")
exit 1
end
end
return
/*%incdone $term */
/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
$term:
trace "O"
if zretc /= 0 then do
zerralrm = "YES"
if zerrsm = "" then ,
zerrsm = left(_commnd,8)"- Rc("zretc")"
if zerrlm = "" then ,
zerrlm = left(_commnd,8)"- Rc("zretc") :" || _errmsg
call $ispex "SETMSG MSG(ISRZ002) "
end
else do
if _inner then do
call $isred "SAVE "
call $isred "END "
end
if _endms then do
zerralrm = "NO"
if zerrsm = "" then ,
zerrsm = left(_commnd,8)"- Ended"
if zerrlm = "" then ,
zerrlm = left(_commnd,8)"- Ended With Rc("zretc") "
call $ispex "SETMSG MSG(ISRZ002) "
end
end
return
/*%incdone $tsoex */
$tsoex:
trace "O"
Address TSO arg(1)
tso_0rc = rc
return tso_0rc
/*%incdone $ispex */
$ispex:
trace "O"
Address ISPEXEC arg(1)
isp_0rc = rc
return isp_0rc
/*%incdone $isred */
$isred:
trace "O"
Address ISREDIT arg(1)
isr_0rc = rc
return isr_0rc
/*%incdone $$end */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Standard %Include end */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
Quote: |
I need to increment the value of XXX variable everytime at the end of the macro. |
You use VGET, which is good. But your SET instruction is not valid. It is a rexx instruction, not an editor instruction. Do not use quotes. and use VPUT to save it for next time.
Code: |
xxx= xxx+1
Address ISPEXEC "VPUT (xxx) PROFILE" |
|
|
Back to top |
|
|
|