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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

problem calling a subroutine from within a load

Hello

I'm having a problem calling a subroutine.

I've created the subroutine:

SUB CheckPrice(pCustomer, pProduct, pSalesDate)
LOAD SalesPrice
FROM DateFile.txt
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq)
WHERE
CustomerCode = '$(pCustomer)' AND
ItemCode = '$(pProduct)' AND
FromDate <= '$(pSalesDate)' AND
'$(pSalesDate)' <= ToDate
;
END SUB

When I call the subroutine once for a fixed customer/product/date it returns the price I expect.

However, I want to call the subroutine from within a LOAD. When I try the code below I get 'Error in expresssion:')' expected.

LOAD SalesDate,
CustomerCode,
ItemCode,
IF (ISNULL(Call CheckPrice(CustomerCode, ItemCode, SalesDate)), 'N', 'P') as chkprice
FROM SalesOrder.qvd
(qvd);

Any ideas why this is?

Cherian

8 Replies
ToniKautto
Employee
Employee

Have you tried putting the Sub Call in a dollar expansion?

$( Call CheckPoint( ...

Not applicable
Author

Hello Toni

Tried that but it made no difference

ToniKautto
Employee
Employee

Looking at your example I do not really see how it should work.

The subroutine will only execute a table load, but how does it return a value to trigger the IF conditional check for null? I imagine it would always be interpreted as a NULL.

Have you tried executing the CALL as string in the $-expansion?

$(="IF (ISNULL(Call CheckPrice(CustomerCode, ItemCode, SalesDate)), 'N', 'P')")



rbecher
MVP
MVP

Hi,

what you're trying to achieve is a script function. This is not possible in QV, only sub routine without return values.

- Ralf

Astrato.io Head of R&D
farolito20
Contributor III
Contributor III

It's impossible call a subroutine in LOAD statement?

rbecher
MVP
MVP

Right. You can call a sub routine only via "call"..

Astrato.io Head of R&D
farolito20
Contributor III
Contributor III

Damn :s Thanks :s

About mapping tables and apply match, how do that if I pass more then one field?

For example, I have this

if(match(t_cuni,'LTA','FGS','QQ'), 1, applymap('fnConvToQQ',uniBase)) * t_qhnd as cantReturn;

but here, I just pass one field, unibase to mappiing fnConvToQQ'.

how pass two fields? like this?

applymap('fnConvToQQ',uniBase,cantBase)

rbecher
MVP
MVP

You can use applymap() multiple times in a LOAD statement. One for each field..

Astrato.io Head of R&D