How To Use RPC Dynamic Function for Dynamic List - 4.6.X
The dynamic list allows the user to define the length dynamically using a counter field.
Step1: Generate the entity
Generate an entity from the COBOL.
Open the entity part that includes the field with the entity editor.
Go to the
Fields
→Dynamic Attribute
and check theDynamic field
checkbox.Open the same entity part with the Java editor.
Add the Dynamic function name to the
@RpcDynamicField
annotation.
E.g:@RpcDynamicField(dynamicFunction = "myDynamicFun")
Declare the count value in the
@RpcList
annotation. (It will be overridden by the dynamic function).
E.g:@RpcList(count = 3)
Step 2: implement the DynamicFieldFunction interface.
@Component
public class MyDynamicFieldFunction implements DynamicFieldFunction {
Add an
@Component
annotation before the class declaration.
e.g:Implemant the getName method, it should return the dynamicFunction name from step 6 (myDynamicFun).
@NotNull @Override public String getName() { return "myDynamicFun"; }
3. Implemant public Function1<RpcDeserializeRequest<?>, Integer> getCountOutputFunction()
function, for example:
@Nullable
@Override
public Function1<RpcDeserializeRequest<?>, Integer> getCountOutputFunction() {
return it ->
it.getResult()
.getJsonObject("dfhcommarea") // the "highest" level part of the entity that includes the list
.getInteger("itemNum"); // the counter field
}
4. Implemant the other function by returning null
or true
in case that the function return Boolean.
Since version 4.6.1 it won’t be necessary to implement all the functions.
The Class should look like this:
5. Go to /ts-sdk/src/main/java/com/ts_sdk/openlegacy/config/TsSdkConfiguration.java
.
6. Add your dynamicFieldFunction class as a bean.
E.g: