ภาษาโคบอล (COBOL Language)
เว็บเพจสำรอง (Backup webpages) : thaiall.com | perlphpasp.com
ปรับปรุง : 2551-02-01 (เปลี่ยนที่อยู่ศูนย์ตำรา)


วิธีแปล COBOL 4.5 และ COBOL 3.0 (กุมภาพันธ์ 2548)
หนุ่มน่าน โทรมาถามผมถึงวิธีการแปลภาษา COBOL ทำให้ผมต้องเขียนส่วนนี้เพิ่มเติม
ถ้าเขาไม่ถาม ผมก็ไม่เขียน เพราะคิดไปเองว่าเรื่องแบบนี้ ใคร ๆ ก็คงจะรู้กันอยู่แล้ว

    สารบัญ
  1. ความรู้เบื้องต้น
  2. สารบัญของหนังสือ
  3. วิธีแปล COBOL 4.5
  4. Source code ของ batch file CBL.BAT
  5. ตัวอย่างโปรแกรม (Program sample)
  6. ตัวอย่างเกี่ยวกับการประมวลผลแฟ้มข้อมูล
  7. ตัวอย่างคำสั่ง (Sample command)
  8. สอบย่อย (Quiz)
  9. โครงงาน (Project)
  10. แนะนำเว็บ (Web guides)
ขอแนะนำ : COBUG.COM
COBOL User Groups (COBUG)
COBUG provides the COBOL community with a comprehensive web site that contains current references to COBOL user groups, compilers, code samples, COBOL jobs, and many other COBOL programming resources.
We are committed to developing COBOL user groups and providing an information resource for the COBOL community. We currently have more than 900 members and 10 user groups worldwide. The COBOL community benefits from our local COBOL user groups, website, forums, and peer support.
1. ความรู้เบื้องต้น
ภาษา COBOL คืออะไร
COBOL was one of the earliest high-level programming languages. It was developed in 1959 by a group of computer professionals called the Conference on Data Systems Languages (CODASYL). Since 1959 it has undergone several modifications and improvements. In an attempt to overcome the problem of incompatibility between different versions of COBOL, the American National Standards Institute (ANSI) developed a standard form of the language in 1968. This version was known as American National Standard (ANS) COBOL. In 1974, ANSI published a revised version of (ANS) COBOL, containing a number of features that were not in the 1968 version. In 1985, ANSI published still another revised version that had new features not in the 1974 standard. The language continues to evolve today. Object-oriented COBOL is a subset of COBOL 97, which is the fourth edition in the continuing evolution of ANSI/ISO standard COBOL. COBOL 97 includes conventional improvements as well as object-oriented features. Like the C++ programming language, object-oriented COBOL compilers are available even as the language moves toward standardization. [reference]
ภาษาโคบอล (COBOL : Common Business Oriented Language) เป็นภาษาสำหรับใช้ในงานธุรกิจภาษาแรกของโลก พัฒนาในปีค.ศ. 1962 โดยคณะกรรมการโคดาซิล (The Conference on Data Systems Languages - CODASYL) มีจุดเด่นคือ สามารถใช้งานแฟ้มข้อมูลได้หลายแบบ กำหนดโครงสร้างข้อมูลได้สะดวก มีลักษณะการเขียนโปรแกรม แบบเอกสารอธิบายโปรแกรม ช่วยให้นักพัฒนารุ่นถัดไปเข้าใจได้ง่าย
การเขียนโปรแกรมภาษา COBOL เป็นภาษาที่ง่ายมากภาษาหนึ่ง เพราะไม่มีลูกเล่นให้ใช้มาก ๆ เหมือนพวก VB, C, Pascal หรือ dBase หน้าที่หลกของ COBOL คืออ่านข้อมูลจากแฟ้มมาประมวลผลทางธุรกิจเป็นหลัก สำหรับ ผู้เรียนมือใหม่ อาจบอกว่าภาษานี้ยาก เพราะพวกเขาอาจไปยึดติดกับการจดจำ division ต่าง ๆ ว่ามีอะไรบ้าง ซึ่งสิ่งเหล่านั้นเป็นเพียงหน้ากาก มิใช่ concept ของภาษา ถ้ามีคู่มือสักเล่ม ก็จะเข้าใจ และแกะหน้ากากเหล่านั้นออกได้ แล้วก้าวให้ลึกเข้าไปสู่ตัวภาษาได้โดยง่าย
โดยพื้นฐานแล้ว COBOL ประกอบด้วย 4 Division และหลักแรกต้องเริ่มต้นที่ 8 ส่วนคำสั่งเริ่มหลักที่ 12 สำหรับตัวแปลภาษา COBOL สมัยใหม่ สามารถยอมให้ละ 3 division แรกไว้ได้ จึงใช้ SAMPLE 1 แสดงการเขียน COBOL อย่างสั้น
Division in COBOL
1. identification division.
2. environment division.
3. data division.
4. procedure division.

