ABAP: One of smartforms: data is transmitted from the program to the form.

Source: Internet
Author: User

Both smartforms and sapscript form are tools for designing and printing reports in SAP. However, sapscript needs to manually draw table lines based on coordinates and length and height, which is inconvenient, smartforms has a GUI to draw the interface directly. Therefore, it is much easier to use smartforms to design report printing. In addition, sapsrcipt needs to be transmitted in different clients, which is inconvenient to test. Transactions that transmit sapscriptCodeIs:Scc1, CorrespondingProgramNameRstxscrp.

Transaction code:Smartforms

In SAP's ABAP programming, the general development process is to retrieve all the required data in the report program, process the data, and save it to the output table, print the data in the internal table, but smartforms is an independent external function module. Internal table data defined in the program cannot be directly transmitted, you need to define an external data structure or use a standard table structure. If the program changes and the data to be transferred changes, you need to modify the sturcture, which is inconvenient in smartforms.

Of course, we can also write the data logic in smartforms, but in smartforms programming is not very convenient, and sometimes our data needs to be first displayed in the form of list or ALV list, then print the data. Therefore, writing the data retrieval logic in smartforms is only applicable to some scenarios where requirements are very simple.

We decided to perform the fetch logic in the report program and then try to pass the data to smartforms. We know that an object can be export to the memory or database in SAP, And we can retrieve the data again based on a string similar to a handle, it is no problem to transmit a string to smartforms, so we only need to export the table to the memory or database, and pass the handle to smartforms, in smartforms, you first define an internal table of the same type, and then import the data impor to the internal table to completely restore the data. This completes the data transfer.

The include programs of import and export are as follows:

*&---------------------------------------------------------------------*
*& Including zinc_sf_helper *
*&---------------------------------------------------------------------*

Types buffer_id ( 80 ) Type C.
Data wa_indx type indx.

Define savebuffer.
Perform save_to_buffer using & 1   & 2 .
End - Of - Definition.

Define clearbuffer.
Perform clear_buffer using & 1 .
End - Of - Definition.
*&--------------------------------------------------------------------*
*& Form get_unique_id
*&--------------------------------------------------------------------*
* Text
*---------------------------------------------------------------------*
* --> Id text
*---------------------------------------------------------------------*
* Form get_unique_id using typeid Type C changing ID type C.
* Data: m_buff ( 32 ) Type C.
* Call   Function   ' Th_get_session_id'
* Importing
* Session_id = M_buff
** Id_len =
* .
* Concatenate SY - Repid ' _ 'M_buff typeid into ID.
* Endform. " Get_unique_id


*&--------------------------------------------------------------------*
*& Form save_to_buffer
*&--------------------------------------------------------------------*
* Text
*---------------------------------------------------------------------*
* --> T text
* --> Buff_id text
*---------------------------------------------------------------------*
Form save_to_buffer using T type table typeid type C.
Wa_indx - Aedat = Sy - Datum.
Wa_indx - Usera = Sy - Uname.
Wa_indx - Pgmid = Sy - Repid.
* Perform get_unique_id using buff_id changing buff_id.
Export t To Database indx (HK) ID typeid from wa_indx.
Endform. " Save_to_buffer

*&--------------------------------------------------------------------*
*& Form clear_buffer
*&--------------------------------------------------------------------*
* Text
*---------------------------------------------------------------------*
* --> Buff_id text
*---------------------------------------------------------------------*
Form clear_buffer using buffid type C.
Delete from database indx (HK) ID buffid.
Endform. " Clear_buffer

Form restor_buffer using typeid Type C changing T type table.
Import t from database indx (HK) ID typeid.
Endform.

The following is a call example:

Form frm_print_data.

Data: headername ( 18 ) Type C.
Data: itemsname ( 18 ) Type C.
"Adding the current server time in the handle as the handle name prevents multiple users from using this program at the same time, resulting in the same handle name
Concatenate ' Zspmmf1002hd 'SY-UZEIT into headername.
Concatenate ' Zspmmf1002it 'SY-UZEIT into itemsname.

Savebuffer ig_output_h [] headername. "ig_output_h is the internal table that stores the data in the output table header.
Savebuffer ig_output_d [] itemsname. "ig_output_d is an internal table that stores output data details. It has fields associated with the header data.

Data: wl_fmname type rs38l_fnam.
* Use the smartforms name to obtain the name of the function module after compilation.
Call function 'ssf _ function_module_name'
Exporting
Formname = 'zspmmf1007x' "smartforms name
* Variant =''
* Direct_call =''
Importing
Fm_name = wl_fmname
Exceptions
No_form = 1
No_function_module = 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.
Endif.
Call   Function   Wl_fmname
Exporting
* Archive_index =
* Archive_index_tab =
* Archive_parameters =
* Control_parameters =
* Mail_appl_obj =
* Mail_recipient =
* Mail_sender =
* Output_options =
* User_settings =   ' X'
Ptr_header = Headername
Ptr_items = Itemsname
* Importing
* Document_output_info =
* Job_output_info =
* Job_output_options =
Exceptions
Formatting_error =   1
Internal_error =   2
Send_error =   3
User_canceled =   4
Others =   5
.
If Sy - Subrc <>   0 .
Message ID SY - Msgid type SY - Msgty number SY - Msgno
With Sy - Msgv1 SY - Msgv2 SY - Msgv3 SY - Msgv4.
Endif.

Clearbuffer headername. "delete data after calling
Clearbuffer itemsname.

Endform."Frm_print_data

Data export to memory can achieve better efficiency, but generally the SAP application server uses a cluster, so we will be more secure when exporting data to the database.

In SeriesArticle2. describes the design of smartforms.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.