000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. DYNCUR.
000030 DATA DIVISION.
000040 WORKING-STORAGE SECTION.
000050*
000060 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
000070 01 SQLSTATE PIC X(5).
000080 01 SQLMSG PIC X(255).
000090 01 STRSQL.
000100 49 STRSQL-L PIC S9(4) BINARY.
000110 49 STRSQL-D PIC X(28).
000120 01 CMD.
000130 49 CMD-L PIC S9(4) BINARY.
000140 49 CMD-D PIC X(5).
000150 01 CUR.
000160 49 CUR-L PIC S9(4) BINARY.
000170 49 CUR-D PIC X(5).
000180 01 COUNTRY.
000190 49 COUNTRY-L PIC S9(4) BINARY.
000200 49 COUNTRY-D PIC X(100).
000210 01 COUNTRY_NUM PIC S9(4) BINARY.
000220 EXEC SQL END DECLARE SECTION END-EXEC.
000230*
000240 01 ENDFLAG PIC X(2).
000250 01 INDATA PIC X(2).
000260 01 INNUM PIC S9(2).
000270 01 LOOP PIC S9(2).
000280*
000290 PROCEDURE DIVISION.
000300*
000310 EXEC SQL WHENEVER SQLERROR GOTO :CONNECT-ERROR END-EXEC.
000320 EXEC SQL WHENEVER NOT FOUND GOTO :NOT-FOUND-ERROR END-EXEC.
000330 EXEC SQL CONNECT TO 'DB01' END-EXEC.
000340*
000350 EXEC SQL WHENEVER SQLERROR GOTO :STM-ERROR END-EXEC.
000360 EXEC SQL WHENEVER NOT FOUND GOTO :NOT-FOUND-ERROR END-EXEC.
000370*
000380 PERFORM TEST BEFORE
000390 VARYING LOOP FROM 0 BY 1
000400 UNTIL LOOP > 9
000410*
000420 MOVE LOOP TO INDATA
000430 STRING "SELECT COUNTRY FROM SCH.TBL" INDATA DELIMITED BY "#"
000440 INTO STRSQL-D
000450 MOVE FUNCTION LENG(STRSQL-D) TO STRSQL-L
000460*
000470 STRING "CMD" INDATA DELIMITED BY "#"
000480 INTO CMD-D
000490 MOVE FUNCTION LENG(CMD-D) TO CMD-L
000500 STRING "CUR" INDATA DELIMITED BY "#"
000510 INTO CUR-D
000520 MOVE FUNCTION LENG(CUR-D) TO CUR-L
000530*
000540 EXEC SQL PREPARE :CMD FROM :STRSQL END-EXEC
000550*
000560 EXEC SQL ALLOCATE :CUR CURSOR FOR :CMD END-EXEC
000570 END-PERFORM.
000580*
000590 EXEC SQL WHENEVER NOT FOUND GOTO :NODATA END-EXEC.
000600*
000610 GET-DATA.
000620 DISPLAY "何番目の表のデータを表示するか入力してください (0-9)>> ".
000630 ACCEPT INNUM.
000640 IF INNUM < 0 AND INNUM > 9
000650 DISPLAY "入力されたデータに誤りがあります"
000660 GO TO GET-DATA
000670 END-IF.
000680*
000690 MOVE INNUM TO INDATA.
000700 STRING "CUR" INDATA DELIMITED BY "#"
000710 INTO CUR-D.
000720 MOVE FUNCTION LENG(CUR-D) TO CUR-L.
000730 EXEC SQL OPEN :CUR END-EXEC.
000740*
000750 PERFORM TEST BEFORE
000760 VARYING COUNTRY_NUM FROM 1 BY 1
000770 UNTIL COUNTRY_NUM < 0
000780 EXEC SQL FETCH :CUR INTO :COUNTRY END-EXEC
000790 DISPLAY COUNTRY_NUM "件目の国名は" COUNTRY-D "です"
000800 END-PERFORM.
000810*
000820 NODATA.
000830 EXEC SQL CLOSE :CUR END-EXEC.
000840 EXEC SQL COMMIT WORK END-EXEC.
000850*
000860 DISPLAY "終了しますか?(Y/y) >>".
000870 ACCEPT ENDFLAG.
000880 IF ENDFLAG NOT = "Y" AND ENDFLAG NOT = "y"
000890 GO TO GET-DATA
000900 END-IF.
000910*
000920 EXEC SQL COMMIT WORK END-EXEC.
000930 EXEC SQL DISCONNECT 'DB01' END-EXEC.
000940*
000950 EXIT PROGRAM.
000960*
000970 NOT-FOUND-ERROR.
000980 STM-ERROR.
000990 DISPLAY "SQLSTATE :" SQLSTATE.
001000 DISPLAY "SQLMSG : " SQLMSG.
001010*
001020 EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
001030 EXEC SQL COMMIT WORK END-EXEC.
001040 EXEC SQL DISCONNECT 'DB01' END-EXEC.
001050*
001060 EXIT PROGRAM.
001070*
001080 CONNECT-ERROR.
001090 DISPLAY "SQLSTATE :" SQLSTATE.
001100 DISPLAY "SQLMSG : " SQLMSG.
001110 EXIT PROGRAM. |