Logic Writing for Smartform in ABAP Editor ( SE38 )

  • When we have created the smartform, what we saw was that, we had to write the selection logic for our smartform in the Global definition of our smartform tab.
  • Now, think like this,
    • If someone asks you whether or not you can write logic for your smartform in the ABAP Editor, what will you reply ?

Ans :-

  • Yes, definitely we can write logic for our smartform in the driver program.

Important Points for any Smartform :-

  • Smartforms are only for designing the layout.
  • We should always avoid writing the logic for our smartform in the global definitions as it can impact the performance of our smartform.
  • So, it is always a good practice to write the logic for our smartform into the program, and then we can call the function module for the same and execute the smartform.

So, for our smartform,

Solution :-

  • Step 1 :- We will copy the type structures and select queries from the smartform and we will write it into the driver program.



  • Step 2 :- Create the internal table and work area for the same structures.



  • Step 3 :- Now we will copy the select logic from initialization tab of smartform and will paste it into the driver program after start of selection.



  • Step 4 :- Since, we have removed the logic from global definitions, therefore we need to pass them into the form interface so that we can pass these things from the program.

    So, we will create a structure for employee table and a table type for project table.

  • Step 5 :- Create a structure from ABAP dictionary for the employee table.



  • Step 6 :- Create a structure for Project table.



  • Step 7 :- Since, we have to pass the table for the project details, therefore we will create a table type for our project structure.



  • Step 8 :- Now, we will pass the structure and internal table to the import tab of form interface.



  • Step 9 :- We will pass the work area for the project internal table into the global definition.




Reference Fields for Currency and Quantity Fields :-




Code :-

*&---------------------------------------------------------------------*
*& Report ZAR_SMARTFORM
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAR_SMARTFORM.

TYPES : BEGIN OF ty_employee,
          emp_id   TYPE zar_employee_id,
          emp_name TYPE zar_employee_nam,
          manager  TYPE zar_manager,
          salary   TYPE zar_salary,
        END OF ty_employee.

TYPES : BEGIN OF ty_project,
          proj_id   TYPE zar_proj_id,
          proj_name TYPE zar_proj_nam,
          proj_typ  TYPE zar_proj_typ,
        END OF ty_project.

DATA : lt_employee type table of ty_employee,
       ls_Employee type ty_employee,
       lt_project type table of ty_project,
       ls_project type ty_project.

PARAMETERS : p_emp_id type ZAR_EMPLOYEE_ID.

START-OF-SELECTION.

select EMP_ID emp_name manager salary
  from ZAR_EMPLOYEE_TAB
  into table lt_employee
  where emp_id = p_emp_id.

If lt_employee is not INITIAL.
  select PROJ_ID proj_name proj_typ
    from ZAR_PROJECT_EMP
    into table lt_project
    FOR ALL ENTRIES IN lt_employee
    where EMP_ID = lt_employee-emp_id.

endif.
READ TABLE lt_employee into ls_employee index 1.

DATA : lv_function_module type RS38L_FNAM.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname                 = 'ZAR_SMARTFORM'
*   VARIANT                  = ' '
*   DIRECT_CALL              = ' '
 IMPORTING
   FM_NAME                  = lv_function_module
 EXCEPTIONS
   NO_FORM                  = 1
   NO_FUNCTION_MODULE       = 2
   OTHERS                   = 3
          .

CALL FUNCTION lv_function_module
  EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
*   CONTROL_PARAMETERS         =
*   MAIL_APPL_OBJ              =
*   MAIL_RECIPIENT             =
*   MAIL_SENDER                =
*   OUTPUT_OPTIONS             =
*   USER_SETTINGS              = 'X'
    p_emp_id                   = p_emp_id
    ls_employee                = ls_employee
    lt_project                 = lt_project
* 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
          .

Execute the Code :-



  • Press F8.



Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming

Introduction to SAP