Highlighted
Absent Member.
Absent Member.
652 views

Unable to insert,delete or update

Hi

I have written a visual cobol program. I am able to read the datas from the table but i am unable to insert, delete or update the table. Below is the visual cobol program. Please let me know if i need to change anything.

 

$SET SQL(DBMAN = ODBC)
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST1CBL AS "test1.TEST1CBL".
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT OUTPUT-FILE ASSIGN TO "D:\POC\OUTPUT1.TXT" ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.

FD OUTPUT-FILE
RECORD CONTAINS 80 CHARACTERS
BLOCK CONTAINS 00 RECORDS
DATA RECORD IS OUTREC
LABEL RECORDS ARE STANDARD
RECORDING MODE IS F.
01 OUTREC.
02 O-ACCNO PIC 9(10).
02 FILLER PIC X.
02 O-NAME PIC X(20).
02 FILLER PIC X.
02 O-AMOUNT PIC X(10).
02 FILLER PIC X.
02 O-ACCOUNT_TYPE PIC X(20).
02 FILLER PIC X.
02 O-GENDER PIC X(1).
02 FILLER PIC X(16).
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE SQLCA
END-EXEC.

EXEC SQL
INCLUDE RRD.CLIENT1
END-EXEC.


EXEC SQL BEGIN DECLARE SECTION
END-EXEC.
01 WS-INDICATORS.
02 WS-EOF-IND PIC X(01) VALUE 'N'.
88 WS-END-OF-FILE VALUE 'Y'.
01 WS-NUMBER PIC 9.
01 WS-ACCNO PIC 9(10).
01 WS-NAME PIC X(20) VALUE "".
01 WS-AMOUNT PIC 9(10) VALUE 0.
01 WS-ACCOUNT_TYPE PIC X(20) VALUE "".
01 WS-GENDER PIC X VALUE "".

LINKAGE SECTION.

* 01 PARM-FIELD.
* 05 PARM-LENGTH PIC S9(4) COMP.
01 PARM-NUMBER PIC 9.
01 PARM-ACCNO PIC 9(10).
01 PARM-NAME PIC X(20).
01 PARM-AMOUNT PIC 9(10).
01 PARM-ACCOUNT_TYPE PIC X(20).
01 PARM-GENDER PIC X.

PROCEDURE DIVISION USING by value PARM-NUMBER,PARM-ACCNO,PARM-NAME,PARM-AMOUNT,PARM-ACCOUNT_TYPE,PARM-GENDER.
DISPLAY "HELLO WORLD".
* EXEC SQL
* CONNECT TO ROHAN USER 'RRD.P@ssw0rd'
* END-EXEC.
EXEC SQL
CONNECT TO ROHAN USER 'RRD' USING 'P@ssw0rd'
END-EXEC.
OPEN OUTPUT OUTPUT-FILE.
MOVE PARM-NUMBER TO WS-NUMBER.
MOVE PARM-ACCNO TO WS-ACCNO.
MOVE PARM-NAME TO WS-NAME.
MOVE PARM-AMOUNT TO WS-AMOUNT.
MOVE PARM-ACCOUNT_TYPE TO WS-ACCOUNT_TYPE.
MOVE PARM-GENDER TO WS-GENDER.

IF WS-NUMBER = 1 THEN
PERFORM 1000-READPARA.

IF WS-NUMBER = 2 THEN
PERFORM 1000-INSERTPARA.

IF WS-NUMBER = 3 THEN
PERFORM 1000-DELETEPARA.

IF WS-NUMBER = 4 THEN
PERFORM 1000-UPDATEPARA.
CLOSE OUTPUT-FILE.

GOBACK.


1000-READPARA.
DISPLAY "HELLO WORLD".
* MOVE SPACES TO OUTREC.
MOVE 0000000000 TO O-ACCNO.
EXEC SQL
SELECT ACCNO, NAME1, AMOUNT, ACCOUNT_TYPE, GENDER
INTO :O-ACCNO, :O-NAME, :O-AMOUNT, :O-ACCOUNT_TYPE, :O-GENDER FROM RRD.CLIENT1
WHERE NAME1=:WS-NAME
END-EXEC.
IF WS-ACCNO = O-ACCNO
PERFORM WRITE-PARA THRU END-PARA
ELSE
DISPLAY "RECORD IS NOT FOUND".

1000-INSERTPARA.


EXEC SQL
INSERT INTO RRD.CLIENT1
(ACCNO, NAME1, AMOUNT, ACCOUNT_TYPE, GENDER)
VALUES
(:WS-ACCNO, :WS-NAME, :WS-AMOUNT, :WS-ACCOUNT_TYPE, :WS-GENDER)
END-EXEC.



1000-DELETEPARA.
EXEC SQL
DELETE FROM CLIENT1
WHERE ACCNO = :WS-ACCNO
END-EXEC.


1000-UPDATEPARA.
EXEC SQL
UPDATE CLIENT1
SET
NAME1 = :WS-NAME,
AMOUNT = :WS-AMOUNT,
ACCOUNT_TYPE = :WS-ACCOUNT_TYPE,
GENDER = :WS-GENDER
WHERE ACCNO = :WS-ACCNO
END-EXEC.


WRITE-PARA.
WRITE OUTREC .
END-PARA.

0 Likes
1 Reply
Highlighted
Outstanding Contributor.
Outstanding Contributor.

You should always test for database errors. Test either field SQLCODE in SQLCA or use

01 mfsqlmessagetext pic X(500).

EXEC SQL
WHENEVER SQLERROR GO TO SQL-ERROR
END-EXEC
EXEC SQL
WHENEVER SQLWARNING GO TO SQL-ERROR
END-EXEC

SQL-ERROR.
display mfsqlmessagetext
....
You don't have a COMMIT statement in your program.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.