Course outline
1. Course introduction
2. Principle of COBOL language
3. Language structuring
4. Command
5. Sequential processing
6. Decision processing
7. Repeating processing
Midterm examination
8. Sequential file access
9. Index file access
Final examination
Case study : Sell system
- sellpro.cbl
- product.txt
- sell.txt

ปรับปรุงตาม
หลักสูตรใหม่
ศูนย์ตำรา อาจารย์นิมิตร จิวะสันติการ
391/1-5 ซอยพัฒนาการ 30 ถนนพัฒนาการ
แขวง/เขตสวนหลวง กรุงเทพฯ 10250
Tel.0-2319-4948 Ext.121 หรือ Tel.0-2719-4075 Ext.121
e-mail: nine@lox1.loxinfo.co.th
ฝ่ายวิชาการ : กาญจนา มงคล Tel.08-6327-9409
คำอธิบายรายวิชา (คำนำ)
ศึกษาโครงสร้างของภาษาโคบอล องค์ประกอบและคำสั่งต่าง ๆ การใช้ภาษาโคบอลในทางธุรกิจ ศึกษาถึงการเขียนโปรแกรม โดยสามารถเขียนและทดสอบโปรแกรมนี้อย่างน้อย 10 โปรแกรม
การเขียนโปรแกรมภาษาโคบอล
(COBOL Programming)

ตรงตามหลักสูตรประกาศนียบัตรวิชาชีพชั้นสูง(ปวส.) กระทรวงศึกษาธิการ
พ.ศ.2540 รหัส 3204-2110 กรมอาชีวศึกษา
พ.ศ.2536 รหัส 05-540-203 สถาบันเทคโนโลยีราชมงคล

