Menu

Problem with calling a subroutine with returning

2023-12-15
2025-01-17
<< < 1 2 (Page 2 of 2)
  • Ralph Linkletter

    It seems to me that the work around is simple.
    Use the normal way of passing a parameter to and from a subroutine.
    Linkage Section
    01 parm1
    01 parm2
    Procedure division using parm1 parm2.

    Encumbering Simon with a MF / IBM feature that hasn't been used by either of your combined 75 years of COBOL lacks logic.

    If the intent is just to "play around" with Gnu COBOL open a bug / wish list ticket
    Ralph

     
    • Bill Komanetsky

      Bill Komanetsky - 2023-12-17

      I agree that the work around is simple, and that's what my functionABC does. But my functionABC2 was to prototype the use of returning, which looks like it doesn't work.

       
    • Bill Komanetsky

      Bill Komanetsky - 2023-12-17

      I am a Professor of Computer Science Emerita and have been doing a lot of Youtube videos on Assembly language, Databases, C/C++ and am planning to start COBOL and Fortran very soon. I am putting together lesson plans/scripts for the videos, and defining/using subprograms/subroutines in one of these videos. I just wanted to get it right as I am planning on using GNUCOBOL even though IBM's COBOL on x86 is easily acquirable, but much more difficult to do so compared to GNUCOBOL. I have decided to show the two methods, and it currently works on IBM's COBOL, but how it can be worked around on GNUCOBOL since it isn't yet implemented (correctly). :-) Thanks for all of your attention to this.

       
      • Simon Sobisch

        Simon Sobisch - 2023-12-17

        Those videos sound good!
        Can you please upload your old and be videos to a free video sharing site, too?

        If you like, we may be able to review your scripts for the COBOL videos here to get a wider view from industrial experts and compiler builders. I always find it sad when quite good videos contain "bad recommendations" or errors...

         
      • Anonymous

        Anonymous - 2025-01-15
         
        • László Erdős

          László Erdős - 2025-01-16

          Hello,

          I watched the COBOL videos in parts, not all the minutes, just parts.

          Interesting, a good and thorough introduction to data types. 13 parts in total. We first do a MOVE in part 9, and a PERFORM in part 13a. So there are still many, many things missing.

          Part 1 deals with the installation for 50 minutes. IBM COBOL (60 days trial version) a few minutes on Linux.

          And GnuCOBOL on Linux and on Windows MSYS. Unfortunately, the fastest option on Windows is not mentioned or shown. This is a typical error in all other GnuCOBOL videos on the internet. You can simply download a precompiled binary code, unzip it and that's it, the compiler runs.

          The link to "Arnold's GnuCOBOL Resources (with prebuilts)" is also on this page: "GnuCOBOL Guides". It really is two clicks, 1. click download, 2. click unzip, and it's done. That's what students like today. You build it all within 50 minutes. But that only scares those interested in COBOL.

          When it comes to GnuCOBOL, at least these pages should be shown to students as information:
          "https://sourceforge.net/projects/gnucobol"
          "https://gnucobol.sourceforge.io/guides.html"
          "https://gnucobol.sourceforge.io/faq/index.html"

          And in addition the "GnuCOBOL Contributions (Tools/Samples incl. Games)" is also important:
          "https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk"
          There are many examples there, both small and large. There a student can see what a real program looks like. Or, for example: how does COBOL work with an SQL database, etc...

          In general, it took a lot of time to set up the development environment and the text editor "Geany". Then the "fix" COBOL format is used and the line numbers are written yourself. Later, an AWK script is created to renumber the numbers after an insert. If you are already on Windows, you could use any Windows text editor. For example, Notepad++ also has COBOL syntax highlighting. And it would be better to work with "free" COBOL format and not confuse the students. Then you can spend more time on COBOL.

          There are sometimes references to C/C++ and COBOL differences in data types. That's why I assume that students who already know other programming languages will take part here. It is definitely very different if you learn the first programming language or not. Then you have to teach accordingly.

          One more comment. The video is not sharp enough for me, and the code or text is not always easy to read if you don't zoom in on the text/code. Unfortunately, it often happens that when your head appears at the bottom right. But maybe I'm just too old and that's why I can't see clearly and well anymore...

          So to sum it up, I'm very happy that you teach COBOL. It's rare these days. And you don't have to take my comments so seriously, keep it up!

          BR
          László

           
          • Simon Sobisch

            Simon Sobisch - 2025-01-17

            Apart from the MYS2 issues in that video (one could only install mingw64 [not all 4-5 environments] and pacman -S mingw-w64-x86_64-gnucobol would install everything needed) you're right that even that is not necessary to "just use GnuCOBOL on Windows".

            Both Arnold's page (providing older and smaller Mingw32 and the MSYS2 mingw64 one repackaged) and installer from https://superbol.eu/en/gnucobol/ (current deep link https://superbol.eu/en/developers/windows-aio-3.2/ - also repackaging the MSYS2 mingw64 one, with a bit of more additional tools) are easy to use options.

            So... is there a good video out there that shows how to do the setup this way, including setup of the environment)? If not: does anyone volunteer? :-)

            Note: the WSL2 setup should be nicer nowadays, for "more intense" development I'd definitely suggesting to have a look for that, because that environment will be commonly much faster to compile and run COBOL. And again doing sudo apt install gnucobol would install all necessary tools (as it would in Mint).

            For both options you can also install VSCodium + one of the COBOL extensions, superbol works quite fine "in general", also including debugging within the IDE.

             
            👍
            1
  • Simon Sobisch

    Simon Sobisch - 2023-12-18

    Adjusted source which:

    • uses program-id and CALL for something that has only passed parameters
    • uses function-id and FUNCTION XYZ() for something that has input parameters and a return value


    and by that, compiles fine without warnings on GC 2.2 and 3.2 - and also works fine in both cases:

       identification division.
       function-id. functionABC2.
       data division.
       working-storage section.
       linkage section.
       77 value1             pic 9999.
       77 someValue          pic 9999.
       procedure division USING value1 returning someValue.
           compute someValue = value1 * 2
           Display "Inside functionABC2: ", someValue
           GoBack.
       END FUNCTION functionABC2.
    
       Identification Division.
       Program-ID.  TestSubProgram.
       Environment Division.
       CONFIGURATION SECTION.
       REPOSITORY. function functionABC2.
       Data Division.
       Working-Storage Section.
       01 ctr1               pic 9999   value 0.
       77 returnvalue        pic 9999   value 0.
       77 avalue2            pic 9999   value 0.
       Linkage Section.
       Procedure Division.
       Begin.
           Display "Hello World!"
           move 10 to ctr1.
           call 'functionABC' USING ctr1 returnvalue.  
           Display "First function return: ", returnvalue.  
           move 2 to avalue2.
           Display "Return value before calling functionABC2:", avalue2.
           MOVE functionABC2 (ctr1) TO avalue2.
           Display "Return value from functionABC2:", avalue2.
           stop run.
    
       identification division.
       program-id. functionABC.
       data division.
       working-storage section.
       77 localvar           pic 999.
       linkage section.
       01 countervar         pic 9999.
       01 avalue             pic 9999   value 0.
       procedure division USING countervar avalue.
           perform countervar times
               Display "hello from sub-program"
           end-perform
           move 999 to avalue.
           exit.
       END PROGRAM functionABC.
       END PROGRAM TestSubProgram.
    

    execution result (no matter if compiled with -debug or not):

    Hello World!
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    hello from sub-program
    First function return: 0999
    Return value before calling functionABC2:0002
    Inside functionABC2: 0020
    
     
<< < 1 2 (Page 2 of 2)

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.