Tuesday, 28 June 2011

Find BADI's in Different ways

1>First go to any transaction->iN THE menu bar SYSTEM->STATUS->Get the program name ->double click->u will go to the program attached to the tcode.Now search term will be CALL CL_EXITHANDLER.Now u will get list of BADI'S available..

2>Goto SE24->Give class name as CL_EXITHANDLER->Display->double click on get_instance mathod->Now u will go inside the method->Now put break point on the cl_exithandler.Now go to any transaction code and pass dat..U will see that it will be stopped on the break point which u set on the cl_exithandler...In the exit name u can find list of badi's attached to the tcode..

There are multiple ways of searching for BADI.

• Finding BADI Using CL_EXITHANDLER=>GET_INSTANCE
• Finding BADI Using SQL Trace (TCODE-ST05).
• Finding BADI Using Repository Information System (TCODE- SE84).

1. Go to the Transaction, for which we want to find the BADI, take the example of Transaction VD02. Click on System->Status. Double click on the program name. Once inside the program search for ‘CL_EXITHANDLER=>GET_INSTANCE’.
Make sure the radio button “In main program” is checked. A list of all the programs with call to the BADI’s will be listed.
The export parameter ‘EXIT_NAME’ for the method GET_INSTANCE of class CL_EXITHANDLER will have the user exit assigned to it. The changing parameter ‘INSTANCE’ will have the interface assigned to it. Double click on the method to enter the source code.Definition of Instance would give you the Interface name.

2. Start transaction ST05 (Performance Analysis).
Set flag field "Buffer trace"
Remark: We need to trace also the buffer calls, because BADI database tables are buffered. (Especially view V_EXT_IMP and V_EXT_ACT)
Push the button "Activate Trace". Start transaction VA02 in a new GUI session. Go back to the Performance trace session.
Push the button "Deactivate Trace".
Push the button "Display Trace".
The popup screen "Set Restrictions for Displaying Trace" appears.
Now, filter the trace on Objects:
• V_EXT_IMP
• V_EXT_ACT

Push button "Multiple selections" button behind field Objects
Fill: V_EXT_IMP and V_EXT_ACT

All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BADI class interfaces. The BADI name is after the IF_EX_.
So the BADI name of IF_EX_CUSTOMER_ADD_DATA is CUSTOMER_ADD_DATA

3. Go to “Maintain Transaction” (TCODE- SE93).
Enter the Transaction VD02 for which you want to find BADI.
Click on the Display push buttons.
Get the Package Name. (Package VS in this case)

Go to TCode: SE84->Enhancements->Business Add-inns->Definition
Enter the Package Name and Execute.

Here you get a list of all the Enhancement BADI’s for the given package MB.
The simplese way for finding BADI is
1. chooes Tcode Program & package for that Tcode.
2. Go to Tcode se18
3. Press F4
4. search by package or by program.

READ TEXT function module

READ_TEXT function module

how to use the READ_TEXT function module to read SAP long text. Every text in SAP has its own ID and NAME, by passing these parameters into the READ_TEXT function, we can get all the text in the SAP long text object.





step by step flow for inbound

IDOC Step-by-Step. INBOUND process

Continue from outbound process...

In Client 812 Steps:
Function Module Creation:
Create a Function Module to update the table from the IDOC segments
Go to SE37
Specify a name and click on create.

Specify the Import parameters in Import tab

Specify the Export parameters in Export tab

Specify the Table parameters in Tables tab

Specify the Exceptions in Exception tab

Click on Source code Tab.

====================================================
 FUNCTION ZIDOC_ZDEMO_MATEIAL.
*"---------------------------------------------------------------------- *"*"Local Interface: Details for importing, exporting, tables, exceptions
*"  IMPORTING
*"     REFERENCE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"     REFERENCE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"  EXPORTING
*"     REFERENCE(WORKFLOW_RESULT) LIKE  BDWF_PARAM-RESULT
*"     REFERENCE(APPLICATION_VARIABLE) LIKE  BDWF_PARAM-APPL_VAR
*"     REFERENCE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"     REFERENCE(CALL_TRANSACTION_DONE) LIKE  BDWFAP_PAR-CALLTRANS
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

