cobol 中call的功能测试总结

cobol中 call的功能类似于c众的函数调用,其调用方式有以下三种:

                  (1)  by  reference 

                  (2) by    content

                  (3) by  value

其中by reference 和by value  可以改变主函数的所传参数的值,而by  content 不会,在c用,我们知道只有两种方式,一种是传值,一种是传引用,其中传引用可以改变原来的值,而传值不会,传引用的是传的变量的地址。在这里,value 也是传递变量的地址。

在linkage section 定义时,不用再像从jcl中传递参数参数那样要定义参数长度,但最好不要用结构化的变量定义,因为在使用call…… by content时,这样穿进去的值,会出现问题(但为什么 ,我也不知道,希望有看到我能告知一声)。例如:在子函数中如此写

              linkage section.

              01  parms.

                        05    parm-a    pic 9(02).

                        05   parm-b     pic 9(02).

         procedure   division    using parms.

而在主函数中写调用函数时:call   “subprog”   using   by   value       ws-parm1, ws-parm2.

时参数只能传给parm-a。

还有一点要注意,在linkage  section。如果你是接受的两个参数, 要用01 or 77 level 来定义。

 

下面附上所写code,还望大家指教。

 

      IDENTIFICATION DIVISION.                                        
       PROGRAM-ID.    TPGMS01.                                          
       AUTHOR.        xxxxxxxxxxx.                                      

       DATE-WRITTEN. 2009-03-31.                                       
       DATE-COMPILED.                                                   
           
        DATA             DIVISION.                                      00390001
        WORKING-STORAGE  SECTION.                                       00400001
        01 WS-TEST-DATA.                                                00410001
           05 WS-TEST-DATA-A   PIC 9(02) VALUE  2.                      00420001
           05 WS-TEST-DATA-B   PIC 9(02) VALUE  2.                      00430001
           05 WS-TEST-DATA-C   PIC 9(02) VALUE  2.                      00440001
           05 WS-TEST-DATA-D   PIC 9(02) VALUE  2.                      00450001
           05 WS-TEST-DATA-E   PIC 9(02) VALUE  2.                      00460001
           05 WS-TEST-DATA-F   PIC 9(02) VALUE  2.                      00470001
                                                                        00480001
        77   WS-POINT-A USAGE IS POINTER.                               00490001
        77   WS-POINT-B USAGE IS POINTER.                               00500001
                                                                        00510001
        PROCEDURE        DIVISION.                                      00520001
              DISPLAY  'THE PROGRAM IS BEGINNING...'.                   00530001
              DISPLAY  '                           '.                   00540001
                                                                        00550001
      ******************************************************************00560001
      *          PASS PARAMETERBY REFERENCE                            *00570001
      ******************************************************************00580001
              DISPLAY '******** START THE CALL BY REFERENCE*********'.  00590001
              DISPLAY 'THE DATA BEFORE CHANGED:'.                       00600001
              DISPLAY '             WS-TEST-DATA-A :  ', WS-TEST-DATA-A.00610001
              DISPLAY '             WS-TEST-DATA-B :  ', WS-TEST-DATA-B.00620001
              CALL    "TPGMT01"                                         00630001
                    USING BY REFERENCE  WS-TEST-DATA-A, WS-TEST-DATA-B. 00640001
              DISPLAY 'HERE IS AFTER CHANGE'.                           00650001
              DISPLAY '             WS-TEST-DATA-A :  ', WS-TEST-DATA-A.00660001
              DISPLAY '             WS-TEST-DATA-B :  ', WS-TEST-DATA-B.00670001
              DISPLAY ' END CALL BY REFERENCE'.                         00680001
                                                                        00690001
      ******************************************************************00700001
      *          PASS PARAMETERBY BY CONTENT                           *00710001
      ******************************************************************00720001
              DISPLAY '  '.                                             00730001
              DISPLAY '******** START THE CALL BY CONTENT*********'.    00740001
              DISPLAY 'THE DATA BEFORE CHANGED:'.                       00750001
              DISPLAY '             WS-TEST-DATA-E :  ', WS-TEST-DATA-E.00760001
              DISPLAY '             WS-TEST-DATA-F :  ', WS-TEST-DATA-F.00770001
              CALL    "TPGMT01"                                         00780001
                    USING BY CONTENT  WS-TEST-DATA-E, WS-TEST-DATA-F.   00790001
              DISPLAY 'HERE IS AFTER CHANGE :'.                         00800001
              DISPLAY '             WS-TEST-DATA-E :  ', WS-TEST-DATA-E.00810001
              DISPLAY '             WS-TEST-DATA-F :  ', WS-TEST-DATA-F.00820001
              DISPLAY ' END CALL BY CONTEN'.                            00830001
              DISPLAY '  '.                                             00840001
                                                                        00850001
              SET WS-POINT-A TO ADDRESS OF WS-TEST-DATA-C.              00860001
              SET WS-POINT-B TO ADDRESS OF WS-TEST-DATA-D.              00870001
                                                                        00880001
      ******************************************************************00890001
      *          PASS PARAMETERBY BY VALUE                             *00900001
      ******************************************************************00910001
              DISPLAY '******** START THE CALL BY VALUE*********'.      00920001
              DISPLAY 'THE DATA BEFORE CHANGED:'.                       00930001
              DISPLAY '             WS-TEST-DATA-C :  ', WS-TEST-DATA-C.00940001
              DISPLAY '             WS-TEST-DATA-D :  ', WS-TEST-DATA-D.00950001
              CALL "TPGMT01"                                            00960001
                    USING BY VALUE WS-POINT-A, WS-POINT-B.              00970001
              DISPLAY 'HERE IS AFTER CHANGE '.                          00980001
              DISPLAY '             WS-TEST-DATA-C :  ', WS-TEST-DATA-C.00990001
              DISPLAY '             WS-TEST-DATA-D :  ', WS-TEST-DATA-D.01000001
              DISPLAY 'END CALL BY VALUE'.                              01010001
                                                                        01020001
              STOP RUN.                                                 01030001
      *                                                                 01040001
      ******************************************************************01050001
      *                                                                *01060001
      *     C A L L E D   S U B P R O G R A M                          *01070001
      *                                                                *01080001
      ******************************************************************01090001
       IDENTIFICATION DIVISION.                                         01100001
       PROGRAM-ID.    TPGMT01.                                          01110001
       AUTHOR.        WANGGONGJIN.                                      01120001
       DATE-WRITTEN. 2009-03-31.                                        01130001
       DATE-COMPILED.                                                   01140001
                                                                        01150001
      ******************************************************************01160001
      *  E N V I R O N M E N T   D I V I S I O N                       *01170001
      ******************************************************************01180001
       ENVIRONMENT       DIVISION.                                      01190001
                                                                        01200001
      ******************************************************************01210001
      *   D A T A  D I V I S I O N                                     *01220001
      ******************************************************************01230001
       DATA             DIVISION.                                       01240001
       LINKAGE          SECTION.                                        01250001
      * 01 SUB-PASS-PARMS.                                              01260001
      *    05 PARM-LENTH    PIC 9(3)   COMP-3.                          01270001
        77 LG-PARM-A        PIC 9(2).                                   01280001
        77 LG-PARM-B        PIC 9(2).                                   01290001
                                                                        01300001
      ******************************************************************01310001
      *   P R O C D U R E  D I V I S I O N                             *01320001
      ******************************************************************01330001
       PROCEDURE   DIVISION  USING  LG-PARM-A, LG-PARM-B.               01340001
            ADD   20  TO  LG-PARM-A.                                    01350001
            ADD   10  TO  LG-PARM-B.                                    01360001
                                                                        01370001
            DISPLAY  'HERE IS SUBPROGRAM: '.                            01380001
            DISPLAY  '          LG-PARM-A  ' LG-PARM-A.                 01390001
            DISPLAY  '          LG-PARM-B  ' LG-PARM-B.                 01400001
            GOBACK.                                                     01410001
        END PROGRAM TPGMT01.                                            01420001
        END PROGRAM TPGMS01.                                            01430001

 

你可能感兴趣的:(cobol 中call的功能测试总结)