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: 
kirankerudi
Active Participant
27,848

Introduction


One cannot create an extension for generated IDOC types, since the extension concept for ALE interfaces created by T-Code BDBG or BDFG does not run with extension types.


BAPIs are the standardized interfaces for ALE-supported communication. The IDOCtypes required for the ALE services can be generated from BAPIs. So, one can create their own BAPIs in the customer namespace and generate the associated BAPI-ALE interface.


In the process, the following objects are generated for a BAPI:

  • A message type (in customer namespace)
  • A Basic IDoc type, including all of its segments
  • An Outbound function module which uses the BAPI data to generate the IDoc and also dispatches it
  • An Inbound Function Module that fills the BAPI with the IDoc data on the inbound side.


The generated ALE IDoc interface performs the following tasks:

  • Creates an IDoc from the BAPI data
  • Sends the IDoc to the target system
  • Receives the IDoc in the target system, creates the BAPI data from the IDoc and calls the BAPI


Step By Step Procedure for Creating Generated IDOC


STEP 1: Create a new structure with the customer fields that are required under the IDOC type as shown below.


STEP 2: Create a new remote enabled function module which is responsible for generating IDOC through SE37 as shown below.


STEP 3: Once the function module is created we need to create a BAPI for the outbound processing. This is implemented as a Business Object’s (BO) method, and will utilize the outbound function module previously created.


Go to SWO1 transaction and create new Object as a copy of EQUI object as shown below. (We can also create a new object and a method. However in case we need methods of EQUI, we can just copy the Object)

STEP 4: Add new method to the Business Object created with the function module previously created as shown below and press .

STEP 5: Provide Method, Method name and Description and click on .

STEP 6: Do not make any changes here and just click on .

STEP 7: A confirmation popup comes up and select ‘Yes’ to continue.

STEP 8: Once the method is created, do not forget to make the  method function API enabled. This is done as shown below. Double click on the method to get this popup.


Once this is done, notice a small green icon beside the method(). This indicates that the method is API enabled.

STEP 9: Now click on object and go to ‘Edit menu’ and select the release status as ‘To Implemented’ as shown below.


STEP 10: Save the object type with the confirmation that pops up on changing the Release type to Implemented.


STEP 11: Now click on object and go to ‘Edit menu’ and select the release status as ‘To Released’.

You will see a small tick beside object name as seen below on 'Release' which indicates the object is released.


STEP 12: Now click on method and go to ‘Edit menu’ and select the release status as ‘To Released’ as shown below. (Before doing this make sure that the Function module created is set to release.)

You will see a small tick beside method name as shown below on 'Release' which indicates the method is released.


STEP 13: Click on  (Generate) once the above steps are completed successfully and Save.


STEP 14: Now, go to BDBG T-Code and provide the Object and Method names created as shown below and Click on  (Create).


STEP 15: Provide message type and click on .


STEP 16: Provide name for IDoc type, Outbound function module and Inbound function module as required and click on .

Following is the result.


Click on the IDoc type to check the structure generated.


Generated Segment:


One important thing to note here is, we have to make sure that IDOC types and Generated Segments have to be set to release to ensure their visibility across systems.



Configuration Required


Create a Distribution Model – BD64 as shown below (Add BAPI with the Sender and Receiver along with the Object and Method Created above).


Create a new model view.


Select the Model View created and Click on ‘Add BAPI’ and provide the Sender/Receiver and Object/Method details as shown below.


On adding the BAPI, the model view looks like as shown below.


After, this go to Environment-> Generate Partner Profiles. This will create an entry in Outbound parameters of Partner Profile.



Sample ABAP code to try


Following is the sample code to be filled in the Function Module Created.


FUNCTION zbapi_gen_idoc.

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

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(EXTERNAL_NUMBER) LIKE  BAPI_ITOB_PARMS-EQUIPMENT OPTIONAL

*"     VALUE(DATA_GENERAL) LIKE  BAPI_ITOB STRUCTURE  BAPI_ITOB

*"       OPTIONAL

*"     VALUE(DATA_SPECIFIC) LIKE  BAPI_ITOB_EQ_ONLY STRUCTURE

*"        BAPI_ITOB_EQ_ONLY OPTIONAL

*"     VALUE(DATA_FLEET) LIKE  BAPI_FLEET STRUCTURE  BAPI_FLEET

*"       OPTIONAL

*"     VALUE(VALID_DATE) LIKE  BAPI_ITOB_PARMS-INST_DATE OPTIONAL

*"     VALUE(DATA_INSTALL) LIKE  BAPI_ITOB_EQ_INSTALL STRUCTURE

*"        BAPI_ITOB_EQ_INSTALL OPTIONAL

*"     VALUE(DATA_GENERATED) LIKE  ZDATA_GENERATED STRUCTURE

*"        ZDATA_GENERATED OPTIONAL

*"  TABLES

*"      RETURN STRUCTURE  BAPIRET2

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

   DATA: it_receivers TYPE STANDARD TABLE OF bdi_logsys,

         it_filters   TYPE STANDARD TABLE OF bdi_fobj.

* Call the function module to get the receivers list.

   CALL FUNCTION 'ALE_ASYNC_BAPI_GET_RECEIVER'

     EXPORTING

       object                   = 'ZEQUI'

       method                   = 'ZCUSTSEGMENT'

     TABLES

       receivers                = it_receivers

       filterobject_values      = it_filters

     EXCEPTIONS

       error_in_filterobjects   = 1

       error_in_ale_customizing = 2

       OTHERS                   = 3.

   CALL FUNCTION 'ZOUTOUT_GEN_IDOC_EQUI'

     EXPORTING

       externalnumber       = external_number

       datageneral          = data_general

       dataspecific         = data_specific

       datafleet            = data_fleet

       validdate            = valid_date

       datainstall          = data_install

       datagenerated        = data_generated

     TABLES

       receivers            = it_receivers

     EXCEPTIONS

       error_creating_idocs = 1

       OTHERS               = 2.

   IF sy-subrc <> 0.

