PF Status and User Command Using CL_SALV_TABLE Class

 

  • In the previous part, we achieved a requirement using double click.

  • Lets understand today’s requirement,

  • Our requirement, is that User will provide a range of Sales Document number as input.

  • We will display details of that Sales Document number as output from VBAK table in one ALV.

  • I will create a custom button on the ALV.



  • Then I will select one row of ALV and when I will click on the button, It will show the item details from VBAP table for the same selected rows.




Solution :-

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

  • Step 2 :- Create a type structure from VBAK and VBAP table and then create a corresponding internal table for the same

  • Step 3 :- Define a select option for user input.


  • Step 4 :- In start of selection, write a select query from VBAK table.

  • Step 5 :- Now we need to get object of CL_SALV_TABLE by using its factory method.

  • Step 6 :- Then we will use display method to display first ALV.

  • Step 7 :- Now we need to create a set PF Status under start of selection.



  • Step 8 :- Double click on the TEST above.



    • Press Enter., here we will create a DISPLAY button in Application toolbar.



  • Step 9 :- Now we need to set this PF status to our ALV.



    • Step 10 :- Now we will call GET_EVENT method to get the events.


    • It will return the object of event class.
  • Step 11 :- then we will create a class i which we will handle the method ADDED_FUNCTION of the CL_SALV_EVENTS_TABLE class and we will write the logic in the implementation part of that class.


Code :-

*&---------------------------------------------------------------------*
*& Report ZAR_SALES_ORDER_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zar_sales_order_double_click.

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.

DATA : lt_vbak TYPE TABLE OF ty_vbak,
       lt_vbap TYPE TABLE OF ty_vbap.

DATA : lo_grid TYPE REF TO cl_gui_alv_grid.

DATA : lv_vbeln TYPE vbeln_va.
SELECT-OPTIONS : s_vbeln FOR lv_vbeln.

CLASS local DEFINITION.
  PUBLIC SECTION.
    METHODS handle FOR EVENT added_function OF cl_salv_events_table IMPORTING e_salv_function.

ENDCLASS.

CLASS local IMPLEMENTATION.
  METHOD handle.

    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = lo_grid.

    DATA : lt_rows TYPE lvc_t_row,
           ls_rows TYPE lvc_s_row.
    CALL METHOD lo_grid->get_selected_rows
      IMPORTING
        et_index_rows = lt_rows
*       et_row_no     =
      .

    READ TABLE lt_rows INTO ls_rows INDEX 1.
    IF sy-subrc EQ 0.
      READ TABLE lt_vbak INTO DATA(ls_vbak) INDEX ls_rows-index.
      IF sy-subrc EQ 0.
        SELECT vbeln posnr matnr
          FROM vbap
          INTO TABLE lt_vbap
          WHERE vbeln = ls_vbak-vbeln.

        IF lt_vbap IS NOT INITIAL.
          TRY.
              CALL METHOD cl_salv_table=>factory
                EXPORTING
                  list_display = if_salv_c_bool_sap=>false
                IMPORTING
                  r_salv_table = DATA(lo_obj2)
                CHANGING
                  t_table      = lt_vbap.
            CATCH cx_salv_msg.
          ENDTRY.

          lo_obj2->display( ).

        ENDIF.

      ENDIF.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

  SET PF-STATUS 'TEST'.

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

  IF lt_vbak IS NOT INITIAL.

    TRY.
        CALL METHOD cl_salv_table=>factory
          EXPORTING
            list_display = if_salv_c_bool_sap=>false
*           r_container  =
*           container_name =
          IMPORTING
            r_salv_table = DATA(lo_object)
          CHANGING
            t_table      = lt_vbak.
      CATCH cx_salv_msg.
    ENDTRY.

    TRY.
        CALL METHOD lo_object->set_screen_status
          EXPORTING
            report   = sy-repid
            pfstatus = 'TEST'
*           set_functions = C_FUNCTIONS_NONE
          .
    ENDTRY.

    CALL METHOD lo_object->get_event
      RECEIVING
        value = DATA(lo_event).

    DATA(lo_local) = NEW local( ).
    SET HANDLER lo_local->handle FOR lo_event.

    lo_object->display( ).

  ENDIF.

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

Execute the Code :-



  • Press F8.
  • Select any row.


  • Click on button Sales Item details.


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