An example of an enhanced DB2 GnuCOBOL program using GETDBID.
Code: GETDBID.cbl
This is a simple COBOL pgm that can be called by GnuCOBOL programs.
It has the userid and password embedded within it.
Calling this bypasses the ACCEPT of the userid and password.
Copy the text to tcbl/GETDBID.cbl
Change the userid and password to the ones on your system.
NOTE: Just replace the text, make sure the ' surrounding the text is present.
**********************************************************
* Program name: GETDBID
* Original author: David Stagowski
*
* Description: This is a called module to supply the
* the userid and password for the database.
* This was written because I got tired of typing them in
* everytime I ran the program.
*
* Maintenence Log
* Date Author Maintenance Requirement
* --------- ------------ -------------------------------
* 2020-08-18 dastagg
*
*
**********************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. GETDBID.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 DB-User-ID PIC X(10).
01 DB-Passwd-Name PIC X(18).
PROCEDURE DIVISION USING DB-User-ID, DB-Passwd-Name.
MOVE 'userid' TO DB-User-ID.
MOVE 'password' TO DB-Passwd-Name.
GOBACK.
Change to CUSTINQ
Then replace this code:
9811-Get-Credentials.
DISPLAY "CUSTINQ: Need userid and password".
DISPLAY "Enter your user id (default none): "
WITH NO ADVANCING.
ACCEPT DB-User-ID.
DISPLAY "Enter your password : " WITH NO ADVANCING
ACCEPT DB-Passwd-Name.
With this code:
9811-Get-Credentials.
CALL 'GETDBID' USING DB-User-ID, DB-Passwd-Name.
Change to Compile script
In order to use this, the Compile script has to be changed to add GETDBID to the compile step.
Previous version:
#!/bin/bash
# Program parms
PGM=CUSTINQ
# DB2 Load Libraries
export LOADLIB="$DB2_HOME/lib64"
# COBOL and SQL Copy Libraries
export COBCOPY="../cpy"
export SQLCOPY="$DB2_HOME/include/cobol_mf"
# Clean up
rm ../cbl/$PGM.bnd
rm ../tcbl/$PGM.cbl
rm ../bin/$PGM
# DB2 Prep and Bind
db2 -tvf ../sql/$PGM.sql
read -p "Press any key to resume"
# Compile
cobc -std=default -x -o ../bin/$PGM ../tcbl/$PGM.cbl \
-static \
-I $SQLCOPY \
-I $COBCOPY \
-L $LOADLIB \
-l db2 \
-Wall \
-O
# Check return code
if [ "$?" -eq 0 ]; then
echo "Complier Return code was ZERO."
else
echo "Complier Return code not ZERO."
fi
New version
#!/bin/bash
# Program parms
RPGM=CUSTINQ
PGM=CUSTINQ
LLM=GETDBID
# DB2 Load Libraries
export LOADLIB="$DB2_HOME/lib64"
# COBOL and SQL Copy Libraries
export COBCOPY="../cpy"
export SQLCOPY="$DB2_HOME/include/cobol_mf"
# Clean up
rm ../cbl/$PGM.bnd
rm ../tcbl/$PGM.cbl
rm ../bin/$RPGM
# DB2 Prep and Bind
db2 -tvf ../sql/$PGM.sql
read -p "Press any key to resume"
# Compile
cobc -std=default -x -o ../bin/$RPGM ../tcbl/$PGM.cbl ../tcbl/$LLM.cbl \
-static \
-I $SQLCOPY \
-I $COBCOPY \
-L $LOADLIB \
-l db2 \
-Wall \
-O
# Check return code
if [ "$?" -eq 0 ]; then
echo "Complier Return code was ZERO."
else
echo "Complier Return code not ZERO."
fi