Skip to Content
0
Former Member
Apr 13, 2009 at 07:23 PM

SCMS_AO_TABLE_GET - PDF Open Error

401 Views

Hi All,

Iu2019ve a required to attach a vendor invoice attached to Miro document stored using Archive Link.

I'm using SCMS_AO_TABLE_GET to get the archived document into internal table. The internal table is in binary format (1024).

Inoder to convert binary internal table from 1024 to 255 as required by SO_DOCUMENT_SEND_API1, I am converting the raw data using FM SCMS_BINARY_TO_FTEXT and followed by another function module to convert it to solisti1.

I do get an email with a PDF attached but when I click on PDF, it gives an error. Looks like there is some problem decoding the data.

Please help!

_____________________________________________________________________________________

Hereu2019s my piece of code.

DATA: binobject LIKE TBL1024 OCCURS 200,

archivobject LIKE DOCS OCCURS 200 WITH HEADER LINE,

length_bin TYPE I,

length_att TYPE I,

length_archive LIKE SAPB-LENGTH.

REFRESH: binobject, attachment.

CALL FUNCTION 'SCMS_AO_TABLE_GET'

EXPORTING

ARC_ID = archiv_id

DOC_ID = arc_doc_id

COMP_ID = 'data'

IMPORTING

LENGTH = length_bin

TABLES

DATA = binobject

EXCEPTIONS

error_http = 1

error_archiv = 2

error_kernel = 3

error_config = 4

others = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4

RAISING ERROR_RETRIEVAL.

ENDIF.

CALL FUNCTION 'SCMS_BINARY_TO_FTEXT'

EXPORTING

input_length = length_bin

IMPORTING

output_length = length_att

TABLES

binary_tab = binobject

ftext_tab = archivobject

EXCEPTIONS

failed = 1

others = 2.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4

RAISING ERROR_RETRIEVAL.

ENDIF.

length_att = length_bin.

length_archive = length_att.

CALL FUNCTION 'Z_WF_CONVERT_DOCTABLE_2_OFFICE'

EXPORTING

LENGTH = length_archive

TABLES

ARCHIVOBJECT = archivobject

ATTACHMENT = lt_objbin.

length = length_archive.

  • Email Attachment Details

CLEAR l_tab_lines.

DESCRIBE TABLE lt_objbin LINES l_tab_lines.

  • Creation of the entry for the compressed attachment

l_objpack-transf_bin = 'X'.

l_objpack-head_start = 1.

l_objpack-head_num = 1.

l_objpack-body_start = 1.

l_objpack-doc_type = 'PDF'.

l_objpack-obj_name = l_obj.

l_objpack-obj_descr = l_obj.

l_objpack-body_num = l_tab_lines.

l_objpack-doc_size = l_tab_lines * l_c_255.

APPEND l_objpack TO lt_objpack.

CLEAR l_objpack.

  • Completing the recipient list

l_reclist-receiver = p_email.

l_reclist-express = 'X'.

l_reclist-rec_type = 'U'.

APPEND l_reclist TO lt_reclist.

CLEAR l_reclist.

CONCATENATE 'GOS Attachment'(018)

sy-datum INTO l_obj SEPARATED BY space.

APPEND l_obj TO lt_objhead.

  • Email Body Details

CLEAR l_tab_lines.

DESCRIBE TABLE lt_objtxt LINES l_tab_lines.

l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 +

STRLEN( l_string ). "size of doc in bytes

l_doc_chng-obj_name = sy-repid.

l_doc_chng-obj_langu = sy-langu.

l_doc_chng-obj_descr = l_string.

l_doc_chng-sensitivty = 'P'.

  • Send the document

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_doc_chng

put_in_outbox = ' '

commit_work = 'X'

TABLES

packing_list = lt_objpack

object_header = lt_objhead

contents_bin = lt_objbin

contents_txt = lt_objtxt

  • contents_hex = lt_contents_hex

receivers = lt_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

ENDFUNCTION.

FUNCTION Z_WF_CONVERT_DOCTABLE_2_OFFICE.

*"----

-


""Lokale Schnittstelle:

*" IMPORTING

*" VALUE(LENGTH) LIKE SAPB-LENGTH

*" TABLES

*" ARCHIVOBJECT STRUCTURE DOCS

*" ATTACHMENT STRUCTURE SOLISTI1

*"----

-


  • Die ArchiveLink-API liefert das Dokument in einer internen

  • Tabelle, der Länge 1024 zurück.

  • SAP-Office-API benötigt eine interne Tabelle der Länge 255.

******

  • Diese Funktion konvertiert von der ArchiveLink-Tabelle in

  • die SAP-Office konforme Tabelle.

DATA: currentPos TYPE I, " Zeiger auf die Leseposition in

" der ArchiveLink-Tabelle

writePos TYPE I, " Zeiger auf Schreibposition

remain TYPE I, " Anzahl Zeichen in der aktuellen

" Zeile des ArchiveLink-Objektes,

" Max=255

written TYPE I, " Anzahl bytes übertragen

targetLines TYPE I, " Größe der Zieltabelle in Zeilen

lines_attachment TYPE I, " Anzahl der Zeilen im Attachement.

currentIndex TYPE I, " Aktuelle Zeile in der Quelltab.

line_out(255) TYPE C,

line_attachment TYPE solix,

line_len TYPE I. " Länge derselbigen

currentPos = 0.

writePos = 0.

REFRESH: attachment.

CLEAR: line_out, attachment.

targetLines = length / 255.

" Rest prüfen

remain = length - ( targetLines * 255 ).

IF remain <> 0. " Ja, noch eine Restzeile

ADD 1 TO targetLines.

ENDIF.

remain = 255. " Wieder initialisieren

currentIndex = 1.

WHILE lines_attachment <= targetLines.

READ TABLE archivobject INDEX currentIndex.

line_OutwritePos(remain) = archivobjectcurrentPos(remain).

" Concat schluckt spaces

written = remain.

line_len = writePos + remain. " writePos beginnt ja bei 1

writePos = writePos + remain.

IF writePos = 255. " Voll gefüllt, dann appenden

APPEND line_out TO attachment.

CLEAR line_out.

writePos = 0.

ELSEIF writePos > 255.

" exception

ENDIF.

" Jetzt prüfen, ob dies bereits der Rest der Quell-Zeile war.

" Wenn ja, dann müssen wir beim nächsten Durchlauf die

" nächste Zeile lesen.

IF currentPos > 769.

ADD 1 TO currentIndex.

" Und den Rest ausrechnen, mit dem die nächste Zeile

" noch gefüllt werden muss.

remain = currentPos + 255 - 1024.

*---> Insert part IIId

" Wenn die letzten Bytes exakt reingepaßt haben, dann eine

" neue volle zeile lesen

IF remain <= 0.

remain = 255.

ENDIF.

*<---- end of Insert

currentPos = 0.

ELSE. " Die aktuelle Zeile enthält noch genügend Bytes, um

" voll zu lesen.

ADD written TO currentPos. " Zeiger weiterschieben

IF currentPos > 769. " Nächste Zeile kann nicht mehr

" voll gefüllt werden, da keine

" 255 byte übrig sind

*---> Insert part IIId

IF currentPos >= 1024. " Hat genau bis zum Ende gereicht

remain = 255.

ADD 1 TO currentIndex.

currentPos = 0.

ELSE.

remain = 1024 - currentPos. " Rest ausrechnen

ENDIF.

*<---- end of Insert

ELSE.

remain = 255. " sonst voll befüllen

ENDIF.

ENDIF.

DESCRIBE TABLE attachment LINES lines_attachment.

ENDWHILE.

ENDFUNCTION.