Showing posts with label BAPI. Show all posts
Showing posts with label BAPI. Show all posts

Thursday, October 1, 2020

Remote Function Call (RFC) & types of RFC’s in SAP ABAP.

 What is Remote Function Call (RFC) & types of RFC’s?



Ans:

Ø  It is a SAP specific protocol to provide communication between different systems.

Ø  It is the process of calling Function modules from another system.

Ø  SAP Uses CPIC (Common Programming Interface for Communication) Protocol to transfer data between Systems.

                Types:

                1. Synchronous RFC: In case of this RFC both the Sender/Source and Receiver/Target                      systems should be available while distributing the data. The next part of calling program     isn’t continued until call function is completed.

            2. Asynchronous RFC: In case of this RFC both the Sender/Source and Receiver/Target                    systems should not be available while distributing the data. The next part of calling                            program is continued without completing call function.

            3. Transactional RFC (TRFC): It is almost similar to Asynchronous RFC. The Transactional              RFC is executed only once in an RFC server & save the corresponding data under unique                transaction ID in the Database.

            4. Queued RFC: In case of this RFC the multiple transactional RFC’s are serialized in the                                sequence using the Function module ‘TRFC_SET_QUEUE_NAME’.

Ø  An additional statement ‘Destination’ is used while calling Remote Enabled Functions.

What are the differences between Classic (Old) BADI and New (Kernel) BADI?

 

What are the differences between Classic (Old) BADI and New (Kernel) BADI?



Ans :-

Classic or Old BADI

New or Kernel BADI

1. The standard method GET_INSTANCE of the standard class CL_EXIT_HANDLER is used to call

1. The ABAP statements GET BADI & CALL BADI are used to work with New BADI’s.

2. An interface of a BADI referred to create the Reference object

2. The definition of a BADI is referred to create the Reference object

3. It is not faster as like the Kernel BADI

3. It is faster than the Classic BADI 

4. It can be a multiple use BADI

4. It must be a single use BADI

5. The Fall back class can’t be defined

5. The Fall back class can be defined

6. It can be a Filter Dependent BADI

6. It is not possible to maintain the Filter values

Sunday, September 27, 2020

BAPI MATERIAL CREATE Example in SAP ABAP.

BAPI MATERIAL CREATE  Example in SAP ABAP.



BAPI_MATERIAL_SAVEDATA BAPI For material Create in SAP ABAP.

REPORT zbij_bapi_material.

*&---------------------------------------------------------------------*
*& INCLUES FOR ALL EVENTS                                              *
*&---------------------------------------------------------------------*
INCLUDE zbapi_mat_data_declaration.
INCLUDE zbapi_mat_data_selec_screen.
INCLUDE zbapi_mat_data_logic.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  
PERFORM gui_upload.
  
PERFORM bapi.

 

TOP

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_DECLARATION
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& External Table Declaration                                          *
*&---------------------------------------------------------------------*
TABLES bapimatheadbapi_marabapi_maraxbapi_makt.

*&---------------------------------------------------------------------*
*& Internal Table Declaration                                          *
*&---------------------------------------------------------------------*
DATA BEGIN OF it_bapi OCCURS 0,
          material   
TYPE bapimathead-material,
          ind_sector 
TYPE bapimathead-ind_sector,
          matl_type  
TYPE bapimathead-matl_type,
          matl_group 
TYPE bapi_mara-matl_group,
          base_uom   
TYPE bapi_mara-base_uom,
          matl_desc  
TYPE bapi_makt-matl_desc,
        
END OF it_bapi,

       it_return 
LIKE bapiret2,
       it_makt_bapi 
like bapi_makt OCCURS WITH HEADER LINE.

 

SELECTION SCREEN

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_SELEC_SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
"IBIPPARMS-PATH is a export structure of f4 help fm.
*PARAMETERS : p_file TYPE ibipparms-path OBLIGATORY.
PARAMETERS p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*&  At Selection Screen Event                                          *
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  
PERFORM f4_help.

SUB***************************************************

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_LOGIC
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&  Form F4_HELP                                                       *
*&---------------------------------------------------------------------*

FORM f4_help.
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  
syst-cprog
      dynpro_number 
syst-dynnr
*     FIELD_NAME    = ' '
    
IMPORTING
      file_name     
p_file.
ENDFORM.                    "f4_help

*&---------------------------------------------------------------------*
*&  Form GUI_UPLOAD                                                    *
*&---------------------------------------------------------------------*
FORM gui_upload.
************************************************************************
***** For Notepad File

*  DATA:v_file TYPE string.
*  MOVE p_file TO v_file.

