Efficient Data Retrieval with ABAP Classes: Fetching VBAK Table Range Using Method

 

Fetching a range of data from from VBAK table using a method in USUAL ABAP Class

Requirement :-

  • Create a report and take a range a input from user for Sales Document number.
  • Write the logic in a method of Usual ABAP Class.
  • Call that method in program and display the order details using ALV.

Solution :-

  • Step 1 :- Open the Usual ABAP CLASS in change mode which we have used in the previous part.



  • Step 2 :- give a name to the method and make it as an instance method.



  • Step 3 :- Click on parameters.

  • Step 4 :- provide the importing parameter as p_vbeln and also the associated type for range of vbeln.



    How to find the range table for Sales Order :-

    • Go to se11 and in the data type give the name of the data element of Sales document number.



    • Click on where used list



    • Select table type and click on OK.



    • We can see the list.




  • Step 5 :- Create a structure and corresponding table type which will be passed as external parameter in the method.

    • Structure :-



    • Table type :-



  • Step 6 :- Pass this table into the exporting parameter.



  • Step 7 :- Click on source code.



  • Step 8 :- Write the logic in the method.




Calling the Method inside the Program :-

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

  • Step 2 :- declare a internal table of the same structure which was created above.



  • Step 3:- Declare a select option for the Sales document number.



  • Step 4 :- Create object for the class where method was created.





  • Step 5 :- call the method.



  • Step 6 :- Use factory method of CL_SALV_TABLE class to display in form of ALV.




Code :-

*&---------------------------------------------------------------------*
*& Report ZAR_USUAL_ABAP_CLASS
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAR_USUAL_ABAP_CLASS.

DATA : lt_final type table of ZAR_STRUCTURE_SALES_ORDER.

data : lv_vbeln type vbeln_va.
SELECT-OPTIONS : s_vbeln for lv_vbeln.

START-OF-SELECTION.
DATA(lo_object) = new ZAR_USUAL_ABAP_CLASS( ).

CALL METHOD lo_object->get_range_of_vbak_details
  EXPORTING
    p_vbeln  = s_vbeln[]
  IMPORTING
    lt_table = lt_final
    .

TRY.
CALL METHOD cl_salv_table=>factory
  EXPORTING
    list_display   = IF_SALV_C_BOOL_SAP=>FALSE
  IMPORTING
    r_salv_table   = data(lo_data)
  CHANGING
    t_table        = lt_final
    .
  CATCH cx_salv_msg.
ENDTRY.
lo_data->display( ).

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

Execute the Code :-



  • Press F8.


Comments

Popular posts from this blog

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

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

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