Create AMDP class and fetch data based on student branch*

                                                 Refer - Introduction to AMDP

                                                 Example - Sample AMDP example


Step 1: Right click on ABAP project -- New -- ABAP class.

Step 2: Select package, Give class name and description.

Step 3: Click and next and click on finish.

Step 4: Write Code.

CLASS ycl_ab_amdp_stu1 DEFINITION

  PUBLIC

  FINAL

  CREATE PUBLIC .

 

  PUBLIC SECTION.

    INTERFACES : if_amdp_marker_hdb.

    TYPES: begin of ls_stu,

           stu_id TYPE ystu_id,

           stu_name TYPE ystu_name,

           stu_branch TYPE ystu_branch,

           stu_marks TYPE ystu_marks,

           END OF ls_stu.

    TYPES: lt_stu TYPE TABLE of ls_stu.

    Class-METHODS: fetch_data IMPORTING VALUE(stu_bra) TYPE ystu_branch

                        EXPORTING VALUE(lt_data) TYPE lt_stu.

  PROTECTED SECTION.

  PRIVATE SECTION.

ENDCLASS.

CLASS ycl_ab_amdp_stu1 IMPLEMENTATION.

METHOD fetch_data BY DATABASE PROCEDURE FOR HDB

                  LANGUAGE SQLSCRIPT

                  OPTIONS READ-ONLY

                  USING YTL_AB_STU_DET.

      lt_data = select stu_id,

                       stu_name,

                       stu_branch,

                       stu_marks

                       from YTL_AB_STU_DET

                       where stu_branch LIKE :stu_bra;

ENDMETHOD.

ENDCLASS.

Step 5: Calling AMDP class in report.

    REPORT yr_call_amdp_stu1.

    PARAMETERS: p_branch TYPE ystu_branch.

    START-OF-SELECTION.
      DATA: lf_obj TYPE REF TO ycl_ab_amdp_stu1.
      CREATE OBJECT lf_obj.

      CALL METHOD ycl_ab_amdp_stu1=>fetch_data
        EXPORTING
          stu_bra = p_branch
        IMPORTING
          lt_data = DATA(lt_stu).

      cl_demo_output=>display_data( name = 'Student Details' value = lt_stu ).


Table data.


Input.



Output.




********************************Thank You*****************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).