*  CALL FUNCTION 'GUI_UPLOAD'
*    EXPORTING
*     filename                      = v_file
*     filetype                      = 'DAT'
*     has_field_separator           = 'X'
**   HEADER_LENGTH                 = 0
**   READ_BY_LINE                  = 'X'
**   DAT_MODE                      = ' '
**   CODEPAGE                      = ' '
**   IGNORE_CERR                   = ABAP_TRUE
**   REPLACEMENT                   = '#'
**   CHECK_BOM                     = ' '
**   VIRUS_SCAN_PROFILE            =
**   NO_AUTH_CHECK                 = ' '
** IMPORTING
**   FILELENGTH                    =
**   HEADER                        =
*    TABLES
*      data_tab                      = it_bapi.

************************************************************************
***** For EXcel File
  
DATA lv_file TYPE rlgrap-filename,
         lv_raw  
TYPE truxs_t_text_data"truxs_xml_table.
  
MOVE   p_file TO lv_file.

  
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    
EXPORTING
      i_field_seperator    
'X'
*     I_LINE_HEADER        =
      i_tab_raw_data       
lv_raw
      i_filename           
lv_file
    
TABLES
      i_tab_converted_data 
it_bapi.
* EXCEPTIONS
*   CONVERSION_FAILED          = 1
*   OTHERS                     = 2

  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.

ENDFORM.                    "gui_upload

*&---------------------------------------------------------------------*
*&      Form  bapi
*&---------------------------------------------------------------------*
FORM bapi.
  
LOOP AT it_bapi.
    bapimathead
-material   it_bapi-material.
    bapimathead
-ind_sector it_bapi-ind_sector.
    bapimathead
-matl_type  it_bapi-matl_type.
    bapimathead
-basic_view 'X'.

    bapi_mara
-matl_group   it_bapi-matl_group.
    bapi_mara
-base_uom     it_bapi-base_uom.
    bapi_marax
-matl_group  'X'.
    bapi_marax
-base_uom    'X'.

    it_makt_bapi
-matl_desc it_bapi-matl_desc.
    
APPEND it_makt_bapi.
    
CLEAR it_makt_bapi.

    
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      
EXPORTING
        headdata            
bapimathead
        clientdata          
bapi_mara
        clientdatax         
bapi_marax
      
IMPORTING
        
return              it_return
      
TABLES
        materialdescription 
it_makt_bapi.

    
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      
EXPORTING
        
wait 'X'.
    
WRITE / it_return-type.

  
ENDLOOP.
ENDFORM.                    "bapi

Friday, September 25, 2020

BAPI PO CREATE Example in SAP ABAP.

BAPI PO CREATE Example in SAP ABAP. 




BAPI PO CREATE.

REPORT zbapi_po_creation.

include zbapi_po_creation_top. " top include for global data declration

include zbapi_po_creation_sel. " sel include for selecation

include zbapi_po_creation_sub. " f01 subrotine programs

*----------------------------------------------*
* I N I T I A L I Z A T I O N                  *
*----------------------------------------------*
INITIALIZATION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM f4_file_name.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.

PERFORM data_process.      " CONVERTING DATA FROM EXCEL TO INTERNAL TABLE
*PERFORM uplode_data.
*----------------------------------------------*
* E N D - O F - S E  L E C T I O N             *
*----------------------------------------------*
END-OF-SELECTION.

CLEAR gcl_app_log.
*****Application Log
gcl_app_log =  zca_cl_application_log=>get_instance( ).

CALL METHOD gcl_app_log->create_app_log_handle(
EXPORTING
  i_object     = 'ZRKPANDEY'         " Object In SLGO
  i_subobject  = 'ZRKSUB'     " Sub Object In SLGO
  i_tcode      = sy-tcode
  i_repid      = sy-cprog
  RECEIVING
  r_log_handle = gs_log_handle ).
  PERFORM uplode_data.
************************* Save and Display Application Log *************************
CALL METHOD gcl_app_log->save_and_display_app_log
EXPORTING
  i_log_handle = gs_log_handle
  i_flg_save   = abap_false.

*Text elements
*----------------------------------------------------------
* T01 select flat file


*Selection texts
*----------------------------------------------------------
* P_FILE D       .
=============================================================================================
Code listing for: ZBAPI_PO_CREATION_TOP
Description: Include ZBAPI_PO_CREATION_TOP
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_TOP
*&---------------------------------------------------------------------*
TYPES: BEGIN OF  ty_file,
  vendor      TYPE  elifn,   "   vendro
  purch_org   TYPE  ekorg,   "  puraches orgnization
  pur_group   TYPE  bkgrp,   "  purache groups
  co_code     TYPE  bukrs,   "  comapny code
  po_item     TYPE  ebelp,   " po item
  material    TYPE  matnr,   " material number
  short_text  TYPE  txz01,   " short text
  QUANTITY    type  BSTMG, " po quanity
  NET_PRICE	 TYPE	  BAPICUREXT,    " net price
  plant	     TYPE	  EWERK,        " net price
END OF ty_file.

DATA: po_number LIKE  bapimepoheader-po_number.

***** Internal Table
DATA : gt_final  TYPE STANDARD TABLE OF ty_file,
       gs_final  TYPE                   ty_file.
*       gt_return TYPE STANDARD TABLE OF bapireturn.

