Skip to Content

Environment: Webdynpro Java Portal and SAP MDM   

Scenario 1: Create


  1. Create the BinaryBlobRecord instance(blob_instance) from RecordFactory.createEmptyBinaryObjectRecord(BINARY_OBJECTS_TABLE_ID);
  2. Set all the values that are to be updated in the same instance (blob_instance).**
  • blob_instance.setDataGroupId(<value>)
  • blob_instance.setBinary(<Binary Object Byte[]>);
  • blob_instance.setHasOriginal(<boolean>);

     3. Use CreateRecordCommand create = new CreateRecordCommand(<user session context>); to create the Binary Object Record (B1)

          CreateRecordCommand (MDM Java API Library)

     4. Set the value and Update the Main Table Record (R1) with the Link (B1) Result : We have a record (B1) in the Binary Object table linked to the main table* record (R1).

*Can be table of any type


Scenario 2: Update
To update the BLOB object of that particular Binary Object record (B1).Steps:

  1. Search the Binary Objects table with for the record to be updated
    1. Get the link from the main table record (R1)
    2. The return value is Rec ID of the BLOB (B1).
  2. Create the BinaryBlobRecord instance(blob_instance) from RecordFactory.createEmptyBinaryObjectRecord(BINARY_OBJECTS_TABLE_ID,B1);
  3. Set all the values that are to be updated in the same instance (blob_instance).**
    • blob_instance.setDataGroupId(<value>)
    • blob_instance.setBinary(<Binary Object Byte[]>);
    • blob_instance.setHasOriginal(<boolean>);
  4. Use the ModifyRecordCommand to update the Record.

    ModifyRecordCommand (MDM Java API Library)

Result: The Binary Object is updated and hence there is no need to re-link again.


**For the details about the different Parameters of Binary Objects – Working with Binary Large Objects (BLOBs) – SAP NetWeaver Master Data Management (MDM) 7.1 – SAP Library

to set the setDataGroupId(Mandate for all types of BLOBs)

RetrieveGroupTreeCommand tree = new RetrieveGroupTreeCommand(<usersession context>););

tree.setGroupType(GroupTypes.DATA_GROUP_TYPE);

tree.execute();

HierGroupNode node = tree.getGroupTree();

//As per our requirement we just placed all the BLOBs in the first leaf of the node

//you can various options in the HierGroupNode (MDM Java API Library) to traverse and select the relevant leaf.

GroupNodeId gID = node.getAllLeafs()[0].getId();                 

blob_instance.setDataGroupId(gID);                

 

to set the setDataLocationId (Mandatory only for Binary Objects)               

RetrieveGroupTreeCommand location = new RetrieveGroupTreeCommand(<usersession context>);

location.setGroupType(GroupTypes.DATA_LOCATION_TYPE);

location.execute();

HierGroupNode lTree = location.getGroupTree();

//As per our requirement we just placed all the BLOBs in the first leaf of the node

//you can various options in the HierGroupNode (MDM Java API Library) to traverse and select the relevant leaf.

GroupNodeId lID = lTree.getAllLeafs()[0].getId();                

blob_instance.setDataLocationId(lID);


Scenario 3: Deletion
Note : we can delete a Binary Object only if it is not linked anywhere.

Delete the orphaned or the unused records from the Binary Objects table.


  1. Get the Record ID’s from the Binary Object Table

     Using the  RetrieveLimitedRecordsExCommand objExCommand_allData = new RetrieveLimitedRecordsExCommand(<UserSessionContext>);          Command.   

2. Use the below code to get usage of the Binary Object Record (B1).   

RetrieveBinaryObjectUsageCommand objUsageCommand =new                                           RetrieveBinaryObjectUsageCommand(<UserSessionContext>);            

    • objUsageCommand.setTableId(BinaryObjects_tableID));
    • objUsageCommand.setRecordId(B1);
    • objUsageCommand.execute();

     RepositoryItemUsageResult objUsageResult = objUsageCommand .getUsageResult();

     RepositoryItemUsage[] repoUsage=objUsageResult.getUsages();

Refer the link for the return values : Constant Field Values (MDM Java API Library)

If the length of repoUsage is 0 then the Binary Object Record (B1) has no usage. And therefore can be erased.

     3.Use the

     DeleteRecordsCommand objDeleteBLOBRecordsCommand = new DeleteRecordsCommand((<UserSessionContext>);

     DeleteRecordsCommand (MDM Java API Library)

            To delete the Record.

Note :  Trying to delete Binary Object records which are linked will result into an Exception  .

FYI: For your information you can use the Pagination technique for searching Pagination of MDM search result in Java

To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

    1. Arjun Nair Post author

      Hi Jun Wu,

      It has nit been copy pasted from anywhere.

      I have clearly mentioned in the post on how to populate the dataGrupID

      You can find the line

      • blob_instance.setDataGroupId(<value>)

      in the post.

      Also I have included the technique to figure out on how to seperate the orphan records from the dependent ones.

      Hope I answer to your query or have I messed out any point?

      Thanks for the feedback. Its much appreciated.

      Arjun Nair


      (0) 
            1. Arjun Nair Post author

              I have implemented the API and also that its now working perfectly in the production system.

              So I do believe that I have used this API.

              As i said earlier, I have put some extra infromation on the deletion of the Orpaned Binary Records.

              (0) 
              1. Jun Wu

                wow, that sounds great,

                then can you show me a few line of code regarding how the data group and data location is calculated? Hopefully you know what I am talking about.

                (0) 
              2. Jun Wu

                setHasOriginal

                public void setHasOriginal(MdmValue hasOriginal) throws IllegalArgumentException, MdmValueTypeException
                Sets whether the blob is store in the repository (optional).

                Parameters:
                hasOriginaltrue if the blob is store in the repository, otherwise false

                check what you said in your blog, that kind of code can run in production?

                Set all the values that are to be updated in the same instance (blob_instance).
                blob_instance.setDataGroupId(<value>)
                blob_instance.setBinary(<value>);
                blob_instance.setHasOriginal(<Binary Object>);
                3. Use CreateRecordCommand create = new CreateRecordCommand(<user session context>);
                (0) 
                1. Arjun Nair Post author

                  Hi Jun Wu

                  Thanks for Highlighting my mistake.Apologies for that. 🙂

                  I have updated the blog correcting them and also included the code for setting the datagroupID and the LocationID.

                  Please comment.

                  Thanks

                  (0) 
                    1. Arjun Nair Post author

                      Till today I have been honest. And I will be hereafter.

                      I need not proove anyone about that.

                      Request you to appreciate others efforts rather than berating and underestimating new comers.

                      I respect you seniorty and expect a professional interaction.

                      Thanks

                      (0) 

Leave a Reply