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

  1. Generate an entity from the COBOL.

  2. Open the entity part that includes the field with the entity editor.

  3. Go to the FieldsDynamic Attribute and check the Dynamic field checkbox.

     

  4. Open the same entity part with the Java editor.

  5. Add the Dynamic function name to the @RpcDynamicField annotation.
    E.g:@RpcDynamicField(dynamicFunction = "myDynamicFun")

  6. 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 {
  1. Add an @Component annotation before the class declaration.
    e.g:

  2. 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: