Monday, January 16, 2017

Generated ALE-IDOC Interfaces

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 IDOC types 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 (outbound process)
  • An Inbound Function Module that fills the BAPI with the IDoc data on the inbound side. (inbound process)
The generated ALE IDoc interface performs the following tasks:
  • Inbound process:
    • Creates an IDoc from the BAPI data
    • Sends the IDoc to the target system
  • Outbound process:
    • 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.
/wp-content/uploads/2015/10/step1_810913.jpg


STEP 2: Create a new remote enabled function module which is responsible for generating IDOC through SE37 as shown below.
/wp-content/uploads/2015/10/step2_810962.jpg


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)
/wp-content/uploads/2015/10/step3_810964.jpg
STEP 4: Add new method to the Business Object created with the function module previously created as shown below and press /wp-content/uploads/2015/10/tick_811070.png.
/wp-content/uploads/2015/10/step4_811072.jpg
STEP 5: Provide Method, Method name and Description and click on /wp-content/uploads/2015/10/next_811077.png.
/wp-content/uploads/2015/10/step5_811078.jpg
STEP 6: Do not make any changes here and just click on /wp-content/uploads/2015/10/next_811077.png.
/wp-content/uploads/2015/10/step6_811086.jpg
STEP 7: A confirmation popup comes up and select ‘Yes’ to continue.
/wp-content/uploads/2015/10/step7_811089.jpg
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.
/wp-content/uploads/2015/10/step8_811090.jpg


Once this is done, notice a small green icon beside the method(/wp-content/uploads/2015/10/greenicon_811145.png). 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.
/wp-content/uploads/2015/10/step9_811111.jpg


STEP 10: Save the object type with the confirmation that pops up on changing the Release type to Implemented.
/wp-content/uploads/2015/10/step10_811119.jpg


STEP 11: Now click on object and go to ‘Edit menu’ and select the release status as ‘To Released’.
/wp-content/uploads/2015/10/step11_811130.jpg
You will see a small tick beside object name as seen below on ‘Release’ which indicates the object is released.
/wp-content/uploads/2015/10/step11_1_811131.jpg


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.)
/wp-content/uploads/2015/10/step12_811132.png
You will see a small tick beside method name as shown below on ‘Release’ which indicates the method is released.
/wp-content/uploads/2015/10/step12_1_811136.jpg


STEP 13: Click on  /wp-content/uploads/2015/10/generate_811143.png (Generate) once the above steps are completed successfully and Save.
/wp-content/uploads/2015/10/step13_811146.jpg


STEP 14: Now, go to BDBG T-Code and provide the Object and Method names created as shown below and Click on  /wp-content/uploads/2015/10/create_811144.png (Create).
/wp-content/uploads/2015/10/step14_811147.jpg


STEP 15: Provide message type and click on /wp-content/uploads/2015/10/tick_811070.png.
/wp-content/uploads/2015/10/step15_811150.jpg


STEP 16: Provide name for IDoc type, Outbound function module and Inbound function module as required and click on /wp-content/uploads/2015/10/tick_811070.png.
/wp-content/uploads/2015/10/step16_811151.jpg
Following is the result.
/wp-content/uploads/2015/10/result_811153.jpg


Click on the IDoc type to check the structure generated.
/wp-content/uploads/2015/10/idoc_type_811157.jpg


Generated Segment:
/wp-content/uploads/2015/10/gen_segment_811664.jpg


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.
/wp-content/uploads/2015/10/config1_811666.jpg


Select the Model View created and Click on ‘Add BAPI’ and provide the Sender/Receiver and Object/Method details as shown below.
/wp-content/uploads/2015/10/config2_811673.jpg


On adding the BAPI, the model view looks like as shown below.
/wp-content/uploads/2015/10/config3_811674.jpg


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.

No comments:

Post a Comment

SAP giới thiệu mã hỗ trợ AI trong ngôn ngữ ABAP riêng của mình

SAP đã ra mắt một loạt tính năng mã hỗ trợ AI trong môi trường phát triển ứng dụng dựa trên đám mây của mình, đồng thời tham gia vào danh sá...