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: 

GOS: How to create attachment from variable string ?

Jimmy21
Participant
0 Kudos

Hi folks.

I want to create a xml file from string variable, this string have xml content. I found this method to save any document in FB03 but selecting a local file:

CALL METHOD obj_gos->create_attachment

I want to create a xml file but with my variable content.

Thanks in advance.

10 REPLIES 10

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Simply open a file with OPEN DATASET in BINARY MODE and TRANSFER your string?

0 Kudos

This xml file should will save it in FB03 transaction.

raymond_giuseppi
Active Contributor
0 Kudos

Try creating document from your xml string with SO_DOCUMENT_INSERT and attach it to FI document with CL_BINARY_RELATION=>CREATE_LINK.

0 Kudos

Hi Raymond.

I found this tutorial and entered this values in parameters:

p_bo  : BKPF
p_key : [bukrs][doc number][year]
p_url : www.sdn.sap.com

But in FB03 don't created my attachment.

Insure you pass correct internal values (some space, or leading zeroes) Also debug your code as the provided sample just catch the errors but don't return any message/clue on errors (from authorization failures to wrong parameter data or type)

0 Kudos

Instead of BKPF, try passing FIPP and see

former_member185414
Active Contributor
0 Kudos

Hi,

What I understand is you have a variable which has XML data and you need to create an attachment from it.

Can you try using CL_GOS_API->INSERT_AL_ITEM.

Pass the Object details (InstanceId, CategoryId and TypeId) in IS_OBJECT and contents(Filename, AttachmentCategory, Filesize, Content_X, etc.) in IS_ATTCONT and check.

0 Kudos

Hi Ankit,

While trying to attach a .pdf using CL_GOS_API class my attachment category is of ARL(Archive link) type and the insert is not supported for this category yet {SGOS_MSG(E401)}. I would like to know if any OSS notes or alternatives are available to use this API class? My requirement is to create a PDF attachment using GOS and have the document stored at the content server.

Jelena
Active Contributor
0 Kudos

I'm guessing your goal is not to create a "file" but to create a GOS attachment. Those are different things, technically.

FWIW I've dissected the whole GOS process in this blog a while ago. I wouldn't just copy-paste the code since the blog is just very old but the concept explanation is still valid, I believe.

I've used very similar code (again, years ago) to create a program that reads a file into XSTRING variable and then creates a GOS attachment with that data. It works for PDF and XML, code is exactly the same (only the extension is different) since we're dealing with binary data.

1. cl_document_bcs=>xstring_to_solix to convert XSTRING to SOLIX type internal table

2. FM SO_FOLDER_ROOT_ID_GET

3. SO_DOCUMENT_INSERT_API1 (contents_hex = SOLIX type table from step 1; folder_id from step 2)

4. FM BINARY_RELATION_CREATE_COMMIT

Again - I'm not saying you must use these exact FMs (check the class Raymond mentioned instead). This is just an example of what works in our rather old system to outline the steps needed.

former_member185414
Active Contributor
0 Kudos

Hi Sumanth sumanth_pyaraka ,

I am not sure of the issue w.r.t PDF object in ARL category type. As far as I remember, generally we can upload PDF types but category type I don't remember. For SAP notes you should search below as a quick search did not reveal me anything.

https://support.sap.com/en/my-support/knowledge-base.html

Thanks.