#!/bin/ksh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#

tmpin=$1
tmpin=`echo $tmpin | sed -e 's/  *(/(/g'`
tmpin=`echo $tmpin | sed -e 's/  *)/)/g'`
set "$tmpin"

BATCH_default_record_length_msg="80 byte default"
BATCH_default_record_length=80
BATCH_default_record_format=record    #fixed length records
BATCH_default_file_type=FS

explicit_replace_action=""
explicit_reuse_action=""
GDG_O1=null
GDG_I1=null

ebm_sortmem_mb=""
EBM_SORTMEM_OPTION=""; export EBM_SORTMEM_OPTION

EBMTMPDIR=`ebmsed $EBMTMPDIR`
if [ "a$FILEMAP" = a ]
then
   echo "REPRO (S) File_Map environment variable is not set"
   exit 255
fi
input_dsn_type=''
output_dsn_type=''
echo "IDCAMS : start REPRO"
if [ $IDEBUG = "yes" ] 
then
	echo "$0  starts with :"
   split=0
   index=0
   maxsplit=2
   for i in $1
   do
      if [ $index -lt $maxsplit ]
      then
         if [ $split = "0" ]
         then
            key=`echo $i | cut -f1 -d'('`
            echo "                     key=$key\c"
         fi
         if [ $index -eq 1 ]
         then
            if [ $key = "ENVIRONMENT" ]
            then
               maxsplit=3
            fi
         fi
         echo $i |grep '(' >$DEVNULL
         ret=$?
         if [ $ret != "0" ]
         then
            split=1
         else
            split=0
         fi
         if [ $split = "0" ]
         then
            param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
            echo "    param=$param"
            index=`expr $index + 1`
         fi
      else
         param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
         key=`echo $i | cut -f1 -d'('`
         echo "                     key=$key     param=$param"
      fi
   done
fi



dispcatalog=1;export dispcatalog
split=0
index=0
maxsplit=2
input=null
output=null
param=null
types=null
temp=0
nosupp=0
FROKEY=null
FRONUM=null
TOKEY=null
TONUM=null
TOSKIP=null
TOCOUNT=null

#------------------------------------------------------------------------------
# Set default REPRO actions
#------------------------------------------------------------------------------
if [ $IDEBUG = "yes" ]
then
   set -x
fi
default_replace_action='-k noreplace'
if [ "a$EBM_REPRO_DEFAULT" = "aREU" -o "a$EBM_REPRO_DEFAULT" = "aREUSE" ]
then
   default_reuse_action='-p reuse'
else 
   default_reuse_action='-p noreuse'
fi

for i in $1
do
   if [ $index -lt $maxsplit ]
   then
      if [ $split = "0" ]
      then
         key=`echo $i | cut -f1 -d'('`
      fi
      if [ $index -eq 1 ]
      then
         if [ $key = "ENVIRONMENT" ]
         then
            maxsplit=3
         fi
      fi
      echo $i |grep '(' >$DEVNULL
      ret=$?
      if [ $ret != "0" ]
      then
         split=1
      else
         split=0
      fi
      if [ $split = "0" ]
      then
         param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
         index=`expr $index + 1`
      fi
   else
      param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
      key=`echo $i | cut -f1 -d'('`
   fi

   case $key in

      EBM_SORTMEM | ebm_sortmem)
         ebm_sortmem_mb=`eval echo $param`
         tmp=`eval echo $ebm_sortmem_mb | tr -d '[0-9]'`
         if [ a$tmp != a ]
         then
            echo " "
            echo "REPRO: invalid syntax, EBM_SORTMEM(${ebm_sortmem_mb})"
            echo "REPRO: EBM_SORTMEM must be numeric and represent the memory sort is to allocate in megabytes"
            echo " "
            exit 255
         fi
         if [ a$IDEBUG = ayes  -o "a$VERBOSE" = aYES ]
         then
            echo "REPRO: Sort memory specified is: $ebm_sortmem_mb megabytes"
         fi
         EBM_SORTMEM_OPTION="-M ${ebm_sortmem_mb}"
         export EBM_SORTMEM_OPTION
      ;;




      INFILE | IFILE | infile | ifile)
         aa=$`ebmsed GDG_$param`
         GDG_I1=`eval ebmsed $aa`
         if [ "a$GDG_I1" = "a" ]
         then
            # for GDG_I1 not set for base gdg, set to null
            GDG_I1=null
         fi
         infile_ddname=$param
         bb=$`ebmsed DD_$param`
         DD_I1=`eval ebmsed $bb`
	 ORIG_DD_I1=$DD_I1
