cancel
Showing results for 
Search instead for 
Did you mean: 

Issues in background attachment to service order

ankit_munshi2
Participant
0 Kudos

Hello Guys,

I am reading JPEG files placed over app server and attaching them to service orders (IW33). I am using below method :

swc_create_object lo_message 'MESSAGE' lv_message_key.

swc_set_table lt_message_container 'DocumentContent' lt_doc_content.
swc_call_method lo_message 'CREATE' lt_message_container.

lt_doc_container contains data from file placed at unix directory. File content is added to this table by below piece of code :

DATA : lt_wide_content TYPE STANDARD TABLE OF dxrawdata-data
WITH HEADER LINE.

OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc EQ 0.
DO.
READ DATASET p_file INTO lt_wide_content.
IF sy-subrc EQ 0 OR sy-index EQ 1.
* Appending to 5000 wide char text itab.
APPEND lt_wide_content.
ELSE.
APPEND lt_wide_content.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_file.
ENDIF.

DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line WITH HEADER LINE.

lt_doc_content[] = lt_wide_content[].

DATA: lo_is_object_a TYPE sibflporb.
lo_is_object_a-instid = p_bo_id.
lo_is_object_a-typeid = p_botype.
lo_is_object_a-catid = 'BO'.
* Create attachment BO object_b
DATA: lo_is_object_b TYPE sibflporb.
lo_is_object_b-instid = lv_message_key.
lo_is_object_b-typeid = p_docty.
lo_is_object_b-catid = 'BO'.
*TRY.
CALL METHOD cl_binary_relation=>create_link
EXPORTING
is_object_a = lo_is_object_a
* IP_LOGSYS_A =
is_object_b = lo_is_object_b
* IP_LOGSYS_B =
ip_reltype = p_reltyp.

*******************************************************

Now this piece of code does add attachment to order in background, but when we try to open the attachment, we get an error saying Windows photo viewer cannot open the file (implying file may not have been attached in proper format) … Could someone suggest way out please ? Do I need a data conversion or something here?

Thanks,

AM

ankit_munshi2
Participant
0 Kudos

Please note the code provided is representative and not a direct copy . So please ignore sequencing issues.

Accepted Solutions (1)

Accepted Solutions (1)

Sandra_Rossi
Active Contributor

You must not read a JPEG file using the OPEN DATASET ... IN TEXT MODE, use IN BINARY MODE (a JPEG file does not contain text) and adapt your code adequately :

  • read the file into an XSTRING variable
  • then, call the function module SCMS_XSTRING_TO_BINARYto convert the xstring into a table of characters which contains bytes (if I remember well, you are using a very old code which needs such a weird "object").

ps: note that your issue is not related to the background execution, it would also fail in dialog mode. Did it ever work using a file on the application server? Make sure that your file is not corrupted on the application server. By the way, did you make sure you copied it using BINARY mode? (with TEXT mode, you could corrupt it)

Answers (1)

Answers (1)

ankit_munshi2
Participant
0 Kudos

thank you. problem solved. Attaching code for future reference :

OPEN DATASET lv_file FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
DO.
READ DATASET lv_file INTO ls_doc_content.
IF sy-subrc EQ 0 OR sy-index EQ 1.
APPEND ls_doc_content TO xyt_content.
ELSE.
* Make sure to append last line
APPEND ls_doc_content TO xyt_content.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_file.
ENDIF.

CLEAR : lv_msgtyp , lv_string1, lv_string2.

SPLIT ls_files-name AT '.' INTO lv_string1 lv_string2.
lv_msgtyp = lv_string2.

* Now create instance of each file
swc_create_object lo_message 'MESSAGE' lv_message_key.
* define container to pass the parameter values to the method call* in next steps.
swc_container lt_message_container.

*Populate container with parameters for method
swc_set_element lt_message_container 'DOCUMENTTITLE' ls_files-name.
swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.
swc_set_element lt_message_container 'NO_DIALOG' abap_true.
swc_set_element lt_message_container 'DOCUMENTNAME' lv_docty.
swc_set_element lt_message_container 'DOCUMENTTYPE' lv_msgtyp.
swc_set_table lt_message_container 'DocumentContent' lt_doc_content.
swc_call_method lo_message 'CREATE' lt_message_container.
* Refresh to get the reference of create 'MESSAGE' object for attachment
swc_refresh_object lo_message.
* 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
lo_is_object_a-instid = lv_order.
lo_is_object_a-typeid = 'BUS2088'.
lo_is_object_a-catid = 'BO'.

* Create attachment BO object_b
lo_is_object_b-instid = lv_message_key.
lo_is_object_b-typeid = lv_docty.
lo_is_object_b-catid = 'BO'.

* Create link between business object /service order and document to be attached
CALL METHOD cl_binary_relation=>create_link
EXPORTING
is_object_a = lo_is_object_a
is_object_b = lo_is_object_b
ip_reltype = lv_reltyp.