write a program to read from a VSAM file , there will be a
5 records to create name. empno. resignation and address
to update in a db2 table and call another program using
dynamic call to find the matching fields in program 1 to
update in db2 table.

anybody pls send de program for dis ?

thanks in advance...



write a program to read from a VSAM file , there will be a 5 records to create name. empno. resig..

Answer / Priti Rani

Here's an example of how you might write a program in RPG LE (RPG IV) to read from a VSAM file, update records, and call another program. This assumes you have the necessary IBM DB2 connectivity libraries.
1. Define the program parameters:
```less
D DCL-PR S 01 O*
D DSN S 02A 50 I DSQA(20) INZ((DSN))
D FILE S 03A 50 O DSQA(20) OUTZ((FILE))
D TMPDAT S 04A 80 O PARM
```
2. Define the program specifications and open the file:
```less
D SPECIFICATIONS S 05 O*
D DESCRIPTION S 01 80 A 'VSAM Reader and Updater'
D PROGRAM S 02 80 A 'YOURPGMNAME'
D DATE S 03 4 I X'*YYMMDD*'
D TIME S 04 4 I X'*HHMMSS*'
D SYSTEM S 05 8 I X'*ABCDEFGH*'
D USERID S 06 8 I X'*12345678*'
D PASSWORD S 07 8 I X'*98765432*'

D E EXEC SQL
OPEN DB2FILE FOR FILE => :FILE USING :DSN;
```
3. Define the VSAM file descriptor and data structures:
```less
D FILEDESC S 08 O*
D FLD_NAME S 01 40 C 'Name'
D FLD_EMPNO S 02 5 X 'Empno'
D FLD_RESIGNATION S 03 1 X 'Resignation'
D FLD_ADDRESS S 04 70 A 'Address'

D E EXEC SQL
DECLARE CURSOR VSAMCURSOR IS SELECT * FROM :FILE;
```
4. Loop through the records in the cursor, update the DB2 table, and call another program:
```less
D E EXEC SQL
FETCH NEXT FROM VSAMCURSOR INTO :TMPDAT;
IF SQLCODE = 0 THEN
DYNPROG('OTHERPGM', TMPDAT);
-- Update the DB2 table with matching fields
UPDATE EMPLOYEE SET Resignation = :TMPDAT.Resignation, Address = :TMPDAT.Address WHERE Empno = :TMPDAT.Empno;
ELSE IF SQLCODE = -104 THEN
-- Reach end of file
EXIT PROGRAM;
ENDIF;
```
5. Close the file and end the program:
```less
D E EXEC SQL
CLOSE VSAMCURSOR;
EXITPROG;
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More VSAM Interview Questions

How to insert values for variables that are declared as COMP-3 variables in COBOL program in an already created VSAM file.

3 Answers  


what will happen if there is no secondary allocation made for datasets?

1 Answers   IBM,


What is the COBOL RECORD KEY clause?

2 Answers  


name a few common vsam status codes?

1 Answers   IBM,


Define base cluster?

1 Answers  


What is the device independent method to indicate where a record is stored?

1 Answers  


what is control interval(CI) and control Area(CA)

4 Answers   EDS,


How to rename one vsam file as well as it's index?

4 Answers   BEA,


What are the access method services used in vsam?

1 Answers  


explain in brief how you can create a vsam file?

1 Answers   IBM,


what do you mean by the repro command?

1 Answers   IBM,


what is meant by dirty read in vsam?

1 Answers   IBM,


Categories