Downloading a SO10 text in word format(In presentation server) in wda abap.

·        Create an input field and  button on the view.

·        In the input field user enters the SO10 text that needs to be downloaded

·        Assign an action to this button.So that when user clicks on the button , desired So10 text should get downloaded in MS word.

·        Then the entire coding of reading the input field and downloading the SO10 text can be done in the action method say for eg ONACTIONONDOWNLOAD

·        Copy paste the below code in the method.

method ONACTIONONDOWNLOAD .

  DATA lo_el_context TYPE REF TO if_wd_context_element.
 
DATA ls_context TYPE wd_this->element_context.
 
DATA lv_so10_text TYPE wd_this->element_context-so10_text.
* get element via lead selection
  lo_el_context = wd_context->get_element( ).* @TODO handle not set lead selection
 
IF lo_el_context IS INITIAL.
 
ENDIF.
* get single attribute
  lo_el_context->get_attribute(
   
EXPORTING
      name = 
`SO10_TEXT`
   
IMPORTING
     
value = lv_so10_text ).

    DATA lt_lines TYPE TABLE OF TLINE.
   
DATA wa_lines TYPE tline.*** DECLARATION OF CONSTANTCONSTANTS: lc_ID TYPE THEAD-TDID VALUE ‘ST’,
           lc_object
TYPE THEAD-TDOBJECT VALUE ‘TEXT’.
DATA: lv_name TYPE thead-tdname.
lv_name = lv_so10_text.
** CALLING OF THE STANDARD TEXTSCALL FUNCTION ‘READ_TEXT’
 
EXPORTING
  
CLIENT                         = SY-MANDT
   
ID                            = lc_ID
   
LANGUAGE                      = sy-langu
    NAME                          = lv_name 
    OBJECT                        = lc_object
   ARCHIVE_HANDLE                =
0
   LOCAL_CAT                     =
‘ ‘* IMPORTING*   HEADER                        =
 
TABLES
   
LINES                         = lt_lines
EXCEPTIONS
  
ID                            = 1
  
LANGUAGE                      = 2
   NAME                          =
3
   NOT_FOUND                     =
4
   OBJECT                        =
5
   REFERENCE_CHECK               =
6
   WRONG_ACCESS_TO_ARCHIVE       =
7
  
OTHERS                        = 8
          .IF SY-SUBRC <> 0.* Implement suitable error handling hereENDIF.DATA: lv_notetmp1 TYPE string,
  lv_note1
TYPE string,
  lv_note2
TYPE xstring.
loop at lt_lines into wa_lines.

lv_notetmp1 = wa_lines-tdline.
concatenate lv_note1 wa_lines-tdline cl_abap_char_utilities=>newline into lv_note1 SEPARATED BY space.

ENDLOOP.
CALL FUNCTION ‘SCMS_STRING_TO_XSTRING’
 
EXPORTING
   
text           = lv_note1*   MIMETYPE       = ‘ ‘*   ENCODING       =
IMPORTING
  
BUFFER         = lv_note2* EXCEPTIONS*   FAILED         = 1*   OTHERS         = 2
          .IF sy-subrc <> 0.* Implement suitable error handling hereENDIF.

CALL METHOD cl_wd_runtime_services=>attach_file_to_response
 
EXPORTING
    i_filename      =
‘.doc’
    i_content       = lv_note2
    i_mime_type     =
‘DOC’*    i_in_new_window = ABAP_FALSE*    i_inplace       = ABAP_FALSE
    .

endmethod.

·        Create the application and run it.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply