Max() is an aggregation function, in a script to to be used in a LOAD statement.
If FN.Filename is a field with different file names in a table somewhere; you can use something like this:
LOAD MAX(Mid(FN.Filename,Len(FN.Filename)-11,8)) AS MaxFileNumber
LET vMaxDate = num(peek('MaxFileNumber'), '00000000');
but only on condition that the 8-character part that you want to strip from the file names is a real numerical value. If this 8-character field is a date (like DD/MM/YY = also 8 characters), you may have to use a different formatting assembly.
I've attached my qvw and example files I'm trying to load are:
The poant of the loop in .qvw is to determine which is the latest phonebook and the loop works correctly.
However, the problem is with storing the value (20160102) in variable and passing it to the path so load statement could load from correct phonebook.
I hope this explanation and .qvw will help you to help me.
EDIT: I uploaded new qvw, there was an error in previous one.
B_L_obsolete.qvw 298.5 K
It seems that you didn't try my solution. Please replace your statement
LET vMaxDate = 'MAX(Mid(FN.Filename,Len(FN.Filename)-11,8))';
(as this won't work outside of a LOAD statement) with this piece of script:
LOAD Max(num(SubField(PB.Filename, '.', -2))) AS MaxDate
LET vMaxDate = num(peek('MinMaxTable.MaxDate'));
DROP Table MinMaxTable;
Then adjust your LOAD statement to again include $(vMaxDate) in the date part.