DATA : gt_return TYPE STANDARD TABLE OF bapiret2,
       gs_return TYPE bapiret2.


DATA : gt_type  TYPE truxs_t_text_data.


DATA: gt_po_items TYPE TABLE OF   bapimepoitem,
      gt_poitemx      TYPE TABLE OF bapimepoitemx,
      gs_poitemx      TYPE  bapimepoitemx,
      wa_po_items   LIKE bapimepoitem,
      return  TYPE  bapireturn,
      po_header TYPE TABLE OF  bapimepoheader,
      wa_poheaderx TYPE   bapimepoheaderx,
      wa_po_header TYPE  bapimepoheader.

* passing constan for values
DATA : gc_x TYPE c VALUE 'X'.

***** Declaration for application log
DATA: gt_return_log TYPE bapiret2_t.
****************** Class/Objects***************************
DATA: gcl_app_log   TYPE REF TO zca_cl_application_log,
****************** Internal Structure *********************
      gs_log_handle TYPE balloghndl.

"Local table
DATA: gt_return1 TYPE STANDARD TABLE OF bapiret2,
      gs_return1 TYPE bapiret2.

DATA: bapiret2 TYPE STANDARD TABLE OF bapiret2.

============================================================================================
Code listing for: ZBAPI_PO_CREATION_SEL
Description: Include ZBAPI_PO_CREATION_SEL
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE TEXT-t01.

  PARAMETER p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK a1.
============================================================================================
Code listing for: ZBAPI_PO_CREATION_SUB
Description: Include ZBAPI_PO_CREATION_SUB
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  UPLODE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM uplode_data .
  DATA : lv_log(100) TYPE c.
***** Uploading the data into the database table
  READ TABLE gt_final INTO gs_final INDEX 1.
* header data in po creation
    wa_po_header-vendor     = gs_final-vendor.
    wa_po_header-purch_org  = gs_final-purch_org.
    PERFORM f_converstion_exit.
    wa_po_header-pur_group  = gs_final-pur_group.
    wa_po_header-comp_code    = gs_final-co_code.
* passing x  values in po item
    wa_poheaderx-vendor    = gc_x.
    wa_poheaderx-purch_org = gc_x.
    wa_poheaderx-pur_group = gc_x.
    wa_poheaderx-comp_code   = gc_x.
* item data move
 LOOP AT gt_final INTO gs_final.
    wa_po_items-po_item    = gs_final-po_item.
    wa_po_items-material   = gs_final-material.
    wa_po_items-short_text = gs_final-short_text.
    wa_po_items-quantity  = gs_final-quantity.
    wa_po_items-net_price  = gs_final-net_price.
    wa_po_items-plant      = gs_final-plant.

* passing x value in po item
    gs_poitemx-po_item = gs_final-po_item.
    gs_poitemx-po_itemx   = gc_x.
    gs_poitemx-material   = gc_x.
    gs_poitemx-short_text = gc_x.
    gs_poitemx-quantity  = gc_x.
    gs_poitemx-po_price  = gc_x.
    gs_poitemx-plant      = gc_x.
    APPEND gs_poitemx TO gt_poitemx.
    APPEND wa_po_items TO gt_po_items.
ENDLOOP.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        poheader         = wa_po_header
        poheaderx        = wa_poheaderx
      IMPORTING
        exppurchaseorder = po_number
      TABLES
        return           = gt_return1
        poitem           = gt_po_items
        poitemx          = gt_poitemx.
    IF gt_return1[] IS NOT INITIAL.
      LOOP AT gt_return1 INTO gs_return1. "data(gs_return1).
        gs_return-type       = gs_return1-type.
        gs_return-id         = gs_return1-id.
        CONCATENATE po_number gs_return1-message
        INTO lv_log SEPARATED BY ' - '.
        gs_return-message_v1 = lv_log.
        APPEND gs_return TO gt_return.
        CLEAR : gs_return1.
      ENDLOOP.
    ENDIF.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
  CHECK sy-subrc EQ 0.
  CALL METHOD gcl_app_log->add_message_to_app_log
    EXPORTING
      i_log_handle = gs_log_handle
      i_tab_return = gt_return.
ENDFORM.                    " UPLODE_DATA
*&---------------------------------------------------------------------*
*&      Form  F4_FILE_NAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f4_file_name .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

ENDFORM.                    " F4_FILE_NAME
*&---------------------------------------------------------------------*
*&      Form  DATA_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_process .
****** Uploading the data in the file into internal table

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = gt_type
      i_filename           = p_file
    TABLES
      i_tab_converted_data = gt_final[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid
    TYPE sy-msgty
    NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " DATA_PROCESS
*&---------------------------------------------------------------------*
*&      Form  F_CONVERSTION_EXIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_converstion_exit .
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = gs_final-pur_group
    IMPORTING
      output = gs_final-pur_group.

ENDFORM.                    " F_CONVERSTION_EXIT
===============================================