#-----------------------------------------------------------------------
#			echo $DD_I1|grep ':' > $DEVNULL
#			temp=$?
#			if [ $temp = "0" ]
#			then
# not a single file, concatenated dataset or base gdg
#			  cat `echo $DD_I1 | sed -e 's/:/ /g'` > ${EBMTMPDIR}/catoutg.$$
#-----------------------------------------------------------------------
         echo $DD_I1 | grep '/' > $DEVNULL
         ret=$?
         if [ $ret -eq 0 ]
         then
            ispath=1
         else
            ispath=0
         fi
         if [ -f "$DD_I1" ]
         then
            isfile=1
         else
            isfile=0
         fi

         if [ $ispath -eq 1 -a $isfile -eq 0 ]
         then
            #-----------------------------------------------------------------
            # Input file pathname contains slash AND input file does not exist
            # as a file, it may be a concatenation.
            #-----------------------------------------------------------------
            if [ -f ${EBMTMPDIR}/catoutg.$$ ]
            then
               rm  ${EBMTMPDIR}/catoutg.$$
               if [ $? -ne 0 ]
               then
                  echo "REPRO (S) ERROR updating file ${EBMTMPDIR}/catoutg.$$"
                  exit 255
               fi
            fi
            touch ${EBMTMPDIR}/catoutg.$$
            if [ $? -ne 0 ]
            then
               echo "REPRO (S) ERROR defining file ${EBMTMPDIR}/catoutg.$$"
               exit 255
            fi
            echo "rm -f {EBMTMPDIR}/catoutg.$$" >> ${JON}_WK4a
            echo "rm -f {EBMTMPDIR}/catoutg.$$" >> ${JON}_WK4n
            cat `ebmsed $DD_I1 splitgdgpaths` > ${EBMTMPDIR}/catoutg.$$ 2>$DEVNULL
            if [ $? -ne 0 ]
            then
               echo "REPRO (S) ERROR $DD_I1 not found"
               exit 254
            fi
            DD_I1=${EBMTMPDIR}/catoutg.$$; export DD_I1
         fi

         temp=0
         aa=$`echo DSN_$param`
         DSN_I1=`eval echo $aa`
         aa=$`echo LRECL_$param`
         LRECL_I1=`eval echo $aa`

         if [ "a$LRECL_I1" = a ]
         then
            LRECL_I1=null; export LRECL_I1
         fi

         tmp_recfor=$`echo RECFOR_$param`
         eval_recfor=`eval echo $tmp_recfor`
         if [ "a$eval_recfor" != a ]
         then
            RECFOR_I1=$eval_recfor; export RECFOR_I1
         fi

         export GDG_I1
         export DSN_I1
         export LRECL_I1

         tmp_filetype=$`echo ${param}_FILETYPE`
         eval_filetype=`eval echo $tmp_filetype`
         if [ "a$eval_filetype" != a ]
         then
            case $eval_filetype in
               FS|TEMP|INSTREAM)
                  input_dsn_type=FS 
               ;;
               VS)
                  input_dsn_type=VS
               ;;
            esac
         fi
      ;;

      ENVIRONMENT | ENV| environment| env)
      ;;

      INDATASET | IDS | indataset | ids)	
         input_dsn_type=''    
         GDG_I1=`gdg_suffix "$i"`
         if [ "a$GDG_I1" = "a" ]
         then
            GDG_I1="null"; export GDG_I1
         fi
         DSN_I1=$param
		   if [ "$GDG_I1" = "null" ]
		   then
            DD_I1=`ftval $DSN_I1 $JOB_CAT 4`
            stat=$?
            if [ $stat -ne 0 ]
            then
               #-------------------------------------------------------
               #dataset not found in File_Map, may be a temporary file
               #-------------------------------------------------------
               echo $DSN_I1 | grep "^&&" > $DEVNULL 2>&1
               stat=$?
               if [ $stat -eq 0 ]
               then
                  #------------------------------
                  # INDATASET is a temporary file
                  #------------------------------
                  tmpdsn=`echo $DSN_I1| cut -f3 -d'&'`
                  DD_I1=${EBMTMPDIR}/${JOBNAME}_${tmpdsn}.${EBMSYS}.${JON}
                  input_dsn_type=TEMP
                  DSN_I1_orig=$DSN_I1
                  DSN_I1=${JOBNAME}_${tmpdsn}
                  #-----------------------------------------------------------
                  # If a file attribute is not defined, check if defined
                  # in a previous step
                  #-----------------------------------------------------------
                  if [ "aRECFOR_I1" = a  -o "a$LRECL_I1" = a ]
                  then
                     if [ -f ./assgndd.job_tmpdsn_attr.${EBMSYS}.${JON} ]
                     then
                        tmpdsn_entry=`grep $DD_I1 ./assgndd.job_tmpdsn_attr.${EBMSYS}.${JON}`
                        stat=$?
                        if [ $stat -eq 0 ]
                        then
		                     recfor=`echo $tmpdsn_entry | awk '{print $2}'`
                           recsize=`echo $tmpdsn_entry | awk '{print $3}'`
                        fi
                        if [ "a$RECFOR_I1" = a ]
                        then
                           RECFOR_I1=$recfor
                        fi
                        if [ "a$LRECL_I1" = a ]
                        then
                           LRECL_I1=$recsize
                        fi
                     fi
                  fi
               fi 
            fi
         else
		      gdgnum=`ftval $DSN_I1 $JOB_CAT 6`
		      if [ $gdgnum != "0" ]
		      then
               #----------------------------
               # INDATASET is a basename gdg                    
               #----------------------------
		         aa=`ftval $DSN_I1 $JOB_CAT 4`
		         gdgb=`eval ebmsed $aa`
               if [ -f ${EBMTMPDIR}/awktemp.$$ ]
               then
                  rm ${EBMTMPDIR}/awktemp.$$
                  if [ $? -ne 0 ]
                  then
                     echo "REPRO (S) ERROR updating file ${EBMTMPDIR}/awktemp.$$"
                     exit 255
                  fi
               fi
               touch  ${EBMTMPDIR}/awktemp.$$
               if [ $? -ne 0 ]
               then
                  echo "REPRO (S) ERROR defining file ${EBMTMPDIR}/awktemp.$$"
                 exit 255
               fi
               # construct a : seperated list of members in the DD_
               echo $gdgb $gdgnum | awk '
               {
	               for( i = 0; i < $2; i++ )
	               if (( i + 1 ) == $2 )
	                  printf "%s_%2.2d", $1, i 
	               else			
	                  printf "%s_%2.2d:", $1, i 
	            }' > ${EBMTMPDIR}/awktemp.$$
	            DDstr=`cat ${EBMTMPDIR}/awktemp.$$`
	            rm ${EBMTMPDIR}/awktemp.$$ 2>$DEVNULL
               # now rotate list if .tmp gdg members exist
	            num=0
	            for i in `ebmsed $DDstr splitconcpaths` 
	            do
	               num=`expr $num + 1`
	               if [ -f `eval ebmsed $gdgb.tmp$num` ]
	               then
                       newlst="`eval ebmsed $gdgb.tmp$num` `ebmsed $DDstr splitconcpaths`"
  
                     if [ -f ${EBMTMPDIR}/awktemp2.$$ ]
                     then
                        rm ${EBMTMPDIR}/awktemp2.$$
                        if [ $? -ne 0 ]
                        then
                           echo "REPRO (S) ERROR updating file ${EBMTMPDIR}/awktemp2.$$"
	                      exit 255
                        fi
                     fi
                     touch ${EBMTMPDIR}/awktemp2.$$
                     if [ $? -ne 0 ]
                     then
                        echo "REPRO (S) ERROR defining file ${EBMTMPDIR}/awktemp2.$$"
	                     exit 255
                     fi
   
                     # pass each tmp gdg and current rotated list to the awk
		               echo $gdgnum $newlst | awk '
		               {
		                  for( i = 2; i <= ($1 + 1); i++ )
		                  if ( i == ($1 + 1))
		                     printf "%s", $i
		                  else
		                     printf "%s:", $i  
		               }' > ${EBMTMPDIR}/awktemp2.$$
		               DDstr=`cat ${EBMTMPDIR}/awktemp2.$$`
		               rm ${EBMTMPDIR}/awktemp2.$$ 2>$DEVNULL
		            fi
		         done
               if [ -f ${EBMTMPDIR}/catoutg.$$ ]
               then
                  rm ${EBMTMPDIR}/catoutg.$$
                  if [ $? -ne 0 ]
                  then
                     echo "REPRO (S) ERROR updating file ${EBMTMPDIR}/catoutg.$$"
                     exit 255
                  fi
               fi
               touch ${EBMTMPDIR}/catoutg.$$
               if [ $? -ne 0 ]
               then
                  echo "REPRO (S) ERROR defining file ${EBMTMPDIR}/catoutg.$$"
                  exit 255
               fi
               cat `ebmsed $DDstr splitconcpaths` > ${EBMTMPDIR}/catoutg.$$
               DD_I1=${EBMTMPDIR}/catoutg.$$; export DD_I1
	         fi
            # END gdgnum not eq zero - basename gdg
         fi
         # END  $GDG_I1 eq null 
         if [ "a$LRECL_I1" = a ]
         then
           LRECL_I1="null"
         fi
	      export GDG_I1
	      export DSN_I1
	      export LRECL_I1

         if [ "a$input_dsn_type" = a ]
         then
            input_dsn_type=`ftval $DSN_I1 $JOB_CAT 3`
            stat=$?
            if [ $stat -ne 0 ]
            then
               echo "REPRO (S) input dataset: $DSN_I1 not found in catalog"
               exit 255
            fi
         fi
         #---------------------------------------------------------------
         # INDATASET parameter - no ASSGNDD was executed
         # Set file disposition handling now               
         #---------------------------------------------------------------
         if [ "a$DD_I1" != a ]
         then
            if [ !  -f ./${JON}_WK2n ]
            then
               cat $DEVNULL > ./${JON}_WK2n
               chmod 755 ./${JON}_WK2n
            fi
            if [ !  -f ./${JON}_WK2a ]
            then
               cat $DEVNULL > ./${JON}_WK2a
               chmod 755 ./${JON}_WK2a
            fi
            if [ ! -f ./${JON}_WK4n ]
            then
               cat $DEVNULL > ${JON}_WK4n
               chmod 755 ${JON}_WK4n
            fi
            if [ ! -f ./${JON}_WK4a ]
            then
               cat $DEVNULL > ${JON}_WK4a
               chmod 755 ${JON}_WK4a
            fi
            if [ "a${input_dsn_type}" = aTEMP ]
            then
               echo "echo $DD_I1 PASSED" >> ./${JON}_WK2n 
               echo "echo $DD_I1 PASSED" >> ./${JON}_WK2a 
               echo "rm -f $DD_I1" >> ${JON}_WK4n
               echo "rm -f $DD_I1" >> ${JON}_WK4a
               input_dsn_type=FS
            else
               echo "echo $DD_I1 RETAINED" >> ./${JON}_WK2n 
               echo "echo $DD_I1 RETAINED" >> ./${JON}_WK2a 
            fi
         fi
      # END INDATASET
      ;;

      FROMKEY |FKEY |fromkey |fkey)
			FROKEY=$param
			export FROKEY
      ;;
      FROMADDRESS| FADDR |fromaddress |faddr)
			nosupp=1
      ;;
      FROMNUMBER |FNUM |fromnumber |fnum)
		 	FRONUM=$param
			export FRONUM
      ;;
      TOKEY |tokey)		
         TOKEY=$param
			export TOKEY
      ;;
      TOADDRESS| TADDR |toaddress |taddr)
			nosupp=1
      ;;
      TONUMBER |TNUM |tonumber |tnum)
			TONUM=$param
			export TONUM
      ;;
      SKIP |skip)		
         TOSKIP=$param
			export TOSKIP
      ;;
      COUNT |count)		
         TOCOUNT=$param
			export TOCOUNT
 
      # 7688
         COUNT=$param
         export COUNT
         if [ $COUNT != "0" ]
         then
            echo " "
            echo "$1"
            echo " "
            echo "REPRO  (W) COUNT($COUNT) option is not supported"	
            echo " "
         fi
      ;;
      SYSTEMKEYNAME |SYSKN | systemkeyname |syskn)
		;;
      REPLACE |REP |replace |rep)
         explicit_replace_action="-k replace"
		;;
      NOREPLACE |NREP |noreplace |nrep)
         explicit_replace_action="-k noreplace"
		;;
      REUSE |RUS |reuse |rus)
         explicit_reuse_action="-p reuse"
		;;
      NOREUSE |NRUS |noreuse |nrus)
         explicit_reuse_action="-p noreuse"
	   ;;
      OUTFILE|OFILE |outfile |ofile)
         dispcatalog=0;export dispcatalog
         aa=$`ebmsed GDG_$param`
         GDG_O1=`eval ebmsed $aa`
         if [ "a$GDG_O1" = "a" ]
         then
            GDG_O1="null"; export GDG_O1
         fi
         outfile_ddname=$param
         aa=$`ebmsed DSN_$param`
         DSN_O1=`eval ebmsed $aa`
         aa=$`echo LRECL_$param`
         LRECL_O1=`eval echo $aa`
         aa=$`echo DD_$param`
         DD_O1=`eval echo $aa`
         if [ "a$LRECL_O1" = "a" ]
         then
            LRECL_O1="null"
         fi
         tmp_recfor=$`echo RECFOR_$param`
         eval_recfor=`eval echo $tmp_recfor`
         if [ "a$eval_recfor" != a ]
         then
            RECFOR_O1=$eval_recfor; export RECFOR_O1
         fi
         export GDG_O1
         export DSN_O1
         export LRECL_O1
         tmp_filetype=$`echo ${param}_FILETYPE`
         eval_filetype=`eval echo $tmp_filetype`
         if [ "a$eval_filetype" != a ]
         then
            if [ $eval_filetype = TEMP ]
            then
               eval_filetype=FS
            fi
            case $eval_filetype in
               FS|TEMP|INSTREAM)
                  output_dsn_type=FS
               ;;
               VS)
                  output_dsn_type=VS
               ;;
            esac
         fi
      ;;
      OUTDATASET|ODS |outdataset |ods)
         dispcatalog=1;export dispcatalog
         GDG_O1=`gdg_suffix "$i"`
         if [ "a$GDG_O1" = "null" ]
         then
            GDG_O1="null"; export GDG_O1
         fi
         DSN_O1=$param
         DD_O1=`ftval $DSN_O1 $JOB_CAT 4`
         stat=$?
         if [ $stat -ne 0 ]
         then
            #dataset not found in File_Map, may be a temporary dataset
            echo $DSN_O1 | grep "^&&" > $DEVNULL 2>&1
            stat=$?
            if [ $stat -eq 0 ]
            then
               # OUTDATASET is a temporary dataset
               tmpdsn=`echo $DSN_O1 | cut -f3 -d'&'`
               DD_O1=${EBMTMPDIR}/${JOBNAME}_${tmpdsn}.${EBMSYS}.${JON}
               output_dsn_type=TEMP
               DSN_O1_orig=$DSN_O1
               DSN_O1=${JOBNAME}_${tmpdsn}
               #-----------------------------------------------------------
               # If a file attribute is not defined, check if defined
               # in a previous step
               #-----------------------------------------------------------
               if [ "aRECFOR_O1" = a  -o "a$LRECL_O1" = a ]
               then
                  if [ -f ./assgndd.job_tmpdsn_attr.${EBMSYS}.${JON} ]
                  then
                     tmpdsn_entry=`grep $DD_O1 ./assgndd.job_tmpdsn_attr.${EBMSYS}.${JON}`
                     stat=$?
                     if [ $stat -eq 0 ]
                     then
                        recfor=`echo $tmpdsn_entry | awk '{print $2}'`
                        recsize=`echo $tmpdsn_entry | awk '{print $3}'`
                     fi
                     if [ "a$RECFOR_O1" = a ]
                     then
                        RECFOR_O1=$recfor
                     fi
                     if [ "a$LRECL_O1" = a ]
                     then
                        LRECL_O1=$recsize
                     fi
                  fi
               fi
            fi
         fi
         if [ "a$LRECL_O1" = a ]
         then
            LRECL_O1="null"
         fi
         export GDG_O1
         export DSN_O1
         export LRECL_O1
         #---------------------------------------------------------------
         # OUTDATASET parameter - no ASSGNDD was executed
         # Set file disposition handling now               
         #---------------------------------------------------------------
         if [ "a$DD_O1" != a ]
         then
            if [ !  -f ./${JON}_WK2n ]
            then
               cat $DEVNULL > ./${JON}_WK2n
               chmod 755 ./${JON}_WK2n
            fi
            if [ !  -f ./${JON}_WK2a ]
            then
               cat $DEVNULL > ./${JON}_WK2a
               chmod 755 ./${JON}_WK2a
            fi
            if [ "a${output_dsn_type}" = aTEMP ]
            then
               output_dsn_type=FS
               echo "echo $DD_O1 PASSED" >> ./${JON}_WK2n 
               echo "echo $DD_O1 PASSED" >> ./${JON}_WK2a 
               if [ ! -f ./${JON}_WK4n ]
               then
                  cat $DEVNULL > ${JON}_WK4n
                  chmod 755 ${JON}_WK4n
               fi
               if [ ! -f ./${JON}_WK4a ]
               then
                  cat $DEVNULL > ${JON}_WK4a
                  chmod 755 ${JON}_WK4a
               fi
               echo "rm -f $DD_O1" >> ${JON}_WK4n
               echo "rm -f $DD_O1" >> ${JON}_WK4a
            else 
               echo "echo $DD_O1 RETAINED" >> ./${JON}_WK2n 
               echo "echo $DD_O1 RETAINED" >> ./${JON}_WK2a 
            fi
         fi
      # END OUTDATASET
      ;;
      ENCIPHER |ENCPHR |encipher|encphr|\
      EXTERNALKEYNAME |EKN |externalkeyname |ekn|\
      INTERNALKEYNAME |IKN |internalkeyname |ikn|\
      PRIVATEKEY |PRIKEY |privatekey |prikey|\
      CIPHERUNIT | CHPRUN |cipherunit |chprun|\
      DATAKEYFILE |DKFILE |datakeyfile |dkfile|\
      DATAKEYVALUE | DKV | datakeyvalue |dkv|\
      SHIPKEYNAME |SHIPKN |shipkeyname |shipkn|\
      STOREDATAKEY | STRDK |storedatakey |strdk|\
      NOSTOREDATAKEY |NSTRDK |nostoredatakey|nstrdk|\
      STOREKEYNAME |STRKN |storekeyname | strkn|\
      USERDATA |UDATA |userdata |udata|\
      DECIPHER |DECPHR |decipher |decphr|\
      DATAKEYFILE |DKFILE |datakeyfile |dkfile|\
      DATAKEYVALUE |DKV |datakeyvalue |dkv|\
      SYSTEMKEY |SYSKEY |systemkey |syskey|\
      SYSTEMDATAKEY | SYSDK |systemdatakey |sysdk|\
      SYSTEMKEYNAME | SYSKN |systemkeyname |syskn)
         if [ $IDEBUG = "yes" ]
         then
            echo "REPRO  (I) $0: parameter $key ignored"
         fi
       ;;
       *)
          echo "REPRO  (I) $key not supported"	
       ;;
   esac
