Changing Library in 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
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Changing Library in Server Module

Post by jyoung »

I have to retrieve some data in another library in a Server Module.

This document http://docs.lansa.com/14/en/lansa048/in ... 8_6710.htm describes what to do (Changing Library List) but not really how to do it.

From this thread http://vlforum.lansa.com.au/viewtopic.p ... brary+list I think I need to call another program on the IBM i. Is that command CHGLIBL?

The way I understand it, is that it changes the library list for the current job. So I would need to change it back to its original state when I am done correct?

Is there anyway to get the current library list that can be stashed away while I change to the new library list, then I can restore the original?

Our test libraries are named something different then the actual libraries, even though they are on separate servers. So I can't hard code the library list without knowing which server I am running on.

For example,
On Dev, I need to go from XXDTALIBT to XXDTALIBCT and then back to XXDTALIBT.
On Production, I need to go from XXDTALIB to XXDTALIBC and then back to XXDTALIB.

Of course that just includes one library in the list, but that is the one I am changing.

If I can get the current library list and I can examine the contents, I could then make a distinction of which library I need to change to. Using CHGJOBD on Dev for DXCPGMLIB/DCXJOBD shows QTEMP, DCXCOMLIB, DCXPGMLIB, QGPL and XXDTALIBT.

I found this query

Code: Select all

 SELECT ORDINAL_POSITION AS POS,
         SYSTEM_SCHEMA_NAME AS LIBRARY,
         TYPE,
         CAST(TEXT_DESCRIPTION AS CHAR(50)) AS TEXT
   FROM QSYS2.LIBRARY_LIST_INFO;
at http://www.rpgpgm.com/2016/02/retrievin ... g-sql.html that may do the job.

Is there a more correct, LANSA way to do this?
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: Changing Library in Server Module

Post by atostaine »

rtvjoba in a Clle is one way. Parse the result. there is probably sql way too.

i can post how we do it. we check the user id every transaction and decide what library list is required.
Art Tostaine
MarkD
Posts: 692
Joined: Wed Dec 02, 2015 9:56 am

Re: Changing Library in Server Module

Post by MarkD »

You might do this as a small CL (Control Language) program which is easy to call from an RDMLX LANSA program.

It could retrieve the L4Web job’s current library list and examine it via RTVJOBA command’s URSLIBL parameter.
Then after deciding what libraries need to be added (or removed) it can use ADDLIBLE, RMVLIBLE or CHGLIBLE to make the required adjustments.

This may mean that often no library list change to the job is required because the one left hanging around from before is okay to use - which is possibly a minor performance benefit.

I don’t think you should reset the library list to what It was originally because that design assumes your program will not fail and always reset it at the end of an interaction. It might be better to always assume that the library may not be correct as the start of any interaction and reset it as required.

Your test and production LANSA configurations presumably have different default L4Web users with different default library lists so you could establish your own ‘environmental’ configuration data area into your test and production systems that are always (and uniquely) accessible from the default library list.

If your CL program can then uniquely retrieve your configuration data area (by the default library list) it would be able to tell what environment it is being used in. For example, the libraries to be added to the library list could be nominated softly in the data area + it could contain a whole bunch of other unique configuration information that will probably arise as your design progresses.

For example, your CL program might always change the job to CHGJOB LOG(4 00 *SECLVL) in testing/development so a job log is always produced, but in production it would not produce a job log, but still allowing you the option to temporarily turn it on for problem analysis purposes in production.

A configuration data area also allows you to easily set up more environments later – such as one for acceptance testing, a movement into a shared computer, etc,
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Changing Library in Server Module

Post by jyoung »

I'm very much an iSeries noob, so bear with me, please. :D

After some discussion it was decided that we want to keep as much of the code inside LANSA as possible, so instead of developing our own CL command that would do this for us, we thought we would try calling the CHGLIBL command ourselves.

To set this up some, we have not changed the user or jobd that the job runs under (except for adding our data libraries).
It is DCXPGMLIB and DCXJOBD.