* Include File containing ALE constants
INCLUDE MBDCONWF.

TABLES : zdemo_material.

DATA : W_ZSEGMENT LIKE ZSEGMENT.

DATA : T_zdemo_material LIKE zdemo_material OCCURS 0 WITH HEADER LINE.
WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.
IF IDOC_CONTRL-MESTYP NE 'ZCLIENTMSG'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.

*  Before reading a new entry, clear application buffer
LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.
W_ZSEGMENT = IDOC_DATA-SDATA.
MOVE-CORRESPONDING W_ZSEGMENT TO T_zdemo_material.
INSERT INTO zdemo_material VALUES T_zdemo_material.
ENDLOOP.

UPDATE zdemo_material FROM T_zdemo_material.

IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = T_zdemo_material-MANDT.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = T_zdemo_material-MANDT.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
ENDLOOP.
ENDFUNCTION.
====================================================

Assign FM to Logical Message:
Go to TCODE WE57
Click on Display / Change button.
Click on New Entries

Define Input Method for Inbound Function Module:
Go to TCODE BD51
Click on Display / Change button
Click on New Entries

Creating Process Code:
Go to TCODE WE42
Click on Display / Change Button
Click on New Entries

It will take to you previous screen. Double Click on Logical Message in left side tree.

Click on Display / Change button

Click on New Entries button

Generating the Partner Profile:
Go to TCODE BD64.
Select the Model View which you distributed in client 812.
Click on Environment Menu -> Generate Partner Profile .Execute.

check the partner profile details.

Go to TCODE WE20. Select the partner system name.

Transferring the IDOC control records from Client 800 to 812:
In source system, go to TCODE SE38. (In client 800)
Execute the Report program which you created.
Check in Destination System: (Here client 800)
Go to TCODE WE02

Check in Destination System: (Here client 812)
Go to TCODE WE02


Check in ZDEMO_MATERIAL table in SE11.

Done!..

====================================================

Took Reference from the link given below:

STEP by STEP IDOC inbound flow

IDOC Step-by-Step. OUTBOUND process

TO Process IDOCS the following TCODES will be used.

On both sides:

Logical System Names SALE
Setup RFC destinations SM59
Port Destinations WE21
In Source system:
Segment Creation WE31
Basic IDOC Type Creation WE30
Message Type Creation WE81
Assign Message Type To Basic IDOC Type WE82
Distribution Model BD64
Writing Report Program SE38
Partner Profile WE20
Message control NACE
Check IDOCs WE02, WE05
In Destination System:
Creating FM SE37
Assign FM to Logical Message WE57
Define I/P method for Inbound FM BD51
Create Process Code WE42
Generate Partner Profile BD64.
--------------------------------------------------------------------------------
Note:Different clients but same server.
Creating the Logical System Names and Assigning to Clients:

created on client 800.


created on client 812.


Creating the RFC Connection Names:

create RFC in SM59 for both clients 800 and 812.



Creating RFC ports:

Go to TCODE WE21.

create in 800 and RFC destination which was created in 812...EC3812


create in 812 and RFC destination which was created in 800...EC3

Creating table structure:
ð Go to TCODE SE11.
ð Specify table name as zdemo_material.( in client 800 EC3)
Creating IDOC Segments:
Go to TCODE WE31.
Specify a name and Click on Create Button.


Creating Basic IDOC Type:
Go to TCODE WE30
Specify a name to your IDOC and click on create button.
after creating NOTE: Go to menu EDIT->Click Set Release


Creating Message Type:
Go to TCODE WE81.
Click on Display / Change button.
Assign Message Type to Basic IDOC Type:
Go to TCODE WE82
Click on Display / Change Button

Creating Model View and Distributing and Generating Partner profile:
Go to TCODE BD64
Click on Display/ Change button
Click on Edit menu -> Model View -> Create

Specify description of model view and technical name in dialog box and press continue.

Select your model view and click on Edit menu -> Add Message type

In dialog box specify the sender, receiver, message type and click on continue.


Click on Environment Menu -> Generate Partner profile

It will show the following screen, click on execute.


Note: Dont create in client 812, because we are using the same server. It will be automatically created in the client 812. check bd64 in client 812.

Click on Back button 2 times, it will take back to Distribution Model screen.

Click on Edit Menu -> Model View -> Distribute.


MODEL VIEW Created.

check partner profile
Go to TCODE WE20
In displayed screen select the partner system in left side tree under Partner Type LS.

Write a Report Program in SE38

To create IDOC control records and transfer it to destination partner system.

====================================================

REPORT ZDEMO_IDOCSEND.

TABLES: zdemo_material.

DATA : S_CTRL_REC LIKE EDIDC, "Idoc Control Record
S_ZSEGMENT LIKE ZSEGMENT. "CUSTOMER Header Data

DATA : T_zdemo_material LIKE zdemo_material OCCURS 0 WITH HEADER LINE.

DATA : T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE. "Data Records
DATA : T_COMM_IDOC LIKE EDIDC OCCURS 0 WITH HEADER LINE. "Generated Communication IDOc

CONSTANTS :C_ZSHSTUSEG LIKE EDIDD-SEGNAM VALUE 'ZSEGMENT'.
CONSTANTS: C_IDOCTP LIKE EDIDC-IDOCTP VALUE 'ZSTUDENTIDOC'.
*** Selection Screen
SELECT-OPTIONS : S_BUKRS FOR zdemo_material-BUKRS OBLIGATORY.
PARAMETERS : C_MESTYP LIKE EDIDC-MESTYP DEFAULT 'ZCLIENTMSG', "Message Type
C_RCVPRT LIKE EDIDC-RCVPRT DEFAULT 'LS', "Partner type of receiver
C_LOGSYS LIKE EDIDC-RCVPRN DEFAULT 'EC3812'.
* C_RCVPOR LIKE EDIDC-RCVPOR DEFAULT 'A000000018',
* C_SNDPRN LIKE EDIDC-SNDPRN DEFAULT 'EC3',
* C_SNDPRT LIKE EDIDC-SNDPRT DEFAULT 'LS'. "Destination System
DATA ZSEGMENT.

***START-OF-SELECTION
START-OF-SELECTION.
PERFORM GENERATE_DATA_RECORDS.
PERFORM GENERATE_CONTROL_RECORD.
PERFORM SEND_IDOC.
*&---------------------------------------------------------------------*
*& Form GENERATE_DATA_RECORDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_DATA_RECORDS .
SELECT * FROM zdemo_material
INTO TABLE T_zdemo_material
WHERE BUKRS IN S_BUKRS.
IF SY-SUBRC NE 0.
MESSAGE E398(00) WITH 'No Company code Found'.
ENDIF.
PERFORM ARRANGE_DATA_RECORDS.
ENDFORM. " GENERATE_DATA_RECORDS
*&---------------------------------------------------------------------*
*& Form GENERATE_CONTROL_RECORD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_CONTROL_RECORD .
* S_CTRL_REC-RCVPOR = C_RCVPOR. "Receiver Port
S_CTRL_REC-MESTYP = C_MESTYP. "Message type
S_CTRL_REC-IDOCTP = C_IDOCTP. "Basic IDOC type
S_CTRL_REC-RCVPRT = C_RCVPRT. "Partner type of receiver
S_CTRL_REC-RCVPRN = C_LOGSYS. "Partner number of receiver
* S_CTRL_REC-SNDPRT = C_SNDPRT. "Sender Partner type
* S_CTRL_REC-SNDPRN = C_SNDPRN. "Sender Partner Number
ENDFORM. " GENERATE_CONTROL_RECORD
*&---------------------------------------------------------------------*
*& Form SEND_IDOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_IDOC .
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = S_CTRL_REC
* OBJ_TYPE = ''
* CHNUM = ''
TABLES
COMMUNICATION_IDOC_CONTROL = T_COMM_IDOC
MASTER_IDOC_DATA = T_EDIDD
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 1
ERROR_WRITING_IDOC_STATUS = 2
ERROR_IN_IDOC_DATA = 3
SENDING_LOGICAL_SYSTEM_UNKNOWN = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
COMMIT WORK.
LOOP AT T_COMM_IDOC.
WRITE:/ 'IDoc Generated - ', T_COMM_IDOC-DOCNUM.
ENDLOOP.
ENDIF.
ENDFORM. " SEND_IDOC
*&---------------------------------------------------------------------*
*& Form ARRANGE_DATA_RECORDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ARRANGE_DATA_RECORDS .

SORT T_zdemo_material BY BUKRS.

LOOP AT T_zdemo_material.
S_ZSEGMENT-MANDT = T_zdemo_material-MANDT.
S_ZSEGMENT-BUKRS = T_zdemo_material-BUKRS.
S_ZSEGMENT-BUTXT = T_zdemo_material-BUTXT.
S_ZSEGMENT-ORT01 = T_zdemo_material-ORT01.
s_ZSEGMENT-ADRNR = T_zdemo_material-ADRNR.
T_EDIDD-SEGNAM = C_ZSHSTUSEG.
T_EDIDD-SDATA = S_ZSEGMENT.
APPEND T_EDIDD.
CLEAR T_EDIDD.
ENDLOOP.
ENDFORM. " ARRANGE_DATA_RECORDS

====================================================

Now execute the program, and specify the range of records to transfer



Idoc generated id you will get.

Go to TCODE WE02 to check the generated IDOC control records.
Click on Execute or Refersh
If u find the Status Yellow.
Then Go se38.. Program name: RSEOUT00...Execute

Go to TCODE WE02 to check the generated IDOC control records.


====================================================

idoc

http://www.scribd.com/doc/4913342/IDOC

ravi BLOG
http://sapsamplepro.blogspot.com/

Data Exchange via IDoc with ALE or EDI

Data Exchange via IDoc with ALE or EDI


IDoc or Intermediate Document is a standard SAP document exchange format. IDocs allow different application systems to be linked via a message-based interface. The IDoc interface consists of the definition of a data structure (where the data structure is the IDoc) and a processing logic for this data structure. There are three main aims behind the use of IDocs:
  • The structured exchange of business documents so that they can be processed automatically.
  • The various degrees of structural complexity as displayed by different application systems can be reduced to a structure which is as simple as possible.
    Example: The structure of an SAP application document and the structure of the corresponding EDI message under the UN/EDIFACT standard.
  • IDocs allow for extensive exception handling before the data is posted to the application.
The following techniques use the IDoc interface to exchange business data between different systems:
  • Electronic Data Interchange (EDI) was the first form of data transfer to use IDocs. In EDI application scenarios, the processes, by definition, involve two partners: The sender and the recipient of an EDI message. EDI is a bilateral, document-oriented form of data transfer.
  • Application Link Enabling (ALE) enables integration of business processes that are developed across several SAP systems or non-SAP systems. Thus, ALE is oriented to connect different applications on different systems. System-wide ALE message flows are modeled in a so called 'distribution model'.
    A typical scenario is the system data administration, where material master records have to be distributed from one central to several satellite systems. Nowadays, pure EDI scenarios are more and more executed on the basis of ALE technology, only that the system connection is 'just' bilateral.

ALE/EDI/BAPI

What is the different between ALE, IDOC and BAPI?
ALE
ALE is SAP proprietary technology that enables data communications between two or more SAP R/3 systems and/or R/3 and external systems. When a new enterprise resource planning (ERP) solution such as R/3 is implemented, companies have to interface the ERP system with legacy systems or other ERP systems.
ALE provides intelligent mechanisms where by clients can achieve integration as well as distribution of applications and data.
ALE technology facilitates rapid application prototyping and application interface development, thus reducing implementation time.
The ALE components are inherently integrated with SAP applications and are robust, leading to a highly reliable system.
ALE comes with application distribution/integration scenarios as well as a set of tools, programs, data definitions, and methodologies that you can easily configure to get an interface up and running.
BAPI
BAPIs provide a stable, standardized method for third-party applications and components to integrate into the Business Framework. These interfaces are being specified as part of SAP's initiative with customers, partners and leading standards organizations. Also, SAP has implemented the emerging Object Application Group (OAG) specifications with BAPIs.
Pros and Cons for both BAPI and Call Transaction
BAPI
One of the big plusses for BAPIs is that the interface and function are not supposed to change.  This is a big plus when you do upgrades or hot packs because the transaction can change (format, required inputs etc) which means you then need to update the call transaction.
Some of the BAPIs are better documented and easier to use than others.
You usually need to perform the BAPI that actually does the COMMIT after you call your BAPI.
The Program coding for calling a BAPI is usually cleaner than setting up the screen flow etc for the Call Transaction.
You don't need to worry about special data circumstances interrupting the normal data flow of the screens and causing errors because of that.
BAPIs probably have better performance since they don't do the screen flow processing.
In general if the BAPI exists for the transaction you want to perform and you can figure out how to use it the BAPI is probably the best way to go.
This is just from my experience working with both BAPI and Call Transaction.  I have had some very good successes with BAPIs, but very occasionally found that I could not get the BAPI to perform the update I needed.
ABAP Tips by: Rajesh
The interface concept of the classic R/3 is based on two different strategies: Remote Function Calls (RFC) and data exchange through IDoc message documents. RFC makes direct and synchronous calls of a program in the remote system. If the caller is an external program it will call an RFC-enabled function in R/3 and if the calling program is the R/3 system it will call an
RFC-function in another R/3-system or it will call a non-R/3 program through a gateway-proxy (usually rfcexec.exe). BAPIs are a subset of the RFC-enabled function modules, especially designed as Application Programming Interface (API) to the SAP business object, or in other words: are function modules officially released by SAP to be called from external programs.
IDocs are text encoded documents with a rigid structure that are used to exchange data between R/3 and a foreign system. Instead of calling a program in the destination system directly, the data is first packed into an IDoc and then sent to the receiving system, where it is analyzed and properly processed.   Therefore an IDoc data exchange is always an
asynchronous process. The significant difference between simple RFC-calls and IDoc data exchange is the fact, that every action performed on IDocs are protocolled by R/3 and IDocs can be reprocessed if an error occurred in one of the message steps.
While IDocs have to be understood as a data exchange protocol, EDI and ALE are typical use cases for IDocs. R/3 uses IDocs for both EDI and ALE to deliver data to the receiving system. ALE is basically the scheduling mechanism that defines when and between which partners and what kind of data will be exchanged on a regular or event triggered basis. Such a set-up is called an ALE-scenario.
The philosophical difference between EDI and ALE can be pinned as follows: If we send data to an external partner, we generally speak of EDI, while ALE is a mechanism to reliable replicate data between trusting systems to store a redundant copy of the IDoc data.   The difference is made clear, when we think of a purchase order that is sent as an IDoc. If we send the purchase order to a supplier then the supplier will store the purchase order as a sales order. However, if we send the purchase order via ALE to another R/3 system, then the receiving system will store the purchase order also as a purchase order.

Monday, 27 June 2011

IDOCS in BOUND FLOW


IDOC Inbound flow steps:
1. Creation of segment (WE31)
2. Basic idoc type creation (WE30)
3. Message type creation (WE81)
4. Assign message type to basic idoc type (WE82)
5. Creating Function module (SE37)
6. Assign Function module to logical system (WE57).
7. Define input Method for Inbound function module (BD51).
8. Creating process code (WE42).
9. Generating the Partner Profile (BD64).
10. Partner profile (WE20)
Create Segment type
Go to t code WE31:
Provide the Segment name: Z1SRQTEV



Click on Create button

Provide short description and field names to we are received data from outbound idoc.






Click on save button














Click on back button find the segment definition is created

Basic idoc type creation:
Go to  WE30:
Provide object name:ZHRRQTEV01
 
Click on create button
Provide description and create new radio button
Click on enter
Click on create





Provide segment type and min and max numbers after click one ok button
Click on save button


MESSAGE type creation:
Go to transaction code: WE81
Click on display change button popup is shown like below click on ok
Click on new entries tab







Provide message type and short text
Click on save button
Message type is created


ASSIGN MESSAGE TYPE TO IDOCTYPE
Go to transaction code: WE82
Click on display change button
Click on new entries tab





Provide message type and basic type and Realease
Click on save button
CREATE FUNCTION MODULE
Go to transaction code:SE37
Provide function module name: ZFHR_PT_CATSDB_APRISO12
Click on create button

Provide  function group name and short text
Click on save button
Create function module
Import, export, tables and source code
FUNCTION ZFHR_PT_CATSDB_APRISO.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"     REFERENCE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"  EXPORTING
*"     REFERENCE(WORKFLOW_RESULT) LIKE  BDWF_PARAM-RESULT
*"     REFERENCE(APPLICATION_VARIABLE) LIKE  BDWF_PARAM-APPL_VAR
*"     REFERENCE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"     REFERENCE(CALL_TRANSACTION_DONE) LIKE  BDWFAP_PAR-CALLTRANS
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------
* Include File containing ALE constants
INCLUDE MBDCONWF.
TABLES : CATSDB,
         PA2003.
DATA : WA_ZSHR_RQTEV      TYPE ZSHR_RQTEV,  "Structure
       WA_Z1SRQTEV        TYPE Z1SRQTEV,    "segment
       wa_data            type edidd,
       WA_CATSDB          TYPE CATSDB,
       IT_CATSDB          TYPE TABLE OF CATSDB,
       WA_P2003           TYPE PA2003,
       IT_P2003           TYPE TABLE OF PA2003,
       return             TYPE bapireturn1.

DATA:  empnumber               TYPE  hr_pernr,
       message                 TYPE string,
       ret                     TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA:  catsrecords_input       LIKE bapicats1 OCCURS 0 WITH HEADER LINE,
       sendercostcentre        TYPE kostl,
       profile                 TYPE catsvarian VALUE 'USP-LGL1',
       wa_i_catsrecords_input  LIKE bapicats1.
  WORKFLOW_RESULT    = C_WF_RESULT_OK.
LOOP AT IDOC_DATA INTO WA_DATA. "WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.
    CASE  WA_DATA-SEGNAM.
      WHEN 'Z1SRQTEV'.
        AT NEW SEGNUM.
          WA_Z1SRQTEV =  WA_DATA-SDATA.
          MOVE-CORRESPONDING  WA_Z1SRQTEV TO WA_P2003.
          MOVE-CORRESPONDING  WA_Z1SRQTEV TO WA_CATSDB.
          APPEND WA_CATSDB TO IT_CATSDB.
        ENDAT.
***********begin of insert data in pa2003 infotype
 CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
       EXPORTING
            number = WA_P2003-pernr
       IMPORTING
            return = return.
 CALL FUNCTION 'HR_INFOTYPE_OPERATION'
   EXPORTING
     infty                  = '2003'
     number                 = WA_P2003-pernr
    SUBTYPE                 = WA_P2003-subty
    VALIDITYEND             = WA_P2003-endda
    VALIDITYBEGIN           = WA_P2003-begda
     record                 = WA_P2003
     operation              = 'INS'
  IMPORTING
    RETURN                  = return
           .
if sy-subrc = 0.
   message 'INSERT DATA IN INFOTYPE SUCCESSFULLY' type 'I'.
 endif.
*mapping
CATSDB-PERNR     = catsrecords_input-employeenumber.
CATSDB-WORKDATE  = catsrecords_input-workdate.
CATSDB-BEGUZ     = catsrecords_input-STARTTIME.
CATSDB-ENDUZ     = catsrecords_input-ENDTIME.
CATSDB-CATSHOURS = catsrecords_input-CATSHOURS.
CATSDB-AWART     = catsrecords_input-ABS_ATT_TYPE.
CATSDB-STATUS    = '30'.

move-corresponding wa_catsdb to catsrecords_input.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = sendercostcentre
  IMPORTING
    output = sendercostcentre.

CALL FUNCTION 'BAPI_CATIMESHEETMGR_INSERT'
 EXPORTING
   profile               = profile
  TABLES
    catsrecords_in        = catsrecords_input
    return                = ret
          .
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  IF ret[] IS INITIAL.
    CONCATENATE 'Time Sheet has been filled successfully for' empnumber INTO message SEPARATED BY space.
  ELSE.
    READ TABLE ret WITH KEY type = 'E'.
    IF sy-subrc EQ 0.
      message = ret-message.
    ELSE.
      READ TABLE ret INDEX 1.
      message = ret-message.
    ENDIF.
  ENDIF.
ELSE.
  READ TABLE ret WITH KEY type = 'E'.
  IF sy-subrc EQ 0.
    message = ret-message.
  ELSE.
    READ TABLE ret WITH KEY type = 'A'.
    IF sy-subrc EQ 0.
      message = ret-message.
    ELSE.
      READ TABLE ret INDEX 1.
      message = ret-message.
    ENDIF.
  ENDIF.
ENDIF.
if sy-subrc = 0.
  message 'INSERT DATA IN CATSDB TABLE SUCCESSFULLY' type 'I'.
  endif.
*****************end of insert the data in catsdb table
    IF SY-SUBRC EQ 0.
      IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
      IDOC_STATUS-STATUS = '53'.
      IDOC_STATUS-MSGTY  = 'I'.
      IDOC_STATUS-MSGID  = 'ZHR'.
      IDOC_STATUS-MSGNO  = '012'.
      IDOC_STATUS-MSGV1  = WA_CATSDB-PERNR.
      APPEND IDOC_STATUS.
      CLEAR IDOC_STATUS.
    ELSE.
      IDOC_STATUS-DOCNUM  = IDOC_CONTRL-DOCNUM.
      IDOC_STATUS-STATUS  = '51'.
      IDOC_STATUS-MSGTY   = 'E'.
      IDOC_STATUS-MSGID   = 'ZHR'.
      IDOC_STATUS-MSGNO   = '013'.
      IDOC_STATUS-MSGV1   = WA_CATSDB-PERNR.
      APPEND IDOC_STATUS.
      CLEAR IDOC_STATUS.
      WORKFLOW_RESULT             = C_WF_RESULT_ERROR.
      RETURN_VARIABLES-WF_PARAM   = 'Error_Idocs'.
      RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
      APPEND RETURN_VARIABLES.
      CLEAR RETURN_VARIABLES.
    ENDIF.
endcase.
endloop.

ENDFUNCTION.
ASSIGN FM TO LOGICAL MESSAGE
Go to transaction code WE57
Click on display and change button
Click on new entries
Provide Function module name, function type, basic idoc type message type and direction
Click on save button
DEFINE INPUT M METHOD FOR INBOUND FUNCTION MODULE
Go to transaction code :BD51
Click on display and change button
Click on new entries
Provide Function module name and input type
Click on save button






CREATING PROCESS CODE
Go to transaction code: WE42
Click on display and changes button
Click on new entries
Provide process code and description
In processing type select the second radio button
Click on save button the below popup is shown
Click ok
Provide Function module name:

Click on save button
Click on logical message tab
Click  on new entries tab
Provide message type
Click on save button
Process code is created
Generating partner profile
Click on display and changes button
Click on create create model view tab
Click on ok button
Our creating view is shown like below
Click on add message type tab
Click on ok
After modal view is shown like below




Select our modal view and go to Environment->Generate partner profile tab
Click on execute button
Our message type is successfully created message is shown