Skip to Content
Author's profile photo Abhijit Mandal

Read GOS (Generic Object Service) Picture Attachments and Display it into Adobe Form

Abhijit Mandal Purpose & Overview: There are lot of threads, wiki’s and blogs available about GOS. Reading and downloading GOS attachment and also we will find lots of article on how to attach a document into GOS.

But there are not many documents which describes the complete cycle of reading GOS object and display it into adobe form dynamically. The idea of this document is to build a complete cycle of reading a GOS attachment and then embed it into SAP Adobe form.

Limitations & Restrictions: This document is to read GOS picture attachments and embedding it into SAP adobe form. As, I have tried for reading a .PDF GOS attachment and embedding it into SAP Adobe form but as per my knowledge SAP doesn’t provide such solutions till now. So, this is restricted to picture format (.JPG, .GIF, .BMP and .PNG etc.). For (.TIFF & .TIF) picture format first we have to convert from .TIF to .JPG format.   

Business Requirement & Descriptions: In this document I will read GOS attachments which are quality certificates and display the quality certificates into SAP Adobe form. This is applicable for other transactions which have got generic object service.

Create a structure & table type which will be sent to SAP adobe form as an import parameter.

Image1.jpg

Create table type:

Image2.jpg

Building the program:

REPORT  zabhi_gos_attachment_read.

DATAlv_lgsystm    TYPE logsys,
       lv_line      
TYPE i,
       lv_input_len 
TYPE i,
       ls_connection
TYPE bdn_con,
       lv_docid     
TYPE so_entryid,
       lv_objkey    
TYPE swo_typeid,
       ls_doc_data  
TYPE sofolenti1,
       ls_certattach
TYPE ztst_itab,
       lv_string    
TYPE xstring.

DATAlt_connection TYPE STANDARD TABLE OF bdn_con,
       lt_content   
TYPE STANDARD TABLE OF solisti1,
       lt_cont_hex  
TYPE STANDARD TABLE OF solix,
       lt_attachment
TYPE ztst_tt_itab.

FIELD-SYMBOLS<lfs_connection> TYPE bdn_con.

 
CLEAR: lv_lgsystm,
       lv_input_len
,
       lv_line
.


* Build selection screen


SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_bo   TYPE bds_clsnam OBLIGATORY DEFAULT ‘BUS2117’,
            p_cert
TYPE qcprcertno OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
* To Get own logical system

CALL FUNCTION ‘OWN_LOGICAL_SYSTEM_GET’
     IMPORTING
      own_logical_system            
= lv_lgsystm
     EXCEPTIONS
      own_logical_system_not_defined
= 1
            OTHERS                                                = 2.
     IF sysubrc <> 0.
     
CLEAR lv_lgsystm .
     ENDIF.

* Retrieves list of attachment (quality certificate images) details through BDS_GOS_CONNECTIONS_GET function module .


CLEAR lv_objkey.
MOVE p_cert TO lv_objkey.

CALL FUNCTION ‘BDS_GOS_CONNECTIONS_GET’
     EXPORTING
      logical_system    
= lv_lgsystm
      classname         
= p_bo
      objkey            
= lv_objkey

     TABLES
      gos_connections   
= lt_connection[]
     EXCEPTIONS
      no_objects_found  
= 1
      internal_error    
= 2
      internal_gos_error
= 3
     
OTHERS                         = 4.
     IF sysubrc = 0.
     
SORT lt_connection .
     ENDIF.

LOOP AT lt_connection ASSIGNING <lfs_connection>.


     
TRANSLATE <lfs_connection>docuclass TO UPPER CASE.
     
MOVE <lfs_connection>loio_id TO lv_docid.

* Reading the content of the image file. Internal table lt_cont_hex is the converted binary format of the image is    generating.


CALL FUNCTION ‘SO_DOCUMENT_READ_API1’
     
EXPORTING
           document_id                
= lv_docid
     
IMPORTING
           document_data              
= ls_doc_data
     
TABLES
            object_content            
= lt_content[]
            contents_hex              
= lt_cont_hex[]
     
EXCEPTIONS
            document_id_not_exist     
= 1
            operation_no_authorization
= 2
            x_error                   
= 3
           
OTHERS                                         = 4.
     
IF sysubrc <> 0.
          
CLEAR ls_doc_data.
     
ENDIF.

CLEAR: lv_line, lv_input_len.

* The most important part is to get correct length. If you do not pass the correct length you image will not be displayed.
     DESCRIBE TABLE lt_cont_hex LINES lv_line.
   lv_input_len 
= lv_line * sytleng .

* Converting binary data to Xstring format

CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING’
     
EXPORTING
           input_length 
= lv_input_len
           first_line   
= 0
           last_line    
= 0
     
IMPORTING
          
buffer                   = lv_string
     
TABLES
           binary_tab  
= lt_cont_hex
     
EXCEPTIONS
           failed      
= 1
          
OTHERS             = 2.
         IF sysubrc <> 0.
     
CLEAR lv_string.
   
ENDIF.

* Now we need to convert the Xstring data to string data otherwise the image will not be shown.
ls_certattach
certno = p_cert.

     CALL FUNCTION ‘SSFC_BASE64_ENCODE’
     
EXPORTING
           bindata
= lv_string

     
IMPORTING
           b64data
= ls_certattachf_string.
     
IF sysubrc <> 0.
          
CLEAR ls_certattachf_string.
     
ENDIF.

      APPEND ls_certattach TO lt_attachment.
     
CLEAR ls_certattach.

ENDLOOP.


* To print the image into adobe form call below subroutine.


PERFORM f_sub_print_form USING lt_attachment.
*&———————————————————————*
*&      Form  F_SUB_PRINT_FORM
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM f_sub_print_form  USING  p_gt_tab TYPE ztst_tt_itab.
     
DATA : ls_sfpoutputparams  TYPE sfpoutputparams,
            ls_docparams       
TYPE sfpdocparams,
            ls_pdf_file        
TYPE fpformoutput,
            lv_formname        
TYPE fpname VALUE ‘ZTEST_DYNAMIC_PICTURE’,
            lv_fmname          
TYPE funcname,
            lv_mseg            
TYPE  string,
            lv_w_cx_root       
TYPE  REF TO cx_root” Exception class

      ls_sfpoutputparamsdest     = ‘XX01’.
      ls_sfpoutputparams
nodialog = ‘X’.
      ls_sfpoutputparams
preview  = ‘X’.

     CALL FUNCTION ‘FP_JOB_OPEN’
     
CHANGING
           ie_outputparams
= ls_sfpoutputparams
     
EXCEPTIONS
           cancel         
= 1
           usage_error    
= 2
           system_error   
= 3
           internal_error 
= 4
          
OTHERS          = 5.

      IF sysubrc <> 0.
          
MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
          
WITH symsgv1 symsgv2 symsgv3 symsgv4.
     
ENDIF.

     TRY .
     
CALL FUNCTION ‘FP_FUNCTION_MODULE_NAME’
          
EXPORTING
                i_name    
= lv_formname
          
IMPORTING
                e_funcname
= lv_fmname.

      CATCH cx_root INTO lv_w_cx_root.
           lv_mseg
= lv_w_cx_root->get_text( ).
          
MESSAGE lv_mseg TYPE ‘E’.

     ENDTRY.

     MOVE: sylangu TO ls_docparamslangu.

     CALL FUNCTION lv_fmname
     
EXPORTING
           /1bcdwb/docparams 
= ls_docparams
           im_itab           
= p_gt_tab
     
IMPORTING
           /1bcdwb/formoutput
= ls_pdf_file
     
EXCEPTIONS
           usage_error       
= 1
           system_error      
= 2
           internal_error    
= 3
     
OTHERS             = 4.

      IF sysubrc <> 0.
          
MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
          
WITH symsgv1 symsgv2 symsgv3 symsgv4.
     
