Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP GOS Services add .txt textfiles in background or without dialog from lokal PC to GOS

frazer
Participant
0 Kudos
1,029

Hi i can't find a solution for following process:

This is the Code to show GOS in our custom transaction.

DATA: gref_manager TYPE REF TO cl_gos_manager,<br>      go_object    TYPE borident.<br><br>  go_object-objtype = 'ZVSDNUMMER'.<br>  go_object-objkey = gv_dnummer.  "e.g. 12345<br><br>  CREATE OBJECT gref_manager<br>    EXPORTING<br>      is_object    = go_object<br>      ip_no_commit = abap_false.

But we don't want to create the attachement with the GOS standard here.

We need to upload all .txt files from a local pc folder and add them to the GOS in background or without the standard dialog by hitting a custom button.

Does someone know a solution?

Thank you for help.

I think i found something.

https://www.inwerken.de/gos-anhange-auslesen-anlegen/

this would do it. now i only need a function module to get all .txt file names from a local pc directory. i think i will find this but thank you all for your fast reactions. 😃

Solution Code:
REPORT ztestgos.

DATA:
" Ordner
gs_folder TYPE soodk,

" Verknüpfung: Quelle & Ziel
gs_object TYPE sibflporb,
gs_objtgt TYPE sibflporb,

" Dokumenten-Grunddaten
gs_doc_info TYPE sofolenti1,
gs_doc_data TYPE sodocchgi1,
gd_doc_type TYPE soodk-objtp,

" Dokumenteninhalt binär
gt_contx TYPE solix_tab,

" Dateinformationen
gd_file TYPE string.
* gd_flen TYPE i.

DATA: lt_files TYPE STANDARD TABLE OF file_info,
l_cnt TYPE i,
ls_file TYPE file_info.

PARAMETERS:
" Eingabefelder für die ID des Business-Objekts
p_instid TYPE sibfboriid OBLIGATORY DEFAULT '12345', "000000000000001331
p_typeid TYPE sibftypeid OBLIGATORY DEFAULT 'ZVSDNUMMER', "BUS1001006
p_catid TYPE sibfcatid OBLIGATORY DEFAULT 'BO'.

START-OF-SELECTION.

*-- Get files
CALL METHOD cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = 'C:\TEMP\' "im_directory
filter = '*.TXT'
CHANGING
file_table = lt_files
count = l_cnt
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6.

LOOP AT lt_files INTO ls_file.

CONCATENATE 'C:\TEMP\' ls_file-filename INTO gd_file.

* gd_file = 'C:\TEMP\LGB.TXT'.

" Datei hochladen
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
filetype = 'BIN'
IMPORTING
filelength = ls_file-filelength "gd_flen
TABLES
data_tab = gt_contx
EXCEPTIONS
OTHERS = 1.

" Root-Folder der GOS ermitteln
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = gs_folder.

" Dateiinfo in Dokumenteninfo übernehmen
CALL FUNCTION 'CH_SPLIT_FILENAME'
EXPORTING
complete_filename = gd_file
IMPORTING
extension = gd_doc_type
name = gs_doc_data-obj_descr
name_with_ext = gs_doc_data-obj_name.
TRANSLATE gd_doc_type TO UPPER CASE.

gs_doc_data-doc_size = ls_file-filelength. "gd_flen.

" Dokument anlegen
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
folder_id = gs_folder
document_data = gs_doc_data
document_type = gd_doc_type
IMPORTING
document_info = gs_doc_info
TABLES
contents_hex = gt_contx.

" Businessobjekt-ID übernehmen
gs_object-instid = p_instid.
gs_object-typeid = p_typeid.
gs_object-catid = p_catid.

" Dokumentdaten als Ziel
* CONCATENATE gs_folder gs_doc_info-object_id
* INTO gs_objtgt-instid RESPECTING BLANKS.

" Alternative:
gs_objtgt-instid = gs_doc_info-doc_id.
gs_objtgt-typeid = 'MESSAGE'.
gs_objtgt-catid = 'BO'.

TRY.
" Verknüpfung anlegen
cl_binary_relation=>create_link(
EXPORTING
is_object_a = gs_object
is_object_b = gs_objtgt
ip_reltype = 'ATTA' ).
COMMIT WORK AND WAIT.
* COMMIT WORK.
CATCH cx_obl_parameter_error cx_obl_model_error cx_obl_internal_error.
ENDTRY.

ENDLOOP.
3 REPLIES 3

raymond_giuseppi
Active Contributor
876

Try to create you own class to upload a whole directory to GOS and add it to the GOS menu (*) or trigger it automatically at some event of the main transaction.

Where are you stuck?

(*) Transaction SGOS (table SGOSCUST) also you could use BAdI GOS_SRV_SELECT to filter this option for non-handled objects

Tomas_Buryanek
Active Contributor
0 Kudos
876

Hello,

what have you tried so far and where did you got stuck?

Basically your program/method should:

  • read list of files from folder
  • upload files one by one
  • create GOS Attachment with each file

To create a GOS attachment I recommend to use:

DATA(lo_gos_api) = cl_gos_api=>create_instance( ... ).
"And then:
lo_gos_api->insert_al_item( ... ). "Do not forget Try/catch and COMMIT is needed. "There should be examples online or in your system/s with usage of this class/method
-- Tomas --

0 Kudos
876

hi thank you i found something and posted the link above but i think your solution would fit to.