ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

ILE concept. Passing a parameter to a C function from a RPG program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ILE concept. Passing a parameter to a C function from a RPG program

    I am trying to learn ILE concepts in AS400. So i thought i'll create a module which contained a function written in C language and i tried calling it from a RPG program. The RPG program is calling the C function without any problems but it is passing incorrect values.

    What im trying to do is have a main RPG program which will take a date from user and pass this date to the C function. In the C function im validating the date. But the C function is receiving incorrect values. I found out that RPG does pass by reference and C is pass by value by default.

    Here are my code snippets

    Main RPG program
    Code:
    HDftactgrp(*no) 
    HBnddir('KARTHIK/SRVPROGRAM') 
    HBnddir('QC2LE') 
    Ddate_check Pr 1 Extproc('DATE_CHECK')
    D 8 0 Value 
     
    C Eval Ch=Date_check(Date2)
    Module written in C
    Code:
    #include 
    char DATE_CHECK(int i) 
    int date_chk;
    date_chk = i;
    Im passing 20080202(for 2008/02/02) from RPG program but the C module is receiving 8396847.

    I would be glad if anybody can help me on this.

    Thanks in advance
    Last edited by kitvb1; July 12, 2008, 01:20 AM. Reason: Added code block

  • #2
    Re: ILE concept. Passing a parameter to a C function from a RPG program

    Calling C++ from RPGLE - System iNetwork Forums
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

    Comment


    • #3
      Re: ILE concept. Passing a parameter to a C function from a RPG program

      Im already using the keyword 'VALUE' in prototype definition.

      I saw the post in

      Calling C++ from RPGLE - System iNetwork Forums

      In that he was tryin to pass a string to the C++ program whereas i am passing numeric value. Does this affect in any way???


      When i tried this

      D date_check Pr 1 Extproc('DATE_CHECK')
      D 16* Value Options(*String)

      i got the error

      *RNF7536-30-The type of the parameter specified for the call does not
      match the prototype.

      Comment


      • #4
        Re: ILE concept. Passing a parameter to a C function from a RPG program

        It looks to me as the RPG has the date defined as 8,0 packed and the C++ has the date defined as integer. Not compatible.

        HTH,
        MdnghtPgmr
        "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

        Comment


        • #5
          Re: ILE concept. Passing a parameter to a C function from a RPG program

          Originally posted by MdnghtPgmr View Post
          It looks to me as the RPG has the date defined as 8,0 packed and the C++ has the date defined as integer. Not compatible.

          HTH,
          MdnghtPgmr
          I concur. IIWY, I would try changing the type of the date parameter to integer.
          "Time passes, but sometimes it beats the <crap> out of you as it goes."

          Comment


          • #6
            Re: ILE concept. Passing a parameter to a C function from a RPG program

            Originally posted by littlepd View Post
            I concur. IIWY, I would try changing the type of the date parameter to integer.
            I tried changing the date to integer but integer is taking length only as 5,0 i want it to be 8,0 for (YYYYMMDD).

            what should i do for that??

            Comment


            • #7
              Re: ILE concept. Passing a parameter to a C function from a RPG program

              Code:
                   d int_field     s             10i 0
              "Time passes, but sometimes it beats the <crap> out of you as it goes."

              Comment


              • #8
                Re: ILE concept. Passing a parameter to a C function from a RPG program

                I changed the type to 10i 0 and it is working..
                thanks a lot for all your help

                Comment

                Working...
                X