
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why the field name in the peek function needs ' ' and not in the applymap?
Hi,
Thank you in advance for your help.
In my opinion, if the peek formula is similar to the applymap -as both use a table and a field-, why the peek needs ' ' and not the applymap?
I tried with this test code below:
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As stalwar1 stated earlier , peek() has the power to pick fields from same table and different tables as well so '' will make sure of the filed name is correctly resolved because peek takes field name as String parameter so quotes will make sure its passed as string only.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From what I understand, peek is used outside the scope of the table and hence requires the use of single quotes around the field name. Whereas applymap is used within the table itself not requiring the use of single quotes


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do not need to pass the field name in quotes for the peek function if there are no spaces in the field name if the peek function is used in the load script.
However, you need quotes if the peek function is called in a set/let statement and I think this is to cater for field names that may contain spaces in them.
You will be required to quote the field in apply map also ,if the field name contains a space.
Hth
Sasi


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As stalwar1 stated earlier , peek() has the power to pick fields from same table and different tables as well so '' will make sure of the filed name is correctly resolved because peek takes field name as String parameter so quotes will make sure its passed as string only.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Julio,
that is not entirely correct, because 2nd parameter of ApplyMap is an Expression (not Field).
See below Exemple
MapTable:
Mapping
LOAD * Inline [
A,B
A,XXX
B,YYY];
TableA:
LOAD *,ApplyMap('MapTable',Field) as MapField Inline [
Field
A
B];
TableB:
LOAD *,ApplyMap('MapTable','A') as MapField1 Inline [
Field1
A
B];
Regards,
Antonio


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the reason is to differ in-context field references and out-of-context field references. See for this: QlikView Quoteology.
- Marcus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I read all posts/replies correctly, I must say I beg to differ a little bit with many of them. Both peek() and applymap() are functions accepting expressions as parameters, but the parameters have a different character.
applymap(A, B) needs A to be a string and B must evaluate to a value to lookup (we'll omit the third parameter because not used in the OP)
peek(A, B, C) seemingly needs A and C to be strings and B must be an expression that evaluates into a row number/index.
What is clear to me if I think about it, is that both functions must receive table and field names in one case, and expression values in other cases. The names must be supplied because each function needs to know in what table (and which field) to go search for the required information. Simply mentioning a field name without quotes won't do, because that is either a reference to a QlikView field (an ordered series of values like what you pass to an aggregation function like sum()) or - and this depends on the context - a reference to a single field value whereby the value will be used instead of any other field characteristic - see the use of a field name in an expression inside an aggregation function call. So what happens when you specify an unquoted field name as parameter C in a call to peek (inside or outside of a LOAD statement)? Depending on the context, you'll be passing one or more field values to the peek() function. Which is probably not what the peek function expects.
Applymap() on the other hand will accept both an unquoted field name (in the proper context), and a quoted field name as parameter B. In the latter case, applymap() will simply look for the string in the lookup table.
However, I wouldn't be surprised that using a call format like
LOAD ..., peek('TableA', -1, UnquotedFieldName) AS ... FROM ...;
would also be ok, On condition that I could manage the input column UnquotedFieldName to contain 1 name of an existing input field. Not that it makes any sense, but I cannot think of a reason why this shouldn't be possible...
Does that make sense?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What about using applymap outside of any table scope? Like in:
MapTable:
MAPPING LOAD * INLINE [
Index, Translation
ABC, 123
DEF, 456
];
LET vResult1 = applymap('MapTable', 'ABC'); // with quotes
LET vLookup = 'DEF';
LET vResult2 = applymap('MapTable', vLookup); // without quotes
There are many variations possible in QlikView Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was not aware of this syntax... have never seen this... I guess learning something new everyday
