cancel
Showing results for 
Search instead for 
Did you mean: 

How to add 'ATTACHMENT' button on confirmation page of SRMSUS BSP

Former Member
0 Kudos

Hi Experts,

I want to add 'Attachment' button on the confirmation page of PO to attach confirmation documents to PO.

I could see the source view is calling GSC view of SRMSUS BSP application.

Could someone help us to add/activate this attachment button on this view.

Regards,

Kusuma K.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Kusuma.

First we need to Change the standard Confirmation view to Z( customizing view) and then in the View we need to add a Browse Button and Upload button and Delete Button

the Following is the BSP code:

<!-- file upload -->
     <htmlb:tray id          = "<%= asn_item_edit_trayname %>"
                 isCollapsed = "<%= ls_item_edit_collapsed %>"
                 onExpand    = "<%= asn_item_edit_trayname %>"
                 onCollapse  = "<%= asn_item_edit_trayname %>"
                 title       = "Attachments"
                 width       = "100%" >
          <htmlb:gridLayout width="100%" columnSize="1" rowSize="4" cellSpacing="2">
           <htmlb:gridLayoutCell columnIndex="1" rowIndex="1" horizontalAlignment="LEFT">
             <htmlb:tableView id="attachments"
                              table="<%=lv_table%>"
                              headerVisible="TRUE"
                              headerText="<%=lv_header_text%>"
                              iterator = "<%= lr_iterator_attach %>"
                              selectedRowKeyTable = "<%= selectedRowKeyTable %>"
                              onRowSelection   = "onRowSelection"
                              selectionMode   = "MULTISELECT"
                              keyColumn       = "doc_id"
                              sort            = "Server"
                              visibleRowCount = "20">
       <htmlb:tableViewColumn sort="TRUE" columnName="COMP_ID" title="<%=otr(SOTR_VOCABULARY_BASIC/DESCRIPTION)%>"></htmlb:tableViewColumn>
       <htmlb:tableViewColumn sort="TRUE" columnName="MIMETYPE" title="<%=otr(ROS_PRE/MIMETYPE)%>"></htmlb:tableViewColumn>
       <htmlb:tableViewColumn sort="TRUE" columnName="COMP_SIZE" title="<%=otr(ros_pre/sizekb)%>"></htmlb:tableViewColumn>
       <htmlb:tableViewColumn sort="TRUE" columnName="CREATED_BY" title="<%=otr(ros_pre/createdby)%>"></htmlb:tableViewColumn>
       <htmlb:tableViewColumn sort="TRUE" columnName="DATE_CREATED" title="<%=otr(ros_pre/createdat)%>"></htmlb:tableViewColumn>
       <htmlb:tableViewColumn sort="TRUE" columnName="TIME_CREATED" title="<%=otr(ros_pre/attime)%>"></htmlb:tableViewColumn>
       </htmlb:tableView>
           </htmlb:gridLayoutCell>
        <htmlb:gridLayoutCell columnIndex="1" rowIndex="2" horizontalAlignment="LEFT">
           <htmlb:textView  text="<%=otr(ROS_PRE/PATH)%>"/>
           <htmlb:fileUpload id="inputFile" size="25" />
        </htmlb:gridLayoutCell>
         <htmlb:gridLayoutCell columnIndex="1" rowIndex="3" horizontalAlignment="LEFT">
              <htmlb:button id="import_attachment" text="<%=otr(ROS_PRE/SAVE)%>"
                            onClick="import_attachment" />
          </htmlb:gridLayoutCell>
          <htmlb:gridLayoutCell columnIndex="1" rowIndex="4" horizontalAlignment="LEFT">
              <htmlb:button id="delete_attachment" text="<%=otr(ROS_PRE/DELETEMARKED)%>" onClick="delete_attachment"/>
          </htmlb:gridLayoutCell>
        </htmlb:gridLayout>
     </htmlb:tray>

after adding the Buttons in BSP page you have to handle those events in GSC  controller(detail_edit.sub) this also you have to convert into z Controller and this This Controller you have to Configure in BBPC_SUS_ACTION table. the Following is the Code.


