Migration from MDM 4J to MDM Java API

Hi,
Can anyone send me details on the migration of MDM 4J to MDM Java API .
Any document on the differences between the two will be really appreciated.
Best Regards
Sid

Hi Siddharth,
MDM4J was the old jar files which has been shipped by SAP. In earlier, for customization of any user requirement which is not avialable in MDM, In this case, we can use the MDM JAVA API. for using the same, we need to deploy the MDM4J.jar file then we can use.
Now, SAP has replaced the old MDM API file name as "MDM4J.jar" with "MDM Java API.jar".
the only difference between two is that they have added some new jar files to do the specific work with the MDM4J.jar itself. you can find the name as below:
MDM4J.jar
mdm-protocol.jar
mdm-data.jar
mdm-core.jar
mdm-common.jar
mdm-admin.jar
they have removed some old functionality from MDM4J.jar file itself and added so many new functionality with it.
for example: by using old java api, we can not get the password of any user but it is possible by new java API jar file. like this they have added so many new fuctionality which we can perform on the MDM Console and MDM Data manager.
for further info about the MDM JAVA API, you can just refer the following links:
http://help.sap.com/saphelp_mdmgds55/helpdata/EN/index.htm
in the left pane,go to programming interface, the required java apis documents is there.
All the documentation is available on the MDM documentation center on SAP Service Marketplace:
http://service.sap.com/installMDM
But for this you need valid service market place id and pwd.
Hope this will help you.
Regards,
Saurabh...
Reward with points if found useful.
Edited by: Saurabh Kumar Sahu on Jan 29, 2008 3:19 PM

