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 Copy – Copy a file on the same web server

This function use the COPY method of HTTP 1.1 protocol to copy a file on the same web server.

ABAP
FUNCTION z_http_COPY.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(URI_SOURCE) TYPE  STRING
*"     VALUE(URI_TARGET) 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
*"      HTTP_SEND_RECEIVE_ERROR
*"      OTHERS
*"----------------------------------------------------------------------
*   IperCube 02.2008
*"----------------------------------------------------------------------
*   http method COPY
*"----------------------------------------------------------------------

  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_source USING ' *'.
  REPLACE ALL OCCURRENCES OF '*' IN uri_source WITH '%20' IN CHARACTER MODE.

  TRANSLATE uri_target USING ' *'.
  REPLACE ALL OCCURRENCES OF '*' IN uri_target WITH '%20' IN CHARACTER MODE.

* 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_source
    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 = 'COPY'.

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

* Set Destination URL
  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = 'destination'
      value = uri_target.


* Send Request via HTTP
  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 http_send_receive_error.
  ENDCASE.

* Receive Response via HTTP
  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 http_send_receive_error.
  ENDCASE.

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

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

  CASE sy-subrc.
    WHEN 1. RAISE http_invalid_state.
    WHEN 2. RAISE others.
  ENDCASE.

ENDFUNCTION.

Posted by ipercube


© 2026 Ipercube Design