ASNA WingsRPG™ Reference Manual

Resetting the Current Library on Wings Interactive Jobs

When Wings establishes an interactive connection to the IBM i through DataGate, it creates an Interactive job on behalf of the user. Interactive jobs are initiated via telnet, with the DATAGATE program given as the initial program to run and the DataGate library as the current library (so that the DATAGATE program can be found). Initiating the job this way has the side effect of overriding the current library specified on the user profile.

If the job must have the current library set to the user profile's specifications, then a program must be called on the job to set the current library. One way of doing this is to create a small CL program that retrieves the current library value for the current user and sets it in the job and then call this program after the DataGate connection has been established. Here is a sample program:

0001.00              PGM                                          
0002.00              DCL        VAR(&INITLIB) TYPE(*CHAR) LEN(10) 
0003.00              RTVUSRPRF  CURLIB(&INITLIB)                  
0004.00              CHGCURLIB  CURLIB(&INITLIB)                  
0005.00              ENDPGM			

Alternatively, the same task can be accomplished from the DataGate client by invoking program QSYRUSRI (IBM's API equivalent to RTVUSRPRF) and then calling QCMDEXC to change the current library. The following C# code shows sample code on calling QSYSUSRI.

private string retreiveUserCurrentLibrary()
    string programName = "QSYRUSRI";
    int bufLen = 150;
    ProgParm RecVar = new ProgParm(new ProgParmType("RecVar", 0, FieldType.NewChar((int)bufLen)), DataDirection.Output);
    ProgParm RecVarLen = new ProgParm(new ProgParmType("RecVarLen", 0, FieldType.NewInteger(4)), DataDirection.Input);
    ProgParm FormatName = new ProgParm(new ProgParmType("FormatName", 0, FieldType.NewChar(8)), DataDirection.Input);
    ProgParm UserName = new ProgParm(new ProgParmType("UserName", 0, FieldType.NewChar(10)), DataDirection.Input);
    ProgParm ErrorCode = new ProgParm(new ProgParmType("ErrorCode", 0, FieldType.NewInteger(4)), DataDirection.InputOutput);

    As400Program rtvUserPrf = new As400Program(myDatabase.Connection, programName);

    rtvUserPrf.ObjectToParm(RecVar, "" as object);
    rtvUserPrf.ObjectToParm(RecVarLen, bufLen as object);
    rtvUserPrf.ObjectToParm(FormatName, "USRI0300" as object);
    rtvUserPrf.ObjectToParm(UserName, "*CURRENT  " as object);
    rtvUserPrf.ObjectToParm(ErrorCode, ((int)0) as object);
    string receiver = "";
        receiver = rtvUserPrf.ParmToObject(RecVar, receiver.GetType()) as string;
    catch (dgException dgEx)
        throw dgEx;
    return receiver.Substring(138, 10);

After establishing the connection to the IBM i, the current library can be reset as follows:

string currentLibrary = retreiveUserCurrentLibrary();
callQCmdExec("CHGCURLIB " + currentLibrary);