Function VSAM131 : Example Tier Aware Subroutine

LANSA

Function VSAM131 : Example Tier Aware Subroutine
Name: VSAM131

Description: The following RDML function demonstrates programming techniques that can be used to make a classic "subroutine" style functions tier aware. Refer to comments in the function for more information.

Special Note: You should check this function into your iSeries server system and compile it there as well as in your Visual LANSA environment.


FUNCTION OPTIONS(*HEAVYUSAGE *DBOPTIMIZE *DIRECT *MLOPTIMIZE);
********** COMMENT(-------------------------------------------------------);
********** COMMENT( This RDML function is an example of a classic);
********** COMMENT( calleable "subroutine" (ie: you put a department code);
********** COMMENT( in and you get a total salary value out again) );
********** COMMENT(-------------------------------------------------------);
********** COMMENT(This is routine is "smart" in that it can figure out);
********** COMMENT(upon which tier to execute itself (the application tier);
********** COMMENT(and from which tier it needs to get it's data (the data);
********** COMMENT(tier).);
********** COMMENT(To the caller of this routine this is invisible.);
********** COMMENT(The caller simply codes a normal CALL command like this);
********** COMMENT( Exchange #Deptment);
********** COMMENT( Call Process(*Direct) Function(VSAM131));
********** COMMENT( << #TotSalary now contains the total value>>);
********** COMMENT(This routine works equally as well in any 5250 green);
********** COMMENT(screen application, L4Web application or L4Win);
********** COMMENT(application. This routine will happily run, unchanged,);
********** COMMENT(in tiered or non-tiered execution environments. );
********** COMMENT(-------------------------------------------------------);
********** COMMENT(Define the standard input/ouput exchange);
********** COMMENT(-------------------------------------------------------);
EXCHANGE FIELDS(#DEPTMENT #TOTSALARY) OPTION(*ALWAYS);
********** COMMENT(-------------------------------------------------------);
********** COMMENT(If we are executing on the application tier then we);
********** COMMENT(are ready to start performing the actual logic that);
********** COMMENT(this routine involves (ie: calculating the total of);
********** COMMENT(all salaries for a specified department));
IF COND('*Appl_Tier = YES');
EXECUTE SUBROUTINE(REAL_LOGIC);
ELSE;
********** COMMENT(Else we are NOT on the application tier, so pass);
********** COMMENT(control to this function on the application tier);
********** COMMENT(so that it can perform the calculation for us. );
DEFINE FIELD(#BIFRETCDE) TYPE(*CHAR) LENGTH(2);
USE BUILTIN(CALL_SERVER_FUNCTION) WITH_ARGS(*APPL_TIER *FUNCTION Y Y) TO_GET(#BIFRETCDE);
ENDIF;
********** COMMENT(Finished);
RETURN;
********** COMMENT(-------------------------------------------------------);
********** COMMENT(This is the real logic in this "subroutine". You put in);
********** COMMENT(a department code in field #DEPTMENT and you get back a);
********** COMMENT(total salary value for the department in #TOTSALARY);
********** COMMENT(-------------------------------------------------------);
SUBROUTINE NAME(REAL_LOGIC);
********** COMMENT(We are now running on the application tier, so we are);
********** COMMENT(ready to do the calculation. The final thing to do);
********** COMMENT((since this logic needs to read database rows) is to);
********** COMMENT(make sure that we are connected to the database tier);
********** COMMENT(as well. To do this we simply make a reference to the);
********** COMMENT(system variable named *Data_Tier which will handle all);
********** COMMENT(the details. This should be done before any data);
********** COMMENT(access is attempted.);
CHANGE FIELD(#STD_OBJ) TO(*DATA_TIER);
********** COMMENT(Check the department exists and either issue a message);
********** COMMENT(or calculate the salary total value);
********** COMMENT( or calculate total);
CHANGE FIELD(#TOTSALARY) TO(0);
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT);
IF_STATUS IS_NOT(*OKAY);
MESSAGE MSGTXT('Invalid department code specified as argument to VSAM131');
ELSE;
SELECT FIELDS(#SALARY) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT);
CHANGE FIELD(#TOTSALARY) TO('#TotSalary + #Salary');
********** COMMENT(These I/Os perform no purpose other than to slow this);
********** COMMENT(routine down to demonstrate performance ddifferences);
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT);
FETCH FIELDS(#SECDESC) FROM_FILE(SECTAB) WITH_KEY(#DEPTMENT #SECTION);
ENDSELECT;
ENDIF;
********** COMMENT(Finished);
ENDROUTINE;