Function VSAM137: Tier Aware Batch Job

LANSA

Function VSAM137: Tier Aware Batch Job
Name: VSAM137

Description: The following RDML function demonstrates programming techniques that can be used to make a batch job tier aware. Refer to comments in the function for more information.

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


FUNCTION OPTIONS(*LIGHTUSAGE *DIRECT *MLOPTIMIZE);
********** COMMENT(=======================================);
********** COMMENT(VSAM137 is a "smart" batch job. When);
********** COMMENT(you call it submits itself to batch.);
********** COMMENT(It is also "tier aware" which means it);
********** COMMENT(can figure out which tier to submit);
********** COMMENT(itself onto and which tier to actually);
********** COMMENT(execute the batch logic on.);
********** COMMENT(=======================================);
********** COMMENT(VSAM137 receives an employee number as);
********** COMMENT(as an input parameter.);
********** COMMENT(The batch task it performs is to locate);
********** COMMENT(the specified employee and than indicate);
********** COMMENT(it has done it's "job" by changing the);
********** COMMENT(employee's name to "==DDDDDDHHMMSS==");
********** COMMENT(=======================================);
********** COMMENT(Standard exchange of parameters);
DEFINE FIELD(#OPVSAM137) TYPE(*CHAR) LENGTH(10) DESC('Requested Operation (Internal Field)') DEFAULT(SUBMIT);
DEFINE FIELD(#BRETCODE) TYPE(*CHAR) LENGTH(2) DESC('Return Code');
EXCHANGE FIELDS(#OPVSAM137 #EMPNO) OPTION(*ALWAYS);
********** COMMENT(==============================);
********** COMMENT(Either EXECUTE the batch logic);
********** COMMENT(==============================);
IF COND('#OPVSAM137 = EXECUTE');
IF COND('*APPL_Tier *NE YES');
********** COMMENT(This is not the application tier so);
********** COMMENT(we have to call the "batch" logic);
********** COMMENT(on the application tier ....);
USE BUILTIN(CALL_SERVER_FUNCTION) WITH_ARGS(*APPL_TIER *FUNCTION Y) TO_GET(#BRETCODE);
ELSE;
********** COMMENT(This is the application tier so);
********** COMMENT(we are free to do the actual batch);
********** COMMENT(logic right now ....);
EXECUTE SUBROUTINE(BATCHWORK);
ENDIF;
ELSE;
********** COMMENT(====================================);
********** COMMENT(Or SUBMIT the batch logic into batch );
********** COMMENT(====================================);
IF COND('*BATCH_Tier *ne YES');
********** COMMENT(This is not the batch tier so);
********** COMMENT(we have to call submit logic);
********** COMMENT(logic on the batch tier ....);
USE BUILTIN(CALL_SERVER_FUNCTION) WITH_ARGS(*BATCH_TIER *FUNCTION Y) TO_GET(#BRETCODE);
ELSE;
********** COMMENT(This is the batch tier, so we are now);
********** COMMENT(free to submit the batch job, carefully);
********** COMMENT(telling it to EXECUTE now .... );
CHANGE FIELD(#OPVSAM137) TO(EXECUTE);
CHANGE FIELD(#PROCESS) TO(*PROCESS);
CHANGE FIELD(#FUNCTION) TO(*FUNCTION);
SUBMIT PROCESS(#PROCESS) FUNCTION(#FUNCTION);
ENDIF;
ENDIF;
********** COMMENT(Finished);
RETURN;
********** COMMENT(===========================================);
********** COMMENT(BatchWork : Do the actual batch "job" );
********** COMMENT(===========================================);
SUBROUTINE NAME(BATCHWORK);
********** COMMENT(This subroutine does the batch "job");
********** COMMENT(Since it accesses the database we need);
********** COMMENT(to ensure we have access to the data);
********** COMMENT(base tier by referencing *DATA_TIER);
********** COMMENT(just before the DBMS access is done);
CHANGE FIELD(#STD_OBJ) TO(*DATA_TIER);
********** COMMENT(======= Real Batch work now starting ======= );
********** COMMENT(======= Real Batch work now starting ======= );
********** COMMENT(======= Real Batch work now starting ======= );
USE BUILTIN(TCONCAT) WITH_ARGS('==' *DATETIMEC '==') TO_GET(#GIVENAME);
UPDATE FIELDS(#GIVENAME) IN_FILE(PSLMST) WITH_KEY(#EMPNO);
********** COMMENT(===== Real Batch work has now finished ===== );
********** COMMENT(===== Real Batch work has now finished ===== );
********** COMMENT(===== Real Batch work has now finished ===== );
ENDROUTINE;