Calling a RPG program from server module

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
csturtev
Posts: 12
Joined: Thu Feb 02, 2017 6:54 am

Calling a RPG program from server module

Post by csturtev » Sat Oct 09, 2021 6:05 am

Trying to call program created via RPGLE from a server module. Below does not error, but doesn't appear to call the program FCB002 either.

#FC02_Level_Type := #LMHD15.Substring( 1 1 )
#FC02_Trend_Type := #LMHD15.Substring( 2 1 )
#FC02_Seasonal_Flag := #LMHD15.Substring( 3 1 )
#FC02_Dmd_Hist_View_Dur := #FC00_Dmd_Hist_View_Dur
Insert Fields(#FCP02B) To_File(FCP02B)

* Call iSeries recalc pgm
Call Pgm(FCB002) Parm(#FC02_Company #FC02_Item_Number #FC02_Record_Type #DemandPeriod1 #ErrorPM)

User avatar
Dino
Posts: 180
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Calling a RPG program from server module

Post by Dino » Mon Oct 11, 2021 1:07 pm

I am not an RPGLE programmer, so I copied/created this program (I called it RPGLEPARM) that calculates the area based in two parameters and return the value to the caller program, and also added a dump in the code, which makes the result available in a nice spool called dump besides returning it to the program.

Code: Select all

 *Program COMPAREA                                    
                                                     
D GetArea         PI                                  
D  Length                        2  0 CONST           
D  Width                         2  0 CONST           
D  Area                          4  0                 
C                   eval      Area = Length * Width   
C                   dump(A)                           
C                   eval      *inlr = '1'             
I tested first from a function, easier to debug, worked fine after fixing errors like:

Code: Select all

Decimal-data error occurred (C G D F).                             
Application error.  MCH1202 unmonitored by RPGLEPARM at statement  
  0000000011, instruction X'0000'.   
which are due to the format of the fields. For this example, they need to be exactly *DEC 2 0 and *DEC 4 0 (i.e. packed not signed) and you need to indicate Num_Len(*DEFINED) in the CALL to avoid LANSA sending the numbers as *all15 by default. Fixed that, this function works fine, it shows the result 25 and creates the spool with the result (i.e. the dump)

Code: Select all

Function Options(*DIRECT)
Define Field(#rrwidth) Type(*dec) Length(2) Decimals(0)
Define Field(#rrlength) Type(*dec) Length(2) Decimals(0)
Define Field(#rrarea) Type(*dec) Length(4) Decimals(0)
Change Field(#rrwidth #rrlength) To(5)
Call Pgm(RPGLEPARM) Parm(#rrwidth #rrlength #rrarea) Num_Len(*DEFINED)
Display Fields(#rrarea)
Return
once that the function was working, I created a simple server module TEST10SM:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_SRVM)
Define Field(#rrwidth) Type(*DEC) Length(2) Decimals(0)
Define Field(#rrlength) Type(*DEC) Length(2) Decimals(0)
Define Field(#rrarea) Type(*DEC) Length(4) Decimals(0)

Srvroutine Name(testrpg)
Field_Map For(*OUTPUT) Field(#rrarea)
Change Field(#rrwidth #rrlength) To(5)
Call Pgm(RPGLEPARM) Parm(#rrwidth #rrlength #rrarea) Num_Len(*DEFINED)
Endroutine
End_Com
called by this webpage:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)

Define_Com Class(#STD_NUM.EditField) Name(#STD_NUM) Displayposition(1) Left(24) Parent(#COM_OWNER) Tabposition(1) Top(23)

Evtroutine Handling(#Com_owner.Initialize)
Define_Com Class(#test10sm.testrpg) Name(#testrpg)
#testrpg.Execute Rrarea(#std_num)
Endroutine
End_Com
and it produced the expected result of 25 and the spool file requested.

kind regards,

csturtev
Posts: 12
Joined: Thu Feb 02, 2017 6:54 am

Re: Calling a RPG program from server module

Post by csturtev » Tue Oct 12, 2021 1:37 am

Thank you for the reply on this.... What you describe is what we are doing, but I still must be missing a piece. Do you need to bring the program object into the Lansa world somehow for it to be able to call them? I know when working with 400 tables we need to import those tables prior to working with them in Lansa. Do we need to do something like this with the program objects from the 400?

User avatar
Dino
Posts: 180
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Calling a RPG program from server module

Post by Dino » Tue Oct 12, 2021 2:02 am

You don't need to bring it to LANSA world (or repository), but if you are not indicating the library in the CALL, then the program should be in the library list. Try calling it from a test function first from a command line, like in CALL QCMD and press F10 for detailed messages, LANSA RUN process(testpro) function(testfun) partition(xxx) in the IBM, that way you can confirm that the call to the RPGLE is working correctly first. RPGLE is very touchy/strict regarding data types and maybe the reason for the problem if the parameters sent from LANSA are not exactly what the RPGLE program is expecting. If that doesn't work, you may need to request help from support.

csturtev
Posts: 12
Joined: Thu Feb 02, 2017 6:54 am

Re: Calling a RPG program from server module

Post by csturtev » Tue Oct 12, 2021 2:21 am

Got it I simplified (easy CL program sending message to QSYSOPR) and now see the call is taking place. I now see the issue is on the 400 side and the program. Thank you for the assistance.

Post Reply