เรียบเรียงโดย บุรินทร์ รุจจนพันธุ์
2. สารบัญของหนังสือ
    บทที่ 1 :: หลักการเบื้องต้นของภาษา
      1.1 ความหมายของโคบอล
      1.2 ข้อดี และข้อเสีย
      1.3 ขั้นตอนการพัฒนาโปรแกรม
      1.4 การทำงานของภาษาที่มีโครงสร้าง
      1.5 โครงสร้างโปรแกรมภาษาโคบอล
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 2 :: โครงสร้างของภาษา
      2.1 สัญลักษณ์ที่ใช้ในการรูปแบบคำสั่ง
      2.2 Identification division
      2.3 Environment division
      2.4 Data division
      2.5 Procedure division
      2.6 สัญลักษณ์ (Symbol)
      2.7 คำ (Words)
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 3 :: คำสั่ง
      3.1 ประเภทของคำสั่ง (Types of statements)
      3.2 คำสั่งที่ใช้ในการคำนวณ (Arithmetic)
      3.3 คำสั่งที่ใช้เคลื่อนย้าย (Data manipulation)
      3.4 คำสั่งที่ใช้ควบคุมขั้นตอน (Procedure branching)
      3.5 คำสั่งที่ใช้รับ และแสดงผล (Input/Output)
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 4 :: การทำงานแบบตามลำดับ
      4.1 การทำงานกับคำสั่งแสดงผล
      4.2 การทำงานกับคำสั่งคำนวณ
      4.3 การตกแต่งผลลัพธ์ก่อนนำไปแสดง
      4.4 Redifines และ Renames
      4.5 การกำหนดตัวแปรอาเรย์ และนำมาใช้
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 5 :: การทำงานแบบมีเงื่อนไข
      5.1 เงื่อนไข (Conditions)
      5.2 ทดสอบความสัมพันธ์ (Relation conditions)
      5.3 ทดสอบเป็นชุด (Nested conditions)
      5.4 ทดสอบประเภทของข้อมูล (Class conditions)
      5.5 ทดสอบเครื่องหมาย (Sign conditions)
      5.6 ทดสอบชื่อเงื่อนไข (Condition-name conditions)
      5.7 ทดสอบที่ซับซ้อน (Complex conditions)
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 6 :: การทำงานแบบวนซ้ำ
      6.1 การเรียก Paragraph มาทำงาน
      6.2 การทำซ้ำด้วยคำสั่ง Go to
      6.3 การกำหนดจำนวนครั้งที่ทำซ้ำ
      6.4 การทำซ้ำจนกระทั่งเงื่อนไขเป็นจริง
      6.5 การทำซ้ำ โดยนำตัวเลขระบุรอบไปใช้งาน
      6.6 การทำซ้ำ กับตัวแปรอาเรย์ (array)
      6.7 การทำซ้ำ กับการเขียนโปรแกรมเมนู
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 7 :: การเข้าถึงแฟ้มแบบตามลำดับ
      7.1 การจัดเก็บข้อมูลในแฟ้มแบบตามลำดับ
      7.2 การอ่านข้อมูลมาประมวลผล และแสดงผล
      7.3 การสร้างแฟ้มข้อมูล
      7.4 การเพิ่มระเบียน
      7.5 การปรับปรุงแฟ้ม
      7.6 การจัดเรียงระเบียนใหม่
      7.7 การขอปรับปรุงข้อมูลจากแฟ้มข้อมูลย่อย
      download : สรุปท้ายบท และแบบฝึกหัด
    บทที่ 8 :: การเข้าถึงแฟ้มแบบดัชนี
      8.1 การสร้างแฟ้มแบบดัชนี
      8.2 การอ่านข้อมูลมาประมวล และแสดงผล
      8.3 การค้นหาระเบียนที่ต้องการ
      8.4 การเพิ่มระเบียน
      8.5 การลบระเบียน
      8.6 การแก้ไขระเบียน
      download : สรุปท้ายบท และแบบฝึกหัด

3. วิธีแปล COBOL 4.5
    - copy โปรแกรมไว้ในห้อง c:\cobol ผลการคัดลอกจะมีห้อง หรือ folder 8 ห้อง
    คือ Binb, Binr, Demo, Docs, Help, Init, Lib, Source
    - Click Start, Run แล้วพิมพ์ Command
    - ต่อจากนี้เราจะทำงานใน DOS Prompt
    - พิมพ์ Doskey เพื่อจะได้ใช้ลูกศร ขึ้น - ลง เรียกคำสั่งเก่าได้ง่าย
    - สั่งกำหนดค่าเริ่มต้น ด้วยการพิมพ์ c:\cobol\binr\new-vars.bat ที่ DOS Prompt
    - ลองพิมพ์คำว่า set ที่ DOS Prompt จะมีคำว่า COBOL ใน 6 บรรทัดสุดท้าย
    - cd c:\cobol เข้าห้องนี้ เพื่อเตรียมทดสอบสร้าง และแปลโปรแกรม
    - พิมพ์ edit test.cbl
    พิมพ์คำว่า procedure division. โดยอักษร p เริ่มหลัก หรือ col หรือ column ที่ 8
    พิมพ์คำว่า display 5. โดยอักษร d เริ่มหลัก หรือ col หรือ column ที่ 12
    ออกจากโปรแกรม edit ด้วยการกด Alt+F, X, Y

    - ทดสอบแปล ลิงค์ และประมวลผล โปรแกรมชื่อ test.cbl ในห้อง c:\cobol
    C:\cobol>cobol test,test,test,nul
    C:\cobol>link test,test,nul,,nul
    C:\cobol>test

FOR Cobol 4.5
C:\>c:\cobol\binr\new-vars.bat

C:\>cd c:\cobol

C:\cobol>cobol test,test,test,nul
Microsoft (R) COBOL Optimizing Compiler Version 4.5

COBOL software by Micro Focus
Copyright (C) Microsoft Corporation 1984,1991.  All rights reserved.
Copyright (C) Micro Focus Ltd. 1984,1991.  All rights reserved.

