Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
harsh_raj1
Explorer

Creating a program to fetch customer details from an AS400 system to SAP S/4HANA via RFC (Remote Function Call) involves several steps. Below is a simplified example to illustrate the process. Note that you need the appropriate authorization and system connectivity settings for RFC communication.

Using Transaction SM59:

  1. Log in to SAP GUI:

    • Log in to the SAP GUI using the appropriate credentials.
  2. Open Transaction SM59:

    • Enter transaction code SM59 in the command field and press Enter.
  3. Choose RFC Connection:

    • In the SM59 screen, navigate to the "RFC Connections" folder in the left-hand tree structure.
  4. Create RFC Destination:

    • Right-click on the "RFC Connections" folder, choose "Create," and select the appropriate connection type (for example, "TCP/IP Connections" for remote systems).
  5. Enter Connection Details:

    • Fill in the required details for the RFC destination, including the connection type, the target system's IP address or hostname, and the system number.
  6. Configure Logon & Security:

    • Configure the logon and security settings. This might include specifying the user credentials that will be used for communication.
  7. Additional Parameters:

    • Depending on your scenario, you may need to configure additional parameters, such as language, code page, or other connection-specific settings.
  8. Test Connection:

    • Before saving the RFC destination, you can use the "Connection Test" button to check if the connection to the target system is successful.
  9. Save the RFC Destination:

    • Once the connection test is successful, save the RFC destination.
  10. Activate and register the RFC Destination:

    • After saving the destination, you may need to activate and register it. The activation ensures that the settings take effect.
  11. Use the RFC Destination in ABAP Programs:

    • You can use the created RFC destination in ABAP programs by calling the remote function modules defined in the target system.harsh_raj1_0-1708951919820.pngharsh_raj1_1-1708952589257.png

      Create RFC-Enabled Function Module in SAP S/4HANA:

      • Create an RFC-enabled function module in SAP S/4HANA that will call the RFC function module in the AS400 system. This function module should take any necessary parameters, call the RFC function module in the AS400 system, and return the customer details. harsh_raj1_4-1708949394238.pngharsh_raj1_5-1708949436424.pngharsh_raj1_6-1708949471493.pngharsh_raj1_7-1708949530552.png

 

FUNCTION zhr_fm_knb1_fico.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_KUNNR) TYPE  ZHR_TTY_KNB1 OPTIONAL
*"  EXPORTING
*"     VALUE(GT_KNB2) TYPE  ZHR_TT_KNB1
*"     VALUE(EP_MSG) TYPE  STRING
*"  TABLES
*"      GT_KNB1 STRUCTURE  KNB1
*"----------------------------------------------------------------------

  IF  im_kunnr  IS NOT INITIAL.

    SELECT  FROM knb1 FIELDS kunnr,
                            bukrs,
                            erdat,
                            ernam
                             WHERE kunnr in _KUNNR INTO CORRESPONDING FIELDS OF TABLE  _knb2 .

    IF  gt_knb1 IS INITIAL.
      ep_msg = 'No record found'.

    ENDIF.



  ENDIF.


ENDFUNCTION.

 

 Creating a report program in SAP S/4HANA using the ABAP Editor (SE38) involves defining a report using the Report statement, fetching data from the database, and displaying the results. Below is a simple example of a report program that retrieves and displays data from knb1 table.

 

 

*&---------------------------------------------------------------------*
*& Report ZHR_RP_FM
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZHR_RP_FM.

DATA: lv_kunnr TYPE kunnr.
*
SELECT-OPTIONS: s_kunnr FOR lv_kunnr.

  DATA: lt_range type RANGE OF kunnr.
     lt_range = VALUE #( sign = 'I' option = 'BT'
                       ( low = s_kunnr-low )
                       ( high = s_kunnr-high )
                     ).

DATA: lt_knb1 TYPE TABLE OF knb1,
      gt_knb1 TYPE TABLE of knb1,
*      gs_knb1 TYPE knb1,
      lv_msg TYPE string.


START-OF-SELECTION.

*
CALL FUNCTION 'ZHR_FM_KNB1_FICO' DESTINATION 'zhr_a4hana_to_s4hana'
  EXPORTING
    im_kunnr       = lt_range
 IMPORTING
   GT_KNB2        =  gt_knb1               "gs_knb1
   EP_MSG         = lv_msg
  tables
    gt_knb1        = lt_knb1
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


IF  gt_knb1[] is NOT INITIAL.
  cl_demo_output=>display( gt_knb1 ).          

ENDIF.

 

output:

give the input and click on execute button.

harsh_raj1_0-1708950301655.png

provide your user-id for s4hana along with password and click on enter.

it will display the desired output.

harsh_raj1_2-1708952759789.png

 

harsh_raj1_2-1708950014638.png