Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
sivaganesh_krishnan
Contributor

Hello Everyone,

There are many way to download program and FM from a package. But there are less resource to find the way to download all the smartforms from a package.This document will let you through on how to download only the smartforms from a package in OOPS concept.

Step 1. Lets start with the declaration part.


TABLES: sscrfields.



TYPES: ty_raw(250TYPE x.


TYPES: BEGIN OF ty_packagedetails,


          formname   TYPE tdsfname,                           "Smart Form name


          package    TYPE devclass,                           "Package


END OF ty_packagedetails.


DATA:   v_name  TYPE formname.                               "For select-option


Step 2 :Now define the screen fields to get the package name. Here I have kept a select option , So we can process multiple packages.


SELECTION-SCREEN BEGIN OF BLOCK bl_devc WITH FRAME TITLE text-003.


SELECTION-SCREEN FUNCTION KEY 1.


SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN:POSITION 1.


SELECTION-SCREEN COMMENT 2(10) text-001 .



SELECTION-SCREEN POSITION 19.                                "For Getting the Package


SELECT-OPTIONS: so_pack FOR v_name                           "Package


                 MODIF ID gp NO INTERVALS.


                


SELECTION-SCREEN END OF LINE.


SELECTION-SCREEN END OF BLOCK bl_devc.



Step 3: Class definition



CLASS lcl_download_smartform DEFINITION FINAL.



   PUBLIC SECTION.


     TYPES ty_name              TYPE RANGE OF stxftxt-formname.


     CONSTANTS: c_extension     TYPE string VALUE 'C:\Users\Siv\Desktop'.


                                                                  "Object declaration


     DATA: lo_ixml              TYPE REF TO if_ixml,              "Object for xml interface.


           lo_xml_document      TYPE REF TO if_ixml_document,     "Object creating xml document


           lo_sform             TYPE REF TO cl_ssf_fb_smart_form, "Object for class CL_SSF_FB_SMART_FORM.


           lo_element           TYPE REF TO if_ixml_element.      "Object for QUERY_INTERFACE


                                                                  "Local Variable For xml


     DATA: lv_xml_ns_prefix_sf  TYPE string,                      "Variable for prefix value in xml


           lv_xml_ns_uri_sf     TYPE string,                      "For xml namespace URL


           lv_xml_ns_uri_ifr    TYPE string.                      "For xml namespace URL




     DATA: lv_formname          TYPE tdsfname,                    "Smart Form Name


           lv_languagename      TYPE sy-langu,                    "Language Name


           lv_fmnumb            TYPE tdfmnumb,                    "For geting import values


           lv_fmnumb_test       TYPE tdfmnumb.                    "For geting import values



     DATA: lv_filename          TYPE string,                      "File Name


           lv_drivepath         TYPE string,                      "Local Drive Path


           lv_filepath          TYPE string,                      "Full Path of File


           lv_result            TYPE i,                           "User Action in FILE_AS_DIALOG


           lv_savepackage       TYPE string,                      "Export parameter in FILE_AS_DIALOG


           lv_package           TYPE string,                      "Export parameter in FILE_AS_DIALOG


           lv_savesmartform     TYPE string,                      "Export parameter in FILE_AS_DIALOG


           lv_smartform         TYPE string,                      "Export parameter in FILE_AS_DIALOG


           lv_namespace         TYPE string,                      "For namespace


           lv_languagestring    TYPE string,                      "For Language text element


           lv_xml               TYPE string.                      "For xml text element





     DATA: lv_xml_document_size TYPE i,                           "Contains document size


           lv_xml_fullpath      TYPE string,                      "Containes the full address


           lv_xml_fullpath_pack TYPE string,                      "Contains full address for package        


           lv_smartname         TYPE tdsfname.                    "Export Parameter in sform


                                                                  "Variables for Language


     DATA: lv_language_str      TYPE string,


           lv_language(2)       TYPE c.



*&---------------Internal table and workarea-----------------------------*


                                                                  "Internal Table to hold Formname


     DATA: lt_table             TYPE STANDARD TABLE OF ty_packagedetails,


           lt_xml_xtable        TYPE STANDARD TABLE OF ty_raw,


           lx_table             TYPE ty_packagedetails.           "Workarea



     METHODS: package           IMPORTING i_packname TYPE ty_packagedetails


                                          i_name     TYPE stxftxt-formname ,                    


              package_download  IMPORTING i_name     TYPE ty_name.



ENDCLASS.                             "lcl_download_smartform DEFINITION




Step 4:We have defined two methods. method package will  help  downloading the smartforms into xml format and into the presentation server and Package_download will help in retrieving all the smartforms from package.



CLASS lcl_download_smartform IMPLEMENTATION.



   METHOD package_download.                                        "To get  all smart forms from package and  pass value to method package



     SELECT formname                                               "Selecting all the smart forms from package


            devclass


       FROM stxfadm


       INTO TABLE lt_table


      WHERE devclass IN i_name.



     IF sy-subrc EQ 0.



       LOOP AT lt_table INTO lx_table .                            "Looping values of workarea to method Package for downloading to xml


         IF lv_result = cl_gui_frontend_services=>action_cancel.


           RETURN.


         ENDIF.


         CALL METHOD package


           EXPORTING


             i_packname = lx_table


             i_name     = lx_table-package.


       ENDLOOP.


     ELSE.


       IF lv_xml_fullpath_pack IS  INITIAL.


                                                                   "Error if Package is not present in SAP


         MESSAGE s000 DISPLAY LIKE 'E'  WITH  text-004.            "Package(s) does not exist


       ENDIF.


     ENDIF.


     CLEAR lx_table.



   ENDMETHOD.                    "package_download


  




   METHOD package.                                               "Converts the smart forms to xml and place each package's smart form in seperate folder



     lv_xml            = text-026.                               ".xml


     lv_languagestring = text-025.                               "language


     lv_namespace      = text-024.                               "xmlns


     lv_xml_ns_uri_sf  = text-016.                               "urn:sap-com:SmartForms:2000:internal-structure


     lv_formname       = i_packname.                             "Formname.


     lv_languagename   = sy-langu.



     CREATE OBJECT lo_sform.


     CALL METHOD lo_sform->load


       EXPORTING


         im_formname    = lv_formname                            "Formname


         im_language    = lv_languagename


         im_active      = space


       IMPORTING


         ex_fmnumb      = lv_fmnumb


         ex_fmnumb_test = lv_fmnumb_test.



     IF lo_ixml IS INITIAL.


       lo_ixml            = cl_ixml=>create( ).


     ENDIF.


     lo_xml_document      = lo_ixml->create_document( ).


     lv_xml_ns_prefix_sf  = 'sf'.


     lv_xml_ns_uri_ifr    = text-023.                             "Urn:sap-com:sdixml-ifr:2000 (XML URL)


     CLEAR: lv_xml_document_size, lt_xml_xtable[].


     lo_sform->xml_init( ).



     CALL METHOD lo_sform->xml_download                           "Create XML for the entire smart form


       EXPORTING


         parent   = lo_xml_document


       CHANGING


         document = lo_xml_document.



     lo_element  = lo_xml_document->get_root_element( ).          "Namespace


     lo_element->set_attribute( name     = lv_xml_ns_prefix_sf


                               namespace = lv_namespace


                               value     = lv_xml_ns_uri_sf ).


     lo_element->set_attribute( name     = lv_namespace


                               value     = lv_xml_ns_uri_ifr ).



     lv_language_str = lv_language.                               "Language


     lo_element->set_attribute(


                         name      = lv_languagestring


                         namespace = lv_xml_ns_prefix_sf


                         value     = lv_language_str ).



     CALL FUNCTION 'SDIXML_DOM_TO_XML'                            "Convert DOM to xml


       EXPORTING


         document     = lo_xml_document


       IMPORTING


         size         = lv_xml_document_size


       TABLES


         xml_as_table = lt_xml_xtable


       EXCEPTIONS


         OTHERS       = 1.


     IF sy-subrc EQ 0.


       lv_savepackage = text-015.                                "Save Package


       lv_package     = text-011.                                "Package



       IF lv_filepath IS INITIAL.



         CALL METHOD cl_gui_frontend_services=>file_save_dialog  "File Save Dialog PopUp


           EXPORTING


             window_title      = lv_savepackage


             default_extension = ''


             default_file_name = lv_package


             initial_directory = c_extension


           CHANGING


             filename          = lv_filename


             path              = lv_drivepath


             fullpath          = lv_filepath


             user_action       = lv_result.


       ENDIF.


       IF lv_result = cl_gui_frontend_services=>action_cancel.


         RETURN.


       ENDIF.



       CONCATENATE lv_filepath                                  "Specifying the Location From Function Module


                   '\'


                   i_name


                   '\'


                   lx_table-formname lv_xml


              INTO lv_xml_fullpath_pack .



       CALL METHOD cl_gui_frontend_services=>gui_download


         EXPORTING


           filename     = lv_xml_fullpath_pack


           filetype     = 'BIN'


           bin_filesize = lv_xml_document_size


         CHANGING


           data_tab     = lt_xml_xtable[]


         EXCEPTIONS


           OTHERS       = 1.


       FREE: lo_xml_document, lt_xml_xtable[], lv_xml_document_size.


     ENDIF.



   ENDMETHOD.                    "package


                                               


 



ENDCLASS.                    "lcl_download_smartform IMPLEMENTATION




Step 5:



START-OF-SELECTION.


DATA: o_obj   TYPE REF TO lcl_download_smartform.


CREATE OBJECT o_obj.




IF so_pack IS  NOT  INITIAL.


       CALL METHOD o_obj->package_download


         EXPORTING


           i_name = so_pack[].


     ELSE.


       MESSAGE s000 DISPLAY LIKE 'E' WITH text-005.    "Enter Package


ENDIF.




So once once you execute , you can specify the package names in multiple selection screen



You can see that i have added zsiva and zdam as packages, and once you execute you will get a pop for selecting the location to store, Default location will be desktop with default folder name as package.

Once you click on save the code gets executed and all the smartforms from the package gets transformed to xml and starts downloading , once its starts to download you will get to see this status

And once the download is over the status changes to


Which means that all you smartforms from your package got downloaded to your presentation server. You can notice that the smartforms will be downloaded in specified package name .


Hope you enjoyed this document .

Sivaganesh




3 Comments