done
#-------
#ENDLOOP
#-------
if [ $nosupp -eq 1 ]
then
   exit 1
fi

if [ "a$GDG_I1" = "anull" ] 
then
   #---------------------------------------
   # input file is not a gdg instance
   #---------------------------------------
   types=''
   if [ "a$input_dsn_type" != a ]
   then
      types=$input_dsn_type
   fi
   if [ "a$DSN_I1" = "a" ]
   then
      #---------------------------------------------------------------
      # 7806
      # datasetname was not specified, check for filename
      #---------------------------------------------------------------
      if [ "a$DD_I1" = a ]
      then
         #---------------------------------------------------------------
         # Must have either datasetname or filename  - abort
         #---------------------------------------------------------------
         echo "REPRO  (S) Input filename or datasetname must be specified"	
         exit 255
      fi

      if [ "a$input_dsn_type" != a ]
      then
         types=$input_dsn_type
      else
         echo " "
         echo "REPRO  (W) $DD_I1"	
         echo "           Setting file type to default: $BATCH_default_file_type"	
         echo " "
         types="FS"
      fi

      if [ "a$types" = "aFS" ]
      then
         #---------------------------------------------------------------
         # Only set for FS, TRANS stores VSAM file attributes internally
         #---------------------------------------------------------------
         if [ "a$LRECL_I1" = "a" -o "a$LRECL_I1" = "anull" ]
         then
            echo " "
            echo "REPRO  (W) $DD_I1"	
            echo "           Setting record length to $BATCH_default_record_length_msg"	
            echo " "
            LRECL_I1=$BATCH_default_record_length; export LRECL_I1
         fi 
         if [ "a$RECFOR_I1" = a ]
         then
            echo " "
            echo "REPRO  (W) $DD_I1"	
            echo "           Setting record format to default: $BATCH_default_record_format"	
            echo " "
            RECFOR_I1=record; export RECFOR_I1
         fi
      fi
          #-----------------------------------------------------------
   else   # $DSN_I1 is not null
          #-----------------------------------------------------------
      if [ "a$input_dsn_type" != a ]
      then
         types=$input_dsn_type
      else
         #-----------------------------------------------------------
         # Must retrieve file type from FileMap
         #-----------------------------------------------------------
         types=`ftval $DSN_I1 $JOB_CAT 3`
         stat=$?
         if [ $stat -ne 0 ]
         then
            #-------------------------------------------------------------------
            # entry not in File_Map, may be a temp file
            # DSN=&&AAA is translated to dataset=${JOBNAME}_AAA.${EBMSYS}.${JON}
            # DD_I1 will be set to ${EBMTMPDIR}/${JOBNAME}_AAA.${EBMSYS}.${JON}
            #-------------------------------------------------------------------
            echo $DSN_I1 | grep "^${JOBNAME}_" > $DEVNULL 2>&1
            if [ $? -eq 0 ]
            then
               if [ "a$DD_I1" != a ]
               then
                  echo $DD_I1 | grep "^$EBMTMPDIR" > $DEVNULL 2>&1
                  stat=$?
                  if [ $stat -eq 0 ]
                  then
                     #----------------------------------------------
                     # input file is a temporary file
                     #----------------------------------------------
                     input_dsn_type=TEMP
                     types=FS
                  fi
               else
                  #----------------------------------------------------
                  # input file is a temporary file and DD_I1 is not set
                  #----------------------------------------------------
                  tmpdsn=`echo $DSN_I1| cut -f3 -d'&'`
                  DD_I1=${EBMTMPDIR}/${JOBNAME}_${tmpdsn}.${EBMSYS}.${JON}
                  input_dsn_type=TEMP
                  types=FS
               fi
            fi
         fi
      fi
      if [ a$types = a ]
      then
         #---------------------------------------------------------------
         # file type is not defined
         # input dsn is not in File_Map and it is not a temporary dataset
         #---------------------------------------------------------------
         echo " "
         echo "REPRO  (W) $DD_I1"	
         echo "           Setting record type to default: $BATCH_default_record_type"	
         echo " "
         types='FS' 
      fi
   fi
   if [ $types != VS -a $types != FS ]
   then
      echo " "
      echo "$1"
      echo " "
      echo "REPRO (S) Input file must be type VS or FS"
      echo "REPRO (S) Invalid input file type: $types"
      echo " "
      echo " "
      exit 255
   fi
   if [ $types  = "FS" ] 
   then 
      #------------------------------------------------------
      # input file is not a gdg instance and input file is FS
      #------------------------------------------------------
      input=FS
      ret=0
      echo $DD_I1 | grep '/' > $DEVNULL
      ret2=$?
      if [ $ret2 != "0" ]
      then
         # DD_I1 has not been set
         echo $DSN_I1 |grep '_' >$DEVNULL
         ret=$?
         if [ $ret -eq 0 ]
         then
            #---------------------------------------------------------
            #  input file is FS, it is not a temporary file 
            #  DD_I1 has not been assigned to the filename
            #  if temp file,  DD_I1 must have been set before this)
            #---------------------------------------------------------
            DD_I1=`ftval $DSN_I1 $JOB_CAT 4`.${JON} 
            temp=$?
            DD_I1=`eval ebmsed $DD_I1`
         else
            DD_I1=`ftval $DSN_I1 $JOB_CAT 4` 
            temp=$?
            DD_I1=`eval ebmsed $DD_I1`
         fi
      fi
      ret2=0
      if [ $temp != "0" ]
      then
         echo "REPRO (S) input dataset: $DSN_I1 not found in catalog"
         exit 255
         # Data set not found in catalog
      fi
      CMD_I1="-inf $DD_I1"
   else
      if [ $types  = "VS" ]
      then
         #------------------------------------------------------
         # input file is VSAM
         #------------------------------------------------------
         input=VS
         if [ "a$DD_I1" = a ]
         then
            DD_I1=`ftval $DSN_I1 $JOB_CAT 4`
            temp=$?
            DD_I1=`eval ebmsed $DD_I1`
            if [ $temp != "0" ]
            then
               exit 255
               # Data set not found in catalog
            fi
         fi
         CMD_I1=$DD_I1
      else
         #-----------------------------------------------------------------
         # input file is not a gdg instance, is not VS and not FS
         # NOTE:  VS file cannot be a temporary file, must be in File_Map
         #-----------------------------------------------------------------
         DD_I1=`ftval $DSN_I1 $JOB_CAT 4`
         temp=$?
         DD_I1=`eval ebmsed $DD_I1`
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR dataset: $DSN_I1 not found in catalog, unable to determine file type"
            exit 255
            # Data set not found in catalog
         fi
         CMD_I1="-ind $DD_I1"
      fi
   fi
