Data Replication 2
Results 1 to 2 of 2

Thread: Implementing the Procedure Driver Differences between C and Fortran

  1. #1
    Gwyn Jones is offline Attunity Customer Support Consultant
    Join Date
    Sep 2006
    Posts
    28
    Rep Power
    0

    Implementing the Procedure Driver Differences between C and Fortran

    Each implementation of AIS has a number of samples supplied. The first example, here, is to take the MATH_SIMPLE routine from the PRC_SAMPLES code within the provided STOREPROC sample.
    navroot:[samples.drivers.storeproc]prc_samples.c
    navroot:[samples.drivers.storeproc]prc_samples.xml

    In C the code looks like this:

    EXPORT_SYMBOL void math_simple(int *sum, int *subtract, int *multiply,
    int *divide, int oper1, int oper2)
    {
    *sum = oper1 + oper2 ;
    *subtract = oper1 - oper2 ;
    *multiply = oper1 * oper2 ;
    *divide = oper1 / oper2 ;
    }
    The XML to support this routine looks like this:
    <procedure name='math_simple' filename='prc_samples'>
    <dbCommand>LANGUAGE=C</dbCommand>

    <fields>

    <field name='SUM1' datatype='int4'>

    <dbCommand>ORDER=1</dbCommand>

    </field>

    <field name='SUBTRACT' datatype='int4'>

    <dbCommand>ORDER=2</dbCommand>

    </field>

    <field name='MULTIPLY' datatype='int4'>

    <dbCommand>ORDER=3</dbCommand>

    </field>

    <field name='DIVIDE' datatype='int4'>

    <dbCommand>ORDER=4</dbCommand>

    </field>

    </fields>

    <parameters>

    <field name='OPER1' datatype='int4'>

    <dbCommand>MECHANISM=VALUE; ORDER=5</dbCommand>

    </field>

    <field name='OPER2' datatype='int4'>

    <dbCommand>MECHANISM=VALUE; ORDER=6</dbCommand>

    </field>

    </parameters>

    </procedure>
    And execution:
    NavSQL > select * from prc_samples:math_simple( 100, 5 ) ;

    SUM1 SUBTRACT MULTIPLY DIVIDE


    105 95 500 20


    1 rows returned


    NavSQL >

    In Fortran the code would look like this:
    subroutine f_math_simple(sum, subtract, multiply, divide, oper1, oper2)
    integer*4 sum, subtract, multiply, divide, oper1, oper2
    sum = oper1 + oper2
    subtract = oper1 - oper2
    multiply = oper1 * oper2
    divide = oper1 / oper2
    return
    end

    The XML to support this routine looks like this:
    Notice that Fortran does not support the MECHANISM=VALUE for inbound parameters
    <procedure name='f_math_simple' filename='f_prc_samples_shr'>
    <dbCommand>LANGUAGE=C</dbCommand>

    <fields>

    <field name='SUM1' datatype='int4'>

    <dbCommand>ORDER=1</dbCommand>

    </field>

    <field name='SUBTRACT' datatype='int4'>

    <dbCommand>ORDER=2</dbCommand>

    </field>

    <field name='MULTIPLY' datatype='int4'>

    <dbCommand>ORDER=3</dbCommand>

    </field>

    <field name='DIVIDE' datatype='int4'>

    <dbCommand>ORDER=4</dbCommand>

    </field>

    </fields>

    <parameters>

    <field name='OPER1' datatype='int4'>

    <dbCommand>ORDER=5</dbCommand>

    </field>

    <field name='OPER2' datatype='int4'>

    <dbCommand>ORDER=6</dbCommand>

    </field>

    </parameters>

    </procedure>

    And execution:
    NavSQL > select * from f_prc_sample:f_math_simple( 200, 25 ) ;

    SUM1 SUBTRACT MULTIPLY DIVIDE


    225 175 5000 8


    1 rows returned


    NavSQL >

    Fortran Numeric and String

    This is fine whilst only dealing with numeric values, but Fortran handles numerics and strings differently.

    This example is Fortran code both with strings and a structure:
    OPTIONS/EXTEND_SOURCE
    INTEGER*4 FUNCTION WORKS_ORDER_DETAIL(WO_REP, UID, ORDER_REF)
    IMPLICIT NONE
    CHARACTER ORDER_REF*6, UID*8
    STRUCTURE /WO_REC/
    CHARACTER*6 ORDER_REF
    CHARACTER*4 PROCEDURE
    CHARACTER*8 ISSUE_DATE ! CCYYMMDD
    CHARACTER*1 STATUS
    CHARACTER*3 SERVICE_TYPE
    END STRUCTURE
    RECORD / WO_REC / WO_REP

    WO_REP.ORDER_REF = ORDER_REF
    WO_REP.PROCEDURE = 'ABCD'
    WO_REP.ISSUE_DATE = '20120521'
    WO_REP.STATUS = '0'
    WO_REP.SERVICE_TYPE = UID
    WORKS_ORDER_DETAIL = 0 ! COMS_SUCCESS

    RETURN
    END

    The XML definition would be:

    <procedure name= 'WORKS_ORDER_DETAIL' filename='works_shr'>
    <dbCommand>LANGUAGE=COB</dbCommand>

    <fields>

    <field name='RETURN_VALUE' datatype='int4'>

    <dbCommand>MECHANISM=VALUE; ORDER=0</dbCommand>

    </field>

    <group name='ORDERDETAILS' >

    <dbCommand>MECHANISM=REFERENCE; ORDER=1</dbCommand>

    <fields>

    <field name='ORDER_REF' datatype='string' size='6'/>

    <field name='PROCEDURE' datatype='string' size='4'/>

    <field name='ISSUE_DATE' datatype='string' size='8'/>

    <field name='STATUS' datatype='string' size='1'/>

    <field name='SERVICE_TYPE' datatype='string' size='3'/>

    </fields>

    </group>

    </fields>

    <parameters>

    <field datatype='string' size='8' name='USER_ID'>

    <dbCommand>MECHANISM=DESCRIPTOR; ORDER=2</dbCommand>

    </field>

    <field datatype='string' size='6' name='ORDER_REF'>

    <dbCommand>MECHANISM=DESCRIPTOR; ORDER=3</dbCommand>

    </field>

    </parameters>

    </procedure>


    And execution:

    NavSQL > call WORKS_ORDER_DETAIL( 'AA3456' , 'BB654321' ) ;

    RETURN_VALUE ORDER_REF PROCEDURE ISSUE_DATE STATUS SERVICE_TYPE


    0 BB6543 ABCD 20120521 0 AA3456


    1 rows returned


    NavSQL >
    To Find Out more About Attunity Technology:
    Attunity
    or:
    Contact Us

  2. #2
    Hein is offline Senior Member
    Join Date
    Dec 2007
    Location
    Nashua, NH - USA.
    Posts
    152
    Rep Power
    12
    Quote Originally Posted by [B
    Notice that Fortran does not support the MECHANISM=VALUE for inbound parameters
    [/B]
    Actually, it is fairly easy to accept INTEGERS by value in OpenVMS Fortran by using the %LOC builtin
    Like the Pascal builtin IADDRESS this will pick up the address odf an assumed reference, but actually will return the VALUE.

    HP OpenVMS systems documentation

    hth,
    Hein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •