When a specific functionality need to be performed in more than one program, it is best to write them separately and call them into each program. Sub Programs can be written in any programming language. They are typically written in a language best suited to the specific task required and thus provide greater flexibility.
CALL statement is used for executing the sub-program from the main program. A sample of CALL statement is given below:
CALL PGM2 USING BY REFERENCE WS-VAR1, BY CONTENT WS-VAR2. PGM2 is called here. WS-VAR1 and WS-VAR2 are working storage items. WS-VAR1 is passed by reference. WS-VAR2 is passed by Content. BY REFERENCE is default in COBOL and need not be coded. BY CONTENT LENGTH phrase permits the length of data item to be passed to a called program.