else
   #------------------------------------
   # gdg instance was specified on input 
   #------------------------------------
   if [ `ftval $DSN_I1 $JOB_CAT 3` = "FS" ] 
   then
      input=FS
      #---------------------------------------------------------
      # gdg instance was specified on input and input file is FS 
      #---------------------------------------------------------
      echo $DD_I1 | grep '/' > $DEVNULL
      ret2=$?
      if [ $ret2 != "0" ]
      then
         #--------------------------------------------------
         # DD_I1 is not set, must retrieve filename
         #--------------------------------------------------
         DD_I1=`ftval $DSN_I1 $JOB_CAT 4`$GDG_I1
         temp=$?
         if [ $temp != "0" ]
         then
            echo " "
            echo $1
            echo " "
            echo "REPRO (S) input dataset: $DSN_I1 not found in catalog"
            exit 255
            # Data set not found in catalog
         fi
         DD_I1=`eval ebmsed $DD_I1`
         CMD_I1="-inf $DD_I1"
      fi
      ret2=0
   else
      if [ `ftval $DSN_I1 $JOB_CAT 3` = "VS" ] 
      then
         #------------------------------------------------------
         # input dataset is a gdg instance and is VS
         #------------------------------------------------------
         input=VS
         if [ "a$DD_I1" = a ]
         then
            DD_I1=`ftval $DSN_I1 $JOB_CAT 4`
            temp=$?
            DD_I1=`eval ebmsed $DD_I1`
            if [ $temp != "0" ]
            then
               echo " "
               echo $1
               echo " "
               echo "REPRO (S) input dataset: $DSN_I1 not found in catalog"
               exit 255
               # Data set not found in catalog
            fi
         fi
         CMD_I1=$DD_I1
      else
         #-----------------------------------------------------------------
         # gdg instance was specified and input file is not VSAM and not FS
         #-----------------------------------------------------------------
         rootgdg=`ftval $DSN_I1 $JOB_CAT 4`
         temp=$?
         rootgdg=`eval ebmsed $rootgdg`
         if [ $temp != "0" ]
         then
            echo " "
            echo $1
            echo " "
            echo "REPRO (S) input dataset: $DSN_I1 not found in catalog"
            echo "REPRO (S) ERROR: $DSN_I1 not found in catalog"
            exit 255
            # Data set not found in catalog
         fi
         DD_I1=${rootgdg}$GDG_I1
         CMD_I1="-ind $DD_I1"
      fi
   fi
