"-Begin-----------------------------------------------------------------
Report  Z_ARCHIVEFILE.

  Data: tabFileName Type filetable,
        rc Type sy-subrc,
        UserAction Type i,
        ArcDocID Type toa01-arc_doc_id.

  "-GUI-----------------------------------------------------------------
  Parameter FileName Type sapb-sappfad Lower Case.
  Parameter ContRep Type toaar-archiv_id.
  Parameter DocTyp Type toadd-doc_type.
  Selection-Screen Skip 1.
  Parameter BusObj Type toaom-sap_object.
  Parameter ArObj Type toaom-ar_object.
  Parameter ObjID Type sapb-sapobjid Lower Case.
  Selection-Screen Skip 1.
  Selection-Screen PushButton /1(79) ArcDoc User-Command ArcDoc.
  Selection-Screen Skip 1.
  Parameter DocID Type toa01-arc_doc_id.

  "-Initialization------------------------------------------------------
  Initialization.
    ArcDoc = 'Put document into archive'(001).

  "-Event press button to select file-----------------------------------
  At Selection-Screen On Value-Request For FileName.

    Clear FileName.
    Clear tabFileName.

    Call Method cl_gui_frontend_services=>file_open_dialog
      Exporting
        window_title = 'Datei zum Upload in das Archiv'
        multiselection = abap_false
        file_filter = '*.*'
      Changing
        file_table = tabFileName
        rc = rc
        user_action = UserAction.

    If UserAction = 0.
      Read Table tabFileName Into FileName Index 1.
    EndIf.

  "-Main----------------------------------------------------------------
  At Selection-Screen.

    Case sy-ucomm.
      When 'ARCDOC'.

        Call Function 'ARCHIVOBJECT_CREATE_FILE'
          Exporting
            ARCHIV_ID = ContRep
            DOCUMENT_TYPE = DocTyp
            PATH = FileName
          Importing
            ARCHIV_DOC_ID = ArcDocID
          Exceptions
            ERROR_ARCHIV = 1
            ERROR_COMMUNICATIONTABLE = 2
            ERROR_UPLOAD = 3
            ERROR_KERNEL = 4
            OTHERS = 5.

          If sy-subrc = 0.
            DocID = ArcDocID.

            Call Function 'ARCHIV_CONNECTION_INSERT'
              Exporting
                ARCHIV_ID = ContRep
                ARC_DOC_ID = ArcDocID
                AR_OBJECT = ArObj
                OBJECT_ID = ObjID
                SAP_OBJECT = BusObj
                DOC_TYPE = DocTyp
              Exceptions
                ERROR_CONNECTIONTABLE = 1
                OTHERS = 2.

              If sy-subrc = 0.
                Message 'Success' Type 'S'.
              Else.

                Call Function 'ARCHIVOBJECT_DELETE'
                  Exporting
                    ARCHIV_ID = ContRep
                    ARCHIV_DOC_ID = ArcDocID
                  Exceptions
                    ERROR_ARCHIV = 1
                    ERROR_COMMUNICATIONTABLE = 2
                    ERROR_KERNEL = 3
                    OTHERS = 4.

                Message 'Connection insert not successful' Type 'E'.
              EndIf.

          Else.
            Message 'Archiving not successful' Type 'E'.
          EndIf.

    EndCase.

"-End-------------------------------------------------------------------