Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. CUSTOMER-MANAGEMENT.
- *>AUTHOR. Natxo Varona.
- *>INSTALLATION. NEW CURSO COBOL 2024.
- *>DATE-WRITTEN. 11/12/2024.
- *>DATE-COMPILED.
- *>SECURITY. NO ES CONFIDENCIAL.
- *>--------------------------------------------------------------*
- *>OBJETIVO:CREAR MENU CRUD DE CLIENTES Y CONECTAR Y GUARDAR *
- *> LOS DATOS EN UNA TABLA DE SQL *
- *>--------------------------------------------------------------*
- ENVIRONMENT DIVISION.
- CONFIGURATION SECTION.
- SOURCE-COMPUTER. PC.
- OBJECT-COMPUTER. PC.
- INPUT-OUTPUT SECTION.
- FILE-CONTROL.
- SELECT CUSTOMER-FILE ASSIGN TO "customers.dat"
- ORGANIZATION IS INDEXED
- ACCESS MODE IS DYNAMIC
- RECORD KEY IS CUSTOMER-ID
- FILE STATUS IS FILE-STATUS.
- DATA DIVISION.
- FILE SECTION.
- FD CUSTOMER-FILE.
- 01 CUSTOMER-RECORD.
- 05 CUSTOMER-ID PIC 9(6).
- 05 CUSTOMER-NAME PIC X(30).
- 05 CUSTOMER-ADDRESS PIC X(50).
- 05 CUSTOMER-PHONE PIC X(15).
- 05 CUSTOMER-EMAIL PIC X(50).
- WORKING-STORAGE SECTION.
- 01 WS-VARS.
- 05 MENU-OPTION PIC 9 VALUE 0.
- 05 FILE-STATUS PIC XX.
- 05 WS-EOF PIC X VALUE 'N'.
- 05 CONTINUE-OPTION PIC X VALUE 'S'.
- 01 WS-CURRENT-DATE-DATA.
- 05 WS-CURRENT-DATE.
- 10 WS-CURRENT-YEAR PIC 9(4).
- 10 WS-CURRENT-MONTH PIC 9(2).
- 10 WS-CURRENT-DAY PIC 9(2).
- PROCEDURE DIVISION.
- MAIN-PROGRAM.
- PERFORM INIT-PROGRAM.
- PERFORM UNTIL MENU-OPTION = 6
- DISPLAY SPACE
- DISPLAY "*** SISTEMA DE GESTION DE CLIENTES ***"
- DISPLAY "1. Inicializar Archivo"
- DISPLAY "2. Alta de Cliente"
- DISPLAY "3. Baja de Cliente"
- DISPLAY "4. Modificacion de Cliente"
- DISPLAY "5. Listado de Clientes"
- DISPLAY "6. Salir"
- DISPLAY "Seleccione una opcion: " WITH NO ADVANCING
- ACCEPT MENU-OPTION
- EVALUATE MENU-OPTION
- WHEN 1
- PERFORM INIT-FILE
- WHEN 2
- PERFORM ADD-CUSTOMER
- WHEN 3
- PERFORM DELETE-CUSTOMER
- WHEN 4
- PERFORM UPDATE-CUSTOMER
- WHEN 5
- PERFORM LIST-CUSTOMERS
- WHEN 6
- PERFORM END-PROGRAM
- WHEN OTHER
- DISPLAY "Opcion no válida."
- END-EVALUATE
- END-PERFORM.
- STOP RUN.
- INIT-PROGRAM.
- OPEN I-O CUSTOMER-FILE
- IF FILE-STATUS = "35"
- OPEN OUTPUT CUSTOMER-FILE
- CLOSE CUSTOMER-FILE
- DISPLAY "Archivo inicializado."
- END-IF
- CLOSE CUSTOMER-FILE.
- INIT-FILE.
- OPEN OUTPUT CUSTOMER-FILE
- CLOSE CUSTOMER-FILE
- DISPLAY "Archivo reinicializado correctamente.".
- ADD-CUSTOMER.
- OPEN I-O CUSTOMER-FILE
- DISPLAY SPACE
- DISPLAY "ALTA DE CLIENTE"
- DISPLAY "ID Cliente (6 dígitos): " WITH NO ADVANCING
- ACCEPT CUSTOMER-ID
- DISPLAY "Nombre: " WITH NO ADVANCING
- ACCEPT CUSTOMER-NAME
- DISPLAY "Direccion: " WITH NO ADVANCING
- ACCEPT CUSTOMER-ADDRESS
- DISPLAY "Telefono: " WITH NO ADVANCING
- ACCEPT CUSTOMER-PHONE
- DISPLAY "Email: " WITH NO ADVANCING
- ACCEPT CUSTOMER-EMAIL
- WRITE CUSTOMER-RECORD
- INVALID KEY
- DISPLAY "Error: ID de cliente ya existe."
- NOT INVALID KEY
- DISPLAY "Cliente añadido correctamente."
- END-WRITE
- CLOSE CUSTOMER-FILE.
- DELETE-CUSTOMER.
- OPEN I-O CUSTOMER-FILE
- DISPLAY SPACE
- DISPLAY "BAJA DE CLIENTE"
- DISPLAY "ID Cliente a eliminar: " WITH NO ADVANCING
- ACCEPT CUSTOMER-ID
- DELETE CUSTOMER-FILE RECORD
- INVALID KEY
- DISPLAY "Error: Cliente no encontrado."
- NOT INVALID KEY
- DISPLAY "Cliente eliminado correctamente."
- END-DELETE
- CLOSE CUSTOMER-FILE.
- UPDATE-CUSTOMER.
- OPEN I-O CUSTOMER-FILE
- DISPLAY SPACE
- DISPLAY "MODIFICACIÓN DE CLIENTE"
- DISPLAY "ID Cliente a modificar: " WITH NO ADVANCING
- ACCEPT CUSTOMER-ID
- READ CUSTOMER-FILE
- INVALID KEY
- DISPLAY "Error: Cliente no encontrado."
- NOT INVALID KEY
- DISPLAY "Datos actuales:"
- DISPLAY "Nombre: " CUSTOMER-NAME
- DISPLAY "Direccion: " CUSTOMER-ADDRESS
- DISPLAY "Telefono: " CUSTOMER-PHONE
- DISPLAY "Email: " CUSTOMER-EMAIL
- DISPLAY SPACE
- DISPLAY "Nuevos datos:"
- DISPLAY "Nombre: " WITH NO ADVANCING
- ACCEPT CUSTOMER-NAME
- DISPLAY "Direccion: " WITH NO ADVANCING
- ACCEPT CUSTOMER-ADDRESS
- DISPLAY "Telefono: " WITH NO ADVANCING
- ACCEPT CUSTOMER-PHONE
- DISPLAY "Email: " WITH NO ADVANCING
- ACCEPT CUSTOMER-EMAIL
- REWRITE CUSTOMER-RECORD
- INVALID KEY
- DISPLAY "Error al actualizar cliente."
- NOT INVALID KEY
- DISPLAY "Cliente modificado correctamente."
- END-REWRITE
- END-READ
- CLOSE CUSTOMER-FILE.
- LIST-CUSTOMERS.
- OPEN INPUT CUSTOMER-FILE
- DISPLAY SPACE
- DISPLAY "LISTADO DE CLIENTES"
- DISPLAY "ID Nombre Telefono"
- DISPLAY "------------------------------------------------"
- MOVE 'N' TO WS-EOF
- READ CUSTOMER-FILE
- AT END MOVE 'Y' TO WS-EOF
- END-READ
- PERFORM UNTIL WS-EOF = 'Y'
- DISPLAY CUSTOMER-ID " "
- CUSTOMER-NAME " "
- CUSTOMER-PHONE
- READ CUSTOMER-FILE
- AT END MOVE 'Y' TO WS-EOF
- END-READ
- END-PERFORM
- CLOSE CUSTOMER-FILE.
- END-PROGRAM.
- DISPLAY "Programa finalizado.".
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement