The read method is the first which we will use and it allows retrieving the configuration of every Communication Channels, once it has all the Communication Channels IDs. A Communication Channel ID is made of three fields:
- PARTY_ID = the name of the party which the Communication Channel belongs.
- COMPONENT_ID = the name of the Business System / Service which the Communication Channel belongs.
- CHANNEL_ID = The name of the Communication Channel.
The structure ZPRREAD_IN_DOC is a simple table. Every line is made by the Communication Channels IDs which we want to read:
So after preparing the input structure we can call the read method:
+data scr_comm_channell_id type ZPRCOMMUNICATION_CHANNEL_ID,+ +scr_comm_channell_id-party_id = ”.+ +scr_comm_channell_id-component_id = ‘BS_CORSO2_SENDER’.+ +scr_comm_channell_id-channel_id = ‘CC_FILE_In’.+ +append scr_comm_channell_id to src_read_req-COMMUNICATION_CHANNEL_READ_RE-COMMUNICATION_CHANNEL_ID.+ +TRY.+ + CALL METHOD src_clientproxy->read+ + EXPORTING+ + input = src_read_req+ + IMPORTING+ + output = src_read_rsp.+ + CATCH cx_ai_system_fault INTO src_sys_exception.+ +ENDTRY.+ The structure “ZPRREAD_OUT_DOC” has two fields: ** LOG_MESSAGE_COLLECTION: A structure which contains the log of the operations. n.b. For this operation there aren’t log messages. If a communication channel is not found in the Integration Directory then it’s not present in the table COMMUNICATION_CHANNEL. Now let’s analyze the structure of a line of table COMMUNICATION_CHANNEL: As we can see there are some attributes which can be accessed directly (The adapter name, direction etc…) and other attributes which are in the table ADAPTER_SPECIFIC_ATTRIBUTE. In order to be able to read and modify them we need to analyze the structures of the table and make some forms: *ADAPTER_SPECIFIC_ATTRIBUTE:* This table is very simple because a line is done by an attribute name and an attribute value: Here’s an example for the “Adapter Status” attribute: | %1,2% | *ADAPTER_SPECIFIC_ATTRIBUTE* | | *NAME* | | *VALUE* | file.adapterStatus | active | n.b. The name of the attributes may depends on adapter type: For example every adapter type has the value “adapterStatus” in the field “name” but File adapters has the value “file.adapterStatus”. The names of the Directory and File Name attributes depend on the direction of our Communication Channel. For a “Sender” we have: | | *NAME* | | *VALUE* | file.sourceDir | / | | file.sourceFileName | file.txt | And for a “Receiver” we have: | | *NAME* | | *VALUE* | file.targetDir | / | | file.targetFileName | file.txt | Now we can code a form which takes the attribute name and return the attribute value. If it can’t find the attribute it returns an initial value (for the complete code see APPENDIX A): +FORM read_adp_sp_attr USING wa_cc type ZPRCOMMUNICATION_CHANNEL+ + attr_name TYPE string+ + CHANGING attr_value TYPE string.+ +…+ +ENDFORM.+ We can make also a form which takes as input a Communication Channel, an attribute name and attribute value. The form look for the line with attribute name: if this line is present it modifies the filed value otherwise it creates and appends anew line. +FORM set_adp_sp_attr USING attr_name TYPE string+ + attr_value TYPE string+ + CHANGING wa_cc type ZPRCOMMUNICATION_CHANNEL.+ +…+ +ENDFORM.+ So we can loop on the response (even if we requested only one communication channel) and read and print some attributes: +data wa_cc type ZPRCOMMUNICATION_CHANNEL.+ +data: attr_value type string,+ + directory_name type string+ +loop at src_read_rsp-response-COMMUNICATION_CHANNEL into wa_cc.+ + ** Print attributes (see APPENDIX A)+ +endloop.+ The next step is to call the openForEdit method: This method locks in a change list all the Communication Channels which we have passed to it. The structure of input structure ZPROPEN_FOR_EDIT_IN_DOC requires only the IDs of the Communication Channels which we want to lock: +append scr_comm_channell_id to src_open_req-COMMUNICATION_CHANNEL_OPEN_FO-COMMUNICATION_CHANNEL_ID.+ +TRY.+ + CALL METHOD src_clientproxy->open_for_edit+ + EXPORTING+ + input = src_open_req+ + IMPORTING+ + output = src_open_rsp.+ + CATCH cx_ai_system_fault INTO src_sys_exception.+ +ENDTRY.+ The response is the structure ZPROPEN_FOR_EDIT_OUT_DOC which contains three fields: 0.1. COMMUNICATION_CHANNEL: The same table of* *ZPRREAD_OUT_DOC.
- LOG_MESSAGE_COLLECTION: The same structure of ZPRREAD_OUT_DOC.
- CHANGE_LIST_ID: A structure with all the details of our new change list.
For the first time we have to read the LOG_MESSAGE_COLLECTION: In fact it’s possible that another user has already locked in modify our Communication Channel. In this case the COMMUNINCATION_CHANNEL and CHANGE_LIST_ID fields are INITIAL and the LOG_MESSAGE_COLLECTION-LOG_MESSAGE_COMMUNICATION_CHA contains the error.
Let’s analyze in details the structure LOG_MESSAGE_COLLECTION:
It contains a lot of tables but the only one which is used by the Communication Channel Service is the LOG_MESSAGE_COMMUNICATION_CHA.
A line of this table is made by two fields:
- COMMUNICATION_CHANNEL_ID: The structures that identifies a Communication Channel
The SEVERITY_CODE is an integer which indicates seriousness of the log. The value 2 indicates a warning and the value 3 indicates an error. In case of warning operations on the Corresponding Communication Channel are executed while in case of error the operation are not executed. The classification code and message are texts which explain the reason of the warning/error.
Here are a simple form which reads the log and then prints it (for the complete code see APPENDIX A):
+FORM print_operation_log USING cc_log_messages TYPE zprlog_message_communicat_tab1.+
Now it’s time to make effective our modifications using the Change operation. So let’s look the ZPRCHANGE_IN_DOC structure:
It’s very simple, in fact the field COMMUNICATION_CHANNEL has a different type among the homonymic structure of ZPRREAD_OUT_DOC and ZPROPEN_FOR_EDIT_OUT_DOC but they are very similar. The field CHANGE_LIST_ID is optional, in fact we can leave it empty and a new change list will be created or we can specify an open change list (for example the value returned by the open operation). Pay attention because the change operation modifies all the values in the COMMUNICATION_CHANNEL_CHANGE structures: so if you leave empty one of them, the operation assumes that you want to modify it with the empty value. The safest way is to modify the fields in the Communication Channel returned by the read/open operation and then copy the structures:
+data wa_change_cc type ZPRCOMMUNICATION_CHANNEL_RESTR.+
+ MOVE-CORRESPONDING wa_cc TO wa_change_cc.+
+ APPEND wa_change_cc TO src_change_req-communication_channel_change-communication_channel.+
Before calling the modify method we have to do further operations:
The first is to check the value of the field MASTER_LANGUAGE because although the read/open can give us any values the only two values admitted by the change are ‘EN’ and ‘DE’. If there isn’t one of them the change on the Communication Channel will fail and it will not be modified!
+if wa_cc-master_language ne ‘EN’ and wa_cc-master_language ne ‘DE’.+
+ wa_cc-master_language = ‘EN’.+
A same behaviour happens for the table DESCRIPTION:
Every line is made by two fields, a LANGUAGE_CODE and a text VALUE. If the line has the language code different from ‘EN’/ ‘DE’ it will be ignored by the change operations and it gives us only a warning. So we can code a simple form which reads the table DESCRIPTION of a Communication Channel and modify the LANGUAGE_CODE different from ‘EN’ and ‘DE’ (for the complete code see APPENDIX A):
+FORM TRANSLATE_DESCRIPTION CHANGING wa_cc TYPE ZPRCOMMUNICATION_CHANNEL.+
The last operation is to modify the value TRANSPORT_PROTOCOL_VERSION: In fact for file adapter this field is missing in the structures returned from read/open. But in the change, this field must be present with initial value otherwise the operation will fail!
If we analyze in more detail the structure ZRPCOMMUNICATION_CHANNEL_CREA1 we see another field called CONTROLLER:
This is a table and the lines are made by a field FIELD and a field VALUE. If we insert in this table a line with the name of an attribute and certain value, the xml generated by this proxy the field will be added with his default value (see for more details sap help (http://help.sap.com/saphelp_nwpi71/helpdata/en/73/3f5c3c3906b006e10000000a11402f/frameset.htm) page for more details):