JSON Iseries batchjob

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
TF-Itservices
Posts: 4
Joined: Tue Mar 08, 2022 6:32 pm

JSON Iseries batchjob

Post by TF-Itservices »

Hello All ,

I have a new RDMLX function created in windows server using the commands below.
On this server this runs OK!

Fuction is checked to Iseries. It's been called in a batch job from RDML function. .

This doesn't work. Error ,Message

Bericht-ID . . . . . . : CPF9898
Datum verzending . . . : 02/06/22 Tijdstip verzending . : 07:34:24

Bericht . . . . : Fatal Error : Process : LVSMOL RDML RPG Interface
Function : EABMOL Statement : 0 Message : (0168) - Recursive invocation of
RDML level function detected. Routine : X_Add_to_Invocation_Stack.

I don't be sure if this kind of function can run on the Iseries.

Maybe some system parameters have to be set. t

Maybe there are tips&tricks



Thanks

Twan


Define_Com Class(#XPRIM_Json) Name(#json)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonpartijObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonkenmerkObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonfotoObj) Reference(*DYNAMIC)
* array
Define_Com Class(#XPRIM_JsonArray) Name(#jsonpartijArray) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonArray) Name(#jsonkenmerkArray) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonArray) Name(#jsonfotoArray) Reference(*DYNAMIC)
* token
Define_Com Class(#MOAPIAUT) Name(#MOAPIAUT)
Define_Com Class(#Prim_dc.UnicodeString) Name(#u_Token)
Define_Com Class(#XPRIM_HttpRequest) Name(#u_Request)

*
Define_Com Class(#XPRIM_Json) Name(#u_JsonRequest)
Define_Com Class(#XPRIM_Json) Name(#u_JsonResponse)
Define_Com Class(#XPRIM_JsonObject) Name(#u_JsonObject) Reference(*DYNAMIC)
* Log tijdelijk
Define_Com Class(#rpHttpLogging) Name(#RPHTTPLOGGING)
#RPHTTPLOGGING.mSetLogging( TRUE )
* make root of JSON document
#jsonObj <= #json.CreateRootObject
* add Bearer token
#u_Request.Options.AddBearerAuthorization( #u_Token )
#tokenval := #u_Token.AsNativeString
#jsonObj.Insertstring Key('aanvoerDatum') String(#aanvdatum)
#jsonObj.Insertstring Key('veilDatum') String(#veildatum)
#jsonObj.Insertstring Key('typeLadingDrager') String(#llm)

#jsonObj.SerializeToFile Path(#PATHNAMDOC)

#u_Request.Content.AddJson Value(#json)
#U_Request.DoPost( #HTTPpost )
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: JSON Iseries batchjob

Post by Dino »

Hi,

I tried your code in my as400 with a few changes (just for the missing field definitions and values) and it works fine... I can see a response from the server:
jsonas40001.png
jsonas40001.png (17.83 KiB) Viewed 8191 times
this is the code I used:

Code: Select all

Function Options(*DIRECT)
Define_Com Class(#XPRIM_Json) Name(#json)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonpartijObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonkenmerkObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonfotoObj) Reference(*DYNAMIC)
* array
Define_Com Class(#XPRIM_JsonArray) Name(#jsonpartijArray) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonArray) Name(#jsonkenmerkArray) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonArray) Name(#jsonfotoArray) Reference(*DYNAMIC)
* token
* Define_Com Class(#MOAPIAUT) Name(#MOAPIAUT)
Define_Com Class(#Prim_dc.UnicodeString) Name(#u_Token)
Define_Com Class(#XPRIM_HttpRequest) Name(#u_Request)

*
Define_Com Class(#XPRIM_Json) Name(#u_JsonRequest)
Define_Com Class(#XPRIM_Json) Name(#u_JsonResponse)
Define_Com Class(#XPRIM_JsonObject) Name(#u_JsonObject) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_OSUtil) Name(#OSUtil)

* ADDED THIS EXTRA LINES BEGIN ************************************************
If ('*OSAPI = IBMI')
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value('/tmp/lansaxlib.configas400.json')
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_TRACEPATH') Value('/LANSA_G14PGMLIB/tmp/log.txt')
Else
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value('c:\temp\lansaxlib.config.json')
#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_TRACEPATH') Value('c:\temp\log1.txt')
Endif

Define Field(#tokenval) Reffld(#STD_STRNG)
Define Field(#aanvdatum) Reffld(#STD_STRNG)
Define Field(#veildatum) Reffld(#STD_STRNG)
Define Field(#llm) Reffld(#STD_STRNG)
Define Field(#pathnamdoc) Reffld(#STD_STRNG)
Define Field(#httppost) Reffld(#STD_STRNG)
#httppost := 'http://jsonplaceholder.typicode.com/todos/1'
* ADDED THIS EXTRA LINES END ************************************************

* Log tijdelijk
* Define_Com Class(#rpHttpLogging) Name(#RPHTTPLOGGING)
* #RPHTTPLOGGING.mSetLogging( TRUE )
* make root of JSON document
#jsonObj <= #json.CreateRootObject
* add Bearer token
#u_Request.Options.AddBearerAuthorization( #u_Token )
#tokenval := #u_Token.AsNativeString
#jsonObj.Insertstring Key('aanvoerDatum') String(#aanvdatum)
#jsonObj.Insertstring Key('veilDatum') String(#veildatum)
#jsonObj.Insertstring Key('typeLadingDrager') String(#llm)

#jsonObj.SerializeToFile Path(#PATHNAMDOC)

#u_Request.Content.AddJson Value(#json)
#U_Request.DoPost( #HTTPpost )
maybe you have some miss configuration, suggestion will be to open a case and review your installation.
Tim McEntee
Posts: 57
Joined: Thu May 26, 2016 8:46 am

Re: JSON Iseries batchjob

Post by Tim McEntee »

My experience is you can get random inexplicable errors when calling RDMLX from RDML programs and vice-versa.

Try creating a stub with very little code where your RDML program calls the stub which then calls the complex RDMLX. Try the stub as an RDML then as an RDMLX.

No guarantee that this will fix your problem.
cesarrafael
Posts: 32
Joined: Tue Dec 01, 2015 3:44 am

Re: JSON Iseries batchjob

Post by cesarrafael »

How are you performing the "CALL"? The message suggests that you're trying to run a LANSA when you're already inside a LANSA environment. Like when you have a function that calls a CL program that calls a LANSA function...This will result in a recursive call to LANSA..
Post Reply