Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

OData model for a simple Remote function module

Hello all,

          I want to create an application SAPUI5 which takes some inputs and gives output results. For that I have a function module with import and export parameters. I want to know the simplest way to create an OData model which uses this RFC (code below). For example- How many entities should I have? What CRUD functions do I have to define and things like that. Any kind of knowledge would be of great help as I am new to this.

FUNCTION zisu_ui5_change_objects.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(OBJECT_TYPE) TYPE  TCDOB-OBJECT OPTIONAL

*"     VALUE(CHANGED_BY) TYPE  CDHDR-USERNAME OPTIONAL

*"     VALUE(DATE_FROM) TYPE  CDHDR-UDATE OPTIONAL

*"     VALUE(DATE_TO) TYPE  CDHDR-UDATE OPTIONAL

*"     VALUE(TIME_FROM) TYPE  CDHDR-UTIME OPTIONAL

*"     VALUE(TIME_TO) TYPE  CDHDR-UTIME OPTIONAL

*"  TABLES

*"      IT_CHANGE_OBJECTS TYPE  ZISU_T_UI5_CHNGOBJ OPTIONAL

*"----------------------------------------------------------------------

   DATA: it_chngobj TYPE STANDARD TABLE OF cdred,

         ls_chngobj TYPE cdred.

   DATA: lt_cdhdr      TYPE STANDARD TABLE OF cdhdr,

         ls_cdhdr      TYPE cdhdr,

         ls_name       TYPE bapiaddr3,

         lt_cdpos      TYPE STANDARD TABLE OF cdpos,

         ls_cdpos      TYPE cdpos,

         ls_out        TYPE zisu_ui5_chngobj,

         lt_tab        TYPE TABLE OF dfies,

         ls_tab        TYPE dfies,

         lt_username   TYPE RANGE OF cdusername,

         ls_username   LIKE LINE OF lt_username,             "#EC NEEDED

         lt_objectclas TYPE RANGE OF cdobjectcl,

         ls_objectclas LIKE LINE OF lt_objectclas,           "#EC NEEDED

         lt_objectid   TYPE RANGE OF cdobjectv,

         ls_objectid   LIKE LINE OF lt_objectid,             "#EC NEEDED

         lt_tabname    TYPE RANGE OF tabname,

         ls_tabname    LIKE LINE OF lt_tabname,              "#EC NEEDED

         lt_return     TYPE TABLE OF bapiret2.

   TRANSLATE object_type TO UPPER CASE .

*CALL FUNCTION 'CHANGEDOCUMENT_READ'

*    EXPORTING

**      changenumber      = nummer

*      date_of_change    = DATE_FROM

*      objectclass       = OBJECT_TYPE

**      objectid          = objektid

**      tablekey          = tabkey

**      tablename         = tabname

*      time_of_change    = TIME_FROM

*      username          = CHANGED_BY

**      local_time        = local_t

**      time_zone         = tzsource

*      date_until        = DATE_TO

*      time_until        = TIME_TO

**    IMPORTING

**      et_cdred_str      = lt_cdred_str[]

*    TABLES

*      editpos           = IT_CHNGOBJ

*    EXCEPTIONS

*      no_position_found = 1

*      OTHERS            = 2.

*

*move-corresponding it_chngobj[] to IT_CHANGE_OBJECTS[].

   CASE object_type.

     WHEN 'CO'.

       ls_tabname-low = 'ES56'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

       ls_tabname-low = 'ES55'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

     WHEN 'IN'.

       ls_tabname-low = 'ES320'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

       ls_tabname-low = 'ES31'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

     WHEN 'CT'.

       ls_tabname-low = 'ES22'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

     WHEN 'PR'.

       ls_tabname-low = 'ES60'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

       ls_tabname-low = 'ES61'.

       ls_tabname-option = 'EQ'.

       ls_tabname-sign   = 'I'.

       APPEND ls_tabname TO lt_tabname.

     WHEN OTHERS.

   ENDCASE.

   IF changed_by IS NOT INITIAL.

     ls_username-low = changed_by.

     ls_username-option = 'EQ'.

     ls_username-sign  = 'I'.

     APPEND ls_username TO lt_username.

   ENDIF.

   SELECT * FROM cdhdr APPENDING TABLE lt_cdhdr

            WHERE username   IN lt_username

            AND   tcode    IN lt_tabname

            and  udate between date_from and date_to

            and  utime between time_from and time_to .

*           AND ( ( udate =  date_from AND utime >= time_from  ) OR udate >  date_from )

*           AND ( ( udate =  date_to AND utime <= time_to ) OR udate <  date_to ).

   IF sy-subrc = 0.

     SELECT * FROM cdpos INTO TABLE lt_cdpos

                         FOR ALL ENTRIES IN lt_cdhdr

                         WHERE changenr = lt_cdhdr-changenr .

     IF sy-subrc = 0.

       LOOP AT lt_cdhdr INTO ls_cdhdr .

         LOOP AT lt_cdpos INTO ls_cdpos WHERE changenr = ls_cdhdr-changenr .

           CALL FUNCTION 'DDIF_FIELDINFO_GET'

             EXPORTING

               tabname        = ls_cdpos-tabname

               fieldname      = ls_cdpos-fname

*             LANGU          = SY-LANGU

             TABLES

               dfies_tab      = lt_tab

*             FIXED_VALUES   =

             EXCEPTIONS

               not_found      = 1

               internal_error = 2

               OTHERS         = 3.

           IF sy-subrc = 0.

             READ TABLE lt_tab INTO ls_tab INDEX 1.

             ls_out-ftext        = ls_tab-fieldtext.

           ENDIF.

         CALL FUNCTION 'BAPI_USER_GET_DETAIL'

           EXPORTING

             username             = ls_cdhdr-username

          IMPORTING

            address              =  ls_name

          TABLES

          return    = lt_return.

IF sy-subrc = 0.

   ls_out-firstname = ls_name-firstname.

   ls_out-lastname  = ls_name-lastname.

ENDIF.

           ls_out-object_type  = object_type.

           ls_out-objectid     = ls_cdhdr-objectid .

           ls_out-changenr     = ls_cdhdr-changenr .

           ls_out-username     = ls_cdhdr-username.

           ls_out-udate        = ls_cdhdr-udate.

           ls_out-utime        = ls_cdhdr-utime.

           ls_out-tcode        = ls_cdhdr-tcode.

           ls_out-tabname      = ls_cdpos-tabname.

           ls_out-chngind      = ls_cdpos-chngind.

           ls_out-fname        = ls_cdpos-fname.

           ls_out-f_old        = ls_cdpos-value_old.

           ls_out-f_new        = ls_cdpos-value_new.

           APPEND ls_out TO it_change_objects.

           CLEAR: ls_cdpos , ls_out, ls_tab, ls_name .

           REFRESH lt_tab.

         ENDLOOP.

         CLEAR ls_cdhdr.

       ENDLOOP.

     ENDIF.

   ENDIF.

SORT it_change_objects BY changenr.

ENDFUNCTION.

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question