Mapping SAP IDocs in Business Connector 46

Hi Guys,

I have a requirement to map fields from IDocs generated by SAP into flat file records using SAP Business Connector 4.6. Using the WmSamples.sample:flatFileParsing.utils. getRecordElements Java service as a model, I’ve created a new Java service, mapIDoc, to process an incoming test case. It’s failing with a java.lang.ClassCastException: com.wm.util.Table error. I’m not sure what I’m doing wrong.

To date, I’ve performed the following steps:

  1. Generated a DTD for my test IDoc using SAP txn WE60.
  2. Created a Business Connector record description from the DTD.
  3. Created a stub service to save the pipeline.
  4. Routed the test IDoc to my service.
  5. Modified the stub service to perform the following steps:
    a. restore the pipeline
    b. recordToDocument –> boundNode.
    c. MAP boundNode –> record reference to the IDoc record from step 2.
    d. call my mapIDoc Java service.
  6. Traced the flow service.

mapIDoc code so far is:

public static final void mapIDoc( IData pipeline ) throws ServiceException

// get a cursor on the pipeline IData object

IDataCursor idcPipeline = pipeline.getCursor();

// initialize variables

IData record = null;
String message = null;
int i = 0;

// get data from pipeline
if (idcPipeline.first(“IDOC_CONTROL_REC_40”))
record = (IData) idcPipeline.getValue();

//print a message in the pipeline]

message = “Retrieved IDOC_CONTROL_REC_40”;
idcPipeline.insertAfter(“message”, message);
// record = (IData) idcPipeline.getValue();

// get cursor on record

//IDataCursor idcRecord = record.getCursor();



It appears that the statement that’s failing is:
record = (IData) idcPipeline.getValue();

This comes directly out of the WmSamples getRecordElements program. Prior to calling mapIDoc, the pipeline shows, in part:



So my questions are:

  1. Am I going about this the right way?
  2. Why does the record = (IData) idcPipeline.getValue(); statement fail?
  3. Is there a model Java service for processing SAP IDocs that I could use?

I apologize for the length of this post and very much appreciate any help you can give me.

– Mike

I should have added that the pipeline shows text fields and values after the IDOC_CONTROL_REC_40[0] and IDOC_DATA_REC_40[0]
segment headers.

Mike, maybe we can simplify what you are trying to do. This is off the top of my head and I will revisit it when I am back in the office.

Okay, excuses aside.

If you are showing values in the pipeline, you can try to manually grab those nodes and map them into a free-standing variable such as the “record reference to the IDoc record from step 2”.

To do that, go to your results tab and highlight the node containing the value (i.e. IDOC_DATA_REC_40[0] ) and press CTRL-C.

Next, use “Set Value…” to assign a value to your record reference. Press CTRL-V in the text box and then select “Perform Variable Substitution”. That will map the value of in the IDOC_DATA_REC_40[0] node to the IDOC record reference.

Then, call a RecordToDocument on the IDOC record reference and take the xmldata output and write it to file using a Java service.

Let me know if this helps you. If not, I will see what I can come up back at my desk.

Good luck,



Thanks so much for your reply. It pointed out that I had some fundamental misunderstandings re: documentToRecord, which I hadn’t mapped to anything at all (DUH!). The approach you recommended worked like a champ in a flow service. To give me some additional flexibility, I’d like to implement the whole service in Java. Is there a sample java service you could point me to that demonstrates how to grab records from a recordlist? Essentially, I’m looking for code to emulate the LOOP over function. Thanks again for your help.

– Mike

If you are looking to emulate LOOP, why not just use LOOP? By creating a Java service, you are taking away from the benefits of using the webMethods IS at all.

Remember, webMethods sells software that is deigned to help you with your integration. Don’t fight it… use it!

If the LOOP does not give you what you need, however, maybe there are other Built-In Services that will. Tell me a bit more about your goal and maybe we can help you reach it.

Thanks again, Dan. Since I need to create fixed format flat files for processing by COBOL programs, I need to ensure that all fields values, including nulls, are padded to their maximum length before I string them together to write to the file. Presumably, I’ll need to create some number arrays to store the field lengths for each segment, and then do a lookup for each incoming field. Perhaps I could just pass the output array from the LOOP process to a progam rather than grabbing the values from within the program itself. This is my first webMethods project, and I freely admit that I don’t really know what I’m doing. Any advice you can offer is way more than welcome.


Check out the webMethods EDI Module: Core Component User’s Guide (v4.5). Appendix A explains how to create an XML template for flat files. Within the template you define the structure, and for fixed length files you also list the field lengths.

Once the template is defined you use it in your flow as follows:

  1. Translate your Idoc into a record list emulating the structure of your flat file.
  2. Use the stringToDocument service with your XML template as the “xmldata” value to convert the record list.
  3. Then use documentToRecord and convertToString to tranfer everything back to a string.

The XML template will pad or truncate your fields as necessary to match the field lengths you specify.

Have fun,

Hi Devan,

Man, that looks a lot easier than what I was trying to do. Sincere thanks to both you and Dan for taking the time to point me in the right direction. I just may be able to keep this job!

– Mike