gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part where I have to change the FILENAME and FS part. Can anyone shed some light on this for me please.

Thanks

#!/bin/ksh
tput clear

dir=/my/dir/here/
ifile=/tmp/ifile
ofile=/tmp/ofile

echo "Enter the date and hour to run this script on [YYMMDDHH]: \c"
read file


/usr/bin/gzcat $file | /usr/xpg4/bin/awk '

BEGIN {
print "headers go here"
}


NR == 3 { print $2,$3"  --  "$4,$5 ; print "" ; next }

/^dise / {
        dipce = substr($2,4,1) * 1000 ; next
           }
/^LC/ {
        lec = substr($0,3,3) + dipce
        f++
        s = ""
        for ( i in arr ) { delete arr }
        }
	   f {
		run some more stuff until gzcat is finished
              }

###Here I want to change FILENAME to "'"$ifile"'" ###

#Run some more awk code here while reading in "'"$ifile"'"




END {
Print some stuff from both processed file
}

You can use getline to start reading the $ifile whenever you want, but I would prefer something like this: define $ifile as a second argument and then process it as usual: NR == FNR -> action -> next for the first one, action for the second.
FS is not a problem, you can change it anytime you want.

To read lines from a different file other than the one you piped through awk, you need "getline" function.

getline <"'"$ifile"'"

or

getline var <"'"$ifile"'"

In the first case, $0 will be overwritten with the first line read from $ifile, in the second case you retain $0 of the original file (=the output of gzcat) and set a new variable "var" holding the first line of $ifile.

If you want, you can also avoid that pretty ugly syntax for the file name ("'"$ifile"'") by using "-v" option of awk:

/usr/bin/gzcat $file | /usr/xpg4/bin/awk -v "ifile=$ifile" ' ... '

and then reference your file with the internal awk variable "ifile", like this:

getline <ifile

Don't miss awk man page for details on getline.

Thanks guys, I have learned so much from the both of you. I am still having issues that I can't figure out, here is the script:

/usr/bin/gzcat $file | /usr/xpg4/bin/awk '

BEGIN {
print "headers go here"
}


NR == 3 { print $2,$3"  --  "$4,$5 ; print "" ; next }

/^dise / {
        dipce = substr($2,4,1) * 1000 ; next
           }
/^LC/ {
        lec = substr($0,3,3) + dipce
        f++
        s = ""
        for ( i in arr ) { delete arr }
        }
	   f {
              if ( $1 == "RRAC" ) {
                s++
                 }
                if ( s ) {
                    if ( $1 == "tsec" ) {
                       lectsec = $2 * 1
                       }
                    if ( $1 == "VAR" ) {
                        car[$2 * 1]+=$8
                        lecCar = $2 * 1
                        c[lec,lectsec,BCar] = 0
                        }
                     c[lec,lectsec,BCar]++
                     if ( c[lec,lectsec,BCar] == 8 ) {
                        car[BCar]+=$8
                        tst[lec"-"BCar]=sprintf("%5.2f",car[BCar] / 12)
                        }
                    }
                if ( $1 == "RRAC-L" ) {
                        f = "" ; next
                   }
                   }


###Here I want to change FILENAME to "'"$ofile"'" ###
#####################################################

{
while (( getline < "'"$ofile"'" ) > 0 ) {
FS = "\;" ; print $1,$3,$4 ; next }
}
#####################################################
END {
for ( i in tst ) { print i,tst }

    } '

/usr/bin/rm $ifile
/usr/bin/rm $ofile

When I change FS it also changes the output of the following:

for ( i in tst ) { print i,tst }

I can't figure this out??? Why does this change the output of the array?

You need to set the OFS variable with the desired Output Field Separator, by default a space.
Or try using "nawk". I've noticed this behavior on Solaris:

> echo "aaa:bbb:ccc" | /usr/xpg4/bin/awk '{ FS=":"; print $2,$3 }'
 
> echo "aaa:bbb:ccc" | /bin/awk '{ FS=":"; print $2,$3 }'
bbb ccc

> echo "aaa:bbb:ccc" | /bin/nawk '{ FS=":"; print $2,$3 }'
bbb ccc

The first command returns null!

@OP, use split inside you while loop

...
while (( getline line< "'"$ofile"'" ) > 0 ) {
 n=split(line,temp,"\")
 print temp[1],temp[3] ......
 next }
}
...

Thanks guys, I will try them both.