fi
#----------------------------------------
# Check if input record length is defined
#----------------------------------------
if [ ! -z $LRECL_I1 ]
then
   if [ $LRECL_I1 != null ]
   then
      IRS_I1="-irs $LRECL_I1"
   else
      IRS_I1=""
   fi
fi

#-------------------------------------------------------------
# Validate output file
#-------------------------------------------------------------
if [ $GDG_O1 = null ] 
then
   #-----------------------------------------------------------
   # output file is not a gdg instance
   #-----------------------------------------------------------
   types=''
   if [ "a$output_dsn_type" != a ]
   then
      types=$output_dsn_type
   fi
   if [ "a$DSN_O1" = a ]
   then
      #---------------------------------------------------------------
      # 7806
      # datasetname was not specified, check for filename
      #---------------------------------------------------------------
      if [ "a$DD_O1" = a ]
      then 
         #---------------------------------------------------------------
         # Must have either datasetname or filename  - abort
         #---------------------------------------------------------------
         echo "REPRO  (S) Output filename or datasetname must be specified"
         exit 255
      fi

      if [ "a$output_dsn_type" != a ]
      then
         types=$output_dsn_type
      else
         echo " "
         echo "REPRO  (W) $DD_O1"
         echo "           Setting file type to default: $BATCH_default_file_type"
         echo " "
         output_dsn_type="FS"
         types="FS"
      fi

      if [ "a$types" = aFS ]
      then
         #---------------------------------------------------------------
         # Only set for FS, TRANS stores VSAM file attributes internally
         #---------------------------------------------------------------
         if [ "a$LRECL_O1" = "a" -o "a$LRECL_O1" = "anull" ]
         then
            echo " "
            echo "REPRO  (W) $DD_O1"
            echo "           Setting record length to $BATCH_default_record_length_msg"
            echo " "
            LRECL_O1=80; export LRECL_O1
         fi
         if [ "a$RECFOR_O1" = a ]
         then
            echo " "
            echo "REPRO  (W) $DD_O1"
            echo "           Setting record format to default: $BATCH_default_record_format"
            echo " "
            RECFOR_O1=record; export RECFOR_O1
         fi
      fi
   fi
   if [ "a$output_dsn_type" = a ]
   then
      #---------------------------------------------------------------------
      # Must determine file type - retrieve from File_Map        
      # output_dsn_type will only be null if DSN_O1 was set.
      # If no datasetname was specified a default has been already applied.
      #---------------------------------------------------------------------
      types=`ftval $DSN_O1 $JOB_CAT 3 2>$DEVNULL`
      stat=$?
      if [ $stat -ne 0 ]
      then
         # entry not in File_Map, could be a temp file
         # DSN=&&AAA was translated to dataset=$JOBNAME_AAA
         echo $DSN_O1 | grep "^${JOBNAME}_" > $DEVNULL 2>&1
         if [ $? -eq 0 ]
         then
            if [ "a$DD_O1" != a ]
            then
               echo $DD_O1 | grep "^$EBMTMPDIR" > $DEVNULL 2>&1
               stat=$?
               if [ $? -eq 0 ]
               then 
                  output_dsn_type=TEMP
                  types=FS
               fi
            fi
         fi
      fi
      if [ "a$types" = a ]
      then
         #-----------------------------------------------------------
         # dataset is not in File_Map and is not a temporary dataset
         # Set to DEFAULT:  FS and issue warning
         #-----------------------------------------------------------
         echo " "
         echo "REPRO  (W) $DD_O1"
         echo "           Setting file type to default: $BATCH_default_file_type"
         echo " "
         output_dsn_type="FS"
         types="FS"
      fi
   else
      types=$output_dsn_type
   fi
   if [ $types  = "FS" ] 
   then 
      #--------------------------------------------------------
      # output file is not a gdg instance and 
      # output file is FS 
      #--------------------------------------------------------
      output=FS
      ret=0
      if [ "a$DD_O1" = a ]
      then 
         echo $DSN_O1 |grep '_' >$DEVNULL
         ret=$?
         if [ $ret -eq 0 ]
         then
            temp=0
            DD_O1=`ftval $DSN_O1 $JOB_CAT 4`.${JON}
            temp=$?
            DD_O1=`eval ebmsed $DD_O1`
         else
            #-----------------------------------------
            # if DD_ has not been set for output file, 
            # retrieve filename from File_Map
            #-----------------------------------------
            DD_O1=`ftval $DSN_O1 $JOB_CAT 4`
            temp=$?
            DD_O1=`eval ebmsed $DD_O1`
         fi
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog\n"
            echo "          Unable to determine output filename"

            exit 255
            # Data set not found in catalog
         fi
      fi
      CMD_O1="-ouf $DD_O1"
   else
      if [ $types  = "VS" ]
      then
         #--------------------------------------
         # output file is not a gdg instance and 
         # output file is VSAM
         #--------------------------------------
         output=VS
         if [ "a$DD_O1" = a ] 
         then
            DD_O1=`ftval $DSN_O1 $JOB_CAT 4`
            temp=$?
            if [ $temp != "0" ]
            then
               echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
               exit 255
               # Data set not found in catalog
            fi
         fi
         DD_O1=`eval ebmsed $DD_O1`
         CMD_O1=$DD_O1
      else
         #--------------------------------------
         # output file is not a gdg instance and 
         # output file is NOT VS or FS
         #--------------------------------------
         DD_O1=`ftval $DSN_O1 $JOB_CAT 4`
         temp=$?
         DD_O1=`eval ebmsed $DD_O1`
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
            exit 255
            # Data set not found in catalog
         fi
         CMD_O1="-oud $DD_O1"
      fi
   fi
