replacing

shireeshn

Member
ABC is one database, in this database i have one table with same name ABC. I want to replace the database ABC with other DATABASE name AAA example :-1) find abc.def where abc.def.def-code = abc.ghi.def-code no-lock no-error.2) find abc.abc where abc.abc.def-code = abc.ghi.def-code no-lock no-error. after replacing it should be1)find AAA.def WHERE AAA.def.def-code = AAA.def.def-code = AAA.ghi.def-code AND AAA.ghi.def-code no-lock no-error.2)find AAA.abc WHERE AAA.abc.def-code = AAA.abc.def-code = AAA.ghi.def-code AND AAA.ghi.def-code no-lock no-error. This is an easy task but see below one AS we all know some times user will not enter the database with table then when he uses ABC table 3)find abc where abc.def-code = abc.ghi.def-code and abc.abc-desc = abc.ghi.ghi-desc no-lock no-error. After replacing it should be 3)find abc where abc.def-code = AAA.ghi.def-code and abc.abc-desc = AAA.ghi.ghi-desc no-lock no-error. last point i have a trouble, my code is below, can some one correct it or help me slove the last problem.IF INDEX(inLine," abc.abc ", " AAA.abc " ) > 0 THEN inLine = REPLACE(inLine," abc.abc " , " AAA.abc " ) .IF INDEX(inLine," abc.abc."," AAA.abc." ) > 0 THEN inLine = REPLACE(inLine," abc.abc.", " AAA.abc." ). for third point i want to write like this IF INDEX(inLine," abc." ) > 0 THEN inLine = REPLACE(inLine," abc.", " AAA." ). but it will replace the abc table also with " AAA." which is wrong iam geting like this which is wrong. 3) find abc where AAA.def-code = AAA.ghi.def-code and AAA.abc-desc = AAA.ghi.ghi-desc no-lock no-error. can any one help me in this, to get correct result as expected above.
 
Same question a bit formatted:

ABC is one database, in this database i have one table with same name ABC.
I want to replace the database ABC with other DATABASE name AAA example :
Code:
find abc.def where abc.def.def-code = abc.ghi.def-code no-lock no-error.
find abc.abc where abc.abc.def-code = abc.ghi.def-code no-lock no-error.
after replacing it should be:
Code:
find AAA.def WHERE AAA.def.def-code = AAA.def.def-code = AAA.ghi.def-code AND AAA.ghi.def-code no-lock no-error.
find AAA.abc WHERE AAA.abc.def-code = AAA.abc.def-code = AAA.ghi.def-code AND AAA.ghi.def-code no-lock no-error.
This is an easy task but see below one AS we all know some times user will not enter the database with table then when he uses ABC table:
Code:
find abc where abc.def-code = abc.ghi.def-code and abc.abc-desc = abc.ghi.ghi-desc no-lock no-error.
After replacing it should be
Code:
find abc where abc.def-code = AAA.ghi.def-code and abc.abc-desc = AAA.ghi.ghi-desc no-lock no-error.
last point i have a trouble, my code is below, can some one correct it or help me slove the last problem.
Code:
IF INDEX(inLine," abc.abc ", " AAA.abc " ) > 0 THEN inLine = REPLACE(inLine," abc.abc " , " AAA.abc " ) .
IF INDEX(inLine," abc.abc."," AAA.abc." ) > 0 THEN inLine = REPLACE(inLine," abc.abc.", " AAA.abc." ).
for third point i want to write like this:
Code:
IF INDEX(inLine," abc." ) > 0 THEN inLine = REPLACE(inLine," abc.", " AAA." ).
but it will replace the abc table also with " AAA." which is wrong iam geting like this which is wrong:
Code:
find abc where AAA.def-code = AAA.ghi.def-code and AAA.abc-desc = AAA.ghi.ghi-desc no-lock no-error.
can any one help me in this, to get correct result as expected above.
 
Now attempting an answer:

What are you actually trying to accomplish. It seems to me that you want to change the code so that it will also work an a database with another name? Is that correct?
Are the databases connected at the same time?

Why do you prefix the table names with the database qualifier in the first place. If you hadn't and only the database name changed then a recompile would be sufficient.

But ok, first I would like to now why you want to do this...

Casper.
 
Note that this also duplicates another thread which starts out with better formatting. Perhaps we should continue there.
 
thanks casper for formatting.. :)


iam working on 9.1D version.

iam moveing all the tables from one database to other, if i want to change the source code of this will be manual work. so iam trying to make by code.

like all the tables of ABC database will be moved to AAA database.

main problem is ABC database has table with same name ABC only, i should not replace this table ABC with AAA. :(

i am struck at third point. so i want help from all.
 
@Tamhas, I think It is just as easy to go further here.

@shireeshn:

I think it is more easy to just skip the database reference and do a global replace of abc. for nothing. That is easy to accomplish using tools like sed.

IMO it is not good practice to use database qualifiers on table names.

Casper.
 
There are times when one has no choice but to use a DB qualifier, but I tend to design to avoid such situations. So, Casper is right here that your first question should be to ask yourself whether the qualifier is required or useful. If not, then get rid of it.

If required, you should also be asking yourself if you can accomplish your requirement with aliases instead of changing code.

Whether changing it or getting rid of it, sed and the like need to be approached with caution because they are not aware of ABL syntax and so will merrily change variable names, comments, quoted strings, etc. that match your replacement. I have a good sed tool, if you are on a *nix platform, which provides a side by side preview of the change that will be made prior to running the script for a final change.

But, ultimately, the best place to do this sort of thing is with Proparse and ProRefactor since they are aware of ABL syntax.
 
sed is a *nix utility for search and replace according to scripts. Available under Windows with one of the Unix toolsets.
 
There are many tools to do this sort of thing.

But you would be well served to spend some time carefully explaining what it is that you are really trying to do.

By explaining what you are doing beyond the need to replace strings you will enable us to suggest other, possibly much better, approaches to the problem.

For example -- it might be that your original database name is "abc" and your source refers to "abc.customer". And perhaps someone has renamed the physical database to "xyz". You can easily solve this problem by using a logical database name at session startup. Just add "-ld abc" to your client startup.

That was just one example. It may not be your situation. You have not explained your problem adequately enough for me to know. There are many other scenarios and many other possible approaches to problems that involve dbname.tablename and very few of them are efficiently solved by global search and replace operations.
 
Back
Top