Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle ProCobol Host Variables

Status
Not open for further replies.

PetePhillips

Programmer
May 31, 2004
2
GB
I'm an IBM Cobol DB2/SQL programmer learning Oracle ProCobol.
The A96109 ProCobol PreCompiler Programmer's Guide 9.2 contains SAMPLE1.PCO on page 2-30 :
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 USERNAME PIC X(10) VARYING.
01 EMP-REC-VARS.
05 EMP-NAME PIC X(10) VARYING.
05 PASSWD PIC X(10) VARYING.
EXEC SQL END DECLARE SECTION END-EXEC.

MOVE "SCOTT" TO USERNAME-ARR.
MOVE 5 TO USERNAME-LEN.
MOVE "TIGER" TO PASSWD-ARR.
MOVE 5 TO PASSWD-LEN.
EXEC SQL CONNECT :USERNAME IDENTIFIED BY :pASSWD
END-EXEC.

QUESTIONS :
1. USERNAME-ARR and USERNAME-LEN are not explicitly
declared.
Does the precompiler generate these field name suffixes
for VARYING variables ?
2.'The DECLARE section is optional' (p.2-20).
What happens if I omit it and code :
01 USERNAME PIC X(10) VARYING.
I don't think VARYING is a valid Cobol datatype (should
be OCCURS DEPENDING).
3. I have forgotten what Cobol datatype is generated
for a DB2 VARCHAR(n). Is it an ODO ?
4. The code also moves spaces to the host variable EMP-NAME- ARR prior to a SELECT. What happens if you don't ?
5. IBM has a DCLGEN utility which generates data
structures from existing DB2 tables to be EXEC SQL
INCLUDEd.
In Oracle should I code my own structures and EXEC SQL
INCLUDE them ?
6. The hardcoded username and password are naive.
Do I AUTO_CONNECT, automatic logon (p.3-9) ?
What's 'best practice' for connects ?

Thankyou.





 
I have to say that if you are asking those questions it looks unlikely that you are doing a conversion from DB2 to Oracle, as you seem to be lacking knowledge on ESQL. (may be wrong!!)

ESQL is a standard, and you should be able to use the same programs with both DB2 and Oracle (and Sybase, and Progress and ADABAS for that matter) if you stick your self with standard SQL statements within the EXEC SQL groups within the Procedure division.
This is probably not the case of someone that has already a production APP, so some work will be required.


The declare is not optional if you are going to use input/output variables.

Regarding the fact that VARYING seems to be an "invalid" COBOL construct, it is not an issue, as the pre-compilers for ESQL will convert this to a proper group.
sample
---------------
* EXEC SQL BEGIN DECLARE SECTION END-EXEC.
*01 USERNAME PIC X(10) VARYING.
01 USERNAME.
02 USERNAME-LEN PIC S9(4) COMP-5.
02 USERNAME-ARR PIC X(10).
*01 PASSWD PIC X(10) VARYING.
01 PASSWD.
02 PASSWD-LEN PIC S9(4) COMP-5.
02 PASSWD-ARR PIC X(10).
---------------
If you ommit the VARYING you need to declare the variable directly as a fixed size
e.g.
01 USERNAME PIC X(10).
and this will also work.


You can verify this easily by precompiling some of the examples and looking at the resulting source-code.

As for login/connections.
This is a program design issue. Offcourse you can have the login username/password on a file, or even use a "trusted connection".

Most people will also code their programs in a way that only one connection is done on a main program, and then this connection is passed to the called programs.
But once again this depends on how you have your programs.

varchar(n) is the same in DB2, ORACLE and SQLSERVER, and Probably the same on the other DB's.



for general migration from DB2 to Oracle see
and more specifically


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top