else
   #------------------------------------------------
   # a  gdg instance is defined for the output file
   #------------------------------------------------
   if [ `ftval $DSN_O1 $JOB_CAT 3` = "FS" ] 
   then
      output=FS
      if [ "a$DD_O1" = "a" ]
      then
         #---------------------------------------------
         # output file is a gdg occurrence and
         # output file is FS 
         #---------------------------------------------
         output=FS
         #---------------------------------------------
         # Set DD_variable to filename{.|_}gdg instance
         #---------------------------------------------
         DD_O1=`ftval $DSN_O1 $JOB_CAT 4`$GDG_O1
         temp=$?
         DD_O1=`eval ebmsed $DD_O1`
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
            exit 255
            # Data set not found in catalog
         fi
         if [ $IDEBUG != "yes" ] 
         then
            rm -f $DD_O1
            touch $DD_O1
            echo "rm -f $DD_O1" >> ${JON}_WK2a
            echo "echo $DD_O1 DELETED" >> ${JON}_WK2a
            if [ $dispcatalog != "0" ]
            then
               rceval=`ftval $DSN_O1 $JOB_CAT 4`
               echo "gdgen $rceval `ftval $DSN_O1 $JOB_CAT 6` $DD_O1 `ftval $DSN_O1 $JOB_CAT 3`" >> ${JON}_WK4n
               echo "gdgen $rceval `ftval $DSN_O1 $JOB_CAT 6` $DD_O1 `ftval $DSN_O1 $JOB_CAT 3`" >> ${JON}_WK4a
            fi
         fi
         CMD_O1="-ouf $DD_O1"
      fi
   else
      if [ `ftval $DSN_O1 $JOB_CAT 3` = "VS" ] 
      then
         #------------------------------------------------
         # a  gdg instance is defined for the output file
         # and  output file is VSAM
         #------------------------------------------------
         output=VS
         #------------------------------------------------
         # if DD_O1 is not set, need to retrieve filename
         #------------------------------------------------
         if [ "a$DD_O1" = "a" ]
         then
            DD_O1=`ftval $DSN_O1 $JOB_CAT 4`
            temp=$?
            DD_O1=`eval ebmsed $DD_O1`
            if [ $temp != "0" ]
            then
               echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
               # Data set not found in catalog
               exit 255
            fi
         fi
         CMD_O1=$DD_O1
      else
         #-----------------------------------------------
         # a gdg instance is defined for the output file
         # and output file is not VS or FS
         #-----------------------------------------------
         rootgdg=`ftval $DSN_O1 $JOB_CAT 4`
         temp=$?
         rootgdg=`eval ebmsed $rootgdg`
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
            exit 255
         fi
         gdgn=`ftval $DSN_O1 $JOB_CAT 6`
         temp=$?
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
            exit 255
         fi
         gdgname=`ftval $DSN_O1 $JOB_CAT 0`
         temp=$?
         if [ $temp != "0" ]
         then
            echo "REPRO (S) ERROR  output dataset: $DSN_O1   not found in catalog"
            exit 255
         fi
         if [ $IDEBUG != "yes" ] 
         then
            clone=`getgn $rootgdg $GDG_O1 $gdgn $gdgname`
            if [ $clone = 0 ] 
            then
               rdmcr -f ${rootgdg}$GDG_O1 -s `ftval $DSN_O1 $JOB_CAT 5`
               temp=$?
               if [ $temp != "0" ]
               then
                  exit 255
               fi
            else
               rdmcr -f ${rootgdg}$GDG_O1 -c ${rootgdg}_00
               temp=$?
               if [ $temp != "0" ]
               then
                  exit 255
               fi
            fi
         fi
         DD_O1=${rootgdg}$GDG_O1
         if [ $IDEBUG != "yes" ] 
         then
            echo "rdmdl -f ${rootgdg}$GDG_O1" >> ${JON}_WK4a
            if [ $dispcatalog != "0" ]
            then
               echo "gdgen $rootgdg $gdgn ${rootgdg}$GDG_O1 `ftval $DSN_O1 $JOB_CAT 3`" >> ${JON}_WK4n
               echo "gdgen $rootgdg $gdgn ${rootgdg}$GDG_O1 `ftval $DSN_O1 $JOB_CAT 3`" >> ${JON}_WK4a
            fi
         fi
         CMD_O1="-oud $DD_O1"
      fi
   fi
fi
#------------------------------------
# END case output file type
#------------------------------------

#------------------------------------
# Generate appropriate command:
#------------------------------------
if [ $LRECL_O1 != null ]
then
	ORS_O1="-ors $LRECL_O1"
else
	ORS_O1=""
fi
if [ $IDEBUG = "yes" ] 
then
	RDMCP="echo rdmcp"
	CP="echo cp"
	UNIKIXBLD="echo unikixbld"
else
	RDMCP=rdmcp
	CP=cp
	UNIKIXBLD="unikixbld"
fi
#------------------------------------------------------------------------------
# Apply explicit reuse and replace actions if defined, otherwise apply defaults
#
# If REUSE has been defined, it forces the replace option to REPLACE
#------------------------------------------------------------------------------
if [ "a$explicit_reuse_action" != a ]
then
   REUSE_ACTION=$explicit_reuse_action
else
   REUSE_ACTION=$default_reuse_action
fi
if [ "a$explicit_replace_action" != a ]
then
   REPLACE_ACTION=$explicit_replace_action
else
   REPLACE_ACTION=$default_replace_action
fi
if [ "$explicit_reuse_action" = "-p reuse" ]
then
   if [ "$explicit_replace_action" = "-k noreplace" ]
   then
      echo "REPRO   (W) REUSE specified, NOREPLACE is ignored"
   fi
   REPLACE_ACTION=""
fi
if [ $input = "FS" ]
then
   #---------------------------------------------
   # INPUT is FS
   #---------------------------------------------
   case $output in
      VS)
      #-----------------------------------------------
      # INPUT is FS and OUTPUT is VS
      #-----------------------------------------------
      #-------------------------------------------------------
      # if INPUT record format is already defined
      # do not retrieve from File_Map
      #-------------------------------------------------------
      if [ "a$RECFOR_I1" != a ]
      then
         RECFOR=$RECFOR_I1; export RECFOR
      else
         if [ "a$DSN_I1" != a ]
         then
            ddfx=`ftval $DSN_I1 $JOB_CAT 5 2>$DEVNULL`
            ddfs=`eval ebmsed $ddfx`
            if [ ! ${ddfs}null = "null" ]
            then
               if [ -f $ddfs ]
               then
                  PARFS=`cat $ddfs`
                  set $PARFS
                  if [ ${1}null = "null" ]
                  then # Attribute file did not contain attributes
                     RECFOR=record
                     echo " "
                     echo "REPRO  (W) $DD_I1"	
                     echo "           Setting record format to default: $BATCH_default_record_format"	
                     echo " "
                  else
                     RECFOR=$1
                  fi	
               else # Attribute file did not exist
                  RECFOR=record
                  echo " "
                  echo "REPRO  (W) $DD_I1"	
                  echo "           Setting record format to default: $BATCH_default_record_format"	
                  echo " "
               fi
            else # No attribute file defined in File_Map
               RECFOR=record
               echo " "
               echo "REPRO  (W) $DD_I1"	
               echo "           Setting record format to default: $BATCH_default_record_format"	
               echo " "
            fi
         else # Datasetname was not defined 
            RECFOR=record
            echo " "
            echo "REPRO  (W) $DD_I1"	
            echo "           Setting record format to default: $BATCH_default_record_format"	
            echo " "
         fi
      fi
      # INPUT is FS and OUTPUT is VS

      #----------------------------------------------------------------------
      # 7099
      # NOTE:  if EBM_REPRO does not equal 'MAINFRAME' then
      #           unikixbld is executed WITHOUT the options  
      #           -p reuse|noreuse and
      #           -k replace|noreplace 
      #           the variables assigning the options are nullified
      #        else
      #           the options are set to what was explicit int the job script
      #        else 
      #           the batch defaults noreuse noreplace are applied
      #
      #----------------------------------------------------------------------
      if [ "a$EBM_REPRO" != "aMAINFRAME" ]
      then
         REUSE_ACTION=''; export REUSE_ACTION
         REPLACE_ACTION=''; export REPLACE_ACTION
      fi
      #----------------------------------------------------------------------
      # 7088 If COUNT keyword specifies zero, then initialize output file 
      #----------------------------------------------------------------------
      BATCH_COMMAND='' 
      if [ "a$COUNT" = "a0" ]
      then
         OUPUT_VS=`eval ebmsed $DD_O1` 
         BATCH_COMMAND="$UNIKIXBLD -i -d `eval echo $CMD_O1`"
      fi
      #----------------------------------------------------------------------
      # 7159
      # NOTE:  unikixbld (and trans vsam in general) can not process
      #        files > 2 gig if TRANS does the IO.  So, if we have
      #        concatenated files, instead of sending along the single
      #        concatenated -s file, make separate -s entries for each
      #        individual file up to the 50 max.  At some point TRANS will
      #        be fixed to go > 2gig files and we may wish to go back to
      #        the original idea of stringing all the input files together
      #        into 1 and eliminating the 50 file restriction
      #
      #----------------------------------------------------------------------

      # if original input was concatenated, make separate -s

      #----------------------------------------------------------------------
      # 7088  If the COUNT keyword was specified and its value was zero,
      #       the number of input files specified is meaningless. 
      #       The output VSAM file is to be reinitialized and BATCH_COMMAND
      #       will already be formatted. 
      # 
      #       Only perform the loop below if the BATCH_COMMAND variable 
      #       has not been set.
      #----------------------------------------------------------------------
      if [ "a$BATCH_COMMAND" = a ]
      then
         garbage=`echo $ORIG_DD_I1 | grep ":" > $DEVNULL`
         grepstat=$?
         if [ "$grepstat" = 0 ]
         then
            unset hyphen_s
            concat_index=1
            while [ "$concat_index" -lt 51 ]
            do
               aa=`echo $ORIG_DD_I1|cut -f$concat_index -d':'`
               if [ "x$aa" != "x" ]
               then
                  hyphen_s="${hyphen_s} -s $aa"
                  concat_index=`expr $concat_index + 1`
               else
                  concat_index=51
               fi
            done
