‎2011 Jul 15 10:38 AM
Hi all,
Im facing the following problem, I have created an ABAP program that is monitoring Idocs. The program will send an Alert by SMS to certain users by doing an external HTTP request . This is working fine when the program is executed in the foreground. In the background however no SMS messages are sent.
METHOD send_alert_by_sms.
DATA:
lv_url TYPE string,
lv_value TYPE string,
lv_return_code TYPE sysubrc,
lv_message TYPE string.
DATA:
lo_client TYPE REF TO if_http_client.
lv_url = 'http://<some_service>.asp'.
* Get http client instance
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
me->mo_appl_log->add_message( ).
ENDIF.
* set method
lo_client->request->set_header_field( EXPORTING name = '~request_method'
value = 'POST' ).
* Type of request (0 = Plain Text message)
lo_client->request->set_form_field( EXPORTING name = 'REQUESTTYPE'
value = '0' ).
* Originator address
lo_client->request->set_form_field( EXPORTING name = 'OADC'
value = 'ITF Alert' ).
* Type of originator address ( 2 = ASCII )
lo_client->request->set_form_field( EXPORTING name = 'OADCTYPE'
value = '2' ).
* Message ID
lv_value = me->ms_edidc-docnum.
lo_client->request->set_form_field( EXPORTING name = 'MESSAGEID'
value = lv_value ).
* The recipient mobile phone number
lv_value = me->ms_alert-tel_number.
lo_client->request->set_form_field( EXPORTING name = 'NUMBERS'
value = lv_value ).
* Message body text
MESSAGE i002(zalert) WITH me->ms_edidc-idoctp
me->ms_edidc-status
me->ms_edidc-docnum INTO lv_value.
lo_client->request->set_form_field( EXPORTING name = 'BODY'
value = lv_value ).
* Send http request to server
CALL METHOD lo_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL METHOD lo_client->get_last_error
IMPORTING
code = lv_return_code
MESSAGE = lv_message.
MESSAGE i000(sr) WITH lv_message INTO lv_message.
me->mo_appl_log->add_message( ).
ENDIF.
ENDMETHOD. "send_alert_by_SMS
The HTTP request is authenticated by source IP address by the external system (is it the same during background processing?)
Does anyone know what the problem might be? Or maybe have an alternate solution to executing the HTTP request?
Thanks in Advance,
Kind regards,
Sandor
‎2011 Jul 15 12:22 PM
with this method should be the application server who is making the call, not your pc, so is the only option for batch processing. maybe you have more than one application server and job runs into someone of them who has not network access to the desired url. in that case speak with admins to check network access from all application servers
‎2011 Jul 15 12:22 PM
with this method should be the application server who is making the call, not your pc, so is the only option for batch processing. maybe you have more than one application server and job runs into someone of them who has not network access to the desired url. in that case speak with admins to check network access from all application servers
‎2011 Jul 15 1:42 PM
The problem was solved by adding the following code:
* Get http response from server
CALL METHOD lo_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL METHOD lo_client->get_last_error
IMPORTING
code = lv_return_code
MESSAGE = lv_message.
MESSAGE i000(sr) WITH lv_message INTO lv_message.
me->mo_appl_log->add_message( ).
ENDIF.