Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Interface

Former Member
0 Kudos

Hi Experts,

Can anybody give me some sample code for practicing Interface programs. Along with plz suggest me what are the pre-requisetes for the same.

And what are various technique for writting these Interface programs.

Thanks

Sangram

3 REPLIES 3

Former Member
0 Kudos

hi,

nterfaces - This type of transfer refers to an ongoing transfer from a complimentary system to the SAP system. In this case, the “complimentary” system is a system that will run along side the SAP system.

For example, customer orders may be taken in another system. For the SAP system to reflect accurate information, these orders must be transferred to the SAP system every night.

BDC can be both interfaces or conversions depending upon the functionality above.

Interfaces are needed when we need data from other than SAP envoronment and vise versa.

Suppose aclient may send his business data through Excel sheet which are to be loaded in his SAP Tables.Then we need to use interfaces.

There are two Categogies.

1.From Presentation Layer to your ABAP Program(and then into Database table)

Presentation layer means from your sytem (from C, drives)

2.From application Server to your ABAP Program(and then into Database table)

Application Server means the server for your Sap System.

For the first case you need to use:From Presentation Layer to your ABAP Program and vise versa)

GUI_UPLOAD to upload data,

GUI_DOWNLOAD to download data

For the Second case(From application Server to your ABAP Program and vise versa)

A.OPEN DATA SET FILE NAME ON APPL.SERVER FOR INPUT ENCODING BY DEFAULT. use tranfer command to send data to application server

B. CLOSE DATA SET.

Regards,

Sankar

former_member189059
Active Contributor
0 Kudos

Hello,

check this code

it finds out all the download / upload functions as well as open datasets in all z programs

it also writes the data to a file on the application server

so make sure you have access to the directory

*&---------------------------------------------------------------------*
*& Report  Z_INTERFACES_CSV
*&
*&---------------------------------------------------------------------*
*& Author : Kris Donald 
*& Date :   07-09-2007
*& Purpose :Finds reports which input and output data through interfaces
*&---------------------------------------------------------------------*

REPORT  z_interfaces_csv.

DATA: lv_csvfile(512) VALUE 'c:Interfaces_'.
CONCATENATE lv_csvfile sy-sysid '_' sy-datum '.csv' INTO lv_csvfile.

DATA: lv_line(5000).
DATA: lv_blankline VALUE ''.
CONSTANTS: comma VALUE ','.


DATA: BEGIN OF itab OCCURS 0,
      line(1000) TYPE c,
      END OF itab,
      wa_itab LIKE LINE OF itab,
      wa_itab_2 LIKE LINE OF itab.

DATA: itab_input LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: itab_output LIKE itab OCCURS 0 WITH HEADER LINE.

DATA it_reposrc TYPE reposrc OCCURS 0 WITH HEADER LINE.

TYPES: BEGIN OF dataio_type,
  repid LIKE sy-repid,      " program name
  text LIKE trdirt-text,    " program title
  fileinterface_type(15),   " open dataset or function
  iomethod(10),             " upload / download
  funcnameline TYPE string, " name of function / line of code
  upload,
  download,
 END OF dataio_type.

DATA: it_dataio TYPE dataio_type OCCURS 0 WITH HEADER LINE.
DATA: wa_dataio_next LIKE LINE OF it_dataio.
DATA: it_dataio_output TYPE dataio_type OCCURS 0 WITH HEADER LINE.
DATA: lv_rowcount TYPE i.

DATA: lv_length TYPE i.
DATA: lv_statement(1000).
DATA: lv_fullstatement TYPE string.
DATA: lv_tabix_one LIKE sy-tabix.
DATA: lv_tabix_two LIKE sy-tabix.

DATA: lv_fdpos LIKE sy-fdpos.
DATA: lv_apospos1 LIKE sy-fdpos.
DATA: lv_apospos2 LIKE sy-fdpos.
DATA: lv_funcname TYPE string.
DATA: lv_iomethod(25).
DATA: flag_uploaddone.
DATA: flag_downloaddone.
DATA: lv_nexttabix LIKE sy-tabix.
DATA: lv_maxtabix LIKE sy-tabix.
DATA: lv_prevrepid LIKE sy-repid.

