Deleting data in a IMS Universal DL/I driver application

Use the delete method in the PCB interface to delete existing segments in the database.

In the IMS Universal DL/I driver, the delete methods provide functionality similar to the DL/I DLET call. The delete call must be preceded by a HOLD operation. Deleting a segment causes all its child segments to be deleted. The delete method will return an IMS status code indicating the results of the DL/I operation.
The following are the general steps to delete existing segments in the database:

Procedure

  1. Obtain an unqualified SSAList instance from the PCB instance representing the database.
  2. Optionally, you can add qualification statements to the SSAList instance.
    See Specifying segment search arguments using the SSAList interface for more information.
  3. Get a Path instance by using the SSAList instance from steps 1 and 2 and calling the getPathForRetrieveReplace method.
  4. Perform a Hold operation before issuing the replace call. The Hold operation can be a getUnique, getNext, or getNextWithinParent method call.
  5. You can delete all the segments on the Path retrieved by step 3 or delete a subset of the segments.
    • To delete all the segments on the Path, call the PCB.delete method with no arguments.
    • If the Path retrieved by step 3 returned multiple segments from the database and you do not want to delete all the segments on the Path, use the PCB.delete method that takes an SSAList argument and pass in an unqualified SSAList for the segment where you want the deletion to begin. An exception is thrown if a qualified SSAList is provided as an argument.

IMS Universal DL/I driver delete examples

The following code fragment illustrates how delete all segments in a Path. Calling the delete method with no arguments removes all PATIENT segments and its dependent segments (ILLNESS, TREATMNT, DOCTOR, BILLING) where the patient name is ANDREA SMITH, the ward name is SURG, the hospital name is ALEXANDRIA, and the patient number is PatientNo7.

SSAList ssaList = pcb.getSSAList("HOSPITAL","ILLNESS");
ssaList.addInitialQualification("HOSPITAL","HOSPNAME",SSAList.EQUALS,"ALEXANDRIA");
ssaList.addInitialQualification("WARD","WARDNAME",SSAList.EQUALS,"SURG");
ssaList.addInitialQualification("PATIENT","PATNAME",SSAList.EQUALS,"ANDREA SMITH");
ssaList.addCommandCode("PATIENT", SSAList.CC_D);
Path path = ssaList.getPathForRetrieveReplace();
if (pcb.getUnique(path, ssaList, true)) { 
   if (path.getString("PATIENT", "PATNUM").equals("PatientNo7")) {  
      pcb.delete(); 
   }
}
while (pcb.getNext(path, ssaList, true)) {   
   if (path.getString("PATIENT", "PATNUM").equals("PatientNo7")) {
      pcb.delete();
   }
}

The following code fragment illustrates how to use delete with an unqualified SSAList. Calling the delete method with an unqualified SSAList removes all ILLNESS segments and its dependent segments (TREATMNT, DOCTOR) where the patient name is ANDREA SMITH, the ward name is SURGICAL, the hospital name is ALEXANDRIA, and the patient number is PatientNo7.

SSAList ssaList = pcb.getSSAList("HOSPITAL","ILLNESS");
ssaList.addInitialQualification("HOSPITAL","HOSPNAME",SSAList.EQUALS,"ALEXANDRIA");
ssaList.addInitialQualification("WARD","WARDNAME",SSAList.EQUALS,"SURGICAL");
ssaList.addInitialQualification("PATIENT","PATNAME",SSAList.EQUALS,"ANDREA SMITH");
ssaList.markAllFieldsForRetrieval("PATIENT", true); 
Path path = ssaList.getPathForRetrieveReplace();
SSAList illnessSSAList = pcb.getSSAList("ILLNESS"); 
if (pcb.getUnique(path, ssaList, true)) { 
   if (path.getString("PATIENT", "PATNUM").equals("PatientNo7")) {  
      pcb.delete(illnessSSAList); 
   }
}
while (pcb.getNext(path, ssaList, true)) {   
   if (path.getString("PATIENT", "PATNUM").equals("PatientNo7")) {
      pcb.delete(illnessSSAList);
   }
}
Important: To persist changes made to the database, your application must call the commit method prior to deallocating the PSB, otherwise the changes are rolled back up to the last point the commit method was called.