Creating and inserting data in a IMS Universal DL/I driver application
Use the create or the insert methods in the PCB interface to add a new segment to the database.
In the IMS Universal DL/I driver, the insert and create methods
provide functionality similar to the DL/I ISRT call. The insert methods will return an IMS status code indicating the results of the DL/I operation,
whereas the create method returns the number of segments created (this will always return 1). An
exception is thrown if a key field is not set.
Procedure
- Obtain an SSAList instance from the PCB instance representing the database.
- Optionally, you can add qualification statements to the SSAList.
- Get a Path instance by using the SSAList instance from the previous steps and calling the getPathForInsert method. The getPathForInsert method takes the name of an existing segment on the SSAList as a parameter. The parameter indicates the name of the segment type for the new segment. For instance, to add a new patient segment, you would pass the segment name PATIENT as the parameter.
- Using the Path instance from the step above, set the field values for the new segment.
- Call the insert or create method to add the new segment.
IMS Universal DL/I driver create and insert example
The following code fragment illustrates how to use the create and
insert methods to add a new patient and illness segment in the database where the hospital name is
SANTA TERESA
and the ward name is
GENERAL
.
SSAList ssaList = pcb.getSSAList("HOSPITAL","PATIENT");
ssaList.addInitialQualification("HOSPITAL","HOSPNAME",
SSAList.EQUALS,"SANTA TERESA");
ssaList.addInitialQualification("WARD","WARDNAME",
SSAList.EQUALS,"GENERAL");
Path path = ssaList.getPathForInsert("PATIENT");
path.setString("PATIENT", "PATNUM", "0088");
path.setString("PATIENT", "PATNAME", "JACK KIRBY");
int i = pcb.create(path, ssaList); // returns i = 1 if successful
System.out.println(i);
SSAList ssaList2 = pcb.getSSAList("HOSPITAL","ILLNESS");
ssaList2.addInitialQualification("HOSPITAL","HOSPNAME",
SSAList.EQUALS,"SANTA TERESA");
ssaList2.addInitialQualification("WARD","WARDNAME",
SSAList.EQUALS,"GENERAL");
ssaList2.addInitialQualification("PATIENT","PATNUM",
SSAList.EQUALS,"0088");
Path path2 = ssaList2.getPathForInsert("ILLNESS");
path2.setString("ILLNAME", "APPENDICITIS");
short status = pcb.insert(path2, ssaList2);
The following code example shows another way to do this in a single call:
SSAList ssaList = pcb.getSSAList("HOSPITAL","ILLNESS");
ssaList.addInitialQualification("HOSPITAL","HOSPNAME",
SSAList.EQUALS,"SANTA TERESA");
ssaList.addInitialQualification("WARD","WARDNAME",
SSAList.EQUALS,"GENERAL");
ssaList.addCommandCode("PATIENT", SSAList.CC_D);
Path path = ssaList.getPathForInsert("PATIENT");
path.setString("PATIENT", "PATNUM", "0088");
path.setString("PATIENT", "PATNAME", "JACK KIRBY");
path.setString("ILLNAME", "APPENDICITIS");
int i = pcb.create(path, ssaList); // returns i = 1 if successful
Important: To persist changes made to the database, your application must call
the PSB.commit method prior to deallocating the PSB, otherwise
the changes are rolled back up to the last point commit was called.