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: 

Download GOS Objects to Application Server in background

Former Member
0 Kudos

I had to download GOS Attachemtns via a batch job - i.e the Attachment needs to be downloaded to app server.

I am not able to find an out of box solution in SAP.So after a bit of research here is the code that I put together and it works perfect:

Code Snippet for Downloading Custom GOS Attachment to Application Server

<code removed by moderator>

Moderator message: please limit yourself to the necessary code parts, stay under 5000 characters altogether to preserve proper formatting, use code tags.

Edited by: Thomas Zloch on Jan 9, 2011 4:37 PM

3 REPLIES 3

Former Member
0 Kudos

Here is the shorter version:

DATA: BEGIN OF i_key OCCURS 0,

instid_a LIKE srgbtbrel-instid_a,

instid_b LIKE srgbtbrel-instid_b,

END OF i_key.

DATA: i_sood LIKE STANDARD TABLE OF sood WITH HEADER LINE.

DATA: BEGIN OF fs_key,

foltp LIKE sood4-foltp,

folyr LIKE sood4-folyr,

folno LIKE sood4-folno,

objtp LIKE sood-objtp,

objyr LIKE sood-objyr,

objno LIKE sood-objno,

END OF fs_key.

DATA: p_objcont LIKE soli OCCURS 0,

p_objhead LIKE soli OCCURS 0,

context LIKE sdokpropty OCCURS 0 WITH HEADER LINE.

DATA: objkey LIKE borident-objkey,

comp_id(255),docid(40),

crepid(30) VALUE 'SOFFDB',

wa_objcont LIKE soli,

binary_flg TYPE sdok_binfl,

data_txt LIKE sdokcntasc OCCURS 1,

data_binLIKE sdokcntbin OCCURS 1,

wa_bin LIKE sdokcntbin, size TYPE i,

mimetype TYPE c,

tab_lines LIKE sy-tabix,

len TYPE i,

context_wa LIKE sdokpropty,

docid1 TYPE sdokobject,

v_file LIKE rlgrap-filename,

owner LIKE soud-usrnam,

phio_object LIKE sdokobject,

sw_document LIKE sood4,

doc_id LIKE soodk,

fol_id LIKE soodk.

CONSTANTS: so_kpro_id(17) VALUE '&SO_KProObjectID=',

so_kpro_context(16) VALUE '&SO_KProContext&',

c_filename(12) VALUE '&SO_FILENAME'.

SELECT instid_a instid_b FROM srgbtbrel INTO TABLE i_key

WHERE typeid_a EQ typeid_a "'ZGOS'

AND instid_a EQ objkey "key to which Attachment is linked

AND reltype EQ reltype. "'ATTA'

  • Get All the attachments per Object Key

LOOP AT i_key.

CLEAR: fs_key, fol_id.

MOVE i_key-instid_b TO fs_key.

MOVE: fs_key-foltp TO fol_id-objtp,

fs_key-folno TO fol_id-objno,

fs_key-folyr TO fol_id-objyr.

MOVE-CORRESPONDING fs_key TO doc_id.

Select attachments

SELECT * FROM sood INTO TABLE i_sood

WHERE objno EQ fs_key-objno

AND objtp EQ fs_key-objtp

AND objyr EQ fs_key-objyr.

IF NOT i_sood[] IS INITIAL.

LOOP AT i_sood.

MOVE-CORRESPONDING i_sood TO sw_document.

MOVE-CORRESPONDING fs_key TO sw_document.

sw_document-file-ext returns a value of pdf or doc or xls and is not useful

CALL FUNCTION 'SO_OBJECT_READ'

EXPORTING

folder_id = fol_id

forwarder = sw_document-fornam

object_id = doc_id

owner = owner

TABLES

objcont = p_objcont

objhead = p_objhead

EXCEPTIONS.

l_param = c_filename.

PERFORM objhead_param_get_internal USING p_objhead[] CHANGING l_param l_value l_tabix.

consider the File extension from below as it returns pdf or docx or xlsx etc

  • &SO_FILENAME

IF l_value IS INITIAL.

LOOP AT p_objhead INTO wa_objhead.

IF wa_objhead-line(12) EQ c_filename.

SPLIT wa_objhead-line AT '=' INTO v1 v2 .

MOVE v2 TO comp_id.

CONCATENATE directory v2 INTO v_file.

EXIT.ENDIF.ENDLOOP.

ELSE.

MOVE l_value TO comp_id.CONCATENATE directory l_value INTO v_file.ENDIF.

CLEAR wa_objcont.

LOOP AT p_objcont INTO wa_objcont.

IF wa_objcont(17) = so_kpro_id.

docid1 = wa_objcont+17.CONTINUE.ENDIF.

IF wa_objcont(16) = so_kpro_context.

context_wa = wa_objcont+16.

APPEND context_wa TO context.

CONTINUE.ENDIF.ENDLOOP.

CALL FUNCTION 'SO_LOIO_PHIO_GET'

EXPORTING

loio_object = docid1

IMPORTING

phio_object = phio_object

TABLES

context = context

EXCEPTIONS.

docid = phio_object+8.

CONDENSE docid NO-GAPS.

  • Get the Content of the attachment from Database

CLEAR: data_txt[], data_bin[].

CALL FUNCTION 'SCMS_R3DB_GET'

EXPORTING

crep_id = crepid "'SOFFDB'

doc_id = docid

mandt = sy-mandt

comp_id = comp_id

IMPORTING

binary_flg = binary_flg

comp_size = size

mimetype = mimetype

TABLES

data_txt = data_txt

data_bin = data_bin.

  • size of the attachment in binary format (1022 chars per line)

DESCRIBE TABLE data_bin LINES tab_lines.

CALL FUNCTION 'HR_CA_DOWNLOAD_TO_APPSERVER'

EXPORTING

filename = v_file

filesize = size

IMPORTING

bytes_transfered = len

TABLES

data_tab = data_bin.

endloop.

form OBJHEAD_PARAM_GET_INTERNAL using objhead type soli_tab

changing param type c

value type c

tabix type sytabix.

data: soli type soli,

found type c,

moff type i,

l_param_search type soli-line,

l_param_head type soli-line,

l_tabix type sytabix.

clear: value, tabix.

find '=' in param match offset moff.

if moff > 0.

param = param(moff).

endif.

l_param_search = param.

translate l_param_search to upper case.

loop at objhead into soli.

l_tabix = sy-tabix.

clear moff.

find '=' in soli-line match offset moff.

check sy-subrc = 0.

l_param_head = soli(moff).

translate l_param_head to upper case.

if l_param_head = l_param_search.

add 1 to moff.

value = soli+moff.

tabix = l_tabix.

return.

endif.

endloop.

endform.

0 Kudos

In the above code, SO_OBJECT_READ does not return proper file name.

So take the file name from sw_document-objdes and file extension from p_objhead (returned by So_OBJECT_READ) and then read the contents and further.

0 Kudos

This message was moderated.