Request
It should be possible to call any RFC-FM from the macro. (see also Innovation "Calling of an RFC function module within a macro")
Examples
For example to use a customer specific FM to find all versions of an document.
Solution
To solve problem, SAP ECTR macros can call services like the ExecuteRfcFmCall service.
service = GET_SERVICE('com.dscsag.plm.spi.interfaces.services.rfc.ExecuteRfcFmCallService')
With this service, the macro can call a RFC-FM like "/DSCSAG/DOC_VERSION_GET_ALL3"
To call those FMs from a macro, the user needs specific knowledge of the FM.
Especially how to call it and how to handle its results.
In this example, to call the FM "/DSCSAG/DOC_VERSION_GET_ALL3", a structure with certain document fields has to be filled.
config = service.configurationBuilder() .functionName("/DSCSAG/DOC_VERSION_GET_ALL3") .importing() .scalar("IV_GET_CUST_ATTR", "") .structure('DOCUMENTKEY', 'DOCUMENTTYPE', props[0], 'DOCUMENTNUMBER', ('0'.repeat(25) + props[1]).slice(-25), 'DOCUMENTVERSION', props[2], 'DOCUMENTPART', props[3]) .build()
After the structure is filled, the service can be executed via the configuration of the FM.
result = service.execute(config)
Next, the results have to be handled.
The FM outputs the table "DOCUMENTS". The table rows have different fields like "DOCUMENTNUMBER".
These fields can be used for further actions such as searching for a specific output and creating an object list.
rfcResult = result.get() const documents = rfcResult.getTable('DOCUMENTS') pmap = PARAMETER_MAP('doc_fields') for (var row = 0; row < documents.getRowCount(); row++) { var tableRow = documents.getRow(row) pmap.DOCUMENTTYPE = tableRow.getFieldValue('DOCUMENTTYPE') pmap.DOCUMENTNUMBER = tableRow.getFieldValue('DOCUMENTNUMBER') pmap.DOCUMENTVERSION = tableRow.getFieldValue('DOCUMENTVERSION') pmap.DOCUMENTPART = tableRow.getFieldValue('DOCUMENTPART')
Here is a full example on how to call an RFC FM and how to show the results in an object list.
function main() { keylist = KEYLIST_FROM_CONTEXT('ACTIVE', 'SELECTED') props = GET_PROPERTY(['DOCUMENTTYPE', 'DOCUMENTNUMBER', 'DOCUMENTVERSION', 'DOCUMENTPART'], keylist) service = GET_SERVICE('com.dscsag.plm.spi.interfaces.services.rfc.ExecuteRfcFmCallService') config = service.configurationBuilder() .functionName("/DSCSAG/DOC_VERSION_GET_ALL3") .importing() .scalar("IV_GET_CUST_ATTR", "") .structure('DOCUMENTKEY', 'DOCUMENTTYPE', props[0], 'DOCUMENTNUMBER', ('0'.repeat(25) + props[1]).slice(-25), 'DOCUMENTVERSION', props[2], 'DOCUMENTPART', props[3]) .build() result = service.execute(config) resultSet = [] if (!result.isCanceled() && !result.isFailed()) { rfcResult = result.get() const documents = rfcResult.getTable('DOCUMENTS') pmap = PARAMETER_MAP('doc_fields') for (row = 0; row < documents.getRowCount(); row++) { tableRow = documents.getRow(row) pmap.DOCUMENTTYPE = tableRow.getFieldValue('DOCUMENTTYPE') pmap.DOCUMENTNUMBER = tableRow.getFieldValue('DOCUMENTNUMBER') pmap.DOCUMENTVERSION = tableRow.getFieldValue('DOCUMENTVERSION') pmap.DOCUMENTPART = tableRow.getFieldValue('DOCUMENTPART') REPORT(tableRow.getFieldValue('DOCUMENTTYPE') + (' / ') + tableRow.getFieldValue('DOCUMENTNUMBER') + (' / ') + tableRow.getFieldValue('DOCUMENTVERSION') + (' / ') + tableRow.getFieldValue('DOCUMENTPART')) searchSet = SEARCH('DOC', pmap) resultSet = OPERATION_SET("UNION", resultSet, searchSet) } kl = KEYLIST_FROM_SET(resultSet) WRITE_OBJECTLIST(kl, 'VersionList') } } main()