CREATE OR REPLACE PROCEDURE sp_fco_crea_ISS_mm
(
   i_cia	IN CHAR,
   i_anio	IN CHAR,
   i_mes	IN CHAR,
   i_cod_SUC	IN CHAR
)
/**********************************************************************************/
/*** Nombre:      sp_crea_mm_ISS.sql     	                                ***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                  ***/
/*** Descripcion: Genera el Medio Magnetico de acuerdo con las especificaciones ***/
/***		  SIGA - Formato Integrado (04)					***/
/*** Autor:	  Juan Carlos Leguizamon					***/
/*** Fecha:	  Junio 26 de 2001 						***/
/*** Version para ORACLE 8							***/
/**********************************************************************************/
AS
  /* VARIABLES ESTRUCTURA MEDIO MAGNETICO */
   CI01_06	Char(58);
   CI07_18 	Char(148);
   CI19_30 	Char(113);
   CI31	 	Char(5);
   CI32	 	Char(5);
   REN_31  	Char(116);
   REN_32  	Char(116);
   REN_33  	Char(116);
   REN_34  	Char(116);
   REN_35  	Char(116);
   REN_36  	Char(116);
   REN_37  	Char(116);
   REN_38  	Char(116);
   REN_39  	Char(116);
   R31C4   	Number(10,0);
   R31C8   	Number(10,0);
   R31C9   	Number(10,0);
   R31C13  	Number(10,0);
   R35C4   	Number(10,0);
   R35C8   	Number(10,0);
   R35C9   	Number(10,0);
   R31C10  	Number(10,0);
   R31C11  	Number(10,0);
   R31C12  	Number(10,0);
   R35C13  	Number(10,0);
   R36C4   	Number(10,0);
   R36C8   	Number(10,0);
   R36C9   	Number(10,0);
   R36C13  	Number(10,0);
   R37C4   	Number(10,0);
   R37C8   	Number(10,0);
   R37C9   	Number(10,0);
   R37C13  	Number(10,0);
   R38C4   	Number(10,0);
   R38C8   	Number(10,0);
   R38C9   	Number(10,0);
   R38C13  	Number(10,0);
   R39C4   	Number(10,0);
   R39C8   	Number(10,0);
   R39C9   	Number(10,0);
   R39C13  	Number(10,0);
   /* VARIABLES AUXILIARES (o de trabajo W) */
   /* Para armar sentencias dinamicamente */
   w_sql_1 	VarChar2(2000);
   w_sql_2 	VarChar2(2000);
   w_sql_3	VarChar2(2000);
   iRows	Integer;
   nombre_cursor Integer;
   /* Para hallar el periodo cotizado a salud (ste) */
   w_per_ste 	Char(6);
   w_mes_ste 	Number(2,0);
   /* Para hallar la forma de presentación y la sucursal */
   w_forma_pres	Char(1);
   w_cod_SUC	Char(10);
   w_suc_iss    Char(10);
   /* Para recuperar datos del ISS */
   w_cod_ISS 	Char(5);
   /* Para recuperar el total de afiliados a pensiones y salud */
   w_total 	Number(5,0);
