Highlighted
Absent Member.
Absent Member.
1296 views

PERFORM a paragraph in other file ?

Jump to solution

Hi everybody.

I have 2 files as below :

1. MAIN.cbl 

2. SUB.cbl

In MAIN.cbl :

+ CALL 'SUB'.

+ PERFORM  HELLO-PAR.

   HELLO-PAR.

   display 'HELLO EVERYBODY'.

In SUB.cbl : I want use HELLO-PAR paragraph and don't want code again it. I try to PERFORM HELLO-PAR but have error.

How do this ? Plz show me. Thanks !  

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

Place the common code required by both MAIN.cbl and SUB.cbl in a copybook and include it in each program using a COPY statement.

e.g. COPY COMMONCODE.CPY.

If the common code contains EXEC SQL statements you will need to include it rather than copy it to make it available to the SQL pre-compiler.

e.g. EXEC SQL INCLUDE COMMONCODE.CPY END-EXEC.

View solution in original post

0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

Can you explain a little more. Where is the HELLO-PAR paragraph?. In MAIN or in SUB?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

HELLO-PAR is written in MAIN. And in SUB i want to use HELLO-PAR again .

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

No, you cannot do that. In this case you have to have MAIN, SUB1 and SUB2. Your old SUB is here SUB1 and SUB2 is a new program you have to write containing HELLO-PAR. This way the code for HELLO-PAR is written once, but can be called from MAIN and SUB1.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

Thanks for your reply.

By the way, I have other example.

My project have many files (MAIN.cbl, SUB1.cbl ...) which use COBOL interact with DB2. In each file, must check error sql as below :  

          CHECK-SQL-ERROR-PAR.

          IF (sqlcode not = 0)

               DISPLAY "Error: SQL error"

               DISPLAY sqlcode

          END-IF.

If write this code in SUB2, how to call SUB2 and pass sqlcode from MAIN or SUB1 ?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

Place the common code required by both MAIN.cbl and SUB.cbl in a copybook and include it in each program using a COPY statement.

e.g. COPY COMMONCODE.CPY.

If the common code contains EXEC SQL statements you will need to include it rather than copy it to make it available to the SQL pre-compiler.

e.g. EXEC SQL INCLUDE COMMONCODE.CPY END-EXEC.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: PERFORM a paragraph in other file ?

Jump to solution

MAIN.cbl:

working-storage section.

01  ws-sqlCode pic xxx.

call 'SUB2' using ws-sqlCode.

SUB1.cbl:

working-storage section.

01  ws-sqlCode pic xxx.

call 'SUB2' using ws-sqlCode.

SUB2. cbl.

linkage section.

01  sqlCode pic xxx.

procedure division using ws-sqlCode.

display 'Error, sql-code =', ws-sqlCode.

exit program.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.