Ver Mensaje Individual
  #2
Antiguo 23 de febrero de 2023, 11:00
JCantero
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Agradecimientos: Por muchos agradecimientos de parte de los Foreros - Issue reason: Por muchos agradecimientos de parte de los Foreros 
Última Actividad 02.09.2026 00:15
Posts Posts: 442
Likes enviados Enviados: 167
Likes recibidos Recibidos: 269

@Marengo97, efectivamente esa seria la idea.

Observación1. Lo primero es que al realizar la venta, no solo tendrias que ver si existe el producto o no, sino tambien que tengas stock para venderlo.

Observación2. En la FD de ventas no necesitas tener la descripción pues hay que evitar los campos duplicados.

Y entrando en tu duda, tienes que inicializar registro de VENTA, leer REPORTE-VENTA, incrementar el numero de elementos vendidos, si NO existia WRITE VESTAS, si existia REWRITE VENTAS

Para esto ultimo necesitas un "file status", para reconocer si un registro existe o no.

Te recomiendo que le eches un vistazo al post de FPAIX: [Información] Ejemplos de manejo de archivos y tecla de funcion

En el hace un mantenimiento de un fichero indexado. Dedicale tiempo y pregunta lo que no entiendas.

Para hacer lo que tu quieres necesitas añadir estas cosas:

en SELECT

Código COBOL:
  1.            SELECT REPORTE-VENTAS  ASSIGN TO "VENTAS.DAT"
  2.                                   ORGANIZATION IS INDEXED
  3.                                   ACCESS MODE  IS DYNAMIC
  4.                                   RECORD KEY   IS ID-PRODUCTO
  5.                                   FILE STATUS FS-REPORTE-VENTAS.

en WORKING ( para hacerlo bien, al abrir el fichero (open i-o) hay que preguntar si f-noexiste-REPORTE-VENTAS (ya que metera un 35 en el file status)y si no permitir crearlo y hacer (open output), cuando leas preguntar esta-REPORTE-VENTAS para despues hacer un write o rewrite)

Código COBOL:
  1.        01  FS-REPORTE-VENTAS PIC XX.
  2.               88 esta-REPORTE-VENTAS             value '00' '02'.
  3.               88 n-esta-REPORTE-VENTAS           value '23'.
  4.               88 fin-REPORTE-VENTAS              value '46'  '10'.
  5.               88 bloqueado-REPORTE-VENTAS        value '99' '90'.
  6.               88 f-bloqueado-REPORTE-VENTAS      value '38' '93'.
  7.               88 f-noexiste-REPORTE-VENTAS       value '35'.

En PROCEDURE

Código COBOL:
  1.        PROCEDURE DIVISION.
  2.        DECLARATIVES.
  3.        File-Error SECTION.
  4.            USE AFTER STANDARD ERROR PROCEDURE ON reporte-ventas.      
  5.        END DECLARATIVES.

ante de hacer el write ventas:
Código COBOL:
  1.                initialize venta
  2.                MOVE LLAVE-NUMERO-PRODUCTO TO ID-PRODUCTO
  3.                read reporte-ventas end-read
  4.                add unidades-vendidas to u-vendidas
  5.                if esta-REPORTE-VENTAS then
  6.                     rewrite venta end-rewrite
  7.                else
  8.                     write venta end-write
  9.                end-if.

y si lo quieres multiproceso tienes que controlar que este bloqueado el registro venta pero esto ya es afinar muchos

Código COBOL:
  1.                initialize venta
  2.                MOVE LLAVE-NUMERO-PRODUCTO TO ID-PRODUCTO
  3.                perform test after until not bloqueado-REPORTE-VENTAS
  4.                     read reporte-ventas end-read
  5.                     if bloqueado-REPORTE-VENTAS then
  6.                         display 'Registro bloqueado. Pulse intro para reintentar'
  7.                         accept ws-continuar
  8.                     end-if
  9.                end-perform
  10.                add unidades-vendidas to u-vendidas
  11.                if esta-REPORTE-VENTAS then
  12.                     rewrite venta end-rewrite
  13.                else
  14.                     write venta end-write
  15.                end-if.

Pregunta lo que no entiendas, pero revisa el link que te he puesto.
JCantero is offline   Responder Con Cita