Function SET1933: Fetch/Update of NT DBMS Table

LANSA

Function SET1933: Fetch/Update of NT DBMS Table
********** COMMENT(=======================================================);
********** COMMENT(Process ........: SET_193);
********** COMMENT(Function .......: SET1933);
********** COMMENT(Created on .....: 12th October 2000);
********** COMMENT(Description ....: Demonstration Function 3);
********** COMMENT(Version.........: 1);
********** COMMENT();
********** COMMENT(Full Description: This function demonstrates);
********** COMMENT( how an AS/400 function can fetch and update details);
********** COMMENT( residing in a DBMS table on a Windows NT/2000 system);
********** COMMENT();
********** COMMENT(Disclaimer: The following material is supplied as);
********** COMMENT( example material only. No warranty concerning this);
********** COMMENT( material or its use in any way whatsoever is);
********** COMMENT( expressed or implied.);
********** COMMENT();
********** COMMENT(Minimum Release of LANSA Required : 8.0);
********** COMMENT();
********** COMMENT(=======================================================);
FUNCTION OPTIONS(*DIRECT *HEAVYUSAGE);
DEF_COND NAME(*AS400) COND('*CPUTYPE = AS400');
********** COMMENT(--------------------------------------);
********** COMMENT(If on an AS/400 execute "client" logic);
********** COMMENT(--------------------------------------);
IF COND(*AS400);
EXECUTE SUBROUTINE(AS_CLIENT);
ELSE;
********** COMMENT(-----------------------------------);
********** COMMENT(else execute NT/2000 "server" logic);
********** COMMENT(-----------------------------------);
EXECUTE SUBROUTINE(NT_SERVER);
ENDIF;
********** COMMENT(--------);
********** COMMENT(Finished);
********** COMMENT(--------);
MENU;
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT( AS_Client: AS/400 "Client" logic);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
SUBROUTINE NAME(AS_CLIENT);
********** COMMENT();
********** COMMENT(Now loop around fetching and updating until cancelled);
********** COMMENT();
MESSAGE MSGTXT('Specify number of employee to be displayed / updated (eg:A0070).');
BEGIN_LOOP;
********** COMMENT();
********** COMMENT(Request number of employee that is to be displayed);
********** COMMENT();
REQUEST FIELDS(#EMPNO) DESIGN(*DOWN) IDENTIFY(*DESC) EXIT_KEY(*NO) MENU_KEY(*YES E10) PROMPT_KEY(*NO);
********** COMMENT();
********** COMMENT(Attempt to fetch the employee from the NT/2000 system);
********** COMMENT();
EXECUTE SUBROUTINE(BEGIN);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ACTION GET);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(EMPNO #EMPNO);
********** COMMENT();
********** COMMENT(Send/Receive details to/from the NT/2000 server system);
********** COMMENT(and get back the I/O status code);
********** COMMENT();
EXECUTE SUBROUTINE(SEND) WITH_PARMS(GENL *FUNCTION *BLANKS);
MESSAGE MSGTXT('Fetching employee details from Windows NT/2000 system') TYPE(*STATUS);
EXECUTE SUBROUTINE(RECEIVE) WITH_PARMS(GENL 30);
CHANGE FIELD(#IO$STS) TO(NR);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS('IO_STATUS' #IO$STS);
********** COMMENT();
********** COMMENT(If found get employee details and display them);
********** COMMENT();
IF COND('#IO$STS = OK');
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(GIVENAME #GIVENAME);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(SURNAME #SURNAME);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS1 #ADDRESS1);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS2 #ADDRESS2);
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(POSTCODE #POSTCODE);
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(SALARY #SALARY);
SET_MODE TO(*DISPLAY);
DOUNTIL COND('#IO$STS = OK');
DISPLAY FIELDS((#EMPNO *OUT)(#GIVENAME)(#SURNAME)(#ADDRESS1)(#ADDRESS2)(#POSTCODE)(#SALARY)) EXIT_KEY(*NO) MENU_KEY(*YES L10) CHANGE_KEY(*YES) PROMPT_KEY(*NO);
********** COMMENT();
********** COMMENT(Handle a change request by getting the);
********** COMMENT(NT/2000 server system to do the update);
********** COMMENT();
IF_MODE IS(*CHANGE);
EXECUTE SUBROUTINE(BEGIN);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ACTION UPDATE);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(EMPNO #EMPNO);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(GIVENAME #GIVENAME);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(SURNAME #SURNAME);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ADDRESS1 #ADDRESS1);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ADDRESS2 #ADDRESS2);
EXECUTE SUBROUTINE(PUT_NUMBER) WITH_PARMS(POSTCODE #POSTCODE);
EXECUTE SUBROUTINE(PUT_NUMBER) WITH_PARMS(SALARY #SALARY);
EXECUTE SUBROUTINE(SEND) WITH_PARMS(GENL *FUNCTION *BLANKS);
MESSAGE MSGTXT('Updating employee details on Windows NT/2000 system') TYPE(*STATUS);
EXECUTE SUBROUTINE(RECEIVE) WITH_PARMS(GENL 30);
CHANGE FIELD(#IO$STS) TO(VE);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS('IO_STATUS' #IO$STS);
ELSE;
********** COMMENT();
********** COMMENT(Else progress to get the next employee number);
********** COMMENT();
CHANGE FIELD(#IO$STS) TO(OK);
ENDIF;
ENDUNTIL;
ENDIF;
********** COMMENT(Loop around for next employee);
L10: END_LOOP;
********** COMMENT();
********** COMMENT(Finished);
********** COMMENT();
E10: EXECUTE SUBROUTINE(ENDSERVICE);
RETURN;
ENDROUTINE;
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT( NT_Server: Windows NT/2000 "Server" logic);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
********** COMMENT(===============================================);
SUBROUTINE NAME(NT_SERVER);
********** COMMENT();
********** COMMENT(Get the requested action code to work out what to do);
********** COMMENT();
EXECUTE SUBROUTINE(FIRST_SET);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ACTION #STD_OBJ);
********** COMMENT();
********** COMMENT(handle various different actions);
********** COMMENT();
CASE OF_FIELD(#STD_OBJ);
********** COMMENT();
********** COMMENT(Handle a GET request);
********** COMMENT();
WHEN VALUE_IS('= GET');
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(EMPNO #EMPNO);
FETCH FIELDS((#SURNAME)(#GIVENAME)(#ADDRESS1)(#ADDRESS2)(#POSTCODE)(#SALARY)) FROM_FILE(PSLMST) WITH_KEY(#EMPNO) ISSUE_MSG(*YES);
EXECUTE SUBROUTINE(BEGIN);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS('IO_STATUS' #IO$STS);
IF_STATUS IS(*OKAY);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(GIVENAME #GIVENAME);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(SURNAME #SURNAME);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ADDRESS1 #ADDRESS1);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS(ADDRESS2 #ADDRESS2);
EXECUTE SUBROUTINE(PUT_NUMBER) WITH_PARMS(POSTCODE #POSTCODE);
EXECUTE SUBROUTINE(PUT_NUMBER) WITH_PARMS(SALARY #SALARY);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS('IO_STATUS' #IO$STS);
ENDIF;
********** COMMENT();
********** COMMENT(Handle an UPDATE request);
********** COMMENT();
WHEN VALUE_IS('= UPDATE');
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(EMPNO #EMPNO);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(GIVENAME #GIVENAME);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(SURNAME #SURNAME);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS1 #ADDRESS1);
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS2 #ADDRESS2);
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(POSTCODE #POSTCODE);
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(SALARY #SALARY);
UPDATE FIELDS((#SURNAME)(#GIVENAME)(#ADDRESS1)(#ADDRESS2)(#POSTCODE)(#SALARY)) IN_FILE(PSLMST) WITH_KEY(#EMPNO) IO_ERROR(*NEXT) VAL_ERROR(*NEXT) ISSUE_MSG(*YES);
EXECUTE SUBROUTINE(BEGIN);
EXECUTE SUBROUTINE(PUT_ALPHA) WITH_PARMS('IO_STATUS' #IO$STS);
********** COMMENT();
********** COMMENT(Handle an unknown request);
********** COMMENT();
OTHERWISE;
MESSAGE MSGTXT('Unknown request received by SET1933');
ENDCASE;
********** COMMENT();
********** COMMENT(Finished);
********** COMMENT();
RETURN;
ENDROUTINE;
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(==== Windows NT/2000 Interface Routines ====);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(These subroutines are used to simplify and);
********** COMMENT( standardize interfacing with a NT/2000);
********** COMMENT( service via function SET193T);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(============================================);
********** COMMENT(Begin: Sets or Resets an interaction between);
********** COMMENT( this program and an NT/2000 server. Use);
********** COMMENT( this subroutine at the start of each);
********** COMMENT( logical transaction.);
********** COMMENT(============================================);
SUBROUTINE NAME(BEGIN);
CHANGE FIELD(#S_193GSR) TO(I);
EXCHANGE FIELDS(#S_193GSR);
EXECUTE SUBROUTINE(CALL_193T);
EXECUTE SUBROUTINE(FIRST_SET);
ENDROUTINE;
********** COMMENT(============================================);
********** COMMENT(EndService: Ends any existing connection with);
********** COMMENT( an NT/200 server and frees resources. Use);
********** COMMENT( when all interactions have been completed.);
********** COMMENT(============================================);
SUBROUTINE NAME(ENDSERVICE);
CHANGE FIELD(#S_193GSR) TO(T);
EXCHANGE FIELDS(#S_193GSR);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(============================================);
********** COMMENT(First_Set : Sets up for the processing the);
********** COMMENT( first set of variable instances);
********** COMMENT(============================================);
SUBROUTINE NAME(FIRST_SET);
CHANGE FIELD(#S_193VIN) TO(1);
ENDROUTINE;
********** COMMENT(============================================);
********** COMMENT(Next_Set : Sets up for the processing the);
********** COMMENT( next set of variable instances);
********** COMMENT(============================================);
SUBROUTINE NAME(NEXT_SET);
CHANGE FIELD(#S_193VIN) TO('#S_193VIN + 1');
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Put_Alpha: Set the value of an alpha variable);
********** COMMENT( instance. Used as Put_Alpha ( <nam> <val> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the variable's symbolic name);
********** COMMENT( <val> is the variable value);
********** COMMENT(================================================);
SUBROUTINE NAME(PUT_ALPHA) PARMS((#S_193VNM *RECEIVED) (#S_193VAV *RECEIVED));
CHANGE FIELD(#S_193GSR) TO(A);
EXCHANGE FIELDS(#S_193GSR #S_193VNM #S_193VIN #S_193VAV);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Put_Number: Set the value of a numeric variable);
********** COMMENT( instance. Used as Put_Number ( <nam> <val> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the variable's symbolic name);
********** COMMENT( <val> is the variable value);
********** COMMENT(================================================);
SUBROUTINE NAME(PUT_NUMBER) PARMS((#S_193VNM *RECEIVED) (#S_193VNV *RECEIVED));
CHANGE FIELD(#S_193GSR) TO(B);
EXCHANGE FIELDS(#S_193GSR #S_193VNM #S_193VIN #S_193VNV);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Get_Alpha: Get the value of an alpha variable);
********** COMMENT( instance. Used as Get_Alpha ( <nam> <val> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the variable's symbolic name);
********** COMMENT( <val> is the variable's returned value);
********** COMMENT(================================================);
SUBROUTINE NAME(GET_ALPHA) PARMS((#S_193VNM *RECEIVED) (#S_193VAV *RETURNED));
CHANGE FIELD(#S_193GSR) TO(C);
EXCHANGE FIELDS(#S_193GSR #S_193VNM #S_193VIN #S_193VAV);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Get_Number: Get the value of a numeric variable);
********** COMMENT( instance. Used as Get_Number ( <nam> <val> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the variable's symbolic name);
********** COMMENT( <val> is the variable's returned value);
********** COMMENT(================================================);
SUBROUTINE NAME(GET_NUMBER) PARMS((#S_193VNM *RECEIVED) (#S_193VNV *RETURNED));
CHANGE FIELD(#S_193GSR) TO(D);
EXCHANGE FIELDS(#S_193GSR #S_193VNM #S_193VIN #S_193VNV);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Send: Send all variables to a service);
********** COMMENT( Used as Send ( <nam> <fun> <com> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the service symbolic name);
********** COMMENT( <fun> is the RDML function to invoke);
********** COMMENT( <com> is the RDML component to invoke);
********** COMMENT(================================================);
SUBROUTINE NAME(SEND) PARMS((#S_193SERV *RECEIVED) (#S_193FUN *RECEIVED) (#S_193COM *RECEIVED));
CHANGE FIELD(#S_193GSR) TO(S);
EXCHANGE FIELDS(#S_193GSR #S_193SERV #S_193FUN #S_193COM);
EXECUTE SUBROUTINE(CALL_193T);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Receive: Receive all variables from a service);
********** COMMENT( Used as Receive ( <nam> <max> ));
********** COMMENT( where :);
********** COMMENT( <nam> is the service symbolic name);
********** COMMENT( <max> is the maximum time to wait);
********** COMMENT(================================================);
SUBROUTINE NAME(RECEIVE) PARMS((#S_193SERV *RECEIVED) (#S_193MAXW *RECEIVED));
CHANGE FIELD(#S_193GSR) TO(R);
EXCHANGE FIELDS(#S_193GSR #S_193SERV #S_193MAXW);
EXECUTE SUBROUTINE(CALL_193T);
EXECUTE SUBROUTINE(FIRST_SET);
ENDROUTINE;
********** COMMENT(================================================);
********** COMMENT(Call_193T: Used to call function SET193T);
********** COMMENT(================================================);
SUBROUTINE NAME(CALL_193T);
CALL PROCESS(*DIRECT) FUNCTION(SET193T);
ENDROUTINE;