* Checking complete with no errors - starting code generation
* Data = 000000613 Code = 000000276 Dictionary = 000001154

C:\cobol>link test,test,nul,,nul

Microsoft (R) Segmented-Executable Linker  Version 5.15
Copyright (C) Microsoft Corp 1984-1991.  All rights reserved.


C:\cobol>test
5

C:\cobol>

4. Source code ของ batch file CBL.BAT
    - ช่วยให้การ compile link และประมวลผล ทำได้ง่ายและเร็ว
    - สำหรับ COBOL compiler version 3.0 หรือ 4.5
    - เมื่อเขียนโปรแกรม x.cbl เสร็จและต้องการแปล ให้พิมพ์ว่า C:\COBOL>CBL x
    คำสั่งที่ใช้แปลโปรแกรมโดยปกติ คือ C:\COBOL>cobol x,x,x,nul
    เมื่อแปลจนได้ obj ก็จะสั่ง link คือ C:\COBOL>link x,x,nul,,nul
    เมื่อได้ x.exe ก็จะสั่งประมวลผล คือ C:\COBOL>x.exe หรือ C:\COBOL>x
    @echo off cls if exist %1.obj del %1.obj >nul if exist %1.exe del %1.exe >nul echo Program is compiled. Please,wait for the compilation. echo cobol %1,%1,%1,nul if not exist %1.obj goto end1 cls echo Program is linked. Please,wait for the linking. link %1,%1,nul,,nul if not exist %1.exe goto end if exist %1.obj del %1.obj >nul if exist %1.lst del %1.lst >nul cls %1 goto end :end1 type %1.lst echo Error on your source. :end echo
