@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:
SELECT REPORTE-VENTAS ASSIGN TO "VENTAS.DAT"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS ID-PRODUCTO
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:
01 FS-REPORTE-VENTAS PIC XX.
88 esta-REPORTE-VENTAS value '00' '02'.
88 n-esta-REPORTE-VENTAS value '23'.
88 fin-REPORTE-VENTAS value '46' '10'.
88 bloqueado-REPORTE-VENTAS value '99' '90'.
88 f-bloqueado-REPORTE-VENTAS value '38' '93'.
88 f-noexiste-REPORTE-VENTAS value '35'.
En PROCEDURE
Código COBOL:
PROCEDURE DIVISION.
DECLARATIVES.
File-Error SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON reporte-ventas.
END DECLARATIVES.
ante de hacer el write ventas:
Código COBOL:
initialize venta
MOVE LLAVE-NUMERO-PRODUCTO TO ID-PRODUCTO
read reporte-ventas end-read
add unidades-vendidas to u-vendidas
if esta-REPORTE-VENTAS then
rewrite venta end-rewrite
else
write venta end-write
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:
initialize venta
MOVE LLAVE-NUMERO-PRODUCTO TO ID-PRODUCTO
perform test after until not bloqueado-REPORTE-VENTAS
read reporte-ventas end-read
if bloqueado-REPORTE-VENTAS then
display 'Registro bloqueado. Pulse intro para reintentar'
accept ws-continuar
end-if
end-perform
add unidades-vendidas to u-vendidas
if esta-REPORTE-VENTAS then
rewrite venta end-rewrite
else
write venta end-write
end-if.
Pregunta lo que no entiendas, pero revisa el link que te he puesto.