Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Scripting code re-use

Hi,

I have 2 db connections, in each connection I have to repeat same code (i.e. I have read same data fields/tables)

How do i implement code re-use functionality? is below logic correct? OR anyone have better idea?

DB Connection 1.

$(Include=test code.txt);

DB Connection 2.

$(Include=test code.txt);

My test code.txt file will contain all my load statements.

Is that correct?

Thanks.

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

I f u have 2 db connections from one database they it is fine.

but if u have 2 db connections from 2 different databases then you can do like this

DB Connection 1.

$(Include=test code.txt);

disconnect;

DB Connection 2.

$(Include=test code.txt);

at a time QV wn't connect to 2 DB's so u need to do Disconnect a 1 db then connect to another db.

View solution in original post

7 Replies
Not applicable
Author

Hi,

I f u have 2 db connections from one database they it is fine.

but if u have 2 db connections from 2 different databases then you can do like this

DB Connection 1.

$(Include=test code.txt);

disconnect;

DB Connection 2.

$(Include=test code.txt);

at a time QV wn't connect to 2 DB's so u need to do Disconnect a 1 db then connect to another db.

jagan
Partner - Champion III
Partner - Champion III

Hi,

This is the best method, if there is a change in Query you can just change query in text file one time no need to change twice.

Regards,

Jagan.

alexandros17
Partner - Champion III
Partner - Champion III

I should write a sub ... end sub and use it with a call so you write the code once and call it as if it was a function ...

Let me know

MK_QSL
MVP
MVP

Open you script editor...

FILE -- Export to Script File

Save to any place as per your choice

Open the Script Editor where you want to re-use

Insert

Include Statement

Select that file...

ashfaq_haseeb
Champion III
Champion III

hi make sure even schema is same.

Then this is best approach.

Regards

ASHFAQ

Not applicable
Author

Hi All Thanks for reply.

I will follow.

DB Connection 1.

$(Include=test code.txt);

disconnect;

DB Connection 2.

$(Include=test code.txt);

@ Alessandro, I didn't get your point. Do you have any sample doc which will help to understand more?

Thanks.

alexandros17
Partner - Champion III
Partner - Champion III

Sub MySubName

     load * from ...

End Sub

Odbc connect to DB1;

CALL MySubName;

Odbc Connect to DB2;

CALL MySubName;