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

Create attachment for Equipment BINARY_RELATION_CREATE

0 Likes
628

Hello,

I need to create an attachment for an equipment using an image resident on my pc[JPG].

 

With the code shown below i have successfully created an attachment for my equipment but the image is corrupted, ie when I click on the attachment the image is not shown.

Any suggestion?

DATA :BEGIN OF gt_f OCCURS 1000,

  data(1000) ,

  END OF gt_f.

  MOVE path TO filename.

  CALL FUNCTION 'GUI_UPLOAD'

      EXPORTING

        filename                = filename

        filetype                = 'BIN'

      TABLES

        data_tab                = gt_f.

   DATA: line TYPE xstring.

 

  LOOP AT gt_f.

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

      EXPORTING

        text   = gt_f-data

      IMPORTING

        buffer = line.

    CONCATENATE atttxt line INTO atttxt IN BYTE MODE.

  ENDLOOP.

     

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      buffer        = atttxt

    IMPORTING

      output_length = size

    TABLES

      binary_tab    = attbin.

  swc_set_table   cont 'DocumentContent' attbin.

  swc_set_element cont 'DOCUMENTSIZE'    size.

   swc_refresh_object msg.

  swc_call_method    msg 'CREATE' cont.

  swc_get_object_key msg msg_key.

  objecta-objkey  = p_equnr.

  objecta-objtype = 'EQUI'.

  objectb-objkey  = msg_key.

  objectb-objtype = 'MESSAGE'.

  CALL FUNCTION 'BINARY_RELATION_CREATE'

    EXPORTING

      obj_rolea      = objecta

      obj_roleb      = objectb

      relationtype   = 'ATTA'

    EXCEPTIONS

      no_model       = 1

      internal_error = 2

      unknown        = 3

      OTHERS         = 4.

  IF sy-subrc <> 0.

* Implement suitable error handling here

  ENDIF.

  COMMIT WORK.

1 REPLY 1
Read only

gokul_radhakrishnan3
Active Participant
0 Likes
382

May be you have to compress & decompress first to convert the binary data from lt_bin (structure TBL1024) to target_tab (structure SOLIX). From Raw 1024 to Raw 255?


Compress table


              CALL FUNCTION 'TABLE_COMPRESS'

                TABLES

                  in             = lt_bin

                  out            = aux_tab

                EXCEPTIONS

                  compress_error = 1

                  OTHERS         = 2.



Decompress table


              CALL FUNCTION 'TABLE_DECOMPRESS'

                TABLES

                  in                   = aux_tab

                  out                  = target_tab

                EXCEPTIONS

                  compress_error       = 1

                  table_not_compressed = 2

                  OTHERS               = 3.