Skip to Content
avatar image
Former Member

Read image file From JMS

Hi Experts,

Here is my requirement

i have a set of invoice image files .. ABC.TIF , XYZ.TIF etc....

and a table maintained in ECC which have 2 fields for every record ( image name and invoice numbers) for example

ABC 01
XYZ 02

This is a JMS to FIle scenario. i need to perform the following step

1) read the image file name from JMS header
2) do a RFC look up and get the corresponding invoice number 
3) create a target directory with that invoice number
4) place the image file in that directory.

Please let me know your experience in such kind of scenarios and what is the best way to handle this.

.

Thanks

Biplab

Edited by: biplab das on Jan 14, 2011 8:03 AM

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jan 14, 2011 at 04:51 AM

    Hi Biplab Das,

    This is a good challenge. I understand your scenario as,

    1. To pickup image file, 2. Based on image file name get invoice number (using RFC lookup), 3. Create a folder with invoice number and place image file in that folder.

    As input is not XML, we cannot use Graphical or XSLT mapping, so we have to use Java mapping.

    Solution:

    Step 1:- In Sender file channel, Advanced tab, select u201CSet Adapter-Specific Message Attributesu201D and u201CFile Nameu201D and u201CDirectoryu201D.

    Step 2:- Create a Dummy Data type: <Root><Child1></Child1><Child2></Child2></Root> and then create a Message type. Create Inbound and Outbound Message Interfaces using above Message Type and then create a Operational mapping.

    Step 3: Create a receiver channel for RFC lookup.

    Step 4: Now, Implement Java Mapping (below).

    Step 5: Write a RFC in R/3, which take u201CFileNameu201D and give out u201CInvoiceNumberu201D. It should be plain text input and plain text output (not XML).

    Step 6:- In Receiver file channel, Advanced tab, select u201CSet Adapter-Specific Message Attributesu201D and u201CFile Nameu201D and u201CDirectoryu201D.

    Note: You need to edit the code according to your requirement.

    Regards,

    Raghu_Vamsee

    Edited by: Raghu Vamsee on Jan 14, 2011 11:03 AM

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 14, 2011 at 04:51 AM
    package com.image.file;
    
    import com.sap.aii.mapping.api.*;
    import com.sap.aii.mapping.lookup.*;
    import java.io.*;
    import java.util.Map;
    
    public class ImageFilePickUp extends AbstractTransformation {
    
        public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
            OutputStream outputstream = null;
            try {
                //Read input payload and write the same to output payload.
                InputStream inputstream = transformationInput.getInputPayload().getInputStream();
                outputstream = transformationOutput.getOutputPayload().getOutputStream();
                byte[] b = new byte[inputstream.available()];
                inputstream.read(b);
                String XMLinputFileContent = new String(b);
                outputstream.write(XMLinputFileContent.getBytes());
    
                //Get all details from SOAP Header
                Map para = transformationInput.getInputHeader().getAll();
                //Get File name http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/DynamicConfiguration.html
                //access dynamic configuration from SAOP Header
                //http://help.sap.com/saphelp_nwpi711/helpdata/en/43/03612cdecc6e76e10000000a422035/frameset.htm
                DynamicConfiguration conf = (DynamicConfiguration) para.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
                DynamicConfigurationKey keyFileName = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
                String inputFileName = conf.get(keyFileName);
    
                //RFC Lookup http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/lookup/RfcAccessor.html
                Channel channel = LookupService.getChannel("BS_BusinessSystem", "CC_InvoiceNumber_RFC");
                RfcAccessor accessor = LookupService.getRfcAccessor(channel);
                
                //Sending "FileName.TIF" to RFC http://help.sap.com/javadocs/pi/SP3/xpi/index.html
                //You need to edit this or correct
                String rfcInput = inputFileName;
                Payload payload = LookupService.getTextPayload(new ByteArrayInputStream(rfcInput.getBytes()), "UTF-8");
                Payload rfcOutput = accessor.call((XmlPayload) payload);
                InputStream inputStreamFromRFC = rfcOutput.getContent();
                byte[] bInputStreamFromRFC = new byte[inputStreamFromRFC.available()];
                inputStreamFromRFC.read(bInputStreamFromRFC);
                String sInvoiceNumbers = new String(bInputStreamFromRFC);
    
                //Set Ouput Directory to DynamicConfiguration SOAP Header
                DynamicConfigurationKey keyDirecory = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
                //You need to edit "C:/User/Desktop"
                String Directory = "C:/User/Desktop/" + sInvoiceNumbers;
                conf.put(keyDirecory, Directory);
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    }

    Edited by: Raghu Vamsee on Jan 14, 2011 11:04 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Raghu,

      Thanks for you approach.

      I was doing the scenario.But unfortunately the Dynamic configuration part is not working.

      i have already checked the following:-
      
      1) ASMA properties are checked in both sender and reciver comm channel
      2) Provided proper Business system and comm channel name in the code.
      
      i have even written a simple code  where i will just read the file name and  write a constant directory path ( just for testing) but its unable to set the Dynamic confuration

      Eclipse is giving a warning for

      Map para = transformationInput.getInputHeader().getAll();

      any help ?

  • avatar image
    Former Member
    Mar 07, 2011 at 02:03 PM

    Hi Experts,

    It is possible to achieve this requirement in Java Mapping.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 27, 2011 at 06:17 AM

    hi all,

    i have successfully done this using java mapping.

    Add comment
    10|10000 characters needed characters exceeded