From_File as a variable parm

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

From_File as a variable parm

Post by adale »

Is it possible to use a variable value in the "From_File" in a Select statement?

I need to run a series of select statements to gather some count info across several files. I was hoping to use an initial list with the different file names listed, and then use the SELCT statement with the file name input as a parm. So far, all my attempts result in an IDE error message "Table not found".
Arlyn Dale
Servias LLC
stevelee67
Posts: 22
Joined: Tue Mar 13, 2018 8:25 am
Location: Madison WI

Re: From_File as a variable parm

Post by stevelee67 »

not in an RDML or standard SELECT statement.

you can do this with SELECT_SQL, RDMLX only, with the USING parameter.

the upside: a heckuva lot of flexibility
the downside: repository features basically gone

for your use case (looking for record counts) it could be fairly easy:

MTHROUTINE uGetRecordCount
DEFINE_MAP *INPUT #STD_TEXT #iFileName help('input file name')
DEFINE_MAP *RESULT #STD_NUM #oRecords help('record count')

#oRecords := *ZERO

#W_SQL := 'SELECT COUNT(1) FROM &1'
SELECT_SQL FIELDS(#LISTCOUNT) USING(#W_SQL)
#oRecords := #LISTCOUNT
LEAVE
ENDSELECT

ENDROUTINE

to use in code:
#zRecords := #com_owner.uGetRecordCount('fileX')
#zRecords := #com_owner.uGetRecordCount('fileY')
#zRecords := #com_owner.uGetRecordCount('fileZ')
The path to wisdom does, in fact, begin with a single step. Where people go wrong is in ignoring all the thousands of other steps that come after it.
Hogfather (Terry Pratchett)
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: From_File as a variable parm

Post by adale »

Interesting. Thanks for the insight! I will give it a go.
Arlyn Dale
Servias LLC
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: From_File as a variable parm

Post by adale »

Is there an equivalent "delete" function that would work with a variable parm as the from file name?
I don't see a delete_sql?
Arlyn Dale
Servias LLC
davidbalansa
Posts: 92
Joined: Mon Feb 01, 2016 10:08 am

Re: From_File as a variable parm

Post by davidbalansa »

From the SELECT_SQL (Free format) documentation, it states you can enter the delete statement in the using parameter.


https://docs.lansa.com/16/en/lansa015/i ... 257C_____0

Screenshot 2025-11-26 063050.png
Screenshot 2025-11-26 063050.png (24.59 KiB) Viewed 7605 times
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: From_File as a variable parm

Post by Dino »

stevelee67
Posts: 22
Joined: Tue Mar 13, 2018 8:25 am
Location: Madison WI

Re: From_File as a variable parm

Post by stevelee67 »

adale wrote: Wed Nov 26, 2025 5:02 am Is there an equivalent "delete" function that would work with a variable parm as the from file name?
I don't see a delete_sql?
i've had mixed success with non-SELECT statements. i've done UPDATEs, INSERTs, and DELETEs but they don't always work for me. i chalk it up to something in the SQL parser engine because the code seems to work when i use ACS's SQL editor.

the format from @davidbalansa's note is the way i've done it and gotten it to work but it doesn't always cooperate. that said, it would still be the first thing i would try.

but if that doesn't work, i've actually found that doing a USE SYSTEM_COMMAND with parameters something like (X 'RUNSQL SQL(''DELETE FROM FILE <file>'') ') is more reliable (pay attention to the COMMIT parameter on RUNSQL... i find COMMIT(*NONE) works best.
The path to wisdom does, in fact, begin with a single step. Where people go wrong is in ignoring all the thousands of other steps that come after it.
Hogfather (Terry Pratchett)
Post Reply