Skip to main content

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 !  

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 !  

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


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 !  

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


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 !  

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


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 !  

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


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 !  

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.


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 !  

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.


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 !  

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 ?


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 !  

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.


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 !  

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.


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 !  

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.


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 !  

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.


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 !  

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.