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 MkCol – Create a folder on a web server

This function use the MKCOL method of HTTP 1.1 protocol to create a folder on a web server. It create also the parent folders.

ABAP
FUNCTION z_http_MKCOL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(URI) TYPE  STRING
*"  EXPORTING
*"     VALUE(CODE) TYPE  I
*"     VALUE(REASON) TYPE  STRING
*"  EXCEPTIONS
*"      NO_LOGIN_ACCOUNT_AVAILABLE
*"      HTTP_COMMUNICATION_FAILURE
*"      HTTP_INVALID_STATE
*"      HTTP_PROCESSING_FAILED
*"----------------------------------------------------------------------
*    IperCube 2008
*"----------------------------------------------------------------------

  DATA: user TYPE string,
        pwd  TYPE string.

* 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.

* Loop on Path and create ancestors (no problem if already exist)
  DATA: itab_elements TYPE TABLE OF string,
        str_element   TYPE string,
        uri_partial   TYPE string.

  REPLACE 'http://' IN uri WITH ''.
  REPLACE 'HTTP://' IN uri WITH ''.

  SPLIT uri AT '/' INTO TABLE itab_elements.

  LOOP AT itab_elements INTO str_element.

    IF sy-tabix = 1.
      CONCATENATE 'http://' str_element INTO uri_partial.

    ELSE.
      CONCATENATE uri_partial '/' str_element INTO uri_partial.

      PERFORM create_directory USING uri_partial user pwd
                               CHANGING code reason.
    ENDIF.

  ENDLOOP.

ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  create_directory
*&---------------------------------------------------------------------*
FORM create_directory USING uri_partial user pwd CHANGING code reason.

* 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_partial
    IMPORTING
      client = client.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

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

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

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

* 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.

  CALL METHOD client->response->get_status
    IMPORTING
      code   = code
      reason = reason.

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

ENDFORM.                    "create_directory

Posted by ipercube


© 2026 Ipercube Design