* Implement suitable error handling here

   ENDIF.

ENDFUNCTION.


Following explains how we can make use of this FM.


Create a new BTE on equipment save and add the below logic. This will trigger the IDOC.


FUNCTION zbte_interface_pm000020 .

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

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(HEQKT_OLD) LIKE  EQKT STRUCTURE  EQKT

*"     REFERENCE(HEQUI_OLD) LIKE  EQUI STRUCTURE  EQUI

*"     REFERENCE(HEQUZ_OLD) LIKE  EQUZ STRUCTURE  EQUZ

*"     REFERENCE(HILOA_OLD) LIKE  ILOA STRUCTURE  ILOA

*"     REFERENCE(HEQBS_OLD) LIKE  EQBS STRUCTURE  EQBS

*"     REFERENCE(HEQKT_NEW) LIKE  EQKT STRUCTURE  EQKT

*"     REFERENCE(HEQUI_NEW) LIKE  EQUI STRUCTURE  EQUI

*"     REFERENCE(HEQUZ_NEW) LIKE  EQUZ STRUCTURE  EQUZ

*"     REFERENCE(HILOA_NEW) LIKE  ILOA STRUCTURE  ILOA

*"     REFERENCE(HEQBS_NEW) LIKE  EQBS STRUCTURE  EQBS

*"  TABLES

*"      IHPA_OLD STRUCTURE  IHPAVB OPTIONAL

*"      IHPA_NEW STRUCTURE  IHPAVB OPTIONAL

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

   INCLUDE: <cntain>.

   DATA: l_return           TYPE swotreturn,

         lt_cont            TYPE swconttab,

         l_objhnd           TYPE swo_objhnd,

         ls_externalnumber  TYPE bapi_itob_parms-equipment,

         lt_datageneral     TYPE STANDARD TABLE OF bapi_itob,

         lt_dataspecific    TYPE STANDARD TABLE OF bapi_itob_eq_only,

         lt_datafleet       TYPE STANDARD TABLE OF bapi_fleet,

         ls_validdate       TYPE bapi_itob_parms-inst_date,

         lt_datainstall     TYPE TABLE OF  bapi_itob_eq_install,

         lt_datagenerated   TYPE TABLE OF  zdata_generated.

   DATA :ls_datageneral     TYPE   bapi_itob,

         ls_dataspecific    TYPE   bapi_itob_eq_only,

         ls_datafleet       TYPE   bapi_fleet,

         ls_datainstall     TYPE   bapi_itob_eq_install,

         ls_datagenerated   TYPE   zdata_generated.

   CALL FUNCTION 'SWO_CREATE'

     EXPORTING

       objtype           = 'ZEQUI_GEN'

       objname           = 'ZBAPIGENIDOC'

     IMPORTING

       object            = l_objhnd

     EXCEPTIONS

       no_remote_objects = 1

       OTHERS            = 2.

   IF sy-subrc <> 0.

     "Error Handling

   ENDIF.

   CLEAR: ls_datageneral,ls_dataspecific,ls_datagenerated.

   swc_set_element lt_cont 'EXTERNALNUMBER'     hequi_new-equnr.

   ls_datageneral-objecttype      = hequi_new-eqart .      " equi

   ls_datageneral-manfacture      = hequi_new-herst .      " equi

   ls_datageneral-descript        = heqkt_new-eqktx .      " eqkt

   ls_datageneral-manmodel        = hequi_new-typbz .      " equi

   ls_datageneral-comp_code       = hiloa_new-bukrs .      " iloa

   swc_set_element lt_cont 'DATAGENERAL'    ls_datageneral.

   ls_dataspecific-material       = hequi_new-matnr.

   ls_dataspecific-serialno       = hequi_new-sernr.

   swc_set_element lt_cont 'DATASPECIFIC'     ls_dataspecific.

   ls_datagenerated-zext1         = 'Equipment'.

   ls_datagenerated-zext12        = 'TestEquipment'.

   swc_set_element lt_cont 'DATAGENERATED' ls_datagenerated.

   CALL FUNCTION 'SWO_INVOKE'

     EXPORTING

       object             = l_objhnd

       verb               = 'ZBAPITESTFINAL'

     IMPORTING

       return             = l_return

     TABLES

       container          = lt_cont.

   COMMIT WORK.

ENDFUNCTION.



Some other ways that you can try


For Inbound usage:

  • The Inbound FM already has the logic to split the SDATA of a segment into required structures. It also calls the FM/BAPI that was used to create the IDoc Structure. So, just by maintaining Partner Profiles in the Inbound parameter is the only config that you might have to do.
  • So, the logic that you want to perform can be written within the FM/BAPI created.


For Outbound usage:

  • Capture the required data into the structures/tables. Call the Outbound FM by passing these structures/tables. That's it !! The triggering of IDoc will be handled by this FM only.


Issues that you may face during this process


  • When a new segment has to be introduced, the whole interface has to be deleted and should be regenerated again. In this process of regenerating, just by generating the program in SWO1 will not create the new segment. So don't panic !! Have a solution for that too.
    • In SWO1, the method that was created has to be deleted. Freshly new method has to be introduced, with the updated Function Module attached to it. Doing this, the parameters will be imported again and the program generated henceforth will have its own logic to generate new segment.


  • The multiple occurrence of segment within the IDOC is restricted to one if we have defined only the import parameters.
    • To have multiple occurrence of a segment, declare the required structure in the ‘Tables’ tab of the function module builder.
9 Comments
Labels in this area