index.js
//Transform json model to ProgramParameter and inject input data
Transform json model to ProgramParameter and inject input data
Transform json model to ProgramParameter and inject input data
generateProgramParameterFromField(field,data) {
		var param=null;
		var passBy=ProgramParameter.PASS_BY_VALUE;
		if(field.kind!=null && (field.kind == "inout" ||  field.kind == "out")) {
			passBy=ProgramParameter.PASS_BY_REFERENCE;
		}
		switch(field.type) {
			case "text" : 
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(new AS400Text(field.size).toBytesSync(data))))
				} else {
					param=new ProgramParameter(passBy,new AS400Text(field.size).getByteLengthSync())
				}
				break;
			case "bin4" : 
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(new AS400Bin4().toBytesSync(data))))
				} else {
					param=new ProgramParameter(passBy,new AS400Bin4().getByteLengthSync())
				}
				break;
			case "zoned" : 
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(new AS400ZonedDecimal(field.size, field.precision).toBytesSync(data))))
				} else {
					param=new ProgramParameter(passBy,new AS400ZonedDecimal(field.size, field.precision).getByteLengthSync())
				}
				break;
			case "packed" : 
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(new AS400PackedDecimal(field.size, field.precision).toBytesSync(data))))
				} else {
					param=new ProgramParameter(passBy,new AS400PackedDecimal(field.size, field.precision).getByteLengthSync())
				}
				break;
			case "array" : 
				var struct=this.generateAs400StructureFromArrayObjectStruct(field.struct);
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					var dataArray=new Array();
					for(var i = 0 ; i < data.length ; i++) {
						dataArray.push(Object.values(data[i]));
					}
					var objectArray=new AS400Array(struct, data.length);
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(objectArray.toBytesSync(dataArray))));
				} else {
					param=new ProgramParameter(new AS400Array(struct, field.size).getByteLengthSync())
				}
				break;
			case "struct" : 
				var struct=this.generateAs400StructureFromArrayObjectStruct(field.struct);
				if(data!=null && (field.kind == "inout" ||  field.kind == "in")) {
					param=new ProgramParameter(passBy,java.newArray('byte',Array.from(struct.toBytesSync(Object.values(data)))));
				} else {
					param=new ProgramParameter(passBy,struct.getByteLengthSync())
				}
				break;
		}
		return param;
	}
generateProgramParameterFromField ( field , data ) { var param = null ; var passBy = ProgramParameter . PASS_BY_VALUE ; if ( field . kind != null && ( field . kind == "inout" || field . kind == "out" ) ) { passBy = ProgramParameter . PASS_BY_REFERENCE ; } switch ( field . type ) { case "text" : if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( new AS400Text ( field . size ) . toBytesSync ( data ) ) ) ) } else { param = new ProgramParameter ( passBy , new AS400Text ( field . size ) . getByteLengthSync ( ) ) } break ; case "bin4" : if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( new AS400Bin4 ( ) . toBytesSync ( data ) ) ) ) } else { param = new ProgramParameter ( passBy , new AS400Bin4 ( ) . getByteLengthSync ( ) ) } break ; case "zoned" : if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( new AS400ZonedDecimal ( field . size , field . precision ) . toBytesSync ( data ) ) ) ) } else { param = new ProgramParameter ( passBy , new AS400ZonedDecimal ( field . size , field . precision ) . getByteLengthSync ( ) ) } break ; case "packed" : if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( new AS400PackedDecimal ( field . size , field . precision ) . toBytesSync ( data ) ) ) ) } else { param = new ProgramParameter ( passBy , new AS400PackedDecimal ( field . size , field . precision ) . getByteLengthSync ( ) ) } break ; case "array" : var struct = this . generateAs400StructureFromArrayObjectStruct ( field . struct ) ; if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { var dataArray = new Array ( ) ; for ( var i = 0 ; i < data . length ; i ++ ) { dataArray . push ( Object . values ( data [ i ] ) ) ; } var objectArray = new AS400Array ( struct , data . length ) ; param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( objectArray . toBytesSync ( dataArray ) ) ) ) ; } else { param = new ProgramParameter ( new AS400Array ( struct , field . size ) . getByteLengthSync ( ) ) } break ; case "struct" : var struct = this . generateAs400StructureFromArrayObjectStruct ( field . struct ) ; if ( data != null && ( field . kind == "inout" || field . kind == "in" ) ) { param = new ProgramParameter ( passBy , java . newArray ( 'byte' , Array . from ( struct . toBytesSync ( Object . values ( data ) ) ) ) ) ; } else { param = new ProgramParameter ( passBy , struct . getByteLengthSync ( ) ) } break ; } return param ; }
Transform json model to ProgramParameter and inject input data
Transform json model to ProgramParameter and inject input data