Application Development and Automation 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: 
Read only

Regarding GOS create attachment

Former Member
0 Likes
1,695

Hi all,

I have a issue in my program.

I am trying to attach a .doc, .pdf document to a customs declaration document.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

TABLES

data_tab = lt_doc_content.

ENDCASE.

I am using the above code to read the file... from the presentaion server.

The file is attached, but the .doc or the .pdf file is corrupted....

do I need to give any specfic file type in the function module like 'BIN', 'DAT', 'ASC'...

Kindly help.......

Thanks in advance.

Jaffer Ali.S

Hi all,

I have a issue in my program.

I am trying to attach a .doc, .pdf document to a customs declaration document.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

TABLES

data_tab = lt_doc_content.

ENDCASE.

I am using the above code to read the file... from the presentaion server.

The file is attached, but the .doc or the .pdf file is corrupted....

do I need to give any specfic file type in the function module like 'BIN', 'DAT', 'ASC'...

Kindly help.......

Thanks in advance.

Jaffer Ali.S

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
962

Yes, you should use BIN.

Regards,

RIch Heilman

Read only

0 Likes
962

Hi Rich,,

I tried it... but still not working....

here is the code...

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filetype = 'BIN'

filename = p_file

TABLES

data_tab = lt_doc_content.

do i need to give any other parameters...

Thanks in advance,

Jaffer Ali.S

Read only

0 Likes
962

What is not working? LT_DOC_CONTENT is not being filled?

Regards,

RIch Heilman

Read only

0 Likes
962

Hi Rich,

The table is filled....

When I tryed listing the document in the Customs Declaration screen the document is attached, but when I opened it.. the word document has junk values...

when it is pdf... I cannot open... it tells the characters are not decoded.

Help me on this issue please....

Thanks,

Jaffer Ali.S

Read only

0 Likes
962

Post your code...

REgards,

RIch HEilman

Read only

0 Likes
962

Here is my code...

&----


*& Report ZGTS0001

*&

&----


*&

*&

&----


REPORT ZGTS0001.

  • Include for BO macros

INCLUDE : <cntn01>.

PARAMETERS:

P_BOTYPE LIKE borident-OBJTYPE DEFAULT 'BUS6800',

P_BO_ID LIKE borident-OBJKEY DEFAULT '10000000022007',

P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'TXT',

P_DOCTY LIKE borident-OBJTYPE DEFAULT 'MESSAGE',

P_RELTYP LIKE BRELTYP-RELTYPE DEFAULT 'ATTA',

P_FNAME like rlgrap-filename Default 'v:\test.doc'.

  • P_FNAME like rlgrap-filename Default

  • '\At2a2\Vol4\Depts\Isprog\files\ports.txt'.

types: BEGIN OF TY_MESSAGE_KEY,

FOLTP TYPE SO_FOL_TP,

FOLYR TYPE SO_FOL_YR,

FOLNO TYPE SO_FOL_NO,

DOCTP TYPE SO_DOC_TP,

DOCYR TYPE SO_DOC_YR,

DOCNO TYPE SO_DOC_NO,

FORTP TYPE SO_FOR_TP,

FORYR TYPE SO_FOR_YR,

FORNO TYPE SO_FOR_NO,

END OF TY_MESSAGE_KEY.

DATA : LV_MESSAGE_KEY type TY_MESSAGE_KEY.

DATA : LO_MESSAGE type SWC_OBJECT.

DATA : LT_DOC_CONTENT type standard table of SOLI-LINE

with header line.

DATA: p_file TYPE string.

  • First derive the Attachment's ( MESSAGE )document type.

P_DOCTY = 'MESSAGE'.

CASE P_RELTYP.

  • In case of URls

WHEN 'URL'.

P_MSGTYP = 'URL'.

  • In case of Notes / Private Notes

WHEN 'NOTE' OR 'PNOT'.

P_MSGTYP = 'RAW'.

WHEN 'ATTA'.

  • Take given parameter e.g. 'DOC', 'PDF' etc.

  • P_MSGTYP = 'EXT'.

WHEN OTHERS.

  • ....exit

EXIT.

ENDCASE.

  • Create an initial instance of BO 'MESSAGE' - to call the

  • instance-independent method 'Create'.

swc_create_object LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.

  • define container to pass the parameter values to the method call

  • in next step.

swc_container LT_MESSAGE_CONTAINER.

  • Populate container with parameters for method

swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' 'JafDoc1'.

swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' 'E'.

swc_set_element LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'.

swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTNAME' P_DOCTY.

swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' P_MSGTYP.

  • In case of URLs..it should be concatenated with &KEY& in the begining.

CASE P_MSGTYP.

WHEN 'URL'.

LT_DOC_CONTENT = '&KEY&http://www.rmtiwari.com' .

append LT_DOC_CONTENT.

  • In case of Notes or Private Notes, get the data from files on appl

  • server or from wherever(? - remember background).

WHEN 'RAW'.

LT_DOC_CONTENT = 'Hi How r u?' .

append LT_DOC_CONTENT.

  • In case of PC File attachments

WHEN OTHERS.

  • OPEN DATASET P_FNAME FOR INPUT IN BINARY MODE.

  • IF SY-subrc EQ 0.

  • DO.

  • READ DATASET P_FNAME INTO LT_DOC_CONTENT.

  • IF SY-subrc EQ 0.

  • append LT_DOC_CONTENT.

    • message i000(mtxt) with 'Inside'.

  • ELSE.

  • append LT_DOC_CONTENT.

    • message i000(mtxt) with 'else'.

  • EXIT.

  • ENDIF.

  • ENDDO.

  • CLOSE DATASET P_FNAME.

  • else.

  • message i000(vtxt) with 'Operation failed...'.

  • ENDIF.

MOVE p_fname TO p_file.

message i000(mtxt) with p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filetype = 'BIN'

filename = p_file

TABLES

data_tab = lt_doc_content.

ENDCASE.

  • message i000(mtxt) with 'Outside function module gui_upload'.

  • 'DocumentContent' is a multi-line element ( itab ).

swc_set_table LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT.

  • Size is required in case of File attachments

data : LV_DOC_SIZE type i.

data : L_FILE_LINES type i.

DESCRIBE TABLE LT_DOC_CONTENT LINES L_FILE_LINES.

READ TABLE LT_DOC_CONTENT INDEX L_FILE_LINES.

LV_DOC_SIZE = ( 255 * ( L_FILE_LINES - 1 ) ) +

STRLEN( LT_DOC_CONTENT ).

swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_DOC_SIZE .

  • Refresh to get the reference of create 'MESSAGE' object for attachment

swc_refresh_object LO_MESSAGE.

swc_call_method LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.

  • Get Key of new object

swc_get_object_key LO_MESSAGE LV_MESSAGE_KEY.

  • Now we have attachment as a business object instance. We can now

  • attach it to our main business object instance.

  • Create main BO object_a

data: LO_IS_OBJECT_A type BORIDENT.

LO_IS_OBJECT_A-OBJKEY = P_BO_ID.

LO_IS_OBJECT_A-OBJTYPE = P_BOTYPE.

  • LO_IS_OBJECT_A-CATID = 'BO'.

  • Create attachment BO object_b

data: LO_IS_OBJECT_B type BORIDENT.

LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY.

LO_IS_OBJECT_B-OBJTYPE = P_DOCTY.

  • LO_IS_OBJECT_B-CATID = 'BO'.

*message i000(mtxt) with P_BO_ID P_BOTYPE LV_DOC_SIZE LV_MESSAGE_KEY.

call function 'BINARY_RELATION_CREATE'

EXPORTING

obj_rolea = LO_IS_OBJECT_A

obj_roleb = LO_IS_OBJECT_B

relationtype = P_RELTYP

EXCEPTIONS

others = 1.

commit work.

Please talk and look and reply....

Thanks Rich....