Function VSAM138: Interactive/Batch and Tier Aware Report

LANSA

Function VSAM138: Interactive/Batch and Tier Aware Report
Name: VSAM138

Description: The following RDML function demonstrates programming techniques that can be used to make a print function interactive/batch and 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(VSAM138 is a "smart" print job. When);
********** COMMENT(you call it can either do it printing);
********** COMMENT(immediately or submit itself to become a);
********** COMMENT(batch job.);
********** 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(VSAM138 receives a department code);
********** COMMENT( and a message as input and lists the employee);
********** COMMENT(that work in the department);
********** COMMENT(=======================================);
DEFINE FIELD(#OPVSAM138) TYPE(*CHAR) LENGTH(10) DEFAULT(SUBMIT);
DEFINE FIELD(#MSVSAM138) REFFLD(#STD_TEXTS) LABEL('Send Report to');
EXCHANGE FIELDS(#OPVSAM138 #MSVSAM138 #DEPTMENT) OPTION(*ALWAYS);
********** COMMENT(=======================================);
DEFINE FIELD(#BRETCODE) TYPE(*CHAR) LENGTH(2) DESC('Return Code');
DEF_COND NAME(*NOTAS400) COND('*CPUTYPE *NE AS400');
********** COMMENT(=======================================);
DEF_REPORT FORMSIZE(*DEFAULT 80);
DEF_HEAD NAME(#HEAD01) FIELDS((#DATE *L001 *P002 )(#REP1PAGE *L001 *P059 )(#TIME *L002 *P002 )(#MSVSAM138 *L004 *P002 )(#DEPTMENT *L006 *P002 )(#DEPTDESC *L007 *P002 )) DESIGN(*DOWN);
DEF_LINE NAME(#DETAIL01) FIELDS(#EMPNO #SURNAME #GIVENAME);
********** COMMENT(=======================================);
********** COMMENT(=======================================);
********** COMMENT(If being asked to print right now);
********** COMMENT(=======================================);
CASE OF_FIELD(#OPVSAM138);
WHEN VALUE_IS('= Print');
IF COND('*PRINT_Tier = YES');
********** COMMENT(This is the printing tier so we);
********** COMMENT(are free to print);
EXECUTE SUBROUTINE(PRINTLOGIC);
ELSE;
********** COMMENT(We have to call this logic);
********** COMMENT(on the printing tier);
USE BUILTIN(CALL_SERVER_FUNCTION) WITH_ARGS(*PRINT_TIER *FUNCTION Y) TO_GET(#BRETCODE);
ENDIF;
********** COMMENT(=======================================);
********** COMMENT(If being asked to submit to the printing);
********** COMMENT(tier);
********** COMMENT(=======================================);
WHEN VALUE_IS('= Submit');
IF COND('*PRINT_Tier = YES');
********** COMMENT(We are on the print tier, so we are now);
********** COMMENT(free to submit the batch job, carefully);
********** COMMENT(telling it to PRINT when it startes execution. );
CHANGE FIELD(#OPVSAM138) TO(PRINT);
CHANGE FIELD(#PROCESS) TO(*PROCESS);
CHANGE FIELD(#FUNCTION) TO(*FUNCTION);
SUBMIT PROCESS(#PROCESS) FUNCTION(#FUNCTION);
ELSE;
********** COMMENT(This is not the print tier so);
********** COMMENT(we have to call submit logic);
********** COMMENT(logic on the print tier ....);
USE BUILTIN(CALL_SERVER_FUNCTION) WITH_ARGS(*PRINT_TIER *FUNCTION Y) TO_GET(#BRETCODE);
ENDIF;
ENDCASE;
********** COMMENT(Finished);
RETURN;
********** COMMENT(===========================================);
********** COMMENT(PrintLogic : Do the actual printing );
********** COMMENT(===========================================);
SUBROUTINE NAME(PRINTLOGIC);
********** COMMENT(This subroutine does the printing.);
********** 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(======= Print work now starting ======= );
********** COMMENT(======= Print work now starting ======= );
********** COMMENT(======= Print work now starting ======= );
********** COMMENT(If if a windows environment we can enabled some);
********** COMMENT(special printing options);
IF COND(*NOTAS400);
USE BUILTIN(SET_SESSION_VALUE) WITH_ARGS(WPEN Y);
ENDIF;
********** COMMENT(Now print the report);
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT);
SELECT FIELDS(#EMPNO #SURNAME #GIVENAME) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT);
PRINT LINE(#DETAIL01);
ENDSELECT;
ENDPRINT;
********** COMMENT(===== Print work has now finished ===== );
********** COMMENT(===== Print work has now finished ===== );
********** COMMENT(===== Print work has now finished ===== );
ENDROUTINE;