To create an implementation of the IWrapper interface called AddressBookWrapper:
This opens the AddressBookWrapper.cbl program in a COBOL editor.
class-id com.addressBookWrapper.AddressBookWrapper public implements type IWrapper.
working-storage section. *> procedural cobol pointer 01 pp procedure-pointer private. *> private values 01 #index binary-long value 0 private. 78 PROCEDURAL_PROGRAM value "recordsProgram" private. 01 func pic 99 private. copy "functions.cpy".
method-id New protected. procedure division. initialize func set pp to entry PROCEDURAL_PROGRAM goback. end method.
method-id openConnection. procedure division. move openFile to func call pp using func omitted omitted set #index to self::maxNumberOfRecords() goback. end method.
You need to explicitly define the rec variable in the local-storage section in the same way it is used in procedural COBOL code. Your code should look something like this:
method-id createRecord. local-storage secion. 01 rec. copy "records.cpy". procedure division returning return-value as type RecordDTO. declare #id as binary-long = self::getUniqueID() declare dto = new RecordDTO(#id) set rec to self::DTOtoRecord(dto) move writeRecord to func call pp using func rec omitted set return-value to dto goback. end method.
Here is an example of the object record translation:
method-id DTOtoRecord private. linkage section. 01 rec. copy "records.cpy". procedure division using by value dto as type RecordDTO returning rec. initialize rec set recordId of rec to dto::recordID set recordName of rec to dto::name set recordFamily of rec to dto::family set recordCode of rec to dto::postalCode set recordCity of rec to dto::city set recordStreet of rec to dto::street set recordPhone of rec to dto::phone goback.
Your code should look something like this:
method-id getAllRecords. local-storage section. 01 arrayParent. 03 array occurs 0 to 1000 depending on #index. copy "records.cpy". 01 rec. copy "records.cpy". procedure division returning return-value as list[type RecordDTO]. initialize arrayParent move readAllRecords to func call pp using func omitted arrayParent create return-value declare i as binary-long. perform varying i from 1 by 1 until i >= #index set rec to array(i) if recordId of rec not= 0 declare dto = self::recordToDTO(rec) invoke return-value::add(dto) end-if end-perform. goback. end method.
You need to create a class WrapperProvider, to handle the creation of the IWrapper implementation. It should contain a single static method to handle the operation:
This opens the WrapperProvider.cbl program in a COBOL editor.
class-id com.addressBookWrapper.WrapperProvider public. method-id getWrapper static. procedure division returning return-value as type IWrapper. set return-value to new AddressBookWrapper() goback. end method. end class.