#############BATCH_COMMAND="$UNIKIXBLD -t v -d `eval echo $CMD_O1` $hyphen_s -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V"

             BATCH_COMMAND="$UNIKIXBLD -t v -d `eval echo $CMD_O1` $hyphen_s -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V $EBM_SORTMEM_OPTION"

         else
   
############BATCH_COMMAND="$UNIKIXBLD -t v -d `eval echo $CMD_O1` -s `eval echo $DD_I1` -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V"

            BATCH_COMMAND="$UNIKIXBLD -t v -d `eval echo $CMD_O1` -s `eval echo $DD_I1` -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V $EBM_SORTMEM_OPTION"
         fi
      fi

      $BATCH_COMMAND
      temp=$?
      if [ $temp -ne 0 ]
      then
         echo " "
         echo "REPRO (S) Command failed: " 
         echo "$BATCH_COMMAND"
         echo " "
      else
         echo " "
         echo "REPRO  (I) Command executed successfully"
         echo "$BATCH_COMMAND"
         echo " "
      fi
      exit $temp
      ;;


      FS)
         #--------------------------
         # input is FS output is FS
         #--------------------------
         if [ "a$COUNT" = "a0" ]
         then
            BATCH_COMMAND="cat $DEVNULL > `eval ebmsed $DD_O1`"
            cat $DEVNULL > `eval ebmsed $DD_O1`
            temp=$?
         else
            BATCH_COMMAND="$CP `eval ebmsed $DD_I1` `eval ebmsed $DD_O1`"
            $BATCH_COMMAND
            temp=$?
         fi
         if [ $temp -ne "0" ]
         then
            echo " "
            echo "REPRO (S) Command failed:"
            echo "$BATCH_COMMAND"
            echo " "
         else
            echo " "
            echo "REPRO  (I) Command executed successfully"
            echo "$BATCH_COMMAND"
            echo " "
         fi
         exit $temp
      ;;

      *)
      #------------------------------------------------------------
      # input is FS output is not FS and is not VS
      #------------------------------------------------------------
      if [ $FRONUM != null -a $TONUM != null ]
      then
         if [ $output = "FS" ]
         then
            #-----------------------------------------------
            # Both FROMNUM and TONUM have values
            # INPUT is FS    OUTPUT is FS
            #-----------------------------------------------
            FROTONUM=\'\'\($FRONUM-$TONUM\)\'\'
            $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
            temp=$?
         else
            #-----------------------------------------------
            # Both FROMNUM and TONUM are not null
            # INPUT is FS    OUTPUT neither FS nor VS     
            #-----------------------------------------------
            FROTONUM=\'\'\($FRONUM-$TONUM\)\'\'
            $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
            temp=$?
         fi
         if [ $temp != "0" ]
         then
            exit 1
         fi
      else
         if [ $TONUM != null -a $TOSKIP != null ]
         then
            if [ $output = "FS" ]
            then
               #-----------------------------------------------
               # Both TONUM and TOSKIP have values  
               # INPUT is FS    OUTPUT is FS
               #-----------------------------------------------
               FROTONUM=\'\'\($TOSKIP-$TONUM\)\'\'
               $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
               temp=$?
            else
               #-----------------------------------------------
               # Both TONUM and TOSKIP have values  
               # INPUT is FS    OUTPUT is NOT VS and NOT FS
               #-----------------------------------------------
               FROTONUM=\'\'\($TOSKIP-$TONUM\)\'\'
               $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
               temp=$?
            fi
            if [ $temp != "0" ]
            then
               exit 1
            fi
         else
            if [ $TONUM != null ]
            then
               if [ $output = "FS" ]
               then
                  #------------------------------------------------
                  # TONUM has a value, FROMNUM and TOSKIP are null 
                  # INPUT is FS    OUTPUT is FS
                  #------------------------------------------------
                  FROTONUM=\'\'\(1-$TONUM\)\'\'
                  $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                  temp=$?
               else
                  #------------------------------------------------
                  # TONUM has a value, FROMNUM and TOSKIP are null 
                  # INPUT is FS    OUTPUT is NOT VS and NOT FS
                  #------------------------------------------------
                  FROTONUM=\'\'\(1-$TONUM\)\'\'
                  $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 
                  temp=$?
               fi
               if [ $temp != "0" ]
               then
                  exit 1
               fi
            else
               #-----------------------------------------------
               # TONUM is null
               #-----------------------------------------------
               if [ $FRONUM != null -a $TOCOUNT != null ]
               then
                  AUX=`expr $FRONUM + $TOCOUNT`
                  if [ $output = "FS" ]
                  then
                     #------------------------------------------------
                     # FRONUM has a value and TOCOUNT has value
                     # INPUT is FS    OUTPUT is FS
                     #------------------------------------------------
                     FROTONUM=\'\'\($FRONUM-$AUX\)\'\'
                     $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                     temp=$?
                  else
                     #------------------------------------------------
                     # FRONUM has a value and TOCOUNT has value
                     # INPUT is FS    OUTPUT is not FS  and NOT VS
                     #------------------------------------------------
                     FROTONUM=\'\'\($FRONUM-$AUX\)\'\'
                     $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
                     temp=$?
                  fi
                  if [ $temp != "0" ]
                  then
                     exit 1
                  fi
               else
                  if [ $FRONUM != null ]
                  then
                     if [ $output = "FS" ]
                     then
                        #------------------------------------------------
                        # FRONUM has value 
                        # INPUT is FS    OUTPUT is FS 
                        #------------------------------------------------
                        FROTONUM=\'\'\($FRONUM-end\)\'\'
                        $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                        temp=$?
                     else
                        #------------------------------------------------
                        # FRONUM has value 
                        # INPUT is FS    OUTPUT is NOT FS  and NOT VS
                        #------------------------------------------------
                        FROTONUM=\'\'\($FRONUM-end\)\'\'
                        $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
                        temp=$?
                     fi
                     if [ $temp != "0" ]
                     then
                        exit 1
                     fi
                  else
                     if [ $TOCOUNT != null -a $TOSKIP != null ]
                     then
                        AUX=`expr $TOSKIP + $TOCOUNT`
                        if [ $output = "FS" ]
                        then
                           #------------------------------------------------
                           # TOCOUNT  has value  and TOSKIP has value
                           # INPUT is FS    OUTPUT is FS 
                           #------------------------------------------------
                           FROTONUM=\'\'\($TOSKIP-$AUX\)\'\'
                           $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                           temp=$?
                        else
                           #------------------------------------------------
                           # TOCOUNT  has value  and TOSKIP has value
                           # INPUT is FS    OUTPUT is not FS and is not VS
                           #------------------------------------------------
                           FROTONUM=\'\'\($TOSKIP-$AUX\)\'\'
                           $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
                           temp=$?
                        fi
                        if [ $temp != "0" ]
                        then
                           exit 1
                        fi
                     else
                        if [ $TOCOUNT != null ]
                        then
                           if [ $output = "FS" ]
                           then
                              FROTONUM=\'\'\(1-$TOCOUNT\)\'\'
                              $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                              temp=$?
                           else
                              FROTONUM=\'\'\(1-$TOCOUNT\)\'\'
                              $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
                              temp=$?
                           fi
                           if [ $temp != "0" ]
                           then
                              exit 1
                           fi
                        else
                           if [ $TOSKIP != null ]
                           then
                              if [ $output = "FS" ]
                              then
                                 FROTONUM=\'\'\($TOSKIP-end\)\'\'
                                 $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1 $ORS_O1
                                 temp=$?
                              else
                                 FROTONUM=\'\'\($TOSKIP-end\)\'\'
                                 $RDMCP $CMD_I1 $CMD_O1 -rg $FROTONUM $IRS_I1
                                 temp=$?
                              fi
                              if [ $temp != "0" ]
                              then
                                 exit 1
                              fi
                           else
                              $RDMCP $CMD_I1 $CMD_O1 $IRS_I1
                              temp=$?
                              if [ $temp != "0" ]
                              then
                                 exit 1
                              fi
                           fi
                        fi
                     fi
                  fi
               fi
            fi
         fi
      fi
      ;;
   esac