SELECT progname FROM reposrc
  INTO CORRESPONDING FIELDS OF TABLE it_reposrc
  WHERE subc = '1'
  AND r3state = 'A'
  AND progname LIKE 'Z%'.

LOOP AT it_reposrc.

* resetting the flags
  flag_downloaddone = ''.
  flag_uploaddone = ''.

  READ REPORT it_reposrc-progname INTO itab.
  LOOP AT itab INTO wa_itab.

*   if we already know that this pgm is used for download and upload,
*    dont continue
    IF flag_downloaddone = '' OR flag_uploaddone = ''.

      SEARCH wa_itab-line FOR 'open dataset'.
      IF sy-subrc = 0
        AND wa_itab-line <> ''.
        IF wa_itab-line+0(1) <> '*' AND wa_itab-line+0(1) <> '"'.

          lv_length = STRLEN( wa_itab-line ) - 1.
          lv_fullstatement = wa_itab-line.
          IF wa_itab-line+lv_length <> '.'.
            PERFORM addnext.
          ENDIF.

          CONDENSE lv_fullstatement.
          IF lv_fullstatement+0(4) = 'OPEN'.

            SEARCH lv_fullstatement FOR 'input'.
            IF sy-subrc = 0 AND flag_uploaddone = ''.
              itab_input-line = lv_fullstatement.
              APPEND itab_input.
              flag_uploaddone = 'X'.

            ELSEIF flag_downloaddone = ''.
              SEARCH lv_fullstatement FOR 'Output'.
              IF sy-subrc = 0.
                itab_output-line = lv_fullstatement.
                APPEND itab_output.
                flag_downloaddone = 'X'.
              ENDIF.
              SEARCH lv_fullstatement FOR 'Appending'.
              IF sy-subrc = 0.
                itab_output-line = lv_fullstatement.
                APPEND itab_output.
                flag_downloaddone = 'X'.
              ENDIF.
              SEARCH lv_fullstatement FOR 'Update'.
              IF sy-subrc = 0.
                itab_output-line = lv_fullstatement.
                APPEND itab_output.
                flag_downloaddone = 'X'.
              ENDIF.
            ENDIF.

          ENDIF. " IF lv_fullstatement+0(4) = 'OPEN'.
        ENDIF.   " if it doesnt start with " or *
      ENDIF.

      IF flag_uploaddone = '' OR flag_downloaddone = ''.
        SEARCH wa_itab-line FOR 'call function'.
        IF sy-subrc = 0.
          lv_fdpos = sy-fdpos.
          lv_apospos1 = 14.

          lv_length = STRLEN( wa_itab-line ) - 1.
          lv_fullstatement = wa_itab-line.
          IF wa_itab-line+lv_length <> '.'.
            PERFORM addnext.
          ENDIF.

          CONDENSE lv_fullstatement.
          IF lv_fullstatement+0(1) NE '*' AND lv_fullstatement+0(1) NE '"'.

            SEARCH lv_fullstatement FOR '''' STARTING AT 16.
            IF sy-subrc = 0.
              lv_apospos2 = sy-fdpos.
              lv_funcname = lv_fullstatement+15(lv_apospos2).
              IF flag_downloaddone = ''.
                lv_iomethod = 'Download'.
                PERFORM search_func_name.
              ENDIF.

              IF flag_uploaddone = ''.
                lv_iomethod = 'Upload'.
                PERFORM search_func_name.

                lv_iomethod = 'TEXT_CONVERT_XLS_TO_SAP'.
                PERFORM search_func_name.
              ENDIF.

            ENDIF.
          ENDIF.

        ENDIF.
      ENDIF. " if flags are not done - for call fn

    ENDIF. " if flags are not done
  ENDLOOP.

  LOOP AT itab_input.
    CONDENSE itab_input-line.
*  WRITE:/ itab_input-line.
    it_dataio-repid = it_reposrc-progname.
    it_dataio-fileinterface_type = 'Open dataset'..
    it_dataio-iomethod = 'Upload'.
*    it_dataio-funcnameline = itab_input-line.
    APPEND it_dataio.
    CLEAR it_dataio.
  ENDLOOP.
  REFRESH itab_input.


  LOOP AT itab_output.
    CONDENSE itab_output-line.
*  WRITE:/ itab_output-line.
    it_dataio-repid = it_reposrc-progname.
    it_dataio-fileinterface_type = 'Open dataset'..
    it_dataio-iomethod = 'Download'.
*    it_dataio-funcnameline = itab_output-line.
    APPEND it_dataio.
    CLEAR it_dataio.
  ENDLOOP.
  REFRESH itab_output.


  REFRESH itab.
  CLEAR itab.

ENDLOOP. " it_reposrc

*SORT it_dataio BY repid iomethod.
*DELETE ADJACENT DUPLICATES FROM it_dataio COMPARING repid iomethod.
DESCRIBE TABLE it_dataio LINES lv_rowcount.
WRITE:/ lv_rowcount, 'rows in table'.
SKIP 1.


* get one internal table with unique data
DESCRIBE TABLE it_dataio LINES lv_maxtabix.
IF it_dataio[] IS NOT INITIAL.
  LOOP AT it_dataio.

    IF lv_prevrepid <> it_dataio-repid.

      IF it_dataio-iomethod = 'Upload'.
        it_dataio-upload = 'X'.
      ELSEIF it_dataio-iomethod = 'Download'.
        it_dataio-download = 'X'.
      ENDIF.

      lv_nexttabix = sy-tabix + 1.

      IF lv_nexttabix <> lv_maxtabix.
        READ TABLE it_dataio INDEX lv_nexttabix INTO wa_dataio_next.
        IF it_dataio-repid = wa_dataio_next-repid.
          IF wa_dataio_next-iomethod = 'Download'.
            it_dataio-download = 'X'.
          ELSEIF wa_dataio_next-iomethod = 'Upload'.
            it_dataio-upload = 'X'.
          ENDIF.
        ENDIF.

      ENDIF.

      lv_prevrepid = it_dataio-repid.
      APPEND it_dataio TO it_dataio_output.
      CLEAR it_dataio.

    ELSE.
      lv_prevrepid = ''.
    ENDIF. " if prev pgm = current pgm

  ENDLOOP.
ENDIF.

* gets program description
LOOP AT it_dataio_output.
  SELECT SINGLE text FROM trdirt INTO it_dataio_output-text
    WHERE sprsl = 'E'
    AND name = it_dataio_output-repid.
  replace all occurrences of comma in it_dataio_output-text with ''.
  MODIFY it_dataio_output.
ENDLOOP.


* writing to csv file
OPEN DATASET lv_csvfile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
  WRITE:/ 'Error in creating file', lv_csvfile,
    /'Please ensure that you have access to the folder'.
  EXIT.
else.
  write:/ 'File', lv_csvfile, 'successfully created'.
ENDIF.

* system details
concatenate 'System' comma sy-sysid into lv_line.
transfer lv_line to lv_csvfile.

concatenate 'Date' comma sy-datum into lv_line.
transfer lv_line to lv_csvfile.

transfer lv_blankline to lv_csvfile.


* sheet name
lv_line = 'Sheet: Interfaces'.
TRANSFER lv_line TO lv_csvfile.
TRANSFER lv_blankline TO lv_csvfile.


* writing header
lv_line = 'Report,Report Description,Data Uploaded,Data Downloaded'.
TRANSFER lv_line TO lv_csvfile.

* writing data
lv_line = ''.
LOOP AT it_dataio_output.
  concatenate it_dataio_output-repid comma it_dataio_output-text comma
    it_dataio_output-upload comma it_dataio_output-download
    into lv_line.
  transfer lv_line to lv_csvfile.
endloop.

close dataset lv_csvfile.
* end of writing data


LOOP AT it_dataio_output.
  WRITE:/ it_dataio_output-repid,
   it_dataio_output-text,
   it_dataio_output-upload,
   it_dataio_output-download.
ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  addnext
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM addnext .

  lv_tabix_one = sy-tabix + 1.

  READ TABLE itab INTO wa_itab_2 INDEX lv_tabix_one.
  CONCATENATE lv_fullstatement wa_itab_2-line INTO lv_fullstatement
    SEPARATED BY space.
  lv_length = STRLEN( wa_itab_2-line ) - 1.
  IF lv_length GT 0 AND wa_itab_2-line+lv_length <> '.'.
    PERFORM addnext.
  ENDIF.

ENDFORM.                    " addnext


*&---------------------------------------------------------------------*
*&      Form  search_func_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM search_func_name .

  SEARCH lv_funcname FOR lv_iomethod.
  IF sy-subrc = 0.
    it_dataio-repid = it_reposrc-progname.
    it_dataio-fileinterface_type = 'Function Call'.
    it_dataio-iomethod = lv_iomethod.
    if lv_iomethod = 'TEXT_CONVERT_XLS_TO_SAP'.
      it_dataio-iomethod = 'Upload'.
    endif.

    IF it_dataio-iomethod = 'Upload'.
      flag_uploaddone = 'X'.
    ELSEIF it_dataio-iomethod = 'Download'.
      flag_downloaddone = 'X'.
    ENDIF.

    append it_dataio.
    clear it_dataio.
  ENDIF.

ENDFORM.                    " search_func_name

Former Member
0 Kudos

Hi

see this

Interfaces



Interfaces only describe the external point of contact of a class (protocols), they do not contain any implementation.
Interfaces are usually defined by a user. The user describes in the interface which services (technical and semantic) it needs in order to carry out a task.
The user never actually knows the providers of these services, but communicates with them through the interface.
In this way the user is protected from actual implementations and can work in the same way with different classes/objects, as long as they provide the services required. This is known as polymorphism with interfaces.

Interfaces features



Separation of external point of contact(interface) and implementation (class)
. The client defines the protocol , the server implements it
. “black box principles “;client only knows the interface , not the implementation
. Looser linking of objects between client and server
Polymorphism
. Generic handling of objects of different classes
Abstraction
. Interfaces as a genaralization of the implementing class
Simulation of multiple inheritance


Defining and Implementing Interface



1)Declaring the interface - interface name.
methods.
endinterface.
2)The server classes make the interface public - class name definition
public section.
interfaces name
endclass
3)Iterfaces are implemented in classes - class name implementation
method name logic
endmethod.
endclass.
4)Interfaces do not have visibility section


Working with Interface components


You can access interface components using an object reference, whose class implements the interface. Syntactically this is done with the interface resolution operator, just as with the method definitions in the implementation part of the class.

Compound Interface

A compound interface contains other interfaces as components (component interfaces) and summarizes the extension of these component interfaces.

*&----


*

*& Subroutinenpool BCALV_REPREP_INTERFACE *

*& *

*&----


*

*& *

*& *

*&----


*

program bcalv_reprep_interface .

type-pools: kkblo.

tables: trsti.

*&----


*

*& Form REPREP_INTERFACE

*&----


*

  • text *

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form reprep_interface tables rt_fieldcat type kkblo_t_fieldcat

rt_outtab

using r_program like sy-repid

rs_selfield type kkblo_selfield

rs_layout type kkblo_layout

rs_others type kkblo_reprep

r_ucomm like sy-ucomm

r_exit type c.

data: l_masterdata(1) type c.

data: ls_communication type kkblo_reprep_communication.

data l_sonam like trsti-sonam.

data l_count like sy-tabix.

data l_subrc like sy-subrc.

data l_fccls(10) type c.

data: l_tabname type kkblo_tabname.

data: l_fieldname type kkblo_fieldname.

data l_fcode like sy-ucomm.

data: l_program like sy-repid.

data: begin of lt_sel_tab occurs 1.

include structure rstisel.

data: end of lt_sel_tab.

data: begin of lt_field_tab occurs 1.

include structure rstifields.

data: end of lt_field_tab.

field-symbols: .

if r_ucomm = 'BEBN'.

perform calling_chain.

exit.

endif.

if r_ucomm = 'BEB2' and not rs_selfield-sel_tab_field is initial.

split rs_selfield-sel_tab_field at

'-' into l_tabname l_fieldname.

l_tabname = rs_selfield-tabname.

if not l_tabname is initial and not l_fieldname is initial.

l_masterdata = 'X'.

endif.

endif.

if rs_others-reprep_id is initial.

call function 'RSTI_REPORT_FIELDS_FIND'

exporting

e_repid = r_program

  • E_TYPE = 'S'

tables

it_sel = lt_sel_tab

it_fields = lt_field_tab

exceptions

others = 1.

else.

if rs_others-reprep_id-tool = 'RT'.

l_program = rs_others-reprep_id-onam.

call function 'RSTI_REPORT_FIELDS_FIND'

exporting

e_repid = l_program

  • E_TYPE = 'S'

tables

it_sel = lt_sel_tab

it_fields = lt_field_tab

exceptions

others = 1.

endif.

endif.

l_subrc = 4.

if not rs_layout-box_fieldname is initial and

rs_selfield-ignore_multi is initial.

assign component rs_layout-box_fieldname of structure rt_outtab

to = 'X'.

l_count = l_count + 1.

perform sel_field_tab_create tables rt_fieldcat

lt_field_tab

lt_sel_tab

using rt_outtab

l_masterdata

l_tabname

l_fieldname

l_count.

l_subrc = 0.

endloop.

endif.

endif.

if l_subrc ne 0.

l_count = 1.

read table rt_outtab index rs_selfield-tabindex.

if sy-subrc = 0.

perform sel_field_tab_create tables rt_fieldcat

lt_field_tab

lt_sel_tab

using rt_outtab

l_masterdata

l_tabname

l_fieldname

l_count.

endif.

endif.

if not rs_others-callback_reprep_sel_modify is initial and not

rs_others-callback_program is initial.

perform (rs_others-callback_reprep_sel_modify)

in program (rs_others-callback_program) tables lt_sel_tab

lt_field_tab

using ls_communication

if found.

if ls_communication-stop = 'X'.

exit.

endif.

endif.

call function 'RSTI_SELECTION_EXPORT'

tables

it_sel = lt_sel_tab

it_fields = lt_field_tab.

  • COH_SONAM = 'KKSD'.

l_sonam = r_program.

l_fccls = r_ucomm+3(1).

l_fcode = r_ucomm.

perform rsti_stack_initialized using r_program

rs_others

l_subrc.

if l_subrc ne 0.

if rs_others-reprep_id is initial.

call function 'RSTI_APPL_STACK_INITIALIZE'

exporting

e_appl = ' '

e_subc = ' '

e_tool = 'RT'

e_onam = l_sonam

exceptions

others = 1.

else.

call function 'RSTI_APPL_STACK_INITIALIZE'

exporting

e_appl = rs_others-reprep_id-appl

e_subc = rs_others-reprep_id-subc

e_tool = rs_others-reprep_id-tool

e_onam = rs_others-reprep_id-onam

exceptions

others = 1.

endif.

endif.

call function 'RSTI_COMMUNICATION_HANDLER'

exporting

e_fcode = l_fcode

e_rexec = 'X'

e_fccls = l_fccls

importing

  • i_rec =

i_exit = r_exit

exceptions

appl_stack_not_initialized = 01

no_lines = 02

no_line_picked = 03

others = 04.

endform. " REPREP_INTERFACE

*&----


*

*& Form REPREP_TRSTI_CHECK

*&----


*

  • text *

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form reprep_trsti_check tables rt_fccls

using r_program like sy-repid

rs_others type kkblo_reprep

r_subrc like sy-subrc.

data: l_subrc type sysubrc.

refresh rt_fccls.

clear rt_fccls.

if rs_others-reprep_id is initial.

*... mandantenabhängiger Tabelle

select fccls from trsti into table rt_fccls

where stool = 'RT'

and ( sotyp = 'E' or sotyp = '1' )

and sonam = r_program.

l_subrc = sy-subrc.

*... mandantenunabhängiger Tabelle

select fccls from trsti0 appending table rt_fccls

where stool = 'RT'

and ( sotyp = 'E' or sotyp = '1' )

and sonam = r_program.

if l_subrc ne 0.

l_subrc = sy-subrc.

endif.

else.

*... mandantenabhängiger Tabelle

select fccls from trsti into table rt_fccls

where stool = rs_others-reprep_id-tool

and sappl = rs_others-reprep_id-appl

and ssubc = rs_others-reprep_id-subc

and ( sotyp = 'E' or sotyp = '1' )

and sonam = rs_others-reprep_id-onam.

l_subrc = sy-subrc.

*... mandantenunabhängiger Tabelle

select fccls from trsti0 appending table rt_fccls

where stool = rs_others-reprep_id-tool

and sappl = rs_others-reprep_id-appl

and ssubc = rs_others-reprep_id-subc

and ( sotyp = 'E' or sotyp = '1' )

and sonam = rs_others-reprep_id-onam.

if l_subrc ne 0.

l_subrc = sy-subrc.

endif.

endif.

r_subrc = l_subrc.

endform. " REPREP_TRSTI_CHECK

*&----


*

*& Form CALLING_CHAIN

*&----


*

  • text *

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form calling_chain.

data: l_level type i.

data: l_exit(1) type c.

call function 'RSTI_NAVIGATE'

exporting

e_level = l_level

importing

i_exit = l_exit

exceptions

appl_stack_not_initialized = 1

others = 2.

if l_exit = 'X'.

set screen 0.

leave screen.

endif.

endform. " CALLING_CHAIN

*&----


*

*& Form RSTI_STACK_INITIALIZED

*&----


*

  • text *

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form rsti_stack_initialized using r_program like sy-repid

rs_others type kkblo_reprep

r_subrc like sy-subrc.

data begin of ls_rec.

include structure rstirec.

data end of ls_rec.

call function 'RSTI_APPL_STACK_POP'

importing

i_rec = ls_rec

exceptions

appl_stack_not_initialized = 1

others = 2.

if rs_others-reprep_id is initial.

if sy-subrc = 1 or

ls_rec-rtool ne 'RT' or

not ls_rec-rappl is initial or

not ls_rec-rsubc is initial or

ls_rec-ronam ne r_program.

r_subrc = 4.

else.

r_subrc = 0.

endif.

else.

if sy-subrc = 1 or

ls_rec-rtool ne rs_others-reprep_id-tool or

ls_rec-rappl ne rs_others-reprep_id-appl or

ls_rec-rsubc ne rs_others-reprep_id-subc or

ls_rec-ronam ne rs_others-reprep_id-onam.

r_subrc = 4.

else.

r_subrc = 0.

endif.

endif.

endform. " RSTI_STACK_INITIALIZED

*&----


*

*& Form SEL_FIELD_TAB_CREATE

*&----


*

  • text *

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form sel_field_tab_create tables rt_fieldcat type kkblo_t_fieldcat

rt_field_tab structure rstifields

rt_sel_tab structure rstisel

using rs_outtab

r_master type c

r_tabname type kkblo_tabname

r_fieldname type kkblo_fieldname

r_count like sy-tabix.

field-symbols: .

append rt_sel_tab.

clear rt_field_tab.

rt_field_tab-field = lt_fcat-fieldname.

rt_field_tab-rollname = lt_fcat-rollname_ddic.

rt_field_tab-memoryid = lt_fcat-memoryid.

rt_field_tab-domname = lt_fcat-domname.

if r_master eq 'X' and lt_fcat-fieldname eq r_fieldname

and lt_fcat-tabname eq r_tabname.

rt_field_tab-mdflg = 'X'.

endif.

append rt_field_tab.

endloop.

endform. " SEL_FIELD_TAB_CREATE

reward if usefull