Sample source code
C sample source code
If you are using the C External Function part, use these files:
catm.c
/* This is the code to support the C ATM sample for VA Smalltalk */
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "catm.h"
#define SAMPLECUSTOMERS 2
ATM_CUSTOMER sample_customers[SAMPLECUSTOMERS] =
{"John", "Smith", "12345", "7890.03", "15384.42",
"Don", "Brady", "54321", "34.23", "196.44" };
/*****************************************************************/
/* */
/* atm() actually receives the requests */
/* */
/*****************************************************************/
void _cdecl atm(unsigned long atm_Action, P_ATM_CUSTOMER pcustomer)
{
short i;
switch (atm_Action)
{
case ATM_QUERY:
for (i=0; i<SAMPLECUSTOMERS; i++ ) {
if (!strcmp(sample_customers[i].pin_number,
pcustomer->pin_number))
{
memcpy(pcustomer, &(sample_customers[i]),
sizeof(ATM_CUSTOMER));
} /* endif */
} /* endfor */
break;
case ATM_UPDATE:
for (i=0; i<SAMPLECUSTOMERS; i++ )
{
if (!strcmp(sample_customers[i].pin_number,
pcustomer->pin_number))
{
strcpy(sample_customers[i].checking_balance,
pcustomer->checking_balance);
strcpy(sample_customers[i].savings_balance,
pcustomer->savings_balance);
memcpy(pcustomer, &(sample_customers[i]),
sizeof(ATM_CUSTOMER));
} /* endif */
} /* endfor */
break;
default:
break;
} /* endswitch */
return;
}
catm.h
/* this header file defines the C ATM example for VA Smalltalk */
#define ATM_QUERY 1
#define ATM_UPDATE 2
typedef struct {
char first_name[20];
char last_name[20];
char pin_number[6];
char checking_balance[9];
char savings_balance9];
} ATM_CUSTOMER, *P_ATM_CUSTOMER;
#define KEY_SIZE 6
void _cdecl atm(unsigned long atm_Action,
P_ATM_CUSTOMER pcustomer);
catm.def
For OS/2, use:
LIBRARY catm
PROTMODE
DATA MULTIPLE
EXPORTS
atm
For Windows, use:
LIBRARY CATM
EXPORTS
_atm
catm.mak
For Windows, use:
# Win32 compile and link catm sample
# Uses VisualAge for C++ compiler
# CFLAGS: C compiler flags
#
# /C Compile only
# /Ms System calling convention
# /Fo$@ Name the object file
# /G4 Optimize code for 486 processor
# /Sm Ignore migration keywords
# /Gd+ Use dynamically linked runtime
# /Ge- Build a DLL
#
CFLAGS = /C /Ms /Fo$@ /G4 /Sm /Gd+ /Ge-
!IFDEF DEBUG
CFLAGS = $(CFLAGS) /Ti+
!ENDIF
# LFLAGS: Linker flags
#
# /Fe$@ Name the executable file
# /Ge- Build a DLL
# /Gm+ Link with the multithread libraries
# /Q+ Link quietly
# /Ti+ Keep executable debug information
#
LFLAGS = /Fe$@ /Ge- /Gm+ /Q+ /Ti+
all: catm.dll
clean:
- del catm.obj
- del catm.res
- del catm.dll
catm.dll: catm.obj catm.exp
icc catm.obj catm.exp $(LFLAGS)
catm.obj: catm.c
icc $(CPPFLAGS) $(CFLAGS) catm.c
catm.exp: catm.def
ilib /geni:$*.lib catm.def
COBOL sample source code
If you are using the COBOL External Function part, use these files:
atm.cbl
*---------------------------------------------------------------
* ATM
* ATM demonstration program.
*---------------------------------------------------------------
IDENTIFICATION DIVISION.
PROGRAM-ID. ATM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
77 CUST-COUNT PIC 9(3) USAGE COMP VALUE ZERO.
78 MAX-CUSTOMERS VALUE 2.
78 FIRST-PIN VALUE "12345".
01 ATM-SAMPLE-CUSTS.
02 CUST-1.
03 FIRST-NAME PIC X(20) VALUE
"John S.".
03 LAST-NAME PIC X(20) VALUE
"Smith".
03 PIN-NUMBER PIC X(5) VALUE
"12345".
03 CHECKING-BALANCE PIC 9(7)V99 VALUE
7890.03.
03 SAVINGS-BALANCE PIC 9(7)V99 VALUE
15384.42.
02 CUST-2.
03 FIRST-NAME PIC X(20) VALUE
"Don".
03 LAST-NAME PIC X(20) VALUE
"Brady".
03 PIN-NUMBER PIC X(5) VALUE
"54321".
03 CHECKING-BALANCE PIC 9(7)V99 VALUE
34.23.
03 SAVINGS-BALANCE PIC 9(7)V99 VALUE
196.44.
02 FILLER PIC X(63) OCCURS 8.
01 ATM-WORK-SPACE PIC X(630).
01 ATM-CUSTOMER-ARRAY OCCURS 10 TIMES
REDEFINES ATM-WORK-SPACE.
02 FIRST-NAME PIC X(20).
02 LAST-NAME PIC X(20).
02 PIN-NUMBER PIC X(5).
02 CHECKING-BALANCE PIC 9(7)V99.
02 SAVINGS-BALANCE PIC 9(7)V99.
*
LINKAGE SECTION.
01 ACTION-CODE.
02 ATM-ACTION PIC X.
88 ATM-QUERY VALUE "Q".
88 ATM-BALANCE-CHANGE VALUE "U".
*
01 ATM-CUSTOMER.
02 FIRST-NAME PIC X(20).
02 LAST-NAME PIC X(20).
02 PIN-NUMBER PIC X(5).
02 CHECKING-BALANCE PIC 9(7)V99.
02 SAVINGS-BALANCE PIC 9(7)V99.
*
PROCEDURE DIVISION USING ACTION-CODE ATM-CUSTOMER.
*
******************************************
ATM-CHECK-ACTION.
******************************************
PERFORM ATM-INIT.
IF ATM-QUERY THEN
PERFORM ATM-Q-CUSTOMER
ELSE
IF ATM-BALANCE-CHANGE THEN
PERFORM ATM-UPDATE
END-IF
END-IF
GO TO ATM-RETURN-CONTROL.
*
ATM-Q-CUSTOMER.
MOVE ZERO TO CUST-COUNT.
PERFORM
NULL-SENTENCE
VARYING CUST-COUNT FROM 1 BY 1
UNTIL PIN-NUMBER OF ATM-CUSTOMER =
PIN-NUMBER OF ATM-CUSTOMER-ARRAY(CUST-COUNT)
OR (CUST-COUNT = MAX-CUSTOMERS + 1).
IF CUST-COUNT = (MAX-CUSTOMERS + 1) THEN
* Cust not found. Reset the fields
MOVE SPACES TO FIRST-NAME OF ATM-CUSTOMER
LAST-NAME OF ATM-CUSTOMER
MOVE ZEROES TO CHECKING-BALANCE OF ATM-CUSTOMER
SAVINGS-BALANCE OF ATM-CUSTOMER
ELSE
MOVE CORRESPONDING
ATM-CUSTOMER-ARRAY(CUST-COUNT) TO ATM-CUSTOMER
END-IF.
ATM-UPDATE.
MOVE ZERO TO CUST-COUNT.
PERFORM
NULL-SENTENCE
VARYING CUST-COUNT FROM 1 BY 1
UNTIL PIN-NUMBER OF ATM-CUSTOMER =
PIN-NUMBER OF ATM-CUSTOMER-ARRAY(CUST-COUNT)
OR (CUST-COUNT = MAX-CUSTOMERS + 1).
IF CUST-COUNT = (MAX-CUSTOMERS + 1) THEN
* Cust not found. Do nothing
CONTINUE
ELSE
MOVE CORRESPONDING
ATM-CUSTOMER TO ATM-CUSTOMER-ARRAY(CUST-COUNT)
END-IF.
ATM-INIT.
IF PIN-NUMBER OF ATM-CUSTOMER-ARRAY(1) = FIRST-PIN THEN
CONTINUE
ELSE
MOVE ATM-SAMPLE-CUSTS TO ATM-WORK-SPACE
END-IF.
*
NULL-SENTENCE.
*
ATM-RETURN-CONTROL.
GOBACK.
atm.cpy
77 CUST-COUNT PIC 9(3) USAGE COMP VALUE ZERO.
78 MAX-CUSTOMERS VALUE 2.
78 FIRST-PIN VALUE "12345".
01 ATM-SAMPLE-CUSTS.
02 CUST-1.
03 FIRST-NAME PIC X(20) VALUE
"John S.".
03 LAST-NAME PIC X(20) VALUE
"Smith".
03 PIN-NUMBER PIC X(5) VALUE
"12345".
03 CHECKING-BALANCE PIC 9(7)V99 VALUE
7890.03.
03 SAVINGS-BALANCE PIC 9(7)V99 VALUE
15384.42.
02 CUST-2.
03 FIRST-NAME PIC X(20) VALUE
"Don".
03 LAST-NAME PIC X(20) VALUE
"Brady".
03 PIN-NUMBER PIC X(5) VALUE
"54321".
03 CHECKING-BALANCE PIC 9(7)V99 VALUE
34.23.
03 SAVINGS-BALANCE PIC 9(7)V99 VALUE
196.44.
02 FILLER PIC X(63) OCCURS 8.
01 ATM-WORK-SPACE PIC X(630).
01 ATM-CUSTOMER-ARRAY OCCURS 10 TIMES
REDEFINES ATM-WORK-SPACE.
02 FIRST-NAME PIC X(20).
02 LAST-NAME PIC X(20).
02 PIN-NUMBER PIC X(5).
02 CHECKING-BALANCE PIC 9(7)V99.
02 SAVINGS-BALANCE PIC 9(7)V99.
*
LINKAGE SECTION.
01 ACTION-CODE.
02 ATM-ACTION PIC X.
88 ATM-QUERY VALUE "Q".
88 ATM-BALANCE-CHANGE VALUE "U".
*
01 ATM-CUSTOMER.
02 FIRST-NAME PIC X(20).
02 LAST-NAME PIC X(20).
02 PIN-NUMBER PIC X(5).
02 CHECKING-BALANCE PIC 9(7)V99.
02 SAVINGS-BALANCE PIC 9(7)V99.
atm.def
LIBRARY INITINSTANCE
PROTMODE
DATA NONSHARED
EXPORTS ATM @1
cblmake.cmd
/* This command file compiles and links a COBOL program.
** Pass the program name in as the first argument.
**
** This command file will work with
** Micro Focus COBOL compiler version 3.0.29
** Microsoft linker 5.10.005
**
*/
arg pgm .
"COBOL "pgm",,,, omf(obj) model(large) litlink nodynam ",
"list("pgm".lst) setting"
"link "pgm,
"/MAP/NOD/ST:32000/SE:1024/A:16/FAR,",
pgm".DLL,"pgm".map,",
"LCOBOL+DOSCALLS,",
pgm".def;"
/* Note: you can change DOSCALLS.LIB to OS2.LIB if it is available */
Instead of using the above .cmd file, try entering at a command prompt:
'COB2 ATM.CBL ATM.DEF'