Contoh Program Statement GOTO Dan Perform Pada COBOL
Pernyataan GO TO
Bentuk 1 :
GO TO nama-paragraph.
Contoh Programnya :
IDENTIFICATION DIVISION.Tampilan outputnya dari Program diatas :
PROGRAM-ID. go-to2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 Jawab PIC A.
PROCEDURE DIVISION.
Tanya.
DISPLAY ‘ Masukkan Jawab berupa huruf ( D/E/F/G ) ? ‘
ACCEPT Jawab.
Seleksi-Jawab.
IF Jawab = ‘D’ GO TO Kode-D.
IF Jawab = ‘E’ GO TO Kode-E.
IF Jawab = ‘F’ GO TO Kode-F.
IF Jawab = ‘G’ GO TO Kode-G.
Kode-D.
DISPLAY ‘ Kampus Depok ‘
GO TO Selesai.
Kode-E.
DISPLAY ‘ Kampus Kelapa Dua ‘
GO TO Selesai.
Kode-F.
DISPLAY ‘ Kampus Cikini ‘
GO TO Selesai.
Kode-G.
DISPLAY ‘ Kampus Kelapa Dua Perempatan ‘
GO TO Selesai.
Selesai.
STOP RUN.
Masukkan Jawab berupa huruf ( D/E/F/G ) ?
E
Kampus Kelapa Dua
Masukkan Jawab berupa huruf ( D/E/F/G ) ?
D
Kampus Depok
Bentuk 2 :
GO TO nama-paragraph-1 [ , nama-paragraph-2 , .... ] DEPENDING ON variable
ContohProgramnya :
IDENTIFICATION DIVISION.Hasil eksekusi :
PROGRAM-ID. hari.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 pilihan PIC 9.
PROCEDURE DIVISION.
pilih-hari.
DISPLAY ( , ) ‘ Pilih salah satu kode daerah waktu di Indonesia ( 1 .. 3 ) = ‘
ACCEPT ( , ) pilihan WITH AUTO SKIP.
DISPLAY SPACES.
GO TO waktu-1, waktu-2, waktu-3 DEPENDING ON pilihan.
GO TO pesan-salah.
waktu-1.
DISPLAY ‘ Waktu Indonesia Bagian Barat ‘.
GO TO akhir-program.
waktu-2.
DISPLAY ‘ Waktu Indonesia Bagian Tengah ‘.
GO TO akhir-program.
waktu-3.
DISPLAY ‘ Waktu Indonesia Bagian Timur ‘.
GO TO akhir-program.
pesan-salah.
DISPLAY ‘ Kode yang dimasukkan salah !!! ‘.
akhir-program.
STOP RUN.
Pilih salah satu kode daerah waktu di Indonesia ( 1 .. 3 ) = 1
Waktu Indonesia Bagian Barat
Pilih salah satu kode daerah waktu di Indonesia ( 1 .. 3 ) = 5
Kode yang dimasukkan salah !!!
Pernyataan PERFORM
Bentuk 1:
PERFORM nama-paragraph-1 { THRU / THROUGH } nama-paragraph-2contoh :
{ nama-data / integer } TIMES
IDENTIFICATION DIVISION.Hasil keluaran :
PROGRAM-ID. ulang1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 nomor-urut PIC 9.
PROCEDURE DIVISION.
Ulang-proses.
PERFORM Cetak-tampilan 5 TIMES.
STOP RUN.
Cetak-tampilan.
ADD 1 to nomor-urut.
DISPLAY ‘ Tampilan ke = ‘, nomor-urut.
Tampilan ke = 1Bentuk 2:
Tampilan ke = 2
Tampilan ke = 3
Tampilan ke = 4
Tampilan ke = 5
PERFORM nama-paragraph-1 { THRU / THROUGH } nama-paragraph-2Contoh:
UNTIL kondisi
IDENTIFICATION DIVISION.Hasil keluaran :
PROGRAM-ID. PERFORM1.
AUTHOR. AYU.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
MULAI.
PERFORM BINTANG.
DISPLAY ‘ C O B O L’.
PERFORM BINTANG.
STOP RUN.
BINTANG.
DISPLAY ‘********************’.
********************Bentuk 3:
C O B O L
********************
PERFORM nama-paragraph-1 { THRU / THROUGH } nama-paragraph-2
VARYING nama-data-1
FROM {nama-data-2 / integer-1} BY {nama-data-3 / integer-2}
UNTIL kondisi-1
[ AFTER nama-data-4
FROM {nama-data-5 / integer-3} BY {nama-data-6 / integer-4 }
UNTIL kondisi-2 ]
[ AFTER nama-data-7
FROM {nama-data-8 / integer-5} BY {nama-data-9 / integer-6 }
UNTIL kondisi-3
Contoh PERFORM – VARYING 1 :
IDENTIFICATION DIVISION.Hasil eksekusi :
PROGRAM-ID. ulang3.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 bilangan PIC 99.
PROCEDURE DIVISION.
Program-utama.
PERFORM Cetak-bilangan
VARYING bilangan FROM 1 BY 1
UNTIL bilangan > 6.
STOP RUN.
Cetak-bilangan.
DISPLAY bilangan.
01Contoh PERFORM – VARYING 2 :
02
03
04
05
06
IDENTIFICATION DIVISION.Hasil eksekusi :
PROGRAM-ID. ulang4.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 bilangan PIC 99.
PROCEDURE DIVISION.
Program-utama.
PERFORM Cetak-bilangan
VARYING bilangan FROM 0 BY 2
UNTIL bilangan > 10.
STOP RUN.
Cetak-bilangan.
DISPLAY bilangan.
00Contoh PERFORM – VARYING – AFTER 1 :
02
04
06
08
10
IDENTIFICATION DIVISION.Hasil eksekusi :
PROGRAM-ID. ulang5.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 X PIC 9.
77 Y PIC 9
PROCEDURE DIVISION.
Program-utama.
PERFORM Cetak-nilai -XY
VARYING X FROM 1 BY 1 UNTIL X > 3
AFTER Y FROM 1 BY 1 UNTIL Y > 2.
STOP RUN.
Cetak-nilai-XY.
DISPLAY ‘ nilai X = ‘ , X, ‘ Y = ‘ , Y.
nilai X = 1 Y = 1
nilai X = 1 Y = 2
nilai X = 2 Y = 1
nilai X = 2 Y = 2
nilai X = 3 Y = 1
nilai X = 3 Y = 2
Posting Komentar