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.
I need to use the command Delete From_File(MYFILE) WITH_KEY and possibly others
where MYFILE is a variable determined at run time and prone to change.
For example say that there is a file named ANOTHER_FILE with a specific string field (MY_FILENAME_FIELD) that denotes a file name
Is somehow the following pseudocode possible?
PS. I know that the above is possible with executing as400 a concatenated command within a LANSA program
e.g. Exec_OS400 Command(#MY_CONCAT_COMMAND_FIELD) but is it possible to implement a similar
thing with only LANSA code?
to read a fields, table, even using a condition, all variable.
But to delete... its a different problem, you cannot use a DELETE command in a SELECT_SQL USING, or to use a DELETE command inside a SELECT/SELECT_SQL without indicating the specific file/table you want to delete the records from
now, if you have LANSA Integrator....you could use the SQLSERVICE to do that job for you from your LANSA code populating the sql string in whatever way you want:
Note: the restriction on using SELECT_SQL is that it *MUST* return a value... so 'adding' the SELECT @@ROWCOUNT to the end of the command (seperated by a semi-colon) will return the number of rows deleted.
You *SHOULD NOT* do this because it *BYPASSES* the OAM, and therefore it *ALSO* Bypasses any Trigger Functions/Validation Logic.
That said, if you feel it is OK, then it should work.
Syntax can be checked using STRSQL or SqlServiceManager but the important bit is that it returns *something*.
After checking with Brendan, a commit is needed at the end, final example here using DEPTAB, which is a non rdmlx table as well, the program deletes one record after I added a department with XXX as key
After trying also with COMMIT the above error unfortunately persists:
========= Messages issued by the task you are currently performing =========
DELETE FROM LANSAMOD.TESTFILE where ACTIONID = 'C ' ;SELECT @@ROWCOUNT;COMMIT
SQL error for table N/AVAIL when using DBM function X_DBM_Open_Cursor . SQL
TESTFILE in LANSAMOD not valid for operation.
Function TESTFU2 failed - see second level text for instructions +
I know that the SQL syntax is correct because it does the job when it is executed from SQL IBM i Access Client Solutions.
also when I tried with a simpler SQL:
#SqlStatement := 'Select * from LANSAMOD.TESTFILE'
the program run without errors, so I guess the problem is with the DELETE, also I cannot use the file DEPTAB for testing since the installed LANSA Version is 13 and the file is missing or deleted after installation.