Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

HTTP Properties Set – Set properties of a file on a web server

This function use the PROPPATCH method of HTTP 1.1 protocol to set the properties of a file on a web server.

ABAP
FUNCTION z_http_property_set.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(URI) TYPE  STRING
*"     VALUE(PROP_NAME) TYPE  STRING OPTIONAL
*"     VALUE(PROP_VALUE) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     VALUE(CODE) TYPE  I
*"     VALUE(REASON) TYPE  STRING
*"  TABLES
*"      TAB_PROP STRUCTURE  SMUM_XMLTB OPTIONAL
*"  EXCEPTIONS
*"      NO_LOGIN_ACCOUNT_AVAILABLE
*"      HTTP_COMMUNICATION_FAILURE
*"      HTTP_INVALID_STATE
*"      HTTP_PROCESSING_FAILED
*"----------------------------------------------------------------------
*    Proof of Concept by IperCube 2007
*"----------------------------------------------------------------------

  DATA: user TYPE string,
        pwd  TYPE string,
        x_bytes TYPE i.

* Set User/Password Logon to web server
  user = 'my_user'.
  pwd  = 'my_password'.
  
* Translate URL
  TRANSLATE uri USING ' *'.
  REPLACE ALL OCCURRENCES OF '*' IN uri WITH '%20' IN CHARACTER MODE.

******************************************************************
* Build XML request 
******************************************************************

  DATA: xml_table        TYPE TABLE OF smum_xmltb,
        wa_xml_table     TYPE smum_xmltb,
        xml_output       TYPE string.

  wa_xml_table-hier = 1.
  wa_xml_table-type = 'V'.
  wa_xml_table-cname = 'propertyupdate'.
  wa_xml_table-cvalue = ''.
  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 1.
  wa_xml_table-type = 'A'.
  wa_xml_table-cname = 'xmlns'.
  wa_xml_table-cvalue = 'DAV:'.
  APPEND wa_xml_table TO xml_table.

*  wa_xml_table-hier = 1.
*  wa_xml_table-type = 'A'.
*  wa_xml_table-cname = 'depth'.
*  wa_xml_table-cvalue = '0'.
*  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 2.
  wa_xml_table-type = 'V'.
  wa_xml_table-cname = 'set'.
  wa_xml_table-cvalue = ''.
  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 3.
  wa_xml_table-type = 'V'.
  wa_xml_table-cname = 'prop'.
  wa_xml_table-cvalue = ''.
  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 4.
  wa_xml_table-type = 'V'.


* Check for Single Propriety
  IF prop_name IS NOT INITIAL.
    wa_xml_table-cname = prop_name.
    wa_xml_table-cvalue = prop_value.
    APPEND wa_xml_table TO xml_table.
  ENDIF.

* Check for Many Proprieties
  IF tab_prop[] IS NOT INITIAL.
    DATA wa_prop TYPE smum_xmltb.
    LOOP AT tab_prop INTO wa_prop.
      wa_xml_table-cname  = wa_prop-cname.
      wa_xml_table-cvalue = wa_prop-cvalue.
      APPEND wa_xml_table TO xml_table.
    ENDLOOP.
  ENDIF.


* Create XML
  CALL FUNCTION 'SMUM_XML_CREATE'
    IMPORTING
      xml_output = xml_output
    TABLES
      xml_table  = xml_table.


******************************************************************
* Set Properties via HTTP 
******************************************************************

* Create HTTP_CLIENT object
  DATA: client TYPE REF TO if_http_client,
        timeout       TYPE i VALUE 0.

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url    = uri
    IMPORTING
      client = client.

* Authentication
  CALL METHOD client->authenticate
    EXPORTING
*    PROXY_AUTHENTICATION = ' '
*      CLIENT               = sy-mandt
      username             = user
      password             = pwd
*      LANGUAGE             = 'E'.

* Set Header Fields - method PROPPATCH
  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'PROPPATCH'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = '~server_protocol'
      value = 'HTTP/1.1'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = 'depth'
      value = 'infinity'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = 'content-type'
      value = 'text/xml'.

  x_bytes = STRLEN( xml_output ).

  CALL METHOD client->request->set_cdata
    EXPORTING
      data   = xml_output
      length = x_bytes.

* send and receive with HTTP server
  CALL METHOD client->send
    EXPORTING
      timeout                    = timeout
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  CASE sy-subrc.
    WHEN 1. RAISE http_communication_failure.
    WHEN 2. RAISE http_invalid_state.
    WHEN 3. RAISE http_processing_failed.
**    WHEN 4. RAISE others.
  ENDCASE.

  CALL METHOD client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  CASE sy-subrc.
    WHEN 1. RAISE http_communication_failure.
    WHEN 2. RAISE http_invalid_state.
    WHEN 3. RAISE http_processing_failed.
**    WHEN 4. RAISE others.
  ENDCASE.

* Get XML - just for fun
  DATA: xml_return TYPE string.
  xml_return = client->response->get_cdata( ).

* Get Global Status 
  CALL METHOD client->response->get_status
    IMPORTING
      code   = code
      reason = reason.

* close connection
  CALL METHOD client->close
    EXCEPTIONS
      http_invalid_state = 1
      OTHERS             = 2.

ENDFUNCTION.

Posted by ipercube


© 2026 Ipercube Design