View previous topic :: View next topic
|
Author |
Message |
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi,
I have an edit macro which is used to replace a particular string in all PDS members and the inputs are given through a user panel.
This is working fine till this point. But, when the length of the line extends more than 80 after the CHANGE command, it throws an error and this can be captured and handled by some means.
My question here is, when the line extends in between 72 to 80, it is simply writing there. As the code should be present within the first 72 bytes, how can I handle this situation?
Thanks in advance
Regards,
Suresh.
PS: I dint find any related topics in the forum, so putting a query here. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Check the length of the line before rewriting it then take necessary actio e.g splitting the line. |
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi Nic,
I was thinking in doing the way you suggested. But, while doing this way I can not use CHANGE command rather I need to find the string first, then replace the string (may be I have to write a funtion to get the linedata into a varible and replace the stringin the variable) and get the length of the line after the replace and then split. So, i am thinking it is not an efficient way of doing this. Please suggest me if there is any other way to acheive this?
Thanks,
Suresh. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Not able to test right now, but I'm pretty sure the return code from the change command will be non-zero if it cannot change every occurrence of a string. Only in that case you would need additional processing. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
one of the problem with creating tools is that there are exceptions to be handled.
File-aid edit/change presents the before image,
the probable after image
and gives you an opportunity to intervene.
in your case it seems that you are going to do all the processing under the covers
thus, you have to insure that everthing that you change is correct.
the are ISPF EDIT macro commands that you can use to find 'CHG'd records/lines and also 'ERR' records/lines.
A couple of methods that I use are:- do the global change
- then locate each 'ERR' line
- use DATALINE to interrogate the result and determine what needs to be done.
- find all targets beyond the column that will allow for a change
- TEXTSPLIT and position the target on the new line
- global change
|
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi Dick,
Thank you very much for the elaborated reply.
This is what I understood from your suggestions.
1. First global change.
2. Then find the changed (CHG’d) and error out (ERR) records using edit commands.
3. For the CHG’d records,
Check the if any alphabetic character is present in 72 – 80 columns of that particular line, then split it accordingly.
Where to split? (May be I have to think about the logic again).
4. For the ERR’d records,
Split the linedata (?) and then use change command again.
Please let me know if my understating is correct.
Thanks,
Suresh. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
no.
either
1 do the global,
2 fix err
or
1 find where error could occur - target beyond column that allows for error free change
2 create additional line in order to avoid error
3 then do global change |
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi Dick,
In the first method you suggested,
We may miss the case where the line exceeds 72 length but not 80, as it would not give any error.
In the second method,
Finding the error where the error could occur is a big task.
In this case, I have to get each line which has this string, then get line data into a variable and then
replace the string and see if the line exceeds the 72 positions using an user function.
This would result in a lot of time taking process.
Thanks,
Suresh. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Sheesh, do you have anything in 72-80? If so, have your boundary up to 80 and "pretend" for your code that 80 is 72 when people (including you) have referred to it in this topic.
If you know what you are replacing, and with what, you know both lengths. You calculate how much it extends the line by. You see if that is past your end-of-line-boundary. That tells you to split the line if so. No biggie at all.
Else, method 1. If boundary at 72 you'd get the ERR for trying to extend beyond. Same with 80, just a different number. The ERR tells you which line to split, and do the change again (will now work).
If all data is within your boundaries, then everything will work as stated. If it isn't then, obviously, it won't - but that is your fault. |
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi Dick/ Bill,
I got the answer. I can keep the bounds as 72 and which would take care of all the issues here.
Thanks a lot for your responses. Sorry it took me some time to understand it clearly.
Regards,
Suresh. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Suresh,
Code: |
target = "data to be changed"
len_target = length(target)
col_not_to_exceed = 72 - len_target
find target first
find_rc = rc
do until find_rc <> 0
(line,col) = cursor
if col > col_not_to_exceed then call split_the_line_routine
FIND target next
find_rc = rc
end
|
not so hard if you use the available commands. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
Quote: |
Finding the error where the error could occur is a big task. |
If you have a complex task, expect that the coding will also be somewhat complex. But as Dick's example shows, it only takes about 10 lines.
Quote: |
This would result in a lot of time taking process. |
Can you define 'a lot'? It all really depends on the size of your file. If you are worried about performance, you probably would not be using the editor for this. |
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi all,
At last, I have completed the macro with your guidance. Thank you very much!!!
This macro does the string replacement in pds members and also does the splitting if needed, for any type of elements like cobol, JCL etc along with some extra features like exclude comments and word string. The macro gets the input from the user panel as below:
Code: |
---------------------DATA STRING REPLACE TOOL--------------------------
COMMAND ====> ________________________________________________________________
DATE- 11/07/28
TIME- 08:01
ENTER THE LOCAL PDS FOR DATA STRING REPLACE:
_____________________________________________________________
OLD STRING : ________________________________________________
NEW STRING : ________________________________________________
EXCLUDE COMMNETS : N_ WORD STRING : N_
(Y - YES, N - NO)
MESSAGE:
ENTER = (PROCESS) PF3 = (END) |
Now, I wanted to add one more feature to it like if user wants to select some of the members in the PDS, not all the members for string replacement.
Is there any way to pop up the member selection panel (3.4 members display panel) from macro and get the control back to macro with the selection criteria and process them?
Thanks in advance. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
I think technically, that you can do what you say you want. But the way you describe it is awkward.
I think you need two programs. The application stack should look like this:
your_member_list -> Editor -> your_macro
See LMMDISP in the ISPF Services Guide. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Stick your member list into an ISPF table. The user can then select those members required to be updated. |
|
Back to top |
|
|
smoningi
New User
Joined: 14 Jul 2011 Posts: 8 Location: Hyderabad, INDIA
|
|
|
|
Hi Nic,
I don’t have any idea about how to set up the user defined ISPF tables, display them in panels to get the user input and capture the inputs back in the macro. Do we have any specific online materials to refer on this topic? I even not able to search them on the forum. Can you please help me on this?
TIA |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Do it the way I did, manual, model, other applications, trial-and-error. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
Quote: |
Stick your member list into an ISPF table. The user can then select those members required to be updated.
|
Or you could use the LMMDISP which will get the member names and put them into an ISPF table. The user can then select those members required to be updated.
You have to write the logic for the line commands that you support. |
|
Back to top |
|
|
|