When I log in as DCXPGMLIB and run DSPLIBL, I get the following library list (QTEMP, DCXCOMLIB, DCXPGMLIB, QGPL, XXDTALIBT and B14MODLIB).
XXDTALIBT is our testing library and I have no idea what B14MODLIB is. It's not on our production server.

So if I want to change the library list to use XXDTALIBCT instead of XXDTALIBT then I execute the following:

Code: Select all

#Dev2 := "QTEMP DCXCOMLIB DCXPGMLIB QGPL XXDTALIBCT B14MODLIB"
#COM_OWNER.ChangeLibraryList(#Dev2)

Code: Select all

mthroutine name(ChangeLibraryList) access(*PRIVATE)
define_map for(*INPUT) class(#STD_STRNG) name(#libraryList)

if (*OSAPI <> IBMI)
#SYS_APPLN.TraceMessageText( "System is NOT IBM i, ignoring library list" )
return
endif

#STD_TEXTL := "LIBL(" + #libraryList + ")"

call pgm(CHGLIBL) parm(#STD_TEXTL)

endroutine

This is failing. I don't know if I am formatting the param (STD_TEXTL) command correctly, the IBM docs say it should be be CHGLIBL LIBL(XXXXX XXXX) but the LANSA docs seem to say CHGLIBL PARM(XXXXX XXXXX).

Also, when I displayed the library list, it did not include DCXMODLIB and DCXDTALIB, but when I run the query in the first post, then those libraries do show up. Should I include those in the library list that I am changing to?

* Edit - fixed pgm name error, CGHLIBL to CHGLIBL - Still fails
GregSippel
Posts: 25
Joined: Thu May 19, 2016 11:34 am

Re: Changing Library in Server Module

Post by GregSippel »

Instead of using the call command, try using the SYSTEM_COMMAND BIF, http://docs.lansa.com/14/en/LANSA015/Co ... ommand.htm

The string you need to pass will be the entrie call command, such as "call pgm(CHGLIBL) libl(value)"

Cheers
KevinW
Posts: 31
Joined: Thu May 26, 2016 11:18 am

Re: Changing Library in Server Module

Post by KevinW »

CHGLIBL is an IBM i command. So what you pass to the SYSTEM_COMMAND BIF is
"CHGLIBL LIBL(XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX ...)"

Alternatively, the EXEC_OS400 RDML command could be used.
MarkD
Posts: 692
Joined: Wed Dec 02, 2015 9:56 am

Re: Changing Library in Server Module

Post by MarkD »

I'm not sure where program CHGLIBL fits into this? Did you create this program?

You could try something like this:

Code: Select all

Mthroutine Name(Test)

#COM_OWNER.ChangeLibraryList To("QGPL LIBRARY1 LIBRARY2 LIBRARY3")

Endroutine


Mthroutine Name(ChangeLibraryList) Access(*PRIVATE)
Define_Map For(*input) Class(#prim_alph) Name(#To)

#COM_OWNER.Execute Clcommand("CHGLIBL LIBL(" + #To + ")")

Endroutine

Mthroutine Name(Execute) Access(*PRIVATE)
Define_Map For(*input) Class(#prim_alph) Name(#CLCommand)
Define_Map For(*Result) Class(#Prim_Boln) Name(#Okay)

#Okay := false

Exec_Os400 Command(#CLCommand) If_Error(*RETURN)

#Okay := true

Endroutine
where method Execute can execute any CL command formatted as you would type them in on a screen.
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Changing Library in Server Module

Post by jyoung »

The CL command came from http://www.ibm.com/support/knowledgecen ... hglibl.htm

Thank you all for the help. I am trying to get it to work now.

Thanks!
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Changing Library in Server Module

Post by jyoung »

Thanks again for everyone's help.
I got it to work as such:

Code: Select all

#command := "CHGLIBL libl(" + #libraryList + ")"
#SYS_APPLN.TraceMessageData( "Executing &1" #command )

use builtin(SYSTEM_COMMAND) with_args(X #command) to_get(#STD_NUM)

if (#STD_NUM = 0)
#SYS_APPLN.TraceMessageText( "Library List Changed Successfully" )
else
#SYS_APPLN.TraceMessageText( "Library List Change Failed" )
endif
Post Reply