SAP JCo Uploader Agent Example(3.0)

This section provides an example of a workflow to illustrate how the SAP JCo Uploader agent can be used. 

Example workflow with SAP JCo Uploader agent

Decoder Agent

An example for the Ultra Format definition for the Decoder can be as follows:

Example - Decoder

external sap_format_external {
    ascii value : terminated_by(0xA);  
};

in_map sap_format_inMap : external (sap_format_external), 
target_internal(sap_format_external_TI) {automatic;};

decoder sap_format_dec : in_map (sap_format_inMap);

This is a simple decoder, decoding by 0xA (line feed) since the file format is flexible.

Analysis Agent

An example for the Analysis agent can be as follows:

Example - Analysis agent

import ultra.SAP_JCO;

boolean receivedHeader;
beginBatch {
    // Set receivedHeader = false.
    receivedHeader = false;
}

consume {
    // First record is the Header, so we will create HeaderUDR and map the value from input to it
    if (receivedHeader == false) {
        HeaderUDR header = udrCreate(HeaderUDR);
        //Assign Filename to HeaderUDR, this is use as primary key for State 
        Handling
        header.sourceFilename = (string) mimGet("Disk_1", "Source Filename");
        //Translate Input record in HeaderUDR
        getListOfBitField(header, input.value);
        //Route HeaderUDR out and set receivedHeader = false
        udrRoute(header);
        receivedHeader = true;
    } else {
        //For every record after Header, it will be the actual data records
        //Create RecordUDR and map values from input to it.
        //This example, input fields are comma separated 
        RecordUDR record = udrCreate(RecordUDR);
        record.listOfFields = strSplit(input.value, ",");
        udrRoute(record);
    }
}

endBatch {
    debug("Response Time=" + mimGet("sap_jco_1", "Average Response Time"));   
    debug("NoOfExecutions=" + mimGet("sap_jco_1", "No of Executions"));   
}

/*  
    This example function split the Header String into multiple BitFieldUDRs
    The example's format has "Version" in Field 1, "RFC Name" in Field 2 and 
    the rest of the format description after that
*/
list<BitFieldUDR> getListOfBitField(HeaderUDR header, string data) {
    list<BitFieldUDR> result = listCreate(BitFieldUDR);
    if (data != null) {
        //All fields are comma seperated
        list <string> fields = strSplit(data, ",");
        if (listSize(fields) > 3) {
            header.version = listGet(fields,0);
            header.rfcName = listGet(fields,1);
            int i = 2;
            //In this example, every bitFieldUDR has the format "FieldName:FieldType"
            while (i < listSize(fields)) {
                BitFieldUDR bitField = udrCreate(BitFieldUDR);
                string value = listGet(fields,i);
                list<string> nameAndType = strSplit(value, ":");
                if (listSize(nameAndType) >= 2) {
                    bitField.fieldName = listGet(nameAndType, 0);
                    bitField.fieldType = listGet(nameAndType, 1);
                } else {
                    bitField.fieldName = value;
                }
                listAdd(result, bitField);
                i = i + 1;
            }

            //Add the entire bitFieldUDR list into HeaderUDR
            header.listOfBitFields = result;
        } else {
            abort ("Header has less than 3 fields!");
        }
    }
    return result;
}