DATA: model1 TYPE REF TO zcl_ros_self_reg_model,
         iv_ebeln TYPE ebeln,
         number(10),
         lv_table TYPE ros_bp_attachments_t,
         wa_table TYPE ros_bp_attachments_s,
          attach_flag,
          selection TYPE REF TO cl_htmlb_event_tableview,
          zattach_list_s TYPE zattach_list_s.

   READ TABLE lo_model->pt_conf_header INDEX 1 ASSIGNING <lf_header>.
   MOVE <lf_header>-be_refobj TO iv_ebeln.
   MOVE <lf_header>-ref_doc_no TO number.
   IF event 'import_attachment'.
     CREATE OBJECT model1.
*** Getting reference number setting to the navigation
*** adding attachment
     CALL METHOD model1->import_attachment
       EXPORTING
         iv_ebeln   = iv_ebeln
         io_runtime = runtime
         number     = number
         doc_type   = 'SES'
       IMPORTING
         message    = file_message.

(Code for the ABOVE MOTHOD)

CONSTANTS: lv_x TYPE rfcpossible VALUE 'X'" Indicate RFC-Compatible

**** data declarations
   DATA: lt_content TYPE ros_bds_content_t,
         lv_filesize TYPE i,
         count TYPE i,
         lv_filename TYPE string,
         lv_mimetype TYPE string,
         p_file_data TYPE xstring,
         lv_attachment_xcontent   TYPE xstring,
         lr_multipart        TYPE REF TO if_http_entity,
         lv_index            TYPE i VALUE 1,
         lt_bds_attachment TYPE ros_bds_content_t,
         lv_number_of_multiparts TYPE i,
         lv_attachment_length TYPE i,
         lv_full_name TYPE string,
         filename1 TYPE string,
         filename2 TYPE string,
         delimiter VALUE '.',
         store_flag,
         size_flag,
         version VALUE '00',
         iv_documentnumber    TYPE doknr,
         l_doknr     TYPE doknr,
         l_doknr1     TYPE doknr,
         e_return    TYPE bapiret2,
         it_dm_files TYPE zdm_tt_files,
         wa_dm_files TYPE zdm_files,
         wa_content TYPE bapiconten,
         lv_filelength TYPE i,
         lt_rawtab TYPE TABLE OF char255,
         l_ext       TYPE sdbad-funct,
         l_filename  TYPE sdbah-actid,
         l_filename1 TYPE char32,
         lv_full_name_new TYPE dbmsgora-filename,
         lv_logsys TYPE logsys.


**-- Get Definition of Back-End Systems in SAP SRM
   SELECT SINGLE log_sys FROM bbp_backend_dest
                         INTO lv_logsys
                         WHERE rfc_poss = lv_x.

* get all the parts of the current HTTP Request
   lv_number_of_multiparts = io_runtime->server->request->num_multiparts( ).

* loop over all parts of the form and search for a file
   WHILE lv_index <= lv_number_of_multiparts.
     lr_multipart = io_runtime->server->request->get_multipart( lv_index ).
     ADD 1 TO lv_index.
     IF lr_multipart->get_header_field( '~content_filename' ) IS INITIAL.
       CONTINUE.
     ELSE.
*     found something, get it
       lv_attachment_xcontent = lr_multipart->get_data( ).
       lv_attachment_length = XSTRLEN( lv_attachment_xcontent ).
       IF lv_attachment_length IS INITIAL.
*       has no length, ignore it, look for the next
         CONTINUE.
       ELSE.
*       length ok, get some meta info
         lv_full_name = lr_multipart->get_header_field( '~content_filename' ).
         EXIT.
       ENDIF.
     ENDIF.
   ENDWHILE.

******** Getting Filename and content details from the attachment
   CALL FUNCTION 'ROS_BUPA_BSP_IMPORT_ATTACHMENT'
     EXPORTING
       io_runtime       = io_runtime
     IMPORTING
       ev_filename      = lv_filename
       ev_filesize      = lv_filesize
       ev_mimetype      = lv_mimetype
     TABLES
       et_content       = lt_content
     EXCEPTIONS
       no_file          = 1
       conversion_error = 2
       OTHERS           = 3.

   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     EXIT.
   ENDIF.

   MOVE lv_full_name TO  lv_full_name_new.

****** preparing data to upload the docuemnt in R/3 DMS system under document type ASN for advance shipping notification

* Convert Binary Data to xstring.

   CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
     EXPORTING
       input_length = lv_filesize
     IMPORTING
       buffer       = p_file_data
     TABLES
       binary_tab   = lt_content
     EXCEPTIONS
       failed       = 1
       OTHERS       = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