Similar Messages

  • Error while creating user id from MDM JAVA API in 7.1 SP7

    Hi,
    We are trying to create user id in MDM 7.1 SP7 using JAVA API in SAP Portal. When trying to create user id, we are getting below error. If you have any solution please let us know.
    com.sap.mdm.commands.CommandException: MDM repository data is out-of-date or is locked by another MDM Server. Refresh the data and try the operation again. If the error persists, contact the system administrator
    Thanks,
    Vinit Pugaliya

    URGENT** How to change  OIM user password from outside OIM

  • How to retrieve the data from MDM hierarchy table using MDM Java API

    Hi,
    I had a hierarchy table in MDM. This table had some column say x. I want to retrieve the values of this x column and need to show them in a drop down using MDM Java API.
    Can anyone help me to solve this?
    Regards
    Vallabhaneni

    Hi,
    Here is your code...
    TableId Hier_TId = repository_schema.getTableId(<hierarchy table id>);
    java.util.List list = new ArrayList();
    ResultDefinition Supporting_result_dfn = null;
    FieldProperties[] Hier_Field_props =rep_schema.getTableSchema(Hier_TId).getFields();
    LookupFieldProperties lookup_field = null;
    TableSchema lookupTableSchema = null;
    FieldId[] lookupFieldIDs = null;
    for (int i = 0, j = Hier_Field_props.length; i < j; i++) {
    if (Hier_Field_props<i>.isLookup()) {     
                                  lookup_field = (LookupFieldProperties) Hier_Field_props<i>;
         lookupTableSchema =repository_schema.getTableSchema(lookup_field.getLookupTableId());
                                  lookupFieldIDs = lookupTableSchema.getFieldIds();
         Supporting_result_dfn = new ResultDefinition(lookup_field.getLookupTableId());
         Supporting_result_dfn.setSelectFields(lookupFieldIDs);
         list.add(Supporting_result_dfn);
    com.sap.mdm.search.Search hier_search =new com.sap.mdm.search.Search(Hier_TId);
    ResultDefinition Hier_Resultdfn =     new ResultDefinition(Hier_TId);
    Hier_Resultdfn.setSelectFields(rep_schema.getTableSchema(Hier_TId).getDisplayFieldIds());
    ResultDefinition[] supportingResultDefinitions =
    (ResultDefinition[])list.toArray(new ResultDefinition [ list.size() ]);
    RetrieveLimitedHierTreeCommand retrieve_Hier_tree_cmd =
    new RetrieveLimitedHierTreeCommand(conn_acc);
    retrieve_Hier_tree_cmd.setResultDefinition(Hier_Resultdfn);
    retrieve_Hier_tree_cmd.setSession(Auth_User_session_cmd.getSession());
    retrieve_Hier_tree_cmd.setSearch(hier_search);
    retrieve_Hier_tree_cmd.setSupportingResultDefinitions(supportingResultDefinitions);
    try {
         retrieve_Hier_tree_cmd.execute();
    } catch (CommandException e5) {
              // TODO Auto-generated catch block
              e5.printStackTrace();
    HierNode Hier_Node = retrieve_Hier_tree_cmd.getTree();
    print(Hier_Node,1);
    //method print()
    static private void print(HierNode node, int level) {
    if (!node.isRoot()) {
         for (int i = 0, j = level; i < j; i++) {
              System.out.print("\t");
         System.out.println(node.getDisplayValue());
    HierNode[] children = node.getChildren();
    if (children != null) {
              level++;
    for (int i = 0, j = children.length; i < j; i++) {
    print(children<i>, level);
    //end method print()
    Best regards,
    Arun prabhu S
    Edited by: Arun Prabhu Sivakumar on Jul 7, 2008 12:19 PM

  • MDM JAVA API to enter value into field of type date

    Hi All,
    I am having an input field in a typical Dynpro application where a date would be entered.I want to enter  the date in my MDM table in a field of type "Date".Do you have any idea about MDM JAVA API's I need to do this.Also how can I do this ?
    Thanks
    Vinay

    Hi,
    Web Dynpro shall return you a type Date field. For Value, you shall have to pass SystemTime Object.
    Just get the substring of Date.toString() and convert them to Integer ..
    So a typical date would look like yyyy-mm-dd (eg: 2006-10-19) and not yyyymmdd.
    SystemTime st = new SystemTime();
    st.setYear( Integer.parseInt(Date.toString().substring(0,4));
    st.setMonth ( Integer.parseInt(Date.toString().substring(5,7));
    st.setDate ( Integer.parseInt(Date.toString().substring(8,10));
    A2iField date = new A2iField("fieldname", new Value(st));
    Hope that helps..
    Regards,
    Tanveer.
    <b>Please mark helpful answers</b>
    Note: The above mentioned code is not pasted from any editor..So might contain syntax error..

  • How to start to work on MDM JAVA API by using webdynpro for java

    Hi all
    I have basic idea on MDM business package thru portal by using standard iViews.
    now i am planning to work on MDM JAVA APIs by using Webdynpro for Java as UI.
    1) can you please share the required documents on the same. how to start working on this by using MDM JAVA APIs in webdynpro for java
    2) what are the JARs files are required and how to integrate those jar files into webdynpro for java application.
    3)  is there any SDN help on MDM JAVA API with webdynpro for java? . can you please send the link on the same.
    4) can you please help by providing sample code on how to use JAVA APIs for retrieving,deleting,inserting and Updating the data in the database.
    if anybody helps on the same then it is the great help to me.
    points are always rewardable...
    Regards
    Suresh babu

    Hi Suresh,
    You can have the MDM JAVA API javadocs from the link
    http://help.sap.com/javadocs/MDM/SP06P2/index.html
    There you can see a package named com.sap.mdm.examples.The classes in it contains some examples using which you can start understanding the code.
    You need to have MDM JAR files for it. And these JAR files to be used at build time can be added to the project thru :-
    Right click on project-> properties->Java Build Path - > Add external JARs
    At run time you can add them the reference in
    Right click on project-> properties->web dynpro references->library reference.
    Thanks
    Namrata

  • Deployment Issue with MDM Java API exposed as Webservice using EJBS

    Hi Experts,
    I am implementing MDM Java APIS in Stateless session bean.Exposed that bean as Webservice and using that webservice in
    Webdynpro through Adaptive Webservice Model.
    I am facing following issue:
    Webservice works fine after deployment,after some number of execution webservice stops working and gives exception.After
    Redeployment of the Webservice, it starts working again works fine some number of execution.
    I am Using new MDMJava API.
    MDM Server Details: MDM 5.5 SP06
    I am using following code for connetion
    //////////////*************Getting Connection************///////
              ConnectionPool pool = null;
              String sessionId = null;
              try {
                   pool = ConnectionPoolFactory.getInstance("Server Ip");
              } catch (ConnectionException e1) {
                   System.out.println(e1.getMessage());
    //////////////*************Repository Session************///////
    CreateRepositorySessionCommand repSeession =
                   new CreateRepositorySessionCommand(p_pool);
              repSeession.setRepositoryIdentifier(p_repId);
              try {
                   repSeession.execute();
              } catch (CommandException e2) {
                   System.out.println(e2.getMessage().toString());
              String repIID = repSeession.getRepositorySession();
              //     Authenticate Repository
              AuthenticateRepositorySessionCommand autRepSeesion =
                   new AuthenticateRepositorySessionCommand(p_pool);
              try {
                   autRepSeesion.setSession(repSeession.getRepositorySession());
                   autRepSeesion.setUserName(p_user);
                   autRepSeesion.setUserPassword(p_Password);
                   autRepSeesion.execute();
              } catch (CommandException e3) {
                   System.out.println(
                        "RepSession Seesion" + e3.getMessage().toString());
              return autRepSeesion.getSession();
    //////////////*************user Session************///////
    GetRepositoryRegionListCommand regionListCommand =
                   new GetRepositoryRegionListCommand(p_pool);
              regionListCommand.setRepositoryIdentifier(p_repId);
              try {
                   regionListCommand.execute();
              } catch (CommandException e) {
                   System.out.println(e.getMessage().toString());
              RegionProperties[] regions = regionListCommand.getRegions();
              //                                 create a user session
              CreateUserSessionCommand UsersessionCommand =
                   new CreateUserSessionCommand(p_pool);
              UsersessionCommand.setRepositoryIdentifier(p_repId);
              UsersessionCommand.setDataRegion(regions[0]);
              // use the first region
              try {
                   UsersessionCommand.execute();
              } catch (CommandException e) {
                   System.out.println("UserSession" + e.getMessage().toString());
              String UsersessionId2 = UsersessionCommand.getUserSession();
    AuthenticateUserSessionCommand authUserCommand =
                   new AuthenticateUserSessionCommand(p_pool);
              authUserCommand.setSession(UsersessionCommand.getUserSession());
              authUserCommand.setUserName(p_userId);
              authUserCommand.setUserPassword(p_password);
              try {
                   authUserCommand.execute();
              } catch (CommandException e) {
                   System.out.println("User Seesion" + e.getMessage().toString());
              return authUserCommand.getSession();
    //////////////*************Destroy Session************///////
         DestroySessionCommand destroySessionCommand =
                   new DestroySessionCommand(p_pool);
              destroySessionCommand.setSession(p_repsession);
              try {
                   destroySessionCommand.execute();
              } catch (CommandException e) {
                   e.printStackTrace();
              destroySessionCommand.setSession(p_Uesrsession);
                   try {
                        destroySessionCommand.execute();
                   } catch (CommandException e) {
                        e.printStackTrace();
    Do we need to relase the connection pool object also?
    Can anyone help me with the code how that can be achived?
    Please Reply if anyone has come accross similar issue or know what can be the solution.
    Thanks in Advance.
    Regards Shruti
    Edited by: Shruti Shah on Dec 18, 2008 12:52 PM

    Hi Nitin,
    Thanks for the prompt Response.
    Even I am guessing that its becose of Connection pool.
    I am destroying session as follows
                   DestroySessionCommand destroySessionCommand =
                   new DestroySessionCommand(p_pool);
              destroySessionCommand.setSession(p_repsession);
              try {
                   destroySessionCommand.execute();
              } catch (CommandException e) {
                   e.printStackTrace();
              destroySessionCommand.setSession(p_Uesrsession);
                   try {
                        destroySessionCommand.execute();
                   } catch (CommandException e) {
                        e.printStackTrace();
    But I didnot find any method by which i can close realsse connection from connection pool.
    It would be great if you can help me how close or realese those connection.In MDM Console i am able to see those sessions even after destroying them.
    Regards Shruti.

  • How to access the SAP MDM destinations using mdm java api in 7.1

    hi,
    I have SAP MDM 7.1 SP11 and SAP Portal 7.3 and developing the custom webdynpro application using the  JAVA MDM API. I want configure the SAP MDM destinations in SAP Portal .
    How to access the MDM destinations in java code using API? and how to create the connection with MDM using the MDM destinations.
    Please provide the code for access the SAP MDM destinations in java code using MDM java api and creating the connection to MDM.
    Thanks

    Jun,
    Thanks for the reply and api information.
    I have got this api information from the following sap documentation. But i am looking for the code by implementing this class and creating the mdm connection.
    Creating an MDM Connection Using Java Code - SAP NetWeaver Master Data Management (MDM) - SAP Library
    if any thing can you share it.
    Thanks

  • Inetgrating MDM Java API's with Java proxies on XI side

    Hello friends
    Can anyone help me on integrating MDM JAVA API's used for talking to MDM Server and the Javaproxies we generate from the XI side.I am having an application class inside the Java API's (it contains the main function)which triggers the functionality on the MDM side.But how to trigger it from the Java proxies side??I can get the different fields that I have to send  in the impl.java program of my generated proxy,but how to trigger the MDM Java API's from inside this.Also there is one problem I needed to pass the datatype fields from the Javaproxy(XI)side to the CRUDMAINTABLERecord program..Since importing the javaproxy package is giving me an error(I don't know why)I don't know how to pass these datatypes to the CRUD program.Please help me out on this urgently.Thank you all in advance.

    Hi Deepthi,
    I had used the below code for retrieving the workflow's id's
      RetrieveWorkflowsCommand RetriveworksFlows = new RetrieveWorkflowsCommand(connections);
    RetriveworksFlows.setSession(session);
    try{
        RetriveworksFlows.execute();
    catch(Exception e)
    WorkflowProperties[] workflowpro = RetriveworksFlows.getWorkflows();
    WorkflowId[] workflowid = new WorkflowId[workflowpro.length];
    for(int n=0;n<workflowpro.length;n++)
    workflowid[n] = workflowpro[n].getId();
    String workfloName = workflowpro[n].getLaunchType()+"";
    System.out.println("id--"workflowid"name"+workfloName);
    and for creating the workflow job id i had written the below code
    CreateWorkflowJobCommand workflowjobcommand = new CreateWorkflowJobCommand(connections);
    workflowjobcommand.setWorkflowId(workflowid[0]);
    workflowjobcommand.setRecordIds(recordId);
    workflowjobcommand.setSession(session);
    try{
        workflowjobcommand.execute();
    catch(Exception e)
    then to start the workflow what  i  have to do .
    please expain me

  • MDM JAVA API ERROR

    Hi,
    we are calling mdm java methods from webdynpro code.
    We are executing java successfully from main method. but,when we try to execute it from webdynpro we are getting the follwing error.
    What this exception means to mdm?
    Unexpected exception:Unexpected field type -1

    Hi Ramu,
    the specified exception may be due to wrong fieldCode or Table Code in MDM Java API which you are using ;
    As per my understanding, you might be searching for MDM data from WebDynpro,so look at your resultset or Search object building , some where you coded with wrong FieldCode;
    problem may not be at your WebDynpro but may be at your MDM JAVA API Code;
    give detail information on your question, if you have still problem on that;
    regards
    Rajasekhar k

  • MDM Java API guide

    Do any other guides about MDM Java API exist (except MDM_API_Tutorial and MDM 5.5 SP05 - Java API Migration Guide.pdf) ?
    Especially MDM Search Java API interesting.

    Heii ,
    For this please follow these links
    http://help.sap.com/saphelp_mdm550/helpdata/en/45/0068570b0c0487e10000000a155369/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/45/efdc5bb7b404a9e10000000a114a6b/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/45/50b345af8e3be6e10000000a1553f7/frameset.htm
    you may find this useful.
    Please reward
    Rgds
    Deepak

  • MDM Java API : urgent

    hi all
    we hv added 5 jar file
             MDM4J.jar
             mdm-admin.jar
             mdm-common.jar
             mdm-core.jar
             mdm-protocol.jar
    but still we are getting error at
    IConnectionSpec spec = connectionFactory.getConnectionSpec();
    saying "Can not resolve IConnectionSpec"
    does any one kno its solution??
    do we need to add more jar files???

    Hello
    We have read installation guide "SAP Netweaver MDM 5.5 SP05", page 22, we want install MDM Connector and MDM Java API, in "installation procedure", it is indicate
    1. Extract the files from the archives.
    The javadoc folders contain an HTMLbased
    collection of documents that
    describe the Java API. Make sure you
    retain the directory structure.
    2. Deploy the SDA files on Web AS
    Java using the Software Deployment
    Manager (SDM). MDM Connector uses
    the mdm4j library as a shared library to
    support generic connection.
    3. Store the JAR files at the standard
    location for the application that uses
    them.
    4. Include the path to the JAR files in
    the class path for the application that
    uses them. This may be an
    environment variable, a command line
    argument, or an application
    configuration parameter.
    Only we are clear point 2, but rest, we are not sure, please could you clear us it ???
    Thanks

  • How to populate boolean fields using MDM Java API's

    Hi Experts!
    I am trying to populate Boolean fields in main table of my repository using MDM JAVA API SP 05 patch 2.
    Problem is i am geting syntax error for any value that i try to put in.
    Please provide me sample code for the purpose.
    Thanks in advance!

    Hi,
    Here is the code snippet to populate boolean values from Main Table in the Repository:
    Populating boolean values from Main Table in the Repository:
    wdContext.currentNodeElement().setABC(Boolean.valueOf((strABC).toString()).booleanValue());
    Putting boolean values in the main table:
    Record objEmptyRecord = RecordFactory.createEmptyRecord(new TableId(strTableId));
    boolean bFieldValue = ((Boolean)strABC).booleanValue();
    objEmptyRecord.setFieldValue(new FieldId(strFieldId),new
    BooleanValue(bFieldValue));
    Hope this helps.
    Regards
    Neha Sharma

  • Some question about mdm java api and portal content

    Hi Gurus,
    I am new to MDM. I am going to develop some web dynpro application using mdm java api.
    My question is regarding the relationship between MDM version and NW version:
    for example
    1.MDM5.5 JAVA api can be deployed to CE 7.11 server?
    2.MDM7.1 JAVA API can be deployed to CE 7.11 server? or can only be deployed to CE server.
    the same question for the MDM portal content.
    the possible dev environment  for our company would be:
    1.MDM7.1
    2.CE7.2(do we need another EP7 server for the UWL?)
    Best regards,
    John

    Hi,
    I am using Portal 7.0. MDM version is 7.1.
    My problem is ... i am trying to connect WebDynpro (JAVA) to MDM7.1. But am unable to do so. I have a WD Frame in which i have a WD iView and the MDM iView. But i am unable to pass parameters from the WD iView to MDM Item Details iView.
    Note:
    1. I have deployed MDM JAVA API on NWDS
    2. I have specified " * " as a parameter to pass from the URL in the Item Details iView.
    Please help.
    Every help that i have read talks about CE7.1 but not NW 7.0
    -Alpana

  • MDM Java API (Creation of table)

    Hi,
    can anyone help me for  creation of tables in repository using MDM java API .
    Can u Provide sample code for this.
    Edited by: Srikanth Josyula on Jun 26, 2008 8:52 AM

    Hi Srikanth,
    Check with this code.It may be useful.
    createflattable.java
    Created on June 25, 2008, 5:08 PM
    To change this template, choose Tools | Options and locate the template under
    the Source Creation and Management node. Right-click the template and choose
    Open. You can then make changes to the template in the Source Editor.
    package tabletype;
    import com.sap.mdm.commands.AuthenticateRepositorySessionCommand;
    import com.sap.mdm.commands.CommandException;
    import com.sap.mdm.commands.CreateRepositorySessionCommand;
    import com.sap.mdm.commands.GetRepositoryRegionListCommand;
    import com.sap.mdm.data.MultilingualString;
    import com.sap.mdm.data.RegionProperties;
    import com.sap.mdm.data.RegionalString;
    import com.sap.mdm.net.ConnectionException;
    import com.sap.mdm.net.ConnectionPool;
    import com.sap.mdm.net.ConnectionPoolFactory;
    import com.sap.mdm.schema.TableProperties;
    import com.sap.mdm.schema.commands.CreateTableCommand;
    import com.sap.mdm.schema.commands.GetFieldListCommand;
    import com.sap.mdm.schema.commands.GetTableListCommand;
    import com.sap.*;
    import com.sap.mdm.server.DBMSType;
    import com.sap.mdm.server.RepositoryIdentifier;
    import java.util.Locale;
    public class createflattable {
        /** Creates a new instance of createflattable */
        public createflattable() {
            private static MultilingualString createMultilingualString(RegionProperties[] regionPropertiesList, String baseString)
            MultilingualString mlString = new MultilingualString();
            for (int i = 0; i < regionPropertiesList.length; i++)
                Locale locale = regionPropertiesList<i>.getLocale();
                //Locale locale = regionPropertiesList<i>.getLocale();
                String regionCode = regionPropertiesList<i>.getRegionCode();
                String string = baseString + "_" + locale.getLanguage() + "_" + locale.getCountry();
                RegionalString regionalstring = new RegionalString(string, regionCode);
                mlString.set(regionalstring);
            return mlString;
        private static TableProperties createFlatTable(RegionProperties[] regionPropertiesList)
            //MultilingualString tableName = createMultilingualString(regionPropertiesList, "NewTable" + System.currentTimeMillis());
    MultilingualString tableName = createMultilingualString(regionPropertiesList, "first"+System.currentTimeMillis());
    System.out.println("table is" +tableName);
            TableProperties table = new TableProperties(TableProperties.FLAT);       
            table.setName(tableName);
            table.setCode("NewCode" + System.currentTimeMillis());
            table.setKeyMappable(true);
            table.setDescription("");
            return table;
          public static void main(String[] args) {
                // System Name
         String tag = "";
        ConnectionPool connections = null;
    try {
        connections = ConnectionPoolFactory.getInstance(tag);
    catch (ConnectionException e)
    e.printStackTrace();
    return;
    //////////////// specify the repository to use
    //RepositoryName
    String repositoryName = "";
    //DataBase Name
    String dbmsName = "";
    RepositoryIdentifier  reposId = new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);
    /////// create a repository session
    CreateRepositorySessionCommand sessionCommand = new CreateRepositorySessionCommand(connections);
    sessionCommand.setRepositoryIdentifier(reposId);
    try {
    sessionCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    System.out.println("Currently connected to "+reposId);
    String sessionId = sessionCommand.getRepositorySession();
    /////////// authenticate the repository session
    String userName = "";
    String userPassword = "";
    AuthenticateRepositorySessionCommand authCommand = new AuthenticateRepositorySessionCommand(connections);
    authCommand.setSession(sessionId);
    authCommand.setUserName(userName);
    authCommand.setUserPassword(userPassword);
    try {
    authCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    //////////////////// retrieve the list of tables
    GetTableListCommand tableListCommand = new GetTableListCommand(connections);
    tableListCommand.setSession(sessionId);
    try {
    tableListCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    // get change stamp
      // this is required when we make any kind of changes to the repository
         int changeStamp = tableListCommand.getChangeStamp();
         //////get repository regionlist
    //A command for retrieving the list of regions supported by the repository.
          // retrieve the available regions (languages) for the repository
          // we need this to set up the table name for each region
      GetRepositoryRegionListCommand gm =  new GetRepositoryRegionListCommand(connections);
       gm.setRepositoryIdentifier(reposId);
            try {
               gm.execute();
            catch (CommandException e) {
                e.printStackTrace();
                return;
       //   RegionProperties[] rs = gm.getRegions();
    RegionProperties[] regionPropertiesList = gm.getRegions();
          TableProperties newtable = createFlatTable(regionPropertiesList);
          CreateTableCommand c = new CreateTableCommand (connections);
            c.setSession(sessionId);
          c.setTable(newtable);
       c.setInChangeStamp(changeStamp);
            try {
                 c.execute();
                System.out.println("sdf");
            catch (CommandException e) {
                e.printStackTrace();
                return;

  • Attachments using MDM java API

    Hi
    How to store attachments in MDM repository using MDM java API.
    Could you please suggest us.
    Thanks
    Sowmya

    Hi Sowmya,
    You can store attachments using MDM Java API. You can use the following piece of code.
    BinaryBlobRecord record2 = RecordFactory.createEmptyBinaryObjectRecord(tableID);
    //Attachment to be saved
    String filePath = wdContext.currentContextElement().getVa_Resource().getUrl(0);
    IWDResource resource = wdContext.currentContextElement().getVa_Resource();
    FileInputStream stream = (FileInputStream)resource.read(true);
    int length = 0;
    while(stream.read() != -1)
         length++;
    byte[] b = new byte[(int) length];
    stream.read(b);
    stream.close();
    record.setName(new StringValue("filename"));
    record.setOriginalName(new StringValue("filename"));
    record.setHasOriginal(new BooleanValue(true);
    RetrieveGroupTreeCommand groupTreeCommand = new    RetrieveGroupTreeCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    groupTreeCommand.setSession(wdContext.currentContextElement().getVa_SessionID());
    groupTreeCommand.setGroupType(GroupTypes.DATA_GROUP_TYPE);
    groupTreeCommand.execute();
    //Set data location and data group ID
    record.setDataLocationId(new GroupNodeId("GN2"));
    record.setDataGroupId(new GroupNodeId("GN2"));
    record.setBinary(new BinaryValue(b));
    CreateRecordCommand createRecComm =
                             new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
    createRecComm.setRecord(record);
    createRecComm.execute();
    //Link this record to the main table record
    Record QRec = RecordFactory.createEmptyRecord(mainTable);
    //Setting the above created record in main table record object
    QRec.setFieldValue(attachmentField, new LookupValue(record.getId()));
    CreateRecordCommand createRecComm =
                        new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
    createRecComm.setRecord(QRec);
    createRecComm.execute();
    Now the main table record is created with an attachment.
    Hope this helps you.
    Regards,
    Sruti

Maybe you are looking for