Friday, 23 November 2012

CONTOH ARRAY 2 DIMENSI PADA COBOL

ARRAY 2 DIM.




IDENTIFICATION DIVISION.
       PROGRAM-ID. ARRAY-2-DIM.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABEL.
           02 I PIC 9(2).
           02 J PIC 9(2).
           02 JMLBRS PIC 9(2).
           02 JMLKOL PIC 9(2).
           02 NILAI-X OCCURS 10 TIMES.
               03 NILAI PIC 9
               OCCURS 1 TO 10 TIMES DEPENDING ON JMLKOL.
       SCREEN SECTION.
       01 CLS.
           02 BLANK SCREEN.
       PROCEDURE DIVISION.
       AWAL.
           DISPLAY CLS.
           DISPLAY (1, 1) 'MASUKKAN BANYAKNYA BARIS [MAKS:10] :'
           ACCEPT ( , ) JMLBRS.
           DISPLAY (2, 1) 'MASUKKAN BANYAKNYA KOLOM [MAKS:10] :'
           ACCEPT ( , ) JMLKOL.
           MOVE 4 TO LIN.
           PERFORM ISI-DATA VARYING I FROM 1 BY 1 UNTIL I > JMLBRS
           AFTER J FROM 1 BY 1 UNTIL J > JMLKOL.
           MOVE 4 TO LIN.
           PERFORM TAMPILKAN-DATA VARYING I FROM 1 BY 1 UNTIL I > JMLBRS
           AFTER J FROM 1 BY 1 UNTIL J > JMLKOL.
       AKHIR.
           STOP RUN.
       ISI-DATA.
           DISPLAY (LIN, 1) 'NILAI KE-[',I,',',J,'] = ',NILAI(I, J).
           ADD 1 TO LIN.
           ACCEPT ( , ) NILAI (I, J).
       TAMPILKAN-DATA.
           DISPLAY (LIN, 25) 'NILAI[',I,',',J,'] = ',NILAI(I, J).
           COMPUTE LIN = LIN + 1.

Hasil running:

 SEKIAN......

No comments:

Post a Comment