Page 1 of 1

Matching Column names

PostPosted: Tue Jun 23, 2015 4:43 pm
by Arunz
Hi,

Is there any way to match the column names between two tables.

EMP:
EMP_NUM
EMP_NAME
EMP_DEPT
EMP_SALARY

SALARY
EMP_NUM
EMP_DEPT
EMP_SALARY

My Requirement

In both the table EMP_NUM, EMP_DEPT, EMP_SALARY got matched. I need to write this in the output. :? :?

Output

EMP_NUM = EMP_NUM
EMP_DEPT = EMP_DEPT
EMP_SALARY = EMP_SALARY

Thanks in advance

Re: Matching Column names

PostPosted: Tue Jun 23, 2015 6:01 pm
by enrico-sorichetti
how does the question relate to REXX ?

Re: Matching Column names

PostPosted: Tue Jun 23, 2015 8:00 pm
by Arunz
Hi Enrico,

This need to be developed in Rexx for some tool creation.

Re: Matching Column names

PostPosted: Tue Jun 23, 2015 8:17 pm
by enrico-sorichetti
still Your explanation of the requirement is clear as mud!

the logical problem is to find out the common symbols/token/words/calltheminanywayYouwant in two lists .

brute force

ls1 = "EMP_NUM EMP_NAME EMP_DEPT EMP_SALARY ONLY_IN_LIST1"

ls2 = "EMP_NUM EMP_DEPT EMP_SALARY ONLY_IN_LIST2"

/*  brute force
*/
do  i = 1 to words(ls1)
    do  j = 1 to words(ls2)
        if  word(ls1, i) = word(ls2, j) then ,
            say "==>" word(ls1, i) "=" word(ls1, i)
    end
end



to get
==> EMP_NUM = EMP_NUM
==> EMP_DEPT = EMP_DEPT
==> EMP_SALARY = EMP_SALARY



frankly it is pretty sad that a tool developer could not come up with a solution
to such a simple matching problem

a more sophisticated solution would have been to sort the two list
and do a two sequences match
but the overhead of sorting would have been probably been higher

Re: Matching Column names

PostPosted: Tue Jun 23, 2015 8:39 pm
by enrico-sorichetti
a slightly less brutal way

/*  less brute force
*/
do  i = 1 to words(ls1)
    if  wordpos(word(ls1, i), ls2) > 0 then ,
        say "==>" word(ls1, i) "=" word(ls1, i)
end

Re: Matching Column names

PostPosted: Tue Jun 23, 2015 9:33 pm
by NicC
And to get the column names use the DCLGENs for the tables.

Re: Matching Column names

PostPosted: Wed Jun 24, 2015 12:22 pm
by Arunz
Got it Enrico.. I am sorry for the bad explanation about my requirement...