ENDIF.

     CALL FUNCTION ‘FP_JOB_CLOSE’
     
*   IMPORTING
     
*     E_RESULT             =
     
EXCEPTIONS
           usage_error         
= 1
           system_error        
= 2
           internal_error      
= 3
          
OTHERS               = 4.

      IF sysubrc <> 0.
          
MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
          
WITH symsgv1 symsgv2 symsgv3 symsgv4.
     
ENDIF.


ENDFORM.                    ” F_SUB_PRINT_FORM


Now build the simple form to test:


Go To SFP: Build an interface ZTEST_I_DYNAMIC_PICTURE and pass the import parameter in INPUT and OUTPUT parameter.

Image3.jpg

Now Build FORM Context.

image 4.jpg

Go to Layout:

Create one Image field into Design view and bind it with F_Sring which is the converted image in string format.


/wp-content/uploads/2014/02/layout_388584.jpg


Activate it.


Now execute your program. Enter the parameters. Business object and Object key. Here object key is the certificate Number and Business object ‘BUS2117’.


If you choose different Business object then you have to give correct object key. To get correct object key you can check the business object in SWO1 transaction.


After executing the output is coming like below.

/wp-content/uploads/2014/02/output_388585.jpg

Reference: I don’t want to mention particular documents but I take help on few threads on GOS and Adobe form in SCN to build this document.


Suggestion: Please feel free to suggest.

Assigned tags

      21 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Expecting suggestions and recommendations.

      Author's profile photo Anil Ahuja
      Anil Ahuja

      You are talking about Interface above but you have clicked on FORM.

      If we create FORM then which Interface will be used here?

      Author's profile photo Siji Thomas
      Siji Thomas

      Hello Abhijit,

      Can we add multiple jpeg images into adobe forms using above?

      Regards,

      Siji Thomas

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Hello Siji,

      It's possible.

      Thanks ,

      Abhijit

      Author's profile photo Mahesh kumar palavalli
      Mahesh kumar palavalli

      A good doc. i found till now on scn which has properly explained content related to GOS functionality.

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks Mahesh ....

      Author's profile photo ASHIS LOHIA
      ASHIS LOHIA

      Nice one.

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks...

      Author's profile photo Arindam Samanta
      Arindam Samanta

      Excellent stuff...Keep posting.. Waiting for next one...

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks Arindam

      Author's profile photo Anurag Sinha
      Anurag Sinha

      Nice 1...:)

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks....Could you please rate it?

      Author's profile photo Anurag Sinha
      Anurag Sinha

      I have done It 🙂

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks...

      Author's profile photo Former Member
      Former Member

      Superb Document!! Well done Abhijit!!

      Author's profile photo Daniel Pereira
      Daniel Pereira

      The restriction to use extension .PDF as a graphic comes from Adobe LiveCycle Designer, check online documentation:

      Adobe LiveCycle Designer 10.4.0_allowed graphic extension.PNG

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Thanks for the information Daniel.

      Author's profile photo Former Member
      Former Member

      Hi Abhijit,

      First of all - thanks for sharing the information in details. It really helps.

      I have a similar requirement of displaying images (.JPG) linked to the notification, which is based on GOS. All steps are clear except the adobe form setting where I have bound the table field of type string to an image field. It doesn't show up. I thought we would have to map it to a table control, which would include an image field

      Can you please share the setting in the form for the image field?

      Author's profile photo Abhijit Mandal
      Abhijit Mandal
      Blog Post Author

      Hello Shyam,

      Thanks for your message and sorry for my late reply. Currently, I am serving different client whom doesn't have the adobe Life Cycle. So, not able to show the setting .

      I will try to do it as early as possible.

      Thanks & Regards,

      Abhijit

      Author's profile photo Lech Dzierzawski
      Lech Dzierzawski

      Hello

      do you know how we can print GOS object on smartform?

       

      thx

      Lech

      Author's profile photo Abhishek Parab
      Abhishek Parab

      Thanks a lot for this Wonderful document