5. ตัวอย่างโปรแกรม (Program sample)
    SAMPLE 1 : Only display
    :: ให้เขียนโปรแกรมพิมพ์เลข 5 บนจอภาพ
    :: print number 5 on screen
      ใน COBOL รุ่นที่ผมใช้อยู่ไม่ต้องเขียนให้ครบทุก division ก็ compile แล้วสั่งประมวลผลได้
      อย่างลืมว่า procedure เริ่มหลักที่ 8 และ display เริ่มหลักที่ 12 เพราะเป็นกฎเหล็กของภาษา
      Source code sample
      procedure division.
      
      display 5.

    SAMPLE 2 : pass or fail
    :: รับค่าไปเปรียบเทียบ แล้วพิมพ์ pass หรือ fail
    :: accept number and compare to display "pass" or "fail"
      Source code sample
      working-storage section.
      01 s   pic 99.
      procedure division.
      
      accept s.
      if s > 50 display "pass".
      if s <= 50 display "fail".
      stop run.
      working-storage section. 01 s pic 99. procedure division.
      accept s.
      if s > 50
        display "pass"
      else
        display "fail".
      stop run.

    SAMPLE 3 : one to ten
    :: พิมพ์ 1 ถึง 10 โดยกำหนดค่าเริ่มต้นเป็น 0 (ตามหน้า 109 ในหนังสือ)
    :: print 1 to 10 by "perform .. until .." on screen
      Source code sample
      working-storage section.
      77 x   pic 99.
      procedure division.
      
      move 0 to x.
      perform cal-para until x >= 10.
      stop run. cal-para.
      add 1 to x.
      display x.

    SAMPLE 4 : Multiple table
    :: สูตรคูณแม่ 2 แบบแต่ง output
    :: print multiple table of 2 on screen
      Source code sample
      working-storage section.
      01  m  pic 999.
      01  a  pic 999.
      01  b  pic 999.
      01  c.
      
      02 filler pic x(5).
      02 mm pic z9.
      02 filler pic xxx value " * ".
      02 nn pic z9.
      02 filler pic xxx value " = ".
      02 oo pic zz9. procedure division.
      move 2 to m.
      move 0 to a.
      perform mul until a >= 12.
      stop run. mul.
      add 1 to a.
      compute b = a * m.
      move m to mm.
      move a to nn.
      move b to oo.
      display c.

    SAMPLE 5 : basic calculation
    :: รับ 2 ค่า แล้วหา add, subtract, multiply และ divide
    :: get 2 value and use command add, subtract, multiply, divide
      Source code sample
      working-storage section.
      01  a  pic 999v99 value 10.
      01  b  pic 999v99 value 5.
      01  c  pic 999v99.
      procedure division.
      
        accept a. accept b. add a to b giving c. display c. subtract a from b giving c. display c. multiply a by b giving c. display c. divide a into b giving c. display c.

    SAMPLE 6 : move to output
    :: รับ 2 ค่าทีละค่า แล้วเปลี่ยนรูปแบบการแสดงผล
    :: get 2 value and change type of output
    :: this program have 2 input variables and 2 output variables
      Source code sample
      working-storage section.
      01  a  pic 999v99.
      01  b  pic zz9.99.
      01  c  pic 9999.
      01  d  pic z,zz9.
      procedure division.
      
        accept a. move a to b. display "1. result is " b. accept c. move c to d. display "2. result is " d.

    SAMPLE 7 : array with grade
    :: รับค่าลงอาร์เรย์ แล้วนำมา display อย่างมีเงื่อนไข (sheetarray.zip)
    :: get value to array and have condition to select the data for the displaying
    input screen sample
      C:\cobol>edit x.cbl C:\cobol>x Stop when d-grade(i) = 'q' Number 01 Get name : tom Get grade: a Number 02 Get name : boy Get grade: b Number 03 Get name : joy Get grade: c Number 04 Get name : Get grade: q
    Source code sample
           identification division.
           program-id.  arraysample.
           author.      burin  rujjanapan.
           installation.  yonok.
           date-written.  20-09-97.
           date-compiler. 20-09-97.
           environment division.
           configuration section.
                  source-computer. pc.
                  object-computer. pc.
           data division.
           working-storage section.
           01  d  occurs 10 times.
               02  d-name     pic x(5).
               02  d-grade    pic x.
           01  cnt-a    pic 99.
           01  i        pic 99.
           01  j        pic 99.
           procedure division.
           main-para.
               display "Stop when d-grade(i) = 'q'".
               move 0 to i.
               perform get-para until d-grade(i) = "q".
               move 0 to j.
               display "" with blank screen.
               display "Report when grade not equal 'f'".
               perform report-para until i = j.
               stop run.
           get-para.
               add 1 to i.
               display "Number " i. 
               display "Get name : " with no advancing.
               accept d-name(i).
               display "Get grade: " with no advancing.
               accept d-grade(i).
           report-para.
               add 1 to j.
               if d-grade(j) not = "a"
                  display j, " : " with no advancing
                  display d-name(j), d-grade(j).
    

    SAMPLE 8 : commission
    :: รับค่าแล้วคำนวณค่านายหน้า
    :: calculate commission
      Source code sample
             working-storage section.
             77 sale      pic 99999 value 0.
             77 comm      pic 9999v99 value 0.
             procedure division.
                display "Sale = " with no advancing.
                accept sale.
                if sale > 10000
                   compute comm = sale * 0.1
                else if sale > 5000
                   compute comm = sale * 0.05
                else if sale > 2000
                   compute comm = sale * 0.03.
                display "Commission = " comm.  
      