BEGIN
   /* Codigo del ISS -Cambiar si es necesario - */
   w_cod_ISS := '''ISS''';
   /* Control del codigo de la sucursal */
   w_cod_SUC := Nvl(i_cod_SUC,' ');
   DELETE FCO_ISS_MM;
   COMMIT;
   /***********************************************************************/
   /*****          CONSTRUCCION DEL REGISTRO TIPO I                   *****/
   /***********************************************************************/
   CI01_06 := '00000104INSTITUTO DE SEGUROS SOCIALES           8600138161';
   SELECT RPad(LTrim(RTrim(SubStr(C.nombre_cia,1,40))), 40, ' ') ||
	  RPad(SubStr(A.tipo_id,1,1), 1, ' ') ||
	  LPad(LTrim(RTrim(fn_fco_tratar_NIT(i_cia))), 9, '0') ||
	  SubStr(C.registro_fiscal, Length(RTrim(C.registro_fiscal)),1) ||
	  RPad(SubStr(A.clase_aportante,1,1), 1, ' ') ||
	  RPad(LTrim(RTrim(SubStr(C.domicilio,1,40))), 40, ' ') ||
	  RPad(LTrim(RTrim(SubStr(M.nombre,1,15))), 15, ' ') ||
	  LPad(LTrim(RTrim(SubStr(LTrim(M.codigo),1,4))), 4, '0') ||
	  RPad(LTrim(RTrim(SubStr(D.nombre,1,15))), 15, ' ') ||
	  LPad(LTrim(RTrim(SubStr(LTrim(D.codigo),1,2))), 2, '0') ||
	  RPad(LTrim(RTrim(SubStr(C.telefono,1,10))), 10, ' ') ||
	  RPad(LTrim(RTrim(SubStr(A.fax,1,10))), 10, ' ')
   INTO CI07_18
   FROM	COMPANIAS C,
	FCO_CIAS_DATOS_ADI A,
	FCO_CIUDADES M,
	FCO_DEPARTAMENTOS D
   WHERE C.compania = A.compania   And
	 M.codigo   = A.cod_ciudad And
	 D.codigo   = A.cod_dpto   And
	 M.cod_dpto = D.codigo 	   And
	 C.compania = i_cia;
   /* Calculo del periodo cotizado a Salud */
   w_mes_ste := To_Number(i_mes) + 1;
   w_per_ste := i_anio || LPad(Rtrim(LTrim(To_Char(w_mes_ste))), 2, '0');
   IF w_mes_ste = 13 THEN
      w_per_ste := RTrim(LTrim(To_Char(To_Number(i_anio) + 1))) || '01';
   END IF;
   /* Forma de Presentación de la Autoliquidación de Aportes */
   w_forma_pres := 'C';
   IF Nvl(Length(LTrim(RTrim(w_cod_SUC))),0) > 0 THEN
	w_forma_pres:='S';
	w_cod_SUC := RPad(w_cod_SUC,10,' ');
	w_suc_iss := RPad(w_cod_SUC,10,' ');
   ELSE
	SELECT forma_presentacion
	INTO   w_forma_pres
	FROM   fco_administradoras
	WHERE  codigo='ISS' AND tipo='EPS';
	w_cod_SUC := RPad(' ',10,' ');
        w_suc_iss := RPad(' ',9,' ')||'1';
   END IF;

   w_total:=0;
   SELECT
      ' SELECT Count(*) AS Total' ||
      ' FROM ' ||
      ' (SELECT Distinct COD_TRAB' ||
      ' FROM FCO_ISS_'||RTrim(i_cia)||'_'||i_anio||'_'||i_mes ||
      Decode(Nvl(Length(LTrim(RTrim(w_cod_SUC))),0),0,'',' WHERE COD_SUC=' ||''''||LTrim(RTrim(w_cod_SUC))||'''') ||
      ' GROUP BY COD_TRAB' ||
      ' HAVING SUM(C23)>0)'
   INTO w_sql_1
   FROM DUAL;
   BEGIN
      nombre_cursor := dbms_sql.open_cursor;
      dbms_sql.parse(nombre_cursor, w_sql_1, dbms_sql.native);
      dbms_sql.define_column(nombre_cursor, 1, w_total);
      iRows := dbms_sql.execute(nombre_cursor);
      IF dbms_sql.fetch_rows(nombre_cursor) > 0 THEN
	 dbms_sql.column_value(nombre_cursor, 1, w_total);
      END IF;
      commit;
      dbms_sql.close_cursor(nombre_cursor);
   EXCEPTION
      WHEN OTHERS THEN
	 Rollback;
	 Raise_Application_Error (-20001, 'Error al recuperar el nro de afiliados en pensiones');
   END ;

   CI19_30 := LTrim(RTrim(i_anio)) || LPad(LTrim(RTrim(i_mes)), 2, '0') ||
	  w_per_ste || Rpad(' ',40,' ') || Rpad(' ',5,' ') ||
	  Rpad(' ',1,' ') || Rpad(' ',6,' ') || RPad(' ',8,' ') ||
	  Rpad(' ',10,' ') || Rpad(' ',15,' ') || w_forma_pres || w_suc_iss ||
	  LPad(LTrim(RTrim(To_Char(w_total))), 5, '0');

   w_cod_SUC := LTrim(RTrim(w_cod_SUC));
   /* Numero de Afiliados al ISS en Pensiones */
   w_total:=0;
   SELECT
      ' SELECT Count(*) AS Total' ||
      ' FROM ' ||
      ' (SELECT Distinct COD_TRAB' ||
      ' FROM FCO_ISS_'||RTrim(i_cia)||'_'||i_anio||'_'||i_mes ||
      ' WHERE COD_FPO='||w_cod_ISS ||
      Decode(Nvl(Length(LTrim(RTrim(w_cod_SUC))),0),0,'',' AND COD_SUC=' ||''''||LTrim(RTrim(w_cod_SUC))||'''') ||
      ' GROUP BY COD_TRAB' ||
      ' HAVING SUM(C23)>0)'
   INTO w_sql_1
   FROM DUAL;
   BEGIN
      nombre_cursor := dbms_sql.open_cursor;
      dbms_sql.parse(nombre_cursor, w_sql_1, dbms_sql.native);
      dbms_sql.define_column(nombre_cursor, 1, w_total);
      iRows := dbms_sql.execute(nombre_cursor);
      IF dbms_sql.fetch_rows(nombre_cursor) > 0 THEN
	 dbms_sql.column_value(nombre_cursor, 1, w_total);
      END IF;
      commit;
      dbms_sql.close_cursor(nombre_cursor);
   EXCEPTION
      WHEN OTHERS THEN
	 Rollback;
	 Raise_Application_Error (-20001, 'Error al recuperar el nro de afiliados en pensiones');
   END ;
   CI31 := LPad(RTrim(LTrim(To_Char(w_total))), 5, '0');
   /* Numero de Afiliados al ISS en Salud */
   w_total:=0;
   SELECT
      ' SELECT Count(*) AS Total' ||
      ' FROM ' ||
      ' (SELECT Distinct COD_TRAB' ||
      ' FROM FCO_ISS_'||RTrim(i_cia)||'_'||i_anio||'_'||i_mes ||
      ' WHERE COD_EPS='||w_cod_ISS ||
      Decode(Nvl(Length(LTrim(RTrim(w_cod_SUC))),0),0,'',' AND COD_SUC=' ||''''||LTrim(RTrim(w_cod_SUC))||'''') ||
      ' GROUP BY COD_TRAB' ||
      ' HAVING SUM(C24)>0)'
   INTO w_sql_1
   FROM DUAL;
   BEGIN
      nombre_cursor := dbms_sql.open_cursor;
      dbms_sql.parse(nombre_cursor, w_sql_1, dbms_sql.native);
      dbms_sql.define_column(nombre_cursor, 1, w_total);
      iRows := dbms_sql.execute(nombre_cursor);
      IF dbms_sql.fetch_rows(nombre_cursor) > 0 THEN
	 dbms_sql.column_value(nombre_cursor, 1, w_total);
      END IF;
      commit;
      dbms_sql.close_cursor(nombre_cursor);
   EXCEPTION
      WHEN OTHERS THEN
	 Rollback;
	 Raise_Application_Error (-20001, 'Error al recuperar el nro de afiliados en salud');
   END ;
   CI32 := LPad(RTrim(LTrim(To_Char(w_total))), 5, '0');
   INSERT INTO FCO_ISS_MM VALUES (0, CI01_06 || CI07_18 || CI19_30 || CI31 || CI32);
   /***********************************************************************/
   /*****          CONSTRUCCION DEL REGISTRO TIPO II                  *****/
   /***********************************************************************/
   w_sql_1 :=
   ' INSERT INTO FCO_ISS_MM' ||
   ' SELECT RowNum,' ||
	' LPad(RowNum, 5, ''0'') ||' ||
	' ''2''||RPad(LTrim(RTrim(SubStr(C03,1,1))),1,'' '') ||' ||
   	' LPad(LTrim(RTrim(SubStr(C04,1,12))), 12, ''0'') ||' ||
   	' fn_Separar_Nombre(C05,15,15,15,15) ||' ||
   	' Decode(Length(RTrim(LTrim(C09))),0,'' '',C09) ||' ||
   	' Decode(Length(RTrim(LTrim(C10))),0,'' '',C10) ||' ||
   	' Decode(Length(RTrim(LTrim(C11))),0,'' '',C11) ||' ||
   	' Decode(Length(RTrim(LTrim(C12))),0,'' '',C12) ||' ||
   	' Decode(Length(RTrim(LTrim(C13))),0,'' '',C13) ||' ||
   	' Decode(Length(RTrim(LTrim(C14))),0,'' '',C14) ||' ||
   	' Decode(Length(RTrim(LTrim(C15))),0,'' '',C15) ||' ||
   	' Decode(Length(RTrim(LTrim(C16))),0,'' '',C16) ||' ||
   	' Decode(Length(RTrim(LTrim(C17))),0,'' '',C17) ||' ||
   	' Decode(Length(RTrim(LTrim(C18))),0,'' '',C18) ||' ||
   	' Decode(Length(RTrim(LTrim(C19))),0,'' '',C19) ||' ||
   	' Decode(Length(RTrim(LTrim(C20))),0,'' '',C20) ||' ||
   	' Decode(Length(RTrim(LTrim(C21))),0,'' '',C21) ||';
   w_sql_2 :=
   	' LPad(LTrim(RTrim(To_Char(Floor(C22)))), 2, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C23)))), 2, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C24)))), 2, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(0)))), 2, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C26)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C27)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C28)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C29)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(0)))), 9, ''0'') ||' ||
	' ''0'' || RPad(LTrim(RTrim(To_Char(C31))), 5, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C32)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C33)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C34)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C35)))), 9, ''0'') ||';
   SELECT
	' LPad(LTrim(RTrim(To_Char(Floor(C36)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C37)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C38)))), 9, ''0'') ||' ||
   	' RPad(LTrim(RTrim(SubStr(C39,1,10)))||'' '', 10, '' '') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C40)))), 9, ''0'') ||' ||
   	' RPad(LTrim(RTrim(SubStr(C41,1,10)))||'' '', 10, '' '') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C42)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C43)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C44)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(C45)))), 9, ''0'') ||' ||
	' LPad(LTrim(RTrim(To_Char(Floor(0)))), 9, ''0'') ||' ||
   	' RPad(LTrim(RTrim(SubStr(C47,1,5)))||'' '', 5, '' '') ||' ||
   	' RPad(LTrim(RTrim(SubStr(C48,1,5)))||'' '', 5, '' '')' ||
   ' FROM FCO_ISS_' || LTrim(RTrim(i_cia)) || '_' || LTrim(RTrim(i_anio)) || '_' || LTrim(RTrim(i_mes)) ||
   ' WHERE CIA=' || '''' || i_cia || '''' ||
   Decode(Nvl(Length(LTrim(RTrim(w_cod_SUC))),0),0,'',' AND COD_SUC=' ||''''||LTrim(RTrim(w_cod_SUC))||'''') ||
   ' AND (C23 + C24 + C25) >0'
   INTO w_sql_3
   FROM DUAL;
commit;
   BEGIN
      nombre_cursor := dbms_sql.open_cursor;
      dbms_sql.parse(nombre_cursor, w_sql_1||w_sql_2||w_sql_3, dbms_sql.native);
      iRows := dbms_sql.execute(nombre_cursor);
      dbms_sql.close_cursor(nombre_cursor);
   EXCEPTION
      WHEN OTHERS THEN
	 Rollback;
	 Raise_Application_Error (-20001, 'Error al llenar la tabla FCO_ISS_MM con los registros Tipo 2');
   END ;
   /***********************************************************************/
   /*****          CONSTRUCCION DEL REGISTRO TIPO III                 *****/
   /***********************************************************************/
   /* Totales para los campos 4, 8, 9, 10, 11, 12 y 13 del medio magnetico (Renglon 31) */
   SELECT
	' SELECT  Nvl(Floor(Sum(C32)),0), Nvl(Floor(Sum(C36)),0),' ||
		' Nvl(Floor(Sum(C38)),0), Nvl(Floor(Sum(C40)),0),' ||
		' Nvl(Floor(Sum(C42)),0), Nvl(Floor(Sum(C43)),0),' ||
		' Nvl(Floor(Sum(C46)),0)' ||
	' FROM FCO_ISS_'||LTrim(RTrim(i_cia))||'_'||LTrim(RTrim(i_anio))||'_'||LTrim(RTrim(i_mes)) ||
	' WHERE cia='||''''||i_cia||'''' ||
        Decode(Nvl(Length(LTrim(RTrim(w_cod_SUC))),0),0,'',' AND COD_SUC=' ||''''||LTrim(RTrim(w_cod_SUC))||'''')
   INTO w_sql_1
   FROM DUAL;
   BEGIN
      nombre_cursor := dbms_sql.open_cursor;
      dbms_sql.parse(nombre_cursor, w_sql_1, dbms_sql.native);
      dbms_sql.define_column(nombre_cursor, 1, R31C4);
      dbms_sql.define_column(nombre_cursor, 2, R31C8);
      dbms_sql.define_column(nombre_cursor, 3, R31C9);
      dbms_sql.define_column(nombre_cursor, 4, R31C10);
      dbms_sql.define_column(nombre_cursor, 5, R31C11);
      dbms_sql.define_column(nombre_cursor, 6, R31C12);
      dbms_sql.define_column(nombre_cursor, 7, R31C13);
      iRows := dbms_sql.execute(nombre_cursor);
      IF dbms_sql.fetch_rows(nombre_cursor) > 0 THEN
	 dbms_sql.column_value(nombre_cursor, 1, R31C4);
	 dbms_sql.column_value(nombre_cursor, 2, R31C8);
	 dbms_sql.column_value(nombre_cursor, 3, R31C9);
	 dbms_sql.column_value(nombre_cursor, 4, R31C10);
	 dbms_sql.column_value(nombre_cursor, 5, R31C11);
	 dbms_sql.column_value(nombre_cursor, 6, R31C12);
	 dbms_sql.column_value(nombre_cursor, 7, R31C13);
      END IF;
      commit;
      dbms_sql.close_cursor(nombre_cursor);
   EXCEPTION
      WHEN OTHERS THEN
	 Rollback;
	 Raise_Application_Error (-20001, 'Error al calcular los totales del renglon 31');
   END ;
   /*******	RENGLON 31	******/
   REN_31 := '000313' || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R31C4))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R31C8))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R31C9))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R31C10))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R31C11))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R31C12))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R31C13))), 10, '0');
   INSERT INTO FCO_ISS_MM VALUES (999931, REN_31);
   /*******	RENGLON 32	******/
   REN_32 := '000323' || RPad(' ',10,' ') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0');
   INSERT INTO FCO_ISS_MM VALUES (999932, REN_32);
   /*******	RENGLON 33	******/
   REN_33 := '000333' || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0');
   INSERT INTO FCO_ISS_MM VALUES (999933, REN_33);
   /*******	RENGLON 34	******/
   REN_34 := '000343' || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0');
   INSERT INTO FCO_ISS_MM VALUES (999934, REN_34);
   /*******	RENGLON 35	******/
   R35C4 := R31C4;
   R35C8 := R31C8;
   R35C9 := R31C9;
   R35C13 := R31C13;
   REN_35 := '000353' || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R35C4))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R35C8))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R35C9))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R35C13))), 10, '0');
   INSERT INTO FCO_ISS_MM VALUES (999935, REN_35);
   /*******	RENGLON 36	******/
   R36C4 := 0;
   R36C8 := 0;
   R36C9 := 0;
   R36C13 := 0;
   REN_36 := '000363' || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R36C4))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R36C8))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R36C9))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R36C13))), 10, '0');
   INSERT INTO FCO_ISS_MM VALUES (999936, REN_36);
   /*******	RENGLON 37	******/
   R37C4 := R35C4 + R36C4;
   R37C8 := R35C8 + R36C8;
   R37C9 := R35C9 + R36C9;
   R37C13 := R35C13 + R36C13;
   REN_37 := '000373' || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R37C4))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R37C8))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R37C9))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R37C13))), 10, '0');
   INSERT INTO FCO_ISS_MM VALUES (999937, REN_37);
   /*******	RENGLON 38	******/
   R38C4 := 0;
   R38C8 := 0;
   R38C9 := 0;
   R38C13 := 0;
   REN_38 := '000383' || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0');
   INSERT INTO FCO_ISS_MM VALUES (999938, REN_38);
   /*******	RENGLON 39	******/
   R39C4 := R37C4 - R38C4;
   R39C8 := R37C8 - R38C8;
   R39C9 := R37C9 - R38C9;
   R39C13 := R37C13 - R38C13;
   REN_39 := '000393' || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R39C4))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R39C8))), 10, '0') ||
	LPad(LTrim(RTrim(To_Char(R39C9))), 10, '0') ||
	LPad('0',10,'0') || LPad('0',10,'0') || LPad('0',10,'0') ||
	LPad(LTrim(RTrim(To_Char(R39C13))), 10, '0');
   INSERT INTO FCO_ISS_MM VALUES (999939, REN_39);
   /***********************************************************************/
   /*****          CONSTRUCCION DEL REGISTRO TIPO IV                  *****/
   /***********************************************************************/
   INSERT INTO FCO_ISS_MM VALUES (999940, '999994');
   COMMIT WORK;
END;
/
CREATE PUBLIC SYNONYM sp_fco_crea_ISS_mm FOR ADAM.sp_fco_crea_ISS_mm;
GRANT EXECUTE ON sp_fco_crea_ISS_mm TO adama;
