cancel
Showing results for 
Search instead for 
Did you mean: 

Get Stream Method Returns garbage values

former_member214928
Participant
0 Kudos

Hi Experts,

I have implemented GET_STREAM method to read GOS attachment from PM Notifications. The service is getting executed but it returns garbage values. Please look at the screenshot attached.

GET_STREAM Method Logic

InstID:      QMEL-QMNUM

TypeID:     BUS2038

CatID:      BO

REL_OPTION: ATTA & URL

" Call Method to read links.

          CALL METHOD cl_binary_relation=>read_links

            EXPORTING

              is_object                = ls_object

              it_relation_options   = lt_rel_option

            IMPORTING

              et_links                 = lt_links.

LOOP AT lt_links into ls_links.

lv_doc_id = ls_links-instid_b.

" FM to Read Link/Attachment.

        CALL FUNCTION 'SO_DOCUMENT_READ_API1'

          EXPORTING

            document_id                = lv_doc_id

          IMPORTING

            document_data              = ls_doc_data

          TABLES

            object_header              = lt_obj_header

            object_content             = lt_obj_cont

            attachment_list            = lt_attachment

            contents_hex               = lt_cont_hex

          EXCEPTIONS

            document_id_not_exist      = 1

            operation_no_authorization = 2

            x_error                    = 3

            OTHERS                     = 4.

TRY.

               " Convert Binary to Xstring

              CALL METHOD cl_bcs_convert=>xtab_to_xstring

                EXPORTING

                  it_xtab    = lt_cont_hex

                RECEIVING

                  rv_xstring = lv_xstring.

            CATCH cx_bcs .

          ENDTRY.

ls_stream-value     = lv_xstring.

          ls_stream-mime_type = ls_doc_data-obj_type.

*

*          TRANSLATE ls_stream-mime_type TO LOWER CASE.

          copy_data_to_ref( EXPORTING is_data = ls_stream

                            CHANGING  cr_data = er_stream ).

endloop.

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Rahul,

Please check the below points once again.

I see that you are calling method copy_data_to_ref inside loop. This has to be called only once at the end.

You need to get the complete media content and call the above method at the end.

Please check this.

Pass back the mime type in lower case and check.

Regards,

Ashwin

former_member214928
Participant
0 Kudos

Hello Ashwin,

Did as you mentioned but still facing the same issue .

Please look at the code below

READ TABLE it_key_tab INTO ls_key_tab  WITH KEY name = 'Qmnum'.

      IF sy-subrc EQ 0.

        lv_qmnum = ls_key_tab-value.

      ENDIF.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

        EXPORTING

          input  = lv_qmnum

        IMPORTING

          output = lv_qmnum.

      lv_instid = lv_qmnum.

      ls_object-instid = lv_instid.

      ls_object-typeid = 'BUS2038'.

      ls_object-catid  = 'BO'.

      ls_rel_option-sign   = 'I'.

      ls_rel_option-option = 'EQ'.

      ls_rel_option-low    = 'URL'.

      APPEND ls_rel_option TO lt_rel_option.

      ls_rel_option-low   = 'ATTA'.

      APPEND ls_rel_option TO lt_rel_option.

      TRY.

          " Call Method to read links.

          CALL METHOD cl_binary_relation=>read_links

            EXPORTING

              is_object           = ls_object

              it_relation_options = lt_rel_option

            IMPORTING

              et_links            = lt_links.

          IF  sy-subrc = 0 .

          ENDIF.

        CATCH cx_obl_parameter_error .

        CATCH cx_obl_internal_error .

        CATCH cx_obl_model_error .

      ENDTRY.

      LOOP AT lt_links INTO ls_links.

        CLEAR lv_doc_id.

        lv_doc_id = ls_links-instid_b.

        " FM to Read Link/Attachment.

        CALL FUNCTION 'SO_DOCUMENT_READ_API1'

          EXPORTING

            document_id                = lv_doc_id

          IMPORTING

            document_data              = ls_doc_data

          TABLES

            object_header              = lt_obj_header

            object_content             = lt_obj_cont

            attachment_list            = lt_attachment

            contents_hex               = lt_cont_hex

          EXCEPTIONS

            document_id_not_exist      = 1

            operation_no_authorization = 2

            x_error                    = 3

            OTHERS                     = 4.

        IF sy-subrc EQ 0.

          lv_length = ls_doc_data-doc_size .

          TRY.

              CALL METHOD cl_bcs_convert=>xtab_to_xstring

                EXPORTING

                  it_xtab    = lt_cont_hex

                RECEIVING

                  rv_xstring = lv_xstring.

            CATCH cx_bcs .

          ENDTRY.

ls_stream-value     = lv_xstring.

          ls_stream-mime_type = ls_doc_data-obj_type.

*

          TRANSLATE ls_stream-mime_type TO LOWER CASE.

        ENDIF.

      ENDLOOP.

      copy_data_to_ref( EXPORTING is_data = ls_stream

                            CHANGING  cr_data = er_stream ).

AshwinDutt
Active Contributor
0 Kudos

What is the Mime Type is being passed ?

former_member214928
Participant
0 Kudos

Mime type at present for testing purpose is jpg, as user will mainly attached photos rather than txt/pdf files.

But it is not restricted to only photos, files can also be attached.

AshwinDutt
Active Contributor
0 Kudos

Ok but what is the Mime Type value is being passed back to GW when you are testing it ?

former_member214928
Participant
0 Kudos

Actually the attachment is added in SAP and not through Gateway. We are just testing how GOS attachment works. But going forward it would be through Gateway.

So if we attach JPG file, it returns JPG in mime type and respectively for other file extensions as well.

First we need to get the GET_STREAM method working properly and then we wil move on to CREATE_STREAM.

AshwinDutt
Active Contributor
0 Kudos

When you read content through GET_STREAM which is .jpg then pass back the mime type as 'image/jpeg ' and check.

former_member214928
Participant
0 Kudos

It's working. Really thanks for the help

What shall we pass for TXT & PDF files??

AshwinDutt
Active Contributor
0 Kudos

Check ->

PDF -  application/pdf

TXT -   text/plain

former_member214928
Participant
0 Kudos

Yes, it's working. Many Thanks

former_member214928
Participant
0 Kudos

Can you also let me know for below mime types are correct??

image/bmp

image/png

image/gif

Or do you list of mime types that can be used to passed from odata service to UI??

It would be really beneficial for everyone

AshwinDutt
Active Contributor
0 Kudos

Yes there are correct.

Ah I don't have list of mime types with me. I just emember few types which are frequently used.

However you can find online Rahul.

former_member214928
Participant
0 Kudos

We have a FM SDOK_MIMETYPE_GET to get the Content-type for file extensions. Pass File extensions as input parameter.

Answers (0)