This website is not affiliated with, sponsored by, or approved by SAP AG.

Mass GOD import -> File corrupt

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Mass GOD import -> File corrupt

Postby silly » Wed Oct 15, 2014 2:44 am

Hi all ,
I'm on SAP ECC 6.0 and I need to mass update attachment from PC to a notification ( object type BUS2080 ) by GOS
My abap code works at 90 %
I'm able to attach the file to the service notification but I cannot open it as the file is corrupt

Can someones help me ?
Below the abap code



Code: Select all
FUNCTION Z_GOS_CREATE_ATTACHMENT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(OBJTYPE) TYPE  BORIDENT-OBJTYPE
*"     REFERENCE(OBJKEY) TYPE  BORIDENT-OBJKEY
*"     REFERENCE(FILEPATH) TYPE  STRING OPTIONAL
*"     REFERENCE(FILENAME) TYPE  STRING OPTIONAL
*"     REFERENCE(DOCTITLE) TYPE  STRING OPTIONAL
*"     REFERENCE(DOCTYPE) TYPE  SOFM-DOCTP OPTIONAL
*"  TABLES
*"      BIN_TAB OPTIONAL
*"  EXCEPTIONS
*"      UNKNOW_ERROR
*"      NO_FILE_OR_BIN
*"      NO_DOC_TYPE
*"----------------------------------------------------------------------

  include : <cntn01>.

  constants:
            c_docnm  type borident-objtype value 'MESSAGE',
            c_reltyp type breltyp-reltype  value 'ATTA'.

  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 : xobject_b type borident.
  data : xobject_a type borident.
  data : xdoc_size    type i.
  data : xfile_lines   type i.
  data : xmessage_key type ty_message_key.
  data : xmessage     type swc_object.
  data : idoc_content type standard table of soli-line.
  data : xdoc_content type soli-line.
  data : xfilenamepath type string.
*  data : xfilenamepath like RLGRAP-FILENAME.

  data : xdoctitle type string.
  data : xdoctype type sofm-doctp.
  data : xfname type string.

  if bin_tab[] is initial
    and ( filename is initial
      or  filepath is initial ).
    raise no_file_or_bin.
  endif.

  if not bin_tab[] is initial
     and doctype is initial.
    raise no_doc_type.
  endif.

  if not bin_tab[] is initial.
    xdoctype = doctype.
    translate xdoctype to upper case.
  else.
    split filename at '.' into xfname xdoctype.
    translate xdoctype to upper case.
  endif.
* Create an initial instance of BO 'MESSAGE' - to call the
* instance-independent method 'Create'.
  swc_create_object xmessage 'MESSAGE' xmessage_key.

* define container to pass the parameter values to the method call
* in next step.
  swc_container imessage_container.

* Populate container with parameters for method
  if doctitle is initial.
    xdoctitle = filename.
  else.
    xdoctitle = doctitle.
  endif.
  swc_set_element imessage_container 'DOCUMENTTITLE'  xdoctitle.
  swc_set_element imessage_container 'DOCUMENTLANGU' 'E'.
  swc_set_element imessage_container 'NO_DIALOG'     'X'.
  swc_set_element imessage_container 'DOCUMENTNAME'   c_docnm.
  swc_set_element imessage_container 'DOCUMENTTYPE'   xdoctype.

  if not bin_tab[] is initial.

* Translate table to 255, if not 255.
    data: tab_len type i.
    read table bin_tab index 1.
    tab_len = strlen( bin_tab ).

    if tab_len < 255.
      data: xbuffer type string.
      loop at bin_tab.
        translate bin_tab using ' ~'.
        concatenate xbuffer bin_tab into xbuffer.
      endloop.
      translate xbuffer using '~ '.
      do.
        xdoc_content = xbuffer.
        append xdoc_content to idoc_content.
        shift xbuffer left by 255 places.
        if xbuffer is initial.
          exit.
        endif.
      enddo.
    else.
      idoc_content[] =  bin_tab[].
    endif.

  else.

    concatenate filepath filename into xfilenamepath.



    call function 'GUI_UPLOAD'
         exporting
              filename = xfilenamepath
              filetype = 'BIN'
         tables
              data_tab = idoc_content
         exceptions
              others   = 17.

  endif.

* 'DocumentContent' is a multi-line element ( itab ).
  swc_set_table imessage_container 'DocumentContent' idoc_content.

* Size is required in case of File attachments
  describe table idoc_content lines xfile_lines.

  read table idoc_content into xdoc_content index xfile_lines.

  xdoc_size = ( 255 * ( xfile_lines - 1 ) ) +
              strlen( xdoc_content  ).

  swc_set_element imessage_container 'DOCUMENTSIZE'   xdoc_size .

* Refresh to get the reference of create 'MESSAGE' object for attachment
  swc_refresh_object xmessage.
  swc_call_method xmessage 'CREATE' imessage_container.

* Get Key of new object
  swc_get_object_key xmessage xmessage_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
  xobject_a-objkey = objkey.
  xobject_a-objtype = objtype.

* Create attachment BO object_b
  xobject_b-objkey = xmessage_key.
  xobject_b-objtype = c_docnm.

  call function 'BINARY_RELATION_CREATE'
       exporting
            obj_rolea    = xobject_a
            obj_roleb    = xobject_b
            relationtype = c_reltyp
       exceptions
            others       = 1.

  if sy-subrc = 1.
*    raise unknown_error.
  endif.

  commit work.

ENDFUNCTION.


Thanks
Silly
Last edited by Gothmog on Wed Oct 15, 2014 3:05 am, edited 1 time in total.
Reason: added code tags - please use them
silly
 
Posts: 95
Joined: Thu May 08, 2008 4:04 am

Re: Mass GOD import -> File corrupt

Postby Gothmog » Wed Oct 15, 2014 3:12 am

Which case corrupt the file? The upload, or the BIN_TAB parameter table?
Also, why are you adapting the line size of BIN_TAB to 255 only if the first line is UNDER 255 characters? Any table with a line size greater than 255 ends up truncated with this code.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1943
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Mass GOD import -> File corrupt

Postby silly » Wed Oct 15, 2014 3:30 pm

You have right, I was not so precius
The upload, Table bin_tab is not use
Only gui_upload from pc
silly
 
Posts: 95
Joined: Thu May 08, 2008 4:04 am

Re: Mass GOD import -> File corrupt

Postby silly » Wed Oct 15, 2014 4:26 pm

Ï've done additional changes and with files word and pdf , FM works ( I'm able to open the attachment from notification )

Here what I've change

old
xdoc_size = ( 255 * ( xfile_lines - 1 ) ) +
strlen( xdoc_content ).
new
xdoc_size = ( 510 * ( xfile_lines - 1 ) ) +
strlen( xdoc_content ).

I'm doing other test for xls , actually system open the attachment ( no curruption ) but inside all char are incorrect
silly
 
Posts: 95
Joined: Thu May 08, 2008 4:04 am


Return to ABAP

Who is online

Users browsing this forum: No registered users and 3 guests



cron


This website is not affiliated with, sponsored by, or approved by SAP AG.