Streamlining ALV Functionality: Setting PF Status in ABAP for Enhanced User Interaction

 

Set PF Status :-

Setting the PF status (Personal Functions) in ALV ABAP allows you to customize the function keys (PF keys) available to the user within the ALV grid. Here are a few points on setting PF status in ALV ABAP.

  1. Customized Functionality: You can define specific functions or actions for function keys like F1 to F12, allowing users to perform common tasks directly from the ALV grid.
  2. User Interaction: By setting PF status, you provide users with intuitive ways to interact with the ALV report, such as navigating between pages, sorting data, filtering, or executing custom actions.
  3. Contextual Actions: PF status can be tailored to the context of the data displayed in the ALV grid, providing relevant functions based on the user's current task or selection.
  4. Integration with Toolbar: PF status can complement the standard toolbar options in ALV, offering additional functionality or shortcuts for frequently used actions.
  5. Personalization: Users can personalize their PF status by configuring their preferred function key assignments, allowing them to optimize their workflow according to their needs and preferences.
  6. Enhanced Productivity: By providing easy access to commonly used functions directly through function keys, PF status contributes to improved user productivity and efficiency in navigating and manipulating data.
  7. Dynamic Functionality: PF status can be dynamically updated based on user actions or changes in the application state, ensuring that the available functions remain relevant and contextual.
  8. Consistency with SAP Standards: Setting PF status aligns with SAP's user interface standards, promoting consistency across different SAP applications and facilitating a familiar user experience for SAP users.

Overall, setting PF status in ALV ABAP enhances the usability and functionality of your ALV reports by providing users with convenient access to relevant functions and actions through function keys.


Requirement :-

  • We will create a custom button on selection screen.



  • Suppose, we have few details from VBAK table above.

  • so, suppose I selected a row and once I click on the button, then it should be showing corresponding line items.


Solution :-

  • Step 1 :- Create a executable program in ABAP Editor.



  • Step 2 :- Create a type structure for few fields from VBAK and VBAP table.



  • Step 3 :- define a select option to take input in range.



  • Step 4 :- Write select queries to fetch data from the VBAK table.



  • Step 5 :- Write field catalogs for the above internal table.



  • Step 6 :- Call Function module REUSE_ALV_GRID_DISPLAY.



  • Step 7 :- Enable I_CALLBACK_PF_STATUS_SET and pass a parameter, also enable I_CALLBACK_PROGRAM.



  • Step 8 :- Now, copy the above parameter I_CALLBACK_PF_STATUS_GET and double click on REUSE_ALV_GRID_DISPLAY. and click on find.



  • Step 9 :- Double click on the function module



  • Step 10 :- again find.



    • Double click on REUSE_ALV_LIST_DISPLAY



    • copy below parameter



    • now find a subroutine with the same name.



  • Step 11 :- go back to the main program and create a subroutine with the same name.



  • Step 12 :- Create a set pf status and double click on it.

  • Step 13 :- Provide a short description.



  • Step 14 :- Open the Application toolbar and give a name in it.





  • Step 15 :- double click on DISPLAY → press enter



  • Step 16 :- Press enter → double click on any shortcut key→ provide the description.



  • Step 17 :- Press enter and activate it.

  • Step 18 :- Get back to original program and enable



  • Step 19 :- now go inside the function module REUSE_ALV_GRID_DISPLAY to copy the name of subroutine for the same and write the below logic.




Code :-

*&-----------------------------------------------------------------
*&Start of Program
*&--------------------------------------------
*&Creating Type Structure
*&----------------
TYPES : BEGIN OF ty_vbak,
          vbeln TYPE vbeln_va,
          erdat TYPE erdat,
          erzet TYPE erzet,
          ernam TYPE ernam,
          vbtyp TYPE vbtypl,
        END OF ty_vbak.

TYPES : BEGIN OF ty_vbap,
          vbeln TYPE vbeln_va,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
        END OF ty_vbap.