else # input is not FS
   if [ $input = "VS" ]
   then
      case $output in
#------------------------------------------------------------------------------
      VS)
         echo " "
         echo "REPRO (S) ERROR  REPRO of input VSAM to output VSAM is not supported in the current version"
         echo " "
         exit 255
      ;;
#------------------------------------------------------------------------------
      FS)
         #-------------------------------------------------------------
         # INPUT is  VS    OUTPUT is FS
         #-------------------------------------------------------------
         REUSE_ACTION=''; export REUSE_ACTION
         REPLACE_ACTION=''; export REPLACE_ACTION
         #-------------------------------------------------------------
         # check first if record format and length are already defined
         # before retrieving from File_Map
         #-------------------------------------------------------------
         if [ "a$RECFOR_O1" != a ]
         then
            RECFOR=$RECFOR_O1; export RECFOR
         else
            if [ "a$DSN_O1" != a ]
            then
               ddfx=`ftval $DSN_O1 $JOB_CAT 5`
               ddfs=`eval ebmsed $ddfx`
               if [ ! ${ddfs}null = "null" ]
               then
                  if [ -f $ddfs ]
                  then
                     PARFS=`cat $ddfs`
                     set $PARFS
                     if [ ${1}null = "null" ]
                     then # Attribute file existed but contained no attributes
                        RECFOR=record
                        echo " "
                        echo "REPRO  (W) $DD_O1"	
                        echo "           Setting record format to default: $BATCH_default_record_format"	
                        echo " "
                     else
                        RECFOR=$1
                     fi	
                  else # Attribute file specified in File_Map did not exist
                     RECFOR=record
                     echo " "
                     echo "REPRO  (W) $DD_O1"	
                     echo "           Setting record format to default: $BATCH_default_record_format"	
                     echo " "
                  fi
               else # Attribute file not specified in 5th position of File_Map
                  RECFOR=record
                  echo " "
                  echo "REPRO  (W) $DD_O1"	
                  echo "           Setting record format to default: $BATCH_default_record_format"	
                  echo " "
               fi
            else # DSN_O1 is not set
               RECFOR=record
               echo " "
               echo "REPRO  (W) $DD_O1"	
               echo "           Setting record format to default: $BATCH_default_record_format"	
               echo " "
            fi
         fi


      #----------------------------------------------------------------------
      # 7099
      # NOTE:  if EBM_REPRO does not equal 'MAINFRAME' then
      #           unikixbld is executed WITHOUT the options  
      #           -p reuse|noreuse and
      #           -k replace|noreplace 
      #           the variables assigning the options are nullified
      #        else
      #           the options are set to what was explicit int the job script
      #        else 
      #           the batch defaults noreuse noreplace are applied
      #
      #----------------------------------------------------------------------
         if [ "a$EBM_REPRO" != "aMAINFRAME" ]
         then
            REUSE_ACTION=''; export REUSE_ACTION
            REPLACE_ACTION=''; export REPLACE_ACTION
         fi

         
         #----------------------------------------------------------------------
         # 7088 If COUNT keyword specifies zero, then initialize output file 
         #----------------------------------------------------------------------
         if [ "a$COUNT" = "a0" ]
         then
            OUTPUT_FS=`eval ebmsed $DD_O1` 
            BATCH_COMMAND="cat $DEVNULL > `eval ebmsed $DD_O1`"
            cat $DEVNULL > `eval ebmsed $DD_O1`
            temp=$?
         else
########### BATCH_COMMAND="$UNIKIXBLD -t s -d `eval ebmsed $CMD_I1` -s `eval ebmsed $DD_O1` -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V"
            BATCH_COMMAND="$UNIKIXBLD -t s -d `eval ebmsed $CMD_I1` -s `eval ebmsed $DD_O1` -r $RECFOR $REUSE_ACTION $REPLACE_ACTION -V $EBM_SORTMEM_OPTION"
            $BATCH_COMMAND
            temp=$?
         fi
         if [ $temp != "0" ]
         then
            echo " "
            echo "REPRO (S) Command failed:" 
            echo "$BATCH_COMMAND"
            echo " "
         else
            echo " "
            echo "REPRO  (I) Command executed successfully"
            echo "$BATCH_COMMAND"
            echo " "
         fi
         exit $temp
      ;;
#------------------------------------------------------------------------------
      *)
         #-------------------------------------------------------------------
         # INPUT neither VS or FS         
         #-------------------------------------------------------------------
         if [ $FROKEY != null -a $TOKEY != null ]
         then
            if [ $output = "FS" ]
            then
               #-------------------------------------------------------------
               # INPUT is NOT VS and not FS  and OUTPUT is FS 
               #-------------------------------------------------------------
               FROTOKEY=\'\'\(\"$FROKEY\"\,\"$TOKEY\"\)\'\'
               $RDMCP $CMD_I1 $CMD_O1 -kr $FROTOKEY $ORS_O1
               temp=$?
            else
               #-------------------------------------------------------------
               # INPUT is NOT VS and not FS  and OUTPUT is NOT FS 
               #-------------------------------------------------------------
               FROTOKEY=\'\'\(\"$FROKEY\"\,\"$TOKEY\"\)\'\'
               $RDMCP $CMD_I1 $CMD_O1 -kr $FROTOKEY
               temp=$?
            fi
            if [ $temp != "0" ]
            then
               exit 1
            fi
         else
            if [ $FROKEY != null ]
            then
               if [ $output = "FS" ]
               then
                  FROTOKEY=\'\'\(\"$FROKEY\"\,\)\'\'
                  $RDMCP $CMD_I1 $CMD_O1 -kr $FROTOKEY $ORS_O1
                  temp=$?
               else
                  FROTOKEY=\'\'\(\"$FROKEY\"\,\)\'\'
                  $RDMCP $CMD_I1 $CMD_O1 -kr $FROTOKEY
                  temp=$?
                fi
                if [ $temp != "0" ]
                then
                   exit 1
                fi
            else
                if [ $output = "FS" ]
                then
                   $RDMCP $CMD_I1 $CMD_O1 $ORS_O1
                   temp=$?
                else
                   $RDMCP $CMD_I1 $CMD_O1
                   temp=$?
                fi
                if [ $temp != "0" ]
                then
                   exit 1
                fi
             fi
          fi
      ;;
#------------------------------------------------------------------------------
      esac
   else
      echo " "
      echo "$1"
      echo " "
      echo "REPRO (S) Input file must be type VS or FS"
      echo "REPRO (S) Invalid input file type: $input"
      echo " "
      exit 255
   fi
fi
# cleanup processing for tmp files
if [ -f ${EBMTMPDIR}/catoutg.$$ ]
then 
  rm ${EBMTMPDIR}/catoutg.$$ 2>$DEVNULL
fi
exit $temp
