Wednesday, 27 February 2019

RFC creation using AMDP

I will explain how to create an RFC, using AMDP, with a practical example, from the analysis of the standard tables, the creation of the structure and type of output table, the creation of the RFC, the AMDP and finally the tests

Analysis of the Table to consult.

We begin by identifying the tables and fields we need for the RFC. For this we enter the se11, se11n, se16 or se16n to consult the columns of the tables:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We will use the tables MARA (Matnr, Mtart, Meins) and MAKT (Maktx).

Creation of output structure.

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We select Structure:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We enter a name for our structure and the fields that our structure will have with their respective data elements:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We save, activate, in indicate in which package the created object will be stored:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We created an OT to subsequently make the pass to the other constituents:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We go back to the se11 and create the table type:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We select Type Table:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

In the Line type tab, we enter the structure previously created, Save and activate:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

Creation of AMDP.

We enter Eclipse and in our Abap Project, we select the package where our class will be, we select Source Code Library and in classes, we select New Abap Class:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We enter a Name and Description for our Class:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We select or create a new OT, for the transport to the other constituents, the fields of the query must coincide with the Table Type Created:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We enter the following code in which, we define the method that we will use in the RFC:

CLASS xxxxx DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.

    INTERFACES: if_amdp_marker_hdb.

    CLASS-METHODS get_xxx
      IMPORTING VALUE(im_begda)  TYPE begda
                VALUE(im_endda)  TYPE endda
      EXPORTING VALUE(tt_result) TYPE Tipo Tabla Creado

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS xxxxx IMPLEMENTATION.

  METHOD get_xxx BY DATABASE PROCEDURE
  FOR HDB
  LANGUAGE SQLSCRIPT
  OPTIONS READ-ONLY
  USING mara makt.

    TT_RESULT = SELECT M.MATNR, M.MTART, MT.MAKTX, M.MATKL, MEINS
                FROM MARA AS M
                INNER JOIN MAKT AS MT ON M.MATNR = MT.MATNR AND SPRAS = 'S' AND MT.MANDT = SESSION_CONTEXT('CLIENT')
                WHERE (CASE WHEN M.LAEDA = '00000000' THEN '19500101' ELSE M.LAEDA END BETWEEN IM_BEGDA AND IM_ENDDA) AND M.MANDT = SESSION_CONTEXT('CLIENT')
                ORDER BY M.MATNR;

  ENDMETHOD.

ENDCLASS.

Creation of RFC.

We enter the se80, select Function Group and enter a name for our Function Group:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We enter a description for the Function Group:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

Right click on Modules functions and click on Create:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

We enter a name and description for the function module:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

In the Attributes tab, we select Remote Access Module:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

In the Import tab, we enter the parameters of our RFC:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

In the Export tab we indicate our type output table:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

In the tab of Code. fte. We enter the following ABAP code, where xxxx is the name of our Class and get_xxx is the name of our created method:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

xxxx=>get_xxx( EXPORTING im_begda = im_begda im_endda = im_endda IMPORTING tt_result = tt_result )

Tests.

We execute the RFC, enter the parameters and verify the result:

SAP ABAP Study Material, SAP ABAP Guides, SAP ABAP Learning

No comments:

Post a Comment