The overall approach seems a bit complex, selecting rows with identical criteria from a few different tables. How about serving a single db2
invocation a script, selecting all the criteria with an IN clause from a table, and running this across the tables needed? Letting the shell do (almost) all the transformations, although that needs some shell variable crisscross. Like
ARGLIST=$(sed -n ":L; N; \${s/\n/','/g; s/^\|$/'/g; p; q}; bL; " file2)
TABLES=( $(<file1) )
IFS=$'\n'
TABLES=( ${TABLES
[*]/#/select DOCID from ICMADMIN.} )
db2 <<< "${TABLES
[*]/%/ where ITEMID in ($ARGLIST);}"
select DOCID from ICMADMIN.NNDTY4_DOC_05001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
select DOCID from ICMADMIN.NNDTY5_DOC_05001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
.
.
.
select DOCID from ICMADMIN.NZGPIM_DAT_01001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
IFS=$' \t\n'