ABAP Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 
ykaldirim
Active Participant
422

SAP has many functionalities that simplify coders. But We didn't sometimes find a simple requirement. This is one of them. Pattern for RFCs. Here the steps of solution.

All of ABAP coders know and like Patterns. But there is not a simple way to put RFC functions.

ykaldirim_0-1764679866673.png

Here the solution:

1- Define Custom Pattern 

Follow SE38->Utilities->More Utilities->Edit Pattern  node and define a new one with the name Z_RFC_FUNCTION.

 

ykaldirim_2-1764680094304.png

ykaldirim_3-1764680154442.png

2- We will create a function in both systems. First below code is for source system which will call target RFC. Function name should start with the name of pattern Z_RFC_FUNCTION and follow EDITOR_EXIT So it's : Z_RFC_FUNCTION_EDITOR_EXIT.

You will see I'm calling a function which will return required source code for RFC call at the line of 31. Of course you should change the DESTINATION with your system rfc. 

FUNCTION z_rfc_function_editor_exit.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      BUFFER TYPE  RSWSOURCET
*"----------------------------------------------------------------------
  DATA lt_sval TYPE STANDARD TABLE OF sval.
  DATA ls_sval TYPE sval.

  DATA: buffer2 TYPE rswsourcet.

* Get name of structure from user
  ls_sval-tabname = 'RS38L'.
  ls_sval-fieldname = 'NAME'.
  ls_sval-field_attr  = '00'.
  APPEND ls_sval TO lt_sval.

  CALL FUNCTION 'POPUP_GET_VALUES'
    EXPORTING
      popup_title     = 'Enter Function Name'
    TABLES
      fields          = lt_sval
    EXCEPTIONS
      error_in_fields = 1
      OTHERS          = 2.

* Get the given structure name
  READ TABLE lt_sval INTO ls_sval INDEX 1.
  check ls_sval-value is not INITIAL.

  CALL FUNCTION 'Z_RFC_FUNCTION_EDITOR_EXIT'
    DESTINATION 'KHDCLNT100'
    EXPORTING
      funcname = ls_sval-value
    IMPORTING
      buffer   = buffer2.

  LOOP AT buffer2 INTO DATA(ls_buffer).

    APPEND ls_buffer TO buffer.

  ENDLOOP.
ENDFUNCTION.

3- Second is for target system which RFC will be run. I gave the same name for the function to get the source code from target system. Here it's Z_RFC_FUNCTION_EDITOR_EXIT.

FUNCTION z_rfc_function_editor_exit.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(FUNCNAME) TYPE  RS38L-NAME
*"  EXPORTING
*"     VALUE(BUFFER) TYPE  RSWSOURCET
*"----------------------------------------------------------------------

  DATA: l_pattern_obj TYPE REF TO cl_sedi_pattern_generator,
        l_pattern     TYPE swbse_max_line_tab,
        l_pattern_new TYPE swbse_max_line_tab.

  DATA: lv_line TYPE LINE OF swbse_max_line_tab.

  CREATE OBJECT l_pattern_obj
    EXPORTING
      i_column  = 0
      i_include = CONV #( 'ZTESTYK' ).

  l_pattern_obj->built_function(
             EXPORTING
               i_function_name = CONV #( funcname )
             IMPORTING
               e_pattern       = l_pattern ).
  LOOP AT l_pattern INTO lv_line.

    APPEND lv_line TO l_pattern_new.

    IF lv_line CP 'CALL FUNCTION*'.
      APPEND 'DESTINATION ''KHDCLNT100''' TO l_pattern_new.
    ENDIF.


  ENDLOOP.

  buffer[] = l_pattern_new.

ENDFUNCTION.

And it's coming to test 🙂

You will simply select other pattern and it will ask function name.

ykaldirim_4-1764680784387.png

Just put the RFC function name.

ykaldirim_5-1764680884299.png

Here it comes.

ykaldirim_6-1764681084355.png

Also i suggest doing the below settings for better editorial.

ykaldirim_7-1764681124455.png

Cheers ykburda 🙂

 

 

 

Top kudoed authors