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: 

Create Z program to append files to z-table.

Former Member
0 Kudos

Hi,

I need to create a Z program that will attach files to a Z table, how should I create this table to store files type attachments and if this is really possible,

thank you so much.

8 REPLIES 8

horst_keller
Product and Topic Expert
Product and Topic Expert

You need something like a table with a key and a RAWSTRING (BLOB) column. Convert the contents of the files to binary and store them in the BLOB column. The MIME repository delivered by SAP works like this.

Examples, how that can be done by streaming can be found here. The table key might be enhanced for columns that denote the file type etc. Streaming might become necessary for large files. Otherwise, you might INSERT normally.

0 Kudos

How about using Cluster tables like standard sap table INDX. Instead of insert statement we can use Export to database, import from database.

RJv

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

You can use export/import tables for this. But of course not INDX. INDX should not be used in production programs. You should create your own export/import tables that correspond to your needs.

former_member182550
Active Contributor

I would use the DMS for this. Store your files in the DMS and then store the DMS document number in your ZTable.

0 Kudos

Hi Harper,

Can you explain me better about this DMS mechanic?

thank you for the tips

0 Kudos

Hi Flavio, The DMS is pretty well documented in SAP. First you define a document type using transaction DC10, whether it should have versions, what statuses it can have etc etc. This is all under DC10. There are lots of sites on the web about how to do this.

As well as this you create a number range for your document type and copy or change include MCDOKZNR to cope with your number range - forms Number_Get_Next and External_Number_Check. You should also change the message class to your own (which is why I prefer to copy it) so that the messages have more meaning.

Then in your code you would use the following BAPI's:

BAPI_DOCUMENT_GETACTVERSION

BAPI_DOCUMENT_SETSTATUS

BAPI_DOCUMENT_ENQUEUE

BAPI_DOCUMENT_DELETE_DIRECT

BAPI_DOCUMENT_DEQUEUE

BAPI_DOCUMENT_CREATENEWVRS2

BAPI_DOCUMENT_CHANGE2

BAPI_DOCUMENT_CHECKIN2

BAPI_DOCUMENT_CREATE2

To display a PDF stored in the DMS for exampleyou could use:

BAPI_DOCUMENT_GETDETAIL2

SCMS_DOC_READ

SCMS_BINARY_TO_STRING

SCMS_BINARY_TO_XSTRING

SCMS_BASE64_ENCODE_STR

Rich

former_member235395
Contributor

Hi Flavio,

Did you check GOS solution? Using GOS, your Z program will create the attach files in GOS, and in your Z Table, you can store a records for each file attached, each record referencing to a file attached. So that when your Z program displays the attached file, you can also view it.

Maybe the solution is focused on the actions you will take with the attachment.

Regards,

Sandra_Rossi
Active Contributor
0 Kudos

As you can see, there are many ways to relate your files to "SAP standard" storages. If you really don't care about what they are, simply store the file as BLOB as Horst says, or give more information what you plan to do with these files.