Unlocking SAP ABAP Secrets: Interactive Classical Reports with GET CURSOR, At User Command, and a Comparison of HIDE Statements

 Welcome back everyone, We were discussing about the interactive classical reports, so let’s continue it.


Interactive Classical Reports- GET CURSOR :-

  • In Interactive Classical Reports, GET CURSOR statement is used to create secondary list according to cursor position.
  • The parameter FIELD provides the name of an output field. The parameter VALUE provide the output value.
  • Syntax : GET CURSOR FIELD <lv_field> VALUE <lv_value>.
  • In the above syntax - the field name and field value will be returned in to variables lv_field and lv_value respectively.

Requirement :-

  • If you remember, In our last two blog, We have been displaying the order header table in a basic list and order item table in the secondary list.

  • We have used SY-LISEL and HIDE statements to achieve the requirement.

  • Now, we have to use the get CURSOR to achieve the same to same requirement.



    Code :-

    *************************************************************
    *Start of Program
    *Declaring Strcutrure for header
    TYPES: BEGIN OF ty_header,
             order_number TYPE zar_order_number,
             order_date   TYPE zar_order_date,
             payment_mode TYPE zar_payment_mode,
             currency     TYPE zar_curency,
           END OF ty_header.
    
    *********************
    *Internal table and Work Area
    DATA : lt_header TYPE TABLE OF ty_header,
           ls_header TYPE ty_header.
    
    ****************
    *Declaring Strcuture for item table
    TYPES: BEGIN OF ty_item,
             order_number      TYPE zar_order_number,
             order_item_number TYPE zar_order_item_number,
             item_cost         TYPE zar_total_amount,
           END OF ty_item.
    
    ************************************
    *Declaring internal table and work area
    DATA : lt_item TYPE TABLE OF ty_item,
           ls_item TYPE ty_item.
    
    *******************************
    *Variable declaration.
    DATA : lv_field(30) TYPE c,
           lv_value(30) TYPE c.
    *******************************
    *Select option Declaration
    DATA : lv_order TYPE zar_order_number.
    SELECT-OPTIONS : s_order  FOR lv_order.
    
    *********************************
    *Writing a select query for header
    START-OF-SELECTION.
      SELECT order_number order_date
        payment_mode currency
        FROM zar_header INTO
        TABLE lt_header
        WHERE order_number IN s_order.
    
    ***************************************
    *Displaying the data
      LOOP AT lt_header INTO ls_header.
        WRITE :/ ls_header-order_number,
                 ls_header-order_date,
                 ls_header-payment_mode,
                 ls_header-currency.
    
      ENDLOOP.
    *********************************
    AT LINE-SELECTION.
    ***********
    *GET Cursor Declaration.
      GET CURSOR FIELD lv_field VALUE lv_value.
    *******************
    *Using stored data in GET CURSOR.
      IF lv_field = 'LS_HEADER-ORDER_NUMBER'.
        SELECT order_number
            order_item_number
            item_cost FROM zar_item
          INTO TABLE lt_item
          WHERE order_number = lv_value.
    
        IF lt_item IS NOT INITIAL.
    ****************************
    *LOOP on item
          LOOP AT lt_item INTO ls_item.
            WRITE :/ ls_item-order_number,
                     ls_item-order_item_number,
                     ls_item-item_cost.
          ENDLOOP.
        ENDIF.
      ENDIF.
    
    ********************************************
    *End of Program
    ***************************************************************
    

    Execute the Program :-



    • Click on execute button.


  • Double click on any order number, suppose on second record.




Comparison of HIDE and GET CURSOR Statements :-

  • HIDE statement responds for a particular line whereas GET CURSOR statement responds for a particular field.
  • HIDE statement is used to store the line with the line number in the hide area whereas GET CURSOR is used to store the value of the selected field name.
  • With HIDE statement, we can not display secondary lists based upon field name and field value whereas with GET CURSOR statement we can display secondary lists based upon the field name and field value.

So, this was all about At Selection Line event, now let’s discuss At User Command Event.

2. At User Command :-

  • When user click on the functions created using pf-status, at that time at user-command event triggers.
    • PF → Personal Functions
  • The system variable SY-UCOMM is used to capture the value of function code.

Let’s understand the At User Command event, with a real life scenario :-

Requirement :-

  • First we display the data of our order header table in a basic list.

  • Then, We will create two functions



  • If, we click on sort using Ascending the data will be sorted in Ascending and IF I will click on descending data will be sorted into descending.

Solution :-

  • Step 1 :- Go to SE38 ( ABAP Editor ).

  • Step 2 :- Create a executable Program.

  • Step 3 :- Normally you can use the steps of the above program, till displaying the basic list.

  • Step 4 :- Use SET PF Status to create function.



  • Step 5 :- Double click on the function.



  • Step 6 :- Click On yes and provide short description and press enter.



  • Step 7 :- Open the Application Toolbar.



  • Step 8 :- Double Click on both ASCENDING and DESCENDING and provide the necessary details → press enter.



    • Same for descending.



  • Step 9 :- Activate the application toolbar.



  • Step 10 :- Write logic for the function in at user command.




Code :-

*************************************************************
*Start of Program
*Declaring Strcutrure for header
TYPES: BEGIN OF ty_header,
         order_number TYPE zar_order_number,
         order_date   TYPE zar_order_date,
         payment_mode TYPE zar_payment_mode,
         currency     TYPE zar_curency,
       END OF ty_header.

*********************
*Internal table and Work Area
DATA : lt_header TYPE TABLE OF ty_header,
       ls_header TYPE ty_header.

*******************************
*Select option Declaration
DATA : lv_order TYPE zar_order_number.
SELECT-OPTIONS : s_order  FOR lv_order.

*********************************
*Writing a select query for header
START-OF-SELECTION.
  SELECT order_number order_date
    payment_mode currency
    FROM zar_header INTO
    TABLE lt_header
    WHERE order_number IN s_order.

***************************************
*Displaying the data
  LOOP AT lt_header INTO ls_header.
    WRITE :/ ls_header-order_number,
             ls_header-order_date,
             ls_header-payment_mode,
             ls_header-currency.

  ENDLOOP.
*********************************
*SET PF STATUS
  SET PF-STATUS  'FUNCTION'.

**********************
*At User Command
AT USER-COMMAND.
  IF sy-ucomm EQ 'ASCENDING'.
    SORT lt_header BY order_number.
    LOOP AT lt_header INTO ls_header.
      WRITE :/ ls_header-order_number,
               ls_header-order_date,
               ls_header-payment_mode,
               ls_header-currency.

    ENDLOOP.

  ELSEIF sy-ucomm EQ 'DESCENDING'.
    SORT lt_header BY order_number DESCENDING.
    LOOP AT lt_header INTO ls_header.
      WRITE :/ ls_header-order_number,
               ls_header-order_date,
               ls_header-payment_mode,
               ls_header-currency.

    ENDLOOP.
  ENDIF.

******************
*END OF PROGRAM
************************************************************

Execute the Program :-

  1. Enter the Order Number :-



  2. Press F8 or execute button.





  3. Click on To sort data in Ascending Order.



  4. Click on Sort data in Descending Order.




So, that’s enough for today.

We will see the next interactive report event in our next blog.

Thanx a lot for being a part of this wonderful journey.

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