Skip to Content
-2
Jan 30, 2019 at 03:48 PM

Loop through list of tables, error 260 when name passed through

156 Views Last edit Jan 30, 2019 at 03:50 PM 2 rev

With the following procedure:

CREATE PROCEDURE "GDELIMA"."ZPSAEXPORT"
LANGUAGE SQLSCRIPT AS
BEGIN
	declare pos int = 1;
	declare i int = 1;
	declare dat varchar(8) = '20991231';
	declare counter int;
	
	CREATE LOCAL TEMPORARY COLUMN TABLE #ZPSA_TEMP as(
			SELECT "TABLE_NAME", ROW_NUMBER() OVER (Order by "TABLE_NAME") as ROW_NUM
			FROM "SYS"."TABLES"
			WHERE "SCHEMA_NAME" = 'SAPBIW'
			AND "TABLE_NAME" IN('/BIC/AZSDOA62600','/BIC/AZSDOA65400','/BIC/AZSDOA65500','/BIC/AZSDOA65900','/BIC/AZSDOA66300','/BIC/AZSDOA66400','/BIC/AZSDOA66500','/BIC/AZSDOA66700','/BIC/AZSDOA66800','/BIC/AZSDOA66900','/BIC/AZSDOA67100','/BIC/AZSDOA67200','/BIC/AZSDOA67300','/BIC/AZSDOA67500','/BIC/AZSDOA67600','/BIC/AZSDOA67700','/BIC/AZSDOA67900','/BIC/AZSDOA68000','/BIC/AZSDOA68100','/BIC/AZSDOA68100','/BIC/AZSDOA68800','/BIC/AZSDOA68900')
		);


	select max("ROW_NUM") as n into counter from #ZPSA_TEMP;
	--Limited to 2 for testing, replace 2 with :counter when ready
	FOR i in 1..2 DO	--:counter 
		SELECT * from(
			SELECT '"SAPBIW".'||'"'||"TABLE_NAME"||'"' as TABNAME from #ZPSA_TEMP WHERE "ROW_NUM"= :pos  --;
					  )
		WHERE "VAL_END">=:dat;
		pos=:pos+1;
	END FOR;
	
	DROP TABLE #ZPSA_TEMP;
END;


call ZPSAEXPORT();

When pass-through the table name, the procedure generates

SAP DBTech JDBC: [260]: invalid column name: VAL_END: line 25 col 9 (at pos 1129)

To, me this is telling me it's not referencing the actual table. How can I get around this?