*&-----------------------------------------
*& Defining internal table and work area
DATA : lt_vbak TYPE TABLE OF ty_vbak,
       ls_vbak TYPE ty_vbak,
       lt_vbap TYPE TABLE OF ty_vbap,
       ls_vbap TYPE ty_vbap.

DATA : lt_fieldcat1 TYPE TABLE OF slis_fieldcat_alv,
       ls_fieldcat1 TYPE slis_fieldcat_alv,
       lt_fieldcat2 TYPE TABLE OF slis_fieldcat_alv,
       ls_fieldcat2 TYPE slis_fieldcat_alv.
*&-------------------------------------------------
*&-Defining select options
DATA : lv_vbeln TYPE vbeln_va.
SELECT-OPTIONS : s_vbeln FOR lv_vbeln.

SELECT vbeln erdat erzet ernam vbtyp
  FROM vbak INTO TABLE lt_vbak
  WHERE vbeln IN s_vbeln.

IF lt_vbak IS NOT INITIAL.
  ls_fieldcat1-seltext_l = 'Sales Document Number'.
  ls_fieldcat1-fieldname = 'VBELN'.
  APPEND ls_fieldcat1 TO lt_fieldcat1.
  CLEAR ls_fieldcat1.

  ls_fieldcat1-seltext_l = 'Creation Date'.
  ls_fieldcat1-fieldname = 'ERDAT'.
  APPEND ls_fieldcat1 TO lt_fieldcat1.
  CLEAR ls_fieldcat1.

  ls_fieldcat1-seltext_l = 'Time'.
  ls_fieldcat1-fieldname = 'ERZET'.
  APPEND ls_fieldcat1 TO lt_fieldcat1.
  CLEAR ls_fieldcat1.

  ls_fieldcat1-seltext_l = 'Created By'.
  ls_fieldcat1-fieldname = 'ERNAM'.
  APPEND ls_fieldcat1 TO lt_fieldcat1.
  CLEAR ls_fieldcat1.

  ls_fieldcat1-seltext_l = 'Document Category'.
  ls_fieldcat1-fieldname = 'VBTYP'.
  APPEND ls_fieldcat1 TO lt_fieldcat1.
  CLEAR ls_fieldcat1.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'PF_STATUS'
     I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
*     I_CALLBACK_TOP_OF_PAGE   = ' '
*     I_STRUCTURE_NAME         =
      it_fieldcat              = lt_fieldcat1
    TABLES
      t_outtab                 = lt_vbak
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

ENDIF.

FORM pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'SALES'.
ENDFORM.
FORM USER_COMMAND  USING R_UCOMM LIKE SY-UCOMM
                                  RS_SELFIELD TYPE SLIS_SELFIELD.
  SELECT vbeln posnr matnr FROM vbap
    INTO TABLE lt_vbap
    WHERE vbeln = RS_SELFIELD-value.
  IF lt_vbap IS NOT INITIAL.
		REFRESH lt_fieldcat1.

    ls_fieldcat2-seltext_l = 'Sales Document Number'.
    ls_fieldcat2-fieldname = 'VBELN'.
    APPEND ls_fieldcat2 TO lt_fieldcat2.
    CLEAR ls_fieldcat2.

    ls_fieldcat2-seltext_l = 'Item Number'.
    ls_fieldcat2-fieldname = 'POSNR'.
    APPEND ls_fieldcat2 TO lt_fieldcat2.
    CLEAR ls_fieldcat2.

    ls_fieldcat2-seltext_l = 'Material Number'.
    ls_fieldcat2-fieldname = 'MATNR'.
    APPEND ls_fieldcat2 TO lt_fieldcat2.
    CLEAR ls_fieldcat2.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       IT_FIELDCAT                       = lt_fieldcat2
      TABLES
        t_outtab                          = lt_vbap
     EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
              .
  ENDIF.

ENDFORM.

*&-------------------------------------------
*&End of Program
*&-------------------------------------------------------------

Execute the code :-



  • Select any row and click on the custom button.


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