6. ตัวอย่างเกี่ยวกับการประมวลผลแฟ้มข้อมูล (File processing sample)
      SAMPLE 91 : read and write to file
      :: อ่านข้อมูลจากแฟ้มมาพิมพ์โดยสมบูรณ์ (ตามหน้า 6 ในหนังสือ)
      :: read data from a file and print to another file and display count of record on screen
      ก่อนเขียนโปรแกรม ต้องสร้างแฟ้มข้อมูล inf.txt ซึ่งมีขนาด 34 Byte (17 Byte * 2 Records)
      Data sample
      012345678901234
      012345678901234
      ผลการ run โปรแกรมข้างล่างนี้ จะสร้างแฟ้ม outf.txt (34 Byte) ซึ่งเหมือนแฟ้ม inf.txt ทุกประการ
      Source code sample
             identification division.
             program-id.  sample.
             author.      burin  rujjanapan.
             installation.  lcct.
             date-written.  20-09-97.
             date-compiler. 20-09-97.
             environment division.
             configuration section.
                    source-computer. pc.
                    object-computer. pc.
             input-output section.
             file-control.
                    select infile assign to disk.
                    select outfile assign to disk.
             data division.
             file section.
             fd infile record contains 17 characters
                    label record is standdard
                    value of file-id "inf.txt".
             01 inrec pic x(17).
             fd outfile record contains 15 characters
                    label record is standard
                    value of file-id "outf.txt".
             01 outrec pic x(15).
             working-storage section.
             77 num      pic 99 value 0.
             77 flag-end pic x  value "0".
             procedure division.
             initial-para.
                    open input infile
                         output outfile.
                    read infile at end move "1" to flag-end.
                    perform main-para until flag-end = "1".
                    close outfile.
                    display num.
                    stop run.
             main-para.
                    add 1 to num.
                    write outrec from inrec before advancing 1 line.
                    read infile at end move "1" to flag-end.
      

      SAMPLE 92 : read and write to file (shorter)
      :: change from sample 91 but it is shorter
      ก่อนเขียนโปรแกรม ต้องสร้างแฟ้มข้อมูล inf.txt ซึ่งมีขนาด 51 Byte (17 Byte * 3 Records)
      Data sample
      001boy...50000M
      002maria.65000F
      003jack..16500M
      ผลการ run โปรแกรมข้างล่างนี้ จะสร้างแฟ้ม outf.txt (51 Byte) ซึ่งเหมือนแฟ้ม inf.txt ทุกประการ
      if you found "Run time error number: 018", please check the size of inf.txt
      Source code sample
             environment division.
             input-output section.
             file-control.
                    select infile  assign to disk.
                    select outfile assign to disk.
             data division.
             file section.
             fd infile value of file-id "inf.txt".
             01 inrec.
                02 i-id     pic x(3).
                02 i-name   pic x(6).
                02 i-salary pic 999v99.
                02 i-sex    pic X.
                02 i-lf     pic XX.
             fd outfile value of file-id "outf.txt".
             01 outrec.
                02 o-id     pic x(3).
                02 o-name   pic x(6).
                02 o-salary pic 999v99.
                02 o-sex    pic X.
             working-storage section.
             77 num      pic 99 value 0.
             77 flag-end pic x  value "0".
             procedure division.
             initial-para.
                    open input infile
                         output outfile.
                    read infile at end move "1" to flag-end.
                    perform main-para until flag-end = "1".
                    close outfile.
                    display "Total records : " num.
                    stop run.
             main-para.
                    add 1 to num.
                    move inrec to outrec.
                    if i-sex = "M"
                       write outrec from inrec before advancing 1 line
                       display o-id o-name.
      	      read infile at end move "1" to flag-end.
      

      SAMPLE 93 : tax and total tax
      :: คำนวณภาษี และผลรวมภาษี
      :: calulate for tax and total tax (10%)
      :: source code by Mr.Toni Tapio Eskelinen (http://www.kixor.com)
      Source code sample
             environment division.
             input-output section.
             file-control.
                    select infile  assign to disk.
             data division.
             file section.
             fd infile value of file-id "inf.txt".
             01 inrec.
                02 i-id     pic x(3).
                02 i-name   pic x(6).
                02 i-salary pic 999v99.
                02 i-sex    pic X.
                02 i-lf     pic XX.
             working-storage section.
             77 num      pic 99 value 0.
             77 flag-end pic x  value "0".
             77 tax      pic 999v99.
             77 stax     pic 999v99 value 0.
             procedure division.
             initial-para.
                    display "ID  NAME   SAL   S TAX".
                    open input infile.
                    read infile at end move "1" to flag-end.
                    perform main-para until flag-end = "1".
                    close infile.
                    display "Total records : " num.
                    display "Total tax: " stax.
                    stop run.
             main-para.
                    add 1 to num.
                    multiply i-salary by 0.1 giving tax.
                    add tax to stax.
                    display i-id " " i-name " " i-salary " " i-sex " " tax.
                    read infile at end move "1" to flag-end.
      

      SAMPLE 94 : read (line sequential)
      :: อ่านข้อมูลจากแฟ้มมาพิมพ์แบบ line sequential
      :: read data from a file (Line sequential type)
      โปรแกรมนี้ ได้คำแนะนำจาก อ.เยาวลักษณ์ งามแสนโรจน์ เกี่ยวกับการติดต่อแฟ้ม ขอบคุณไว้ ณ ที่นี้
      Source code sample
             identification division.
             program-id.  sample.
             author.      burin  rujjanapan.
             installation.  lcct.
             date-written.  20-09-97.
             date-compiler. 20-09-97.
             environment division.
             configuration section.
                      source-computer. pc.
                      object-computer. pc.
             input-output section.
             file-control.
                      select infile assign to "x.cbl"
                      organization is line sequential.
             data division.
             file section.
             fd  infile.
             01  inrec pic x(70).
             working-storage section.
             77  num      pic 99 value 0.
             77  flag-end pic x  value "0".
             procedure division.
             initial-para.
                      open input infile.
                      read infile at end move "1" to flag-end.
                      perform main-para until flag-end = "1".
                      display "Total line = ",num.
                      stop run.
             main-para.
                      add 1 to num.
                      display inrec.
                      read infile at end move "1" to flag-end.
      

7. ตัวอย่างคำสั่ง (Sample commands)
  1. move 1 to a
  2. add 1 to a
  3. compute a = a + 1
  4. accept a
  5. accept a with background-color is 2 foreground-collor is 0
  6. display 5 line 5 col 10
  7. display 5 with no advancing
  8. display 5 at 0950
  9. if a = 1 display "one"
  10. if a =1 display "one" else display "other".
  11. read xfile at end move "1" to flag-end.
  12. perform x-para
  13. perform y-para until flag-end = "1"
  14. perform z-para 10 times
  15. perform z-para until i >= 12
  16. stop run.
  17. open input file1 fil2
  18. open output file3 file4
  19. close file1
  20. write outrec from inrec before advancing 1 line

8. สอบย่อย (Quiz)
  1. print number 12345 on screen
  2. print 10 to 20 by "perform .. until .." on screen
  3. print multiple table of 5 with 1 to 12
  4. accept number from keyboard in A and display value from A
  5. accept number and show grade (A, B, C, D, F)
  6. accept number to array and print from array
  7. read input file and write to output file
  8. calculate of tax and total tax

9. โครงงาน (Project)
  1. write source program sell.cbl and explain function of each paragraph.
  2. write program to add, delete, update and listing from data file.

10. แนะนำเว็บ (Web guides)
  1. http://www.engin.umd.umich.edu/CIS/course.des/cis400/cobol/cobol.html :: สอน cobol
  2. http://tiny-cobol.sourceforge.net :: Compiler อีก version หนึ่งของ COBOL ตัวนี้ไม่ใช้ Microsoft COBOL
  3. http://www.csis.ul.ie/COBOL/examples/default.htm :: มีตัวอย่าง และ Tutorial ที่ยอดเยี่ยมมาก ๆ (.cbl เพียบ)
  4. http://cobolreport.com/faqs/cobolfaq.htm :: COBOL FAQ เพียบ
  5. http://www.infogoal.com/cbd/cbdcmp.htm :: Directory of COBOL Compilers and COBOL Interpretors
  6. http://members.aol.com/CobolHouse/index.htm :: ผู้เขียน compiler ของ cobol แต่ไม่สำเร็จ เปิดให้นำไปปรับปรุง
  7. http://www.tinycobol.org :: ผู้พัฒนาตัวแปรภาษา cobol รายหนึ่ง
  8. http://www.csis.ul.ie/COBOL :: รวม Link ข้อมูลน่าสนใจ
  9. http://cobolreport.com/faqs/cobolfaq.htm :: รวมถามตอบเกี่ยวกับ cobol
  10. http://www.adtools.com/download :: Fujitzu compiler
  11. http://web.tiscali.it/albertosantini/cobcy/ :: COBOL to C compiler
  12. http://www.thaiall.com/downloadx/cobol3.zip :: COBOL version 3.0 (เพื่อการศึกษา โทรถามรหัสผ่าน 08-1992-7223)
  13. http://www.thaiabc.com/download/cobol3.zip :: COBOL version 3.0

แนะนำเว็บใหม่ : ผลการจัดอันดับ
รักลำปาง : thcity.com : korattown.com : topsiam.com : มหาวิทยาลัยโยนก
ศูนย์สอบ : รวมบทความ : ไอทีในชีวิตประจำวัน : ดาวน์โหลด : yourname@thaiall.com
ติดต่อ ทีมงาน ชาวลำปาง มีฝันเพื่อการศึกษา Tel.08-1992-7223