Skip to content

Commit 99839b4

Browse files
authored
Linkservec01 (#12)
* Add EC01 Link back end * Added EC01 back end * Add INVREQ handling * Tabs to spaces. * Whitespace updates. * Comments * Formatting * Formatting * Added static int return codes for error handling * Removed tabs * Updated comments
1 parent 649df92 commit 99839b4

File tree

7 files changed

+458
-380
lines changed

7 files changed

+458
-380
lines changed

projects/com.ibm.cicsdev.link/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
88
CICS-MainClass: com.ibm.cicsdev.link.LinkProg1,
99
com.ibm.cicsdev.link.LinkProg2,
1010
com.ibm.cicsdev.link.LinkProg3,
11-
com.ibm.cicsdev.link.LinkServEduchan
11+
com.ibm.cicsdev.link.LinkServEduchan,
12+
com.ibm.cicsdev.link.LinkServEC01
1213
Import-Package: com.ibm.cics.server;version="[1.401.0,2.0.0)",
1314
com.ibm.jzos.fields;resolution:=optional
1415
Bundle-ClassPath: lib/EDUPGM.jar,

projects/com.ibm.cicsdev.link/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Provides examples for performing CICS LINK operations using both commareas, and
88
* `LinkProg3` - a class that demonstrates linking to COBOL application `EDUCHAN` using channels and containers.
99
* `LinkProgCommon` - superclass used to provide common services for the `LinkProg` samples.
1010
* `LinkServerEduchan` - A Java version of the `EDUCHAN` COBOL program used as the back-end to `LinkProg3`.
11+
* `LinkServerEC01` - A Java version of the `EC01` COBOL program used as the back-end to `LinkProg1`.
1112

1213

1314
## Supporting files
@@ -23,6 +24,7 @@ Provides examples for performing CICS LINK operations using both commareas, and
2324
1. Compile and deploy the COBOL programs `EC01`, `EDUPGM`, and `EDUCHAN`.
2425
1. Define appropriate PROGRAM definitions, or enable program autoinstall.
2526
1. Optionally add a CICS Java program definiton for LinkServerEduchan called EDUCHAN if you wish to replace the EDUCHAN COBOL sample with the Java implemenation.
27+
1. Optionally add a CICS Java program definiton for LinkServerEC01 called EV01 if you wish to replace the EC01 COBOL sample with the Java implemenation.
2628

2729

2830
## Running the Example

projects/com.ibm.cicsdev.link/src/com/ibm/cicsdev/link/LinkProg1.java

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,90 +14,94 @@
1414
import java.text.MessageFormat;
1515

1616
import com.ibm.cics.server.CicsConditionException;
17+
import com.ibm.cics.server.InvalidRequestException;
1718
import com.ibm.cics.server.Program;
1819
import com.ibm.cics.server.Task;
1920

2021
public class LinkProg1 extends LinkProgCommon {
2122

2223

23-
private static final String PROG_NAME = "EC01"; // COBOL program to be invoked
24-
private static final int CA_LEN = 18 ; // Length of commarea returned by EC01
25-
private static final String LOCALCCSID = System.getProperty("com.ibm.cics.jvmserver.local.ccsid");
26-
27-
28-
/**
29-
* Constructor used to pass data to superclass constructor.
30-
*
31-
* @param task - the current CICS task executing this example.
32-
* @param prog - the program reference we will be manipulating in this example.
33-
*/
34-
private LinkProg1(Task task, Program prog)
35-
{
36-
super(task, prog);
37-
38-
}
39-
40-
/**
41-
* Main entry point to a CICS OSGi program.
42-
* This can be called via a LINK or a 3270 attach
43-
*
44-
* The fully qualified name of this class should be added to the CICS-MainClass
45-
* entry in the parent OSGi bundle's manifest.
46-
*/
47-
public static void main(String[] args)
48-
{
49-
// Get details about our current CICS task
50-
Task task = Task.getTask();
51-
task.out.println(" - Starting LinkProg1");
52-
53-
// Create a reference to the Program we will invoke
54-
Program prog = new Program();
55-
56-
// Specify the properties on the program
57-
prog.setName(PROG_NAME);
58-
// Don't syncpoint between remote links, this is the default
59-
// Setting true ensures each linked program runs in its own UOW and
60-
// allows the a remote server program to use a syncpoint command
61-
prog.setSyncOnReturn(false);
62-
63-
// Create a new instance of the class
64-
LinkProg1 lp = new LinkProg1(task, prog);
65-
66-
// Init commarea and invoke the LINK to CICS program
67-
// Commarea byte array should be as long as the DFHCOMMAREA structure in COBOL
68-
// Commarea will be padded with nulls which ensures CICS can null truncate DPL flows
69-
byte[] ca = new byte[CA_LEN];
70-
lp.linkProg(ca);
71-
72-
// Build output string from commarea assuming returned data encoded in CICS local EBCDIC ccsid
73-
String resultStr;
74-
try {
75-
resultStr = new String(ca,LOCALCCSID);
76-
} catch (UnsupportedEncodingException ue) {
77-
throw new RuntimeException(ue);
78-
}
79-
80-
// Completion message
24+
private static final String PROG_NAME = "EC01"; // COBOL program to be invoked
25+
private static final int CA_LEN = 18 ; // Length of commarea returned by EC01
26+
private static final String LOCALCCSID = System.getProperty("com.ibm.cics.jvmserver.local.ccsid");
27+
28+
29+
/**
30+
* Constructor used to pass data to superclass constructor.
31+
*
32+
* @param task - the current CICS task executing this example.
33+
* @param prog - the program reference we will be manipulating in this example.
34+
*/
35+
private LinkProg1(Task task, Program prog)
36+
{
37+
super(task, prog);
38+
39+
}
40+
41+
/**
42+
* Main entry point to a CICS OSGi program.
43+
* This can be called via a LINK or a 3270 attach
44+
*
45+
* The fully qualified name of this class should be added to the CICS-MainClass
46+
* entry in the parent OSGi bundle's manifest.
47+
*/
48+
public static void main(String[] args)
49+
{
50+
// Get details about our current CICS task
51+
Task task = Task.getTask();
52+
task.out.println(" - Starting LinkProg1");
53+
54+
// Create a reference to the Program we will invoke
55+
Program prog = new Program();
56+
57+
// Specify the properties on the program
58+
prog.setName(PROG_NAME);
59+
// Don't syncpoint between remote links, this is the default
60+
// Setting true ensures each linked program runs in its own UOW and
61+
// allows the a remote server program to use a syncpoint command
62+
prog.setSyncOnReturn(false);
63+
64+
// Create a new instance of the class
65+
LinkProg1 lp = new LinkProg1(task, prog);
66+
67+
// Init commarea and invoke the LINK to CICS program
68+
// Commarea byte array should be as long as the DFHCOMMAREA structure in COBOL
69+
// Commarea will be padded with nulls which ensures CICS can null truncate DPL flows
70+
byte[] ca = new byte[CA_LEN];
71+
lp.linkProg(ca);
72+
73+
// Build output string from commarea assuming returned data encoded in CICS local EBCDIC ccsid
74+
String resultStr;
75+
try {
76+
resultStr = new String(ca,LOCALCCSID);
77+
} catch (UnsupportedEncodingException ue) {
78+
throw new RuntimeException(ue);
79+
}
80+
81+
// Completion message
8182
String msg = MessageFormat.format ("Returned from link to {0} with {1}", prog.getName(),resultStr);
8283
task.out.println(msg);
8384

84-
}
85-
86-
87-
/**
88-
* Link to the CICS COBOL program catching any errors from CICS
89-
* The invoked CICS progra will retrun the date and time
90-
*
91-
* @param ca - commarea object for input and output commarea
92-
*/
93-
private void linkProg(byte[] ca){
94-
95-
// Execute the link to the CICS program
96-
// commarea byte array is updated after the call and does not need to be returned
97-
try {
98-
prog.link(ca);
99-
} catch (CicsConditionException cce) {
100-
throw new RuntimeException(cce);
101-
}
102-
}
85+
}
86+
87+
88+
/**
89+
* Link to the CICS COBOL program catching any errors from CICS
90+
* The invoked CICS progra will retrun the date and time
91+
*
92+
* @param ca - commarea object for input and output commarea
93+
*/
94+
private void linkProg(byte[] ca){
95+
96+
// Execute the link to the CICS program
97+
// commarea byte array is updated after the call and does not need to be returned
98+
// Ignore invalid request and just log
99+
try {
100+
prog.link(ca);
101+
} catch (InvalidRequestException ire) {
102+
task.out.println("Invalid request on link - INVREQ");
103+
} catch (CicsConditionException cce) {
104+
throw new RuntimeException(cce);
105+
}
106+
}
103107
}

projects/com.ibm.cicsdev.link/src/com/ibm/cicsdev/link/LinkProg2.java

Lines changed: 93 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -20,100 +20,97 @@
2020
public class LinkProg2 extends LinkProgCommon {
2121

2222

23-
private static final String PROG_NAME = "EDUPGM"; // COBOL program to be invoked
24-
25-
/**
26-
* Constructor used to pass data to superclass constructor.
27-
*
28-
* @param task - the current CICS task executing this example.
29-
* @param prog - the program reference we will be manipulating in this example.
30-
*/
31-
private LinkProg2(Task task, Program prog)
32-
{
33-
super(task, prog);
34-
35-
}
36-
37-
/**
38-
* Main entry point to a CICS OSGi program.
39-
* This can be called via a LINK or a 3270 attach
40-
*
41-
* The fully qualified name of this class should be added to the CICS-MainClass
42-
* entry in the parent OSGi bundle's manifest.
43-
*/
44-
public static void main(String[] args)
45-
{
46-
// Get details about our current CICS task
47-
Task task = Task.getTask();
48-
task.out.println(" - Starting LinkProg2");
49-
50-
// Create a reference to the Program we will invoke
51-
Program prog = new Program();
52-
53-
// Specify the properties on the program
54-
prog.setName(PROG_NAME);
55-
// Don't syncpoint between remote links, this is the default
56-
// Setting true ensures each linked program runs in its own UOW and
57-
// allows the a remote server program to use a syncpoint command
58-
prog.setSyncOnReturn(false);
59-
60-
// Create a new instance of the class
61-
LinkProg2 lp = new LinkProg2(task, prog);
62-
63-
// build commarea byte array using JZOS record
64-
JZOSCommareaWrapper cw = lp.buildCommarea();
65-
66-
// Invoke the LINK to CICS program converting the record to a byte array
67-
lp.linkProg(cw.getByteBuffer());
68-
69-
// Get output data from commarea
70-
// Use the getters from the commarea record to access the output fields
71-
// in the returned commarea
72-
String resultStr = cw.getResultText();
73-
Integer resultCode = cw.getResultCode();
74-
75-
// Completion message
76-
String msg = MessageFormat.format
77-
("Returned from link to {0} with rc({1}) {2}", prog.getName(),resultCode,resultStr);
78-
task.out.println(msg);
79-
}
80-
81-
82-
/**
83-
* Link to the CICS COBOL program and catch any errors from CICS
84-
*
85-
* @param commarea - byte array as input and output commarea
86-
*/
87-
// LINK to the CICS program
88-
private void linkProg(byte[] commarea){
89-
90-
try {
91-
prog.link(commarea);
92-
} catch (CicsConditionException cce) {
93-
throw new RuntimeException(cce);
94-
}
95-
}
96-
97-
/**
98-
* Build the commarea using the supplied JZOS wrapper
99-
* and set the input fields as required
100-
*
101-
* @return jzos commarea record for EDUPGM copybook
102-
*
103-
*/
104-
private JZOSCommareaWrapper buildCommarea(){
105-
106-
JZOSCommareaWrapper cw = new JZOSCommareaWrapper();
107-
cw.setBinaryDigit(1);
108-
cw.setCharacterString("hello");
109-
cw.setNumericString(1234);
110-
cw.setPackedDigit(123456789);
111-
cw.setSignedPacked(-100);
112-
cw.setBool("1");
113-
return cw;
114-
115-
}
116-
117-
118-
23+
private static final String PROG_NAME = "EDUPGM"; // COBOL program to be invoked
24+
25+
/**
26+
* Constructor used to pass data to superclass constructor.
27+
*
28+
* @param task - the current CICS task executing this example.
29+
* @param prog - the program reference we will be manipulating in this example.
30+
*/
31+
private LinkProg2(Task task, Program prog)
32+
{
33+
super(task, prog);
34+
35+
}
36+
37+
/**
38+
* Main entry point to a CICS OSGi program.
39+
* This can be called via a LINK or a 3270 attach
40+
*
41+
* The fully qualified name of this class should be added to the CICS-MainClass
42+
* entry in the parent OSGi bundle's manifest.
43+
*/
44+
public static void main(String[] args)
45+
{
46+
// Get details about our current CICS task
47+
Task task = Task.getTask();
48+
task.out.println(" - Starting LinkProg2");
49+
50+
// Create a reference to the Program we will invoke
51+
Program prog = new Program();
52+
53+
// Specify the properties on the program
54+
prog.setName(PROG_NAME);
55+
// Don't syncpoint between remote links, this is the default
56+
// Setting true ensures each linked program runs in its own UOW and
57+
// allows the a remote server program to use a syncpoint command
58+
prog.setSyncOnReturn(false);
59+
60+
// Create a new instance of the class
61+
LinkProg2 lp = new LinkProg2(task, prog);
62+
63+
// build commarea byte array using JZOS record
64+
JZOSCommareaWrapper cw = lp.buildCommarea();
65+
66+
// Invoke the LINK to CICS program converting the record to a byte array
67+
lp.linkProg(cw.getByteBuffer());
68+
69+
// Get output data from commarea
70+
// Use the getters from the commarea record to access the output fields
71+
// in the returned commarea
72+
String resultStr = cw.getResultText();
73+
Integer resultCode = cw.getResultCode();
74+
75+
// Completion message
76+
String msg = MessageFormat.format
77+
("Returned from link to {0} with rc({1}) {2}", prog.getName(),resultCode,resultStr);
78+
task.out.println(msg);
79+
}
80+
81+
82+
/**
83+
* Link to the CICS COBOL program and catch any errors from CICS
84+
*
85+
* @param commarea - byte array as input and output commarea
86+
*/
87+
// LINK to the CICS program
88+
private void linkProg(byte[] commarea){
89+
90+
try {
91+
prog.link(commarea);
92+
} catch (CicsConditionException cce) {
93+
throw new RuntimeException(cce);
94+
}
95+
}
96+
97+
/**
98+
* Build the commarea using the supplied JZOS wrapper
99+
* and set the input fields as required
100+
*
101+
* @return jzos commarea record for EDUPGM copybook
102+
*
103+
*/
104+
private JZOSCommareaWrapper buildCommarea(){
105+
106+
JZOSCommareaWrapper cw = new JZOSCommareaWrapper();
107+
cw.setBinaryDigit(1);
108+
cw.setCharacterString("hello");
109+
cw.setNumericString(1234);
110+
cw.setPackedDigit(123456789);
111+
cw.setSignedPacked(-100);
112+
cw.setBool("1");
113+
return cw;
114+
115+
}
119116
}

0 commit comments

Comments
 (0)