Select options in AMDP

Scenario - Create a report which will take in Customer ID (select options) as input and give Loan data.

Table used for this requirement: ZDLOAN








Below is code implemented in the AMDP class:

CLASS zcl_demo_amdp_so1 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_amdp_marker_hdb .

    TYPES: it_loan TYPE TABLE OF zdloan.

    METHODS: get_loan_data IMPORTING VALUE(im_mandt)  TYPE mandt
                                     VALUE(im_custid) TYPE string
                           EXPORTING VALUE(ep_LOAN)   TYPE it_loan.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_demo_amdp_so1 IMPLEMENTATION.
  METHOD get_loan_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT
                          OPTIONS READ-ONLY USING zdloan.
    
    IT_LOAN = select * from ZDLOAN where mandt = IM_MANDT;
    EP_loan = APPLY_FILTER (:IT_LOAN, :IM_CUSTID);

  ENDMETHOD.
ENDCLASS.

Below is the code implemented in the driver program:

*&---------------------------------------------------------------------*
*& Report zvr_amdp_so_con
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zvr_amdp_so_con.

DATA: lv_cus    TYPE zdloan-custid.
*      lt_seltab TYPE if_shdb_def=>tt_named_dref.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.
  SELECT-OPTIONS: s_cus FOR lv_cus OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  t1 = 'Enter Customer Details'.

START-OF-SELECTION.

  data(lt_seltab) = VALUE if_shdb_def=>tt_named_dref( ( name = 'CUSTID' dref = REF #( s_cus[] ) ) ).

  "Convert Select options to String.
  TRY.
      DATA(lv_str) = cl_shdb_seltab=>combine_seltabs(
        EXPORTING
          it_named_seltabs = lt_seltab ).
    CATCH cx_shdb_exception INTO DATA(lo_ex).
      DATA(lv_msg) = lo_ex->get_longtext( ).
      MESSAGE lv_msg TYPE 'I'.
  ENDTRY.

  IF lv_str IS NOT INITIAL.
    "Get data
    DATA(lo_amdp) = NEW zcl_demo_amdp_so1( ).
    lo_amdp->get_loan_data(
      EXPORTING
        im_mandt  = sy-mandt
        im_custid = lv_str
      IMPORTING
        ep_loan   = data(it_fin)
    ).
    "Display data
    cl_demo_output=>display_data(
      EXPORTING
        value   = it_fin
        name    = 'ZDLOAN Data'
*        exclude =
*        include =
    ).
  ENDIF.

Selection screen and output upon execution of the code:













Comments

Popular posts from this blog

Simple AMDP program for CRUD opertaions

Interactive ALV report using ALV IDA