× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



COBOL/400 does not support recursive call. Take a look at V5R2 ILE COBOL
with new recursive support.

> Dear all,
>           I have tried to implement  factorial function using recursive
> calls in COBOL.But
>           I could not get the expected results although recursive calls
> are
> succesfully
>           executed. (I have checked this through debugger).
>
>            The problem is because the work variable declared in the
> program
> gets changed
>            after the recursive calls.This problem does not happen if I use
> functions in C or Java
>            because the work variable's are scoped to the individual
> calls.So
> the work variable
>            when changed in called program it still retains  the old value
> in
> the calling PGM.
>            But this is not the case in  COBOL/400.
>
>            For example.
>
>            i am enclosing  the whole code along so that you will be able
> to
> figure out what the problem
>           is
>
>          program RICUR is the driver program which calls the ricursive pgm
>          RICURTEST.
>
>          problem is beacuse the variable WK-NUMBER-STORE in RICURTEST gets
> changed after
>          the recursive call to RICURTEST.This generally don't happen in C
> &
> JAVA for reasons I have
>          mentioned before.
>
>          Can anybody suggest me a solution for this?
>          One option may be use ILE sub procedure to do the same,though I
> haven't tried it.
>
>
> Program RICUR
> ------------------------------
>
> IDENTIFICATION DIVISION.
> PROGRAM-ID. RICURTEST.
> ENVIRONMENT DIVISION.
> CONFIGURATION SECTION.
> SOURCE-COMPUTER. IBM-AS400.
> OBJECT-COMPUTER. IBM-AS400.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 01 WK-BIG-NUMBER  PIC 9(10).
> 01 WK-NUMBER  PIC 9(4).
> 01 WK-DUMMY  PIC 9(10).
> LINKAGE SECTION.
> PROCEDURE DIVISION.
>      COMPUTE WK-NUMBER = 4.
>      COMPUTE WK-BIG-NUMBER = 0.
>   CALL 'RICURTEST' USING WK-NUMBER WK-BIG-NUMBER.
>     COMPUTE WK-DUMMY = WK-BIG-NUMBER.
> STOP-RUN.
>
>
> Program RICURTEST
> ----------------------
>
> IDENTIFICATION DIVISION.
> PROGRAM-ID. RICURTEST.
> ENVIRONMENT DIVISION.
> CONFIGURATION SECTION.
> SOURCE-COMPUTER. IBM-AS400.
> OBJECT-COMPUTER. IBM-AS400.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 01 WK-BIG-NUMBER  PIC 9(10).
> 01 WK-NUMBER  PIC 9(4).
> 01 WK-NUMBER-STORE PIC 9(4).
> LINKAGE SECTION.
> 01 WSSP-NUMBER PIC 9(4).
> 01 WSSP-BIGNUMBER PIC 9(10).
> PROCEDURE DIVISION USING WSSP-NUMBER WSSP-BIGNUMBER.
>    IF WSSP-NUMBER = 1
>       COMPUTE WSSP-BIGNUMBER = 1
>    END-IF.
>
>    IF WSSP-NUMBER = 2
>       COMPUTE WSSP-BIGNUMBER = 2
>    END-IF.
>
>     IF WSSP-NUMBER > 2
>        COMPUTE WK-NUMBER-STORE = WSSP-NUMBER
>        COMPUTE WK-NUMBER = WSSP-NUMBER - 1
>        COMPUTE WK-BIG-NUMBER = 0
>       CALL 'RICURTEST' USING WK-NUMBER WK-BIG-NUMBER
>        COMPUTE WSSP-BIGNUMBER = WK-BIG-NUMBER * WK-NUMBER-STORE
>    END-IF.
>
>   GOBACK.
>
>
> Thanks in anticipation,
> shijith
>
> _________________________________________________________________
> Sexy, sultry, sensuous. - see why Bipasha Basu is all that and more. Try
> MSN
> Search http://server1.msn.co.in/Profile/bipashabasu.asp
>
> --
> This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
> list
> To post a message email: COBOL400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/cobol400-l
> or email: COBOL400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/cobol400-l.
>
>


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.