**** file name split

   CALL FUNCTION 'SPLIT_FILENAME'
     EXPORTING
       long_filename  = lv_full_name_new
     IMPORTING
       pure_filename  = l_filename
       pure_extension = l_ext.


**** preparing internal table IT_DM_FILES for uploading the document in R/3 DMS system

   CONCATENATE l_filename '.' l_ext INTO l_filename1.
   wa_dm_files-filename      = l_filename1.
   wa_dm_files-file_type     = l_ext.
   wa_dm_files-filepath      = lv_filename.
   wa_dm_files-content       = p_file_data.
   APPEND wa_dm_files TO it_dm_files.

   MOVE p_file_data TO wa_dm_files-content.
   MOVE lv_filename TO l_filename1.
   MOVE number TO iv_documentnumber.



*  CALL FUNCTION 'ZFM_GET_DRAW_TABLE' DESTINATION lv_logsys
*    EXPORTING
*      iv_documentnumber = iv_documentnumber
*      iv_documenttype   = doc_type
*    IMPORTING
*      ev_documentnumber = l_doknr.


  CONCATENATE IV_DOCUMENTNUMBER  DOC_TYPE  INTO IV_DOCUMENTNUMBER.



****** validation ---  check whether file extn is pdf, doc, docx, xls, xlsx, pdf, txt

   SPLIT lv_filename AT delimiter INTO filename1 filename2.
   IF filename2 EQ 'pdf' OR filename2 EQ 'doc' OR  filename2 EQ 'docx' OR
      filename2 EQ 'xls' OR  filename2 EQ 'xlsx' OR  filename2 EQ 'txt'.
     store_flag = 'X'.
   ELSE.
     message = 'Please attach the file with the following types pdf, doc, docx, xls, xlsx, pdf, txt'.
     EXIT.
   ENDIF.

***** validation ---  file size should not exceed 1MB

   IF lv_filesize > 1048576.
     message = 'Size of the file should not exceed 1MB'.
   ELSE.
     size_flag = 'X'.
   ENDIF.

****** overwriting attached file name with document name selected from the table ZROS_DOC_TYPES

   IF document_name IS NOT INITIAL.
     lv_filename = document_name.
   ENDIF.

   IF store_flag = 'X' AND size_flag = 'X'.

******* Uploading the document in R/3 DMS system using document type ASN

     CALL FUNCTION 'ZFM_SR_CREATE_FROM_EXTERNAL' DESTINATION lv_logsys
       EXPORTING
         iv_documentnumber  = IV_DOCUMENTNUMBER
         iv_documenttype    = doc_type
         iv_documentversion = '00'
         iv_documentpart    = '000'
         iv_storage_cat     = 'ZC_SRM'
         iv_dokst           = 'IW'
         it_dm_files        = it_dm_files
         iv_ebeln           = iv_ebeln
       IMPORTING
         ev_documentnumber  = l_doknr1
         es_return          = e_return.

******* Uploading the document in SRM system

     CALL FUNCTION 'ROS_BUPA_PUT_ATTACHMENT'
       EXPORTING
         iv_bp_number    = number
         iv_comp_id      = lv_filename
         iv_mimetype     = lv_mimetype
         iv_comp_size    = lv_filesize
       TABLES
         it_content      = lt_content
       EXCEPTIONS
         nothing_found   = 1
         parameter_error = 2
         not_allowed     = 3
         internal_error  = 4
         error_kpro      = 5
         not_authorized  = 6
         OTHERS          = 7.
     IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

   ENDIF.

   ELSEIF event = 'delete_attachment'.

     CREATE OBJECT model1.

**** Method Changed as per PF9335 for Deleting Documents from BACK END ***

     CALL METHOD model1->delete_attachments_gsc
       EXPORTING
         prevselectedrowkeytable = attach_list
         number                  = number.

   ELSEIF event = 'attachments-multiselect'.
     CREATE OBJECT model1.
     CALL METHOD model1->display_attachment
       EXPORTING
         number   = number
       IMPORTING
         lv_table = lv_table.
     IF attach_list IS INITIAL.
       LOOP AT lv_table INTO wa_table.
         zattach_list_s-attachment = wa_table-doc_id.
         APPEND zattach_list_s TO attach_list.
       ENDLOOP.
     ELSE.
       REFRESH attach_list.
     ENDIF.
   ENDIF.
   IF htmlb_event IS INITIAL.
     EXIT.
   ENDIF.