Code: Alles auswählen.
FUNCTION-POOL zamc_test.
DATA:
gd_message TYPE string.
CLASS lcl_amc_test_text DEFINITION FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_amc_message_receiver_text .
ENDCLASS.
CLASS lcl_amc_test_text IMPLEMENTATION.
METHOD if_amc_message_receiver_text~receive.
gd_message = i_message.
ENDMETHOD.
ENDCLASS.
Code: Alles auswählen.
FUNCTION zamc_test_receiver.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" EXPORTING
*" VALUE(ED_MESSAGE) TYPE STRING
*" VALUE(ED_EXCEPTION) TYPE STRING
*"----------------------------------------------------------------------
DATA:
lr_consumer TYPE REF TO if_amc_message_consumer,
lr_receiver_text TYPE REF TO lcl_amc_test_text.
CLEAR ed_message.
TRY.
lr_consumer = cl_amc_channel_manager=>create_message_consumer( i_application_id = 'ZAMC_TEST'
i_channel_id = '/ping' ).
lr_receiver_text = NEW #( ).
" start of message delivery
lr_consumer->start_message_delivery( i_receiver = lr_receiver_text ).
CATCH cx_root INTO DATA(lx_root).
ed_exception = lx_root->get_text( ).
ENDTRY.
WAIT FOR MESSAGING CHANNELS UNTIL gd_message IS NOT INITIAL.
ed_message = gd_message.
ENDFUNCTION.
Code: Alles auswählen.
REPORT zamc_test_receiver.
DATA:
gd_task TYPE tw_task_id,
gd_message TYPE string.
PARAMETERS: pa_lis TYPE abap_bool RADIOBUTTON GROUP 1 DEFAULT 'X'.
PARAMETERS: pa_fub TYPE abap_bool RADIOBUTTON GROUP 1.
PARAMETERS: pa_cfw TYPE abap_bool RADIOBUTTON GROUP 1.
PARAMETERS: pa_dyn TYPE abap_bool RADIOBUTTON GROUP 1.
PARAMETERS: pa_sub TYPE abap_bool RADIOBUTTON GROUP 1.
START-OF-SELECTION.
SET PF-STATUS 'AMC_TEST'.
WRITE: 'Preparing Test Environment'.
SET USER-COMMAND 'REFRESH'.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'REFRESH'.
PERFORM refresh_message.
ENDCASE.
FORM refresh_message.
DATA:
ld_continue TYPE abap_bool.
PERFORM cancel_receiver.
PERFORM register_receiver CHANGING ld_continue.
IF ld_continue EQ abap_true.
CLEAR sy-lsind.
WRITE: 'Message:', gd_message.
ELSE.
LEAVE PROGRAM.
ENDIF.
ENDFORM.
FORM register_receiver CHANGING cd_continue.
DATA:
ld_message TYPE text255.
CLEAR cd_continue.
gd_task = 'TEST_TASK'.
CALL FUNCTION 'ZAMC_TEST_RECEIVER'
DESTINATION 'NONE'
STARTING NEW TASK gd_task
PERFORMING receive_message ON END OF TASK
EXCEPTIONS
system_failure = 1 MESSAGE ld_message
communication_failure = 2 MESSAGE ld_message
resource_failure = 3
OTHERS = 4.
* TO-DO: Propper RFC-Error-Handling
cd_continue = abap_true.
ENDFORM.
FORM cancel_receiver.
CALL FUNCTION 'RFC_CONNECTION_CANCEL'
EXPORTING
taskname = gd_task
close_connection = abap_true
EXCEPTIONS
task_not_open = 1
OTHERS = 2.
CLEAR gd_task.
ENDFORM.
FORM receive_message USING ud_task TYPE clike.
DATA:
ld_exception TYPE string,
ld_result TYPE string,
ld_message TYPE text255.
CLEAR gd_task.
RECEIVE RESULTS FROM FUNCTION 'ZAMC_TEST_RECEIVER'
IMPORTING
ed_message = ld_result
ed_exception = ld_exception
EXCEPTIONS
system_failure = 1 MESSAGE ld_message
communication_failure = 2 MESSAGE ld_message
OTHERS = 3.
* TO-DO: Propper RFC-Error-Handling
IF ld_exception IS NOT INITIAL.
MESSAGE |EXCEPTION: { ld_exception }| TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
gd_message = ld_result.
PERFORM output_message.
ENDIF.
ENDFORM.
FORM output_message.
DATA:
ld_fcode TYPE syucomm.
CASE abap_true.
WHEN pa_fub.
CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'
EXPORTING
functioncode = 'REFRESH'
EXCEPTIONS
function_not_supported = 1
OTHERS = 2.
WHEN pa_cfw.
cl_gui_cfw=>set_new_ok_code( new_code = 'REFRESH' ).
cl_gui_cfw=>flush( ).
WHEN pa_lis.
SET USER-COMMAND 'REFRESH'.
WHEN pa_sub.
SUBMIT zamc_test_message
WITH pa_msg EQ gd_message
AND RETURN.
WHEN pa_dyn.
ld_fcode = 'REFRESH'.
CALL 'DYNP_OKCODE_SET' ID 'FCODE' FIELD ld_fcode.
ENDCASE.
ENDFORM.
Code: Alles auswählen.
REPORT zamc_test_sender.
PARAMETERS pa_msg TYPE string LOWER CASE.
START-OF-SELECTION.
PERFORM send_message.
FORM send_message.
TRY.
CASE TYPE OF cl_amc_channel_manager=>create_message_producer( i_application_id = 'ZAMC_TEST'
i_channel_id = '/ping' ).
WHEN TYPE if_amc_message_producer_text INTO DATA(lr_producer_text).
lr_producer_text->send( i_message = pa_msg ).
ENDCASE.
CATCH cx_root INTO DATA(lx_root).
MESSAGE lx_root TYPE 'E'.
ENDTRY.
ENDFORM.
Code: Alles auswählen.
REPORT zamc_test_message.
PARAMETERS: pa_msg TYPE string.
Und wie wäre es mit einem DO... times. WAIT FOR MESSAGNING CHANNELS up to x seconds. ENDDO.a-dead-trousers hat geschrieben: ↑12.11.2024 14:59WAIT FOR MESSAGING CHANNELS kann ich in der SAPgui Applikation leider nicht machen, weil dann das Programm "hängen" würde.
Code: Alles auswählen.
CALL FUNCTION func STARTING NEW TASK task
[{CALLING meth}|{PERFORMING subr} ON END OF TASK].
Mit diesem Zusatz kann entweder eine Methode meth oder ein Unterprogramm subr als Callback-Routine angegeben werden, die zur Ausführung registriert wird, nachdem der asynchron aufgerufene Funktionsbaustein beendet wurde.
Danke, aber das hab ich schon gemacht. Siehe Coding.tar hat geschrieben: ↑Heute 05:55Vielleicht damit:
Code: Alles auswählen.
CALL FUNCTION func STARTING NEW TASK task [{CALLING meth}|{PERFORMING subr} ON END OF TASK].
Mit diesem Zusatz kann entweder eine Methode meth oder ein Unterprogramm subr als Callback-Routine angegeben werden, die zur Ausführung registriert wird, nachdem der asynchron aufgerufene Funktionsbaustein beendet wurde.
Aber es "hängt" trotzdem.black_adept hat geschrieben: ↑Gestern 15:38Und wie wäre es mit einem DO... times. WAIT FOR MESSAGNING CHANNELS up to x seconds. ENDDO.a-dead-trousers hat geschrieben: ↑12.11.2024 14:59WAIT FOR MESSAGING CHANNELS kann ich in der SAPgui Applikation leider nicht machen, weil dann das Programm "hängen" würde.
Damit "hängt" das Programm nur so lange du möchtest.
Das ist IMHO auch nervig, wenn die Applikation immer wieder mal "nicht reagiert" (PAI/PBO Lauf) und dann wenn sie reagieren sollte, verspätet reagiert.