ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

how to call service program

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

  • how to call service program

    hi all,

    i've create module
    CRTRPGMOD MODULE(ALIB/ADUR) SRCFILE(#SRC/QRPGLESRC)
    SRCMBR(ADUR)
    and success

    then i create Service program
    CRTSRVPGM SRVPGM(ALIB/ADUR) MODULE(ALIB/ADUR) EXPORT(*ALL)
    and success

    then i create function
    create function ALIB/ADUR
    (Tanggal varchar(8),
    Mode varchar(8),
    Jml varchar(4))
    returns varchar(8)
    returns null on null input
    deterministic
    language rpgle
    no sql
    parameter style general
    external name 'ALIB/ADUR(ADUR)'

    when i call from Sql it's working
    select datedur(char(dt),'*DAYS','1')
    from tableA

    but how to call from my RPGLE program ???

    i've tried but error

    D DATEDUR pr 8a varying
    D Tanggal 8a value
    D Mode 8a value
    D Jml 4a value

    c Eval hasil = datedur(%char(tgl):'*DAYS':'1')

    can anyone help me please ??? how to call and use service program / module in RPGLE ??
    thx u very much

  • #2
    Re: how to call service program

    I suspect it's because you're program isn't binding to the service program...

    First create a binding directory
    Create Binding Directory (CRTBNDDIR)

    Then add your service program to it
    Work with Binding Dir Entries (WRKBNDDIRE)

    Then add an h spec to your program with as many binding directories as you want
    Hbnddir('MYBNDDIR1':'MYBNDDIR2':'MYBNDDIR3':'MYBND DIRn')

    You don't have to do it this way but I find it's the easiest and most scalable. I hope this helps, I didn't really understand what you were on about with the code fragments.
    Ben

    Comment


    • #3
      Re: how to call service program

      Originally posted by benthurley View Post
      I suspect it's because you're program isn't binding to the service program...

      First create a binding directory
      Create Binding Directory (CRTBNDDIR)

      Then add your service program to it
      Work with Binding Dir Entries (WRKBNDDIRE)

      Then add an h spec to your program with as many binding directories as you want
      Hbnddir('MYBNDDIR1':'MYBNDDIR2':'MYBNDDIR3':'MYBND DIRn')

      You don't have to do it this way but I find it's the easiest and most scalable. I hope this helps, I didn't really understand what you were on about with the code fragments.
      this my program ADUR :

      H nomain

      D DATEDUR pr 8a varying
      D Tanggal 8a varying
      D Mode 8a varying
      D Jml 4a varying

      P DATEDUR b export
      D DATEDUR pi 8a varying
      D Tanggal 8a varying
      D Mode 8a varying
      D Jml 4a varying

      D TmpDate S d DatFMT(*ISO)
      D DateNum S 8 0
      D i S 4 0

      after create bnddir, how to call Service program from RPGLE ??

      Comment


      • #4
        Re: how to call service program

        You need the prototype for that service procedure in your program also. You can either copy and paste it in to the d-specs, or you can move it out into a QRPGLEREF file. In the QRPGLEREF file you create an RPGLE object called ADUR that just contains the prototypes for the exported procedures. Then any program that wants to call these procedures can add the following to the d spec.

        PHP Code:
              /copy qrpgleref,ADUR 
        So assuming that you have bound to the service program and you have the prototyped procedures (either directly in the d spec or /copied in), you should be able to call the procedure as you would any other. The way you showed here looks fine to me.

        PHP Code:
        Eval hasil datedur(%char(tgl):'*DAYS':'1'
        If your program doesn't compile then take a look at the compile errors. It should tell you if they are program errors or at the binding step.
        Ben

        Comment

        Working...
        X