Master the Mainframe Global User Group

Expand all | Collapse all

Weekly t-shirt Challenge: Your first COBOL program

  • 1.  Weekly t-shirt Challenge: Your first COBOL program

    Posted Thu April 16, 2020 10:18 PM

    Your First Cobol Program

    You all have been busy I see!  A little home improvements, some programming and some online socializing.  But the votes went to @Fábio Emilio Costa for his fun cosplay and to @Ray Mullins for a little of everything (+ wine).  

    This week I'm inspired by this amazing new video created by @Jeffrey Bisti  showing his first COBOL program and the webinar happening tomorrow morning introducing COBOL programming called "A Beginner's Practical Approach to COBOL".  

    So if you're new to COBOL, take a look at the examples and create your own little COBOL program for us.

    If you already know COBOL, put together a small sample that would be useful and interesting to a beginner.  

    The rules:
    1.  Every Thursday, I'll start a new discussion thread titled Weekly Challenge.

    2.  This week, reply to the thread with your first COBOL program.  

    3.  Vote for your favorite entries by clicking the "Recommend" button next to your favorites.

    4.  The following Thursday, I'll announce the winner and start the next week's thread.

    5.  The person submitting the item with the most votes will receive one of these Legends of Z t-shirts (or equivalent)!


    Misty Decker

  • 2.  RE: Weekly t-shirt Challenge: Your first COBOL program

    Posted Fri April 17, 2020 07:01 PM
    This is my first try on Cobol, a program to calculate a circle circunference. Just did this while learning Cobol with this tutorial from Linked-In

    As a trivia about me: I had some contact on Cobol at '85 (when I was 7) as I received a course on BASIC/Cobol/Graphical Computing using Apple II and the recently launched IBM PC (or their clones here in Brazil). But I remember almost nothing now, so I'm re-learning Cobol from the scratch. Even our shop being a bigger user of Adabas/Natural than Cobol, I think it's cool to remember a little

    Fábio Emilio Costa
    Performance Analyst
    Sao Paulo

  • 3.  RE: Weekly t-shirt Challenge: Your first COBOL program

    Posted Sun April 19, 2020 11:50 PM
      |   view attached
    Hi Misty and all members of this Group,

    I have participated in MTM challenge since 2018 and it has been very inspirational for me to get contact again with an IBM mainframe. I live in Sao Paulo, Brazil and about 40 years ago I debuted the 'dev world' utilizing IBM, Burroughs and HP mainframes and mid-size computers. Few years later I shifted my professional career to business and leadership positions but now I am going back to the basics for targeting my post-retirement activities.

    That said, I developed the COBOL program attached based on MTM content and a programming online course I took in 2019. In summary, the program reads the records of two sequential files, sorts, merges and prints them, without utilizing IBM sort & merge utilities.

    Whether you have any question, I will be glad to answer it to you.

    Thank you!

    Francisco Durante


    test.srclib(cbdsseq2).txt   65 KB 1 version

  • 4.  RE: Weekly t-shirt Challenge: Your first COBOL program

    Posted Mon April 20, 2020 07:15 AM
    Edited by William Downie Mon April 20, 2020 08:50 AM
    Simple Discogs file parser and reporter

    This isn't my first Cobol program but it's the first one that uses several of the techniques I've learned over the past couple of weeks. I've been working as an Assembler programmer for some time now, so have been enjoying comparing Cobol to Assembler.  

    The program is a batch program that :

    - reads in a CSV file generated by Discogs (literally a file of records :) ). See example of a few records below.
    - parses the file and moves to an in-core table
    - reads in SYSIN card that specify an Artist and/or a Title
    - scan the table and report on records that meet the search criteria.

    What I like so far ...

    -  the "Evaluate" statement. Great how multiple selections can be made.
    - "Unstring" verb is very handy, a bit like the REXX parse.
    - "upper-case" and "reverse" functions also very handy.  Looks like there is a whole library of functions.
    - Reference modification allows portion of a string to be referenced.
    move 'abcdef' to OUTPUT-FIELD
    display OUTPUT-FIELD(3:2)
    will output 'cd'

    But, even better, is the start pos and length can be variables. Put this in a loop and it's almost as good as scanning down a string using a register in an Assembler program :)

    What I've found difficulty with ...

    - when a Period is required.  
    - Can't work out how to make lengths 'soft'. e.g. I've got a table field and a report field:
    10 REC-ARTIST         pic X(50).
    05 REPORT-ARTIST      pic X(50)

    Rather than hardcode 50, can this be an equate, defined once.  In Assembler we'd might code something like this :


    Can the the number of table entries be an equate ? e.g. rather than code:

    05 REC-RECORDS occurs 1000 times.    
       10 REC-CATALOG-NBR pic X(30).     
       10 REC-ARTIST      pic X(50).  

    can the 1000 be replaced with an equate which could then be used elsewhere (e.g. when controlling loop reading through the table) ?

    Example of Input CSV from Discogs:
    CAD 0010,Pixies,Bossanova,4AD,"LP, Album",,1990,549718,Uncategorized,12/12/2019 12:28,,,
    TT010,Various,Indie Top 20 Vol X,Beechwood Music,"2xLP, Comp",,1990,449135,Uncategorized,6/2/2019 10:21,,,
    84406,Duke Ellington And His Orchestra Featuring Mahalia Jackson,"Black, Brown And Beige",CBS,"LP, Album",,1982,4307869,Uncategorized,5/19/2019 10:21,,,
    N-16172,Duke Ellington,The Best Of Duke Ellington,Capitol Records,"LP, Comp, Mono, RE",,1980,3188832,Uncategorized,5/12/2019 11:45,,,
    "CBS 26015, BFC 39220",Bangles,All Over The Place,"CBS, CBS","LP, Album",,1984,404065,Uncategorized,5/19/2019 10:23,,,

    William Downie

  • 5.  RE: Weekly t-shirt Challenge: Your first COBOL program

    Posted Tue April 21, 2020 06:08 PM

    Did this one today. My first one is long lost to time, but was never much more sophisticated than this one. It ran under CP/M.


    01 I PIC 99 VALUE 0.



    Ricardo Bánffy

  • 6.  RE: Weekly t-shirt Challenge: Your first COBOL program

    Posted Tue April 21, 2020 06:10 PM

    It works better with the right terminal font:

    Program, with a proper 3270 font
    And don't get me started with IBM Plex ;-)

    Ricardo Bánffy