25 Aralık 2013 Çarşamba

Create IDOC Step By step

Create IDOC Step by step
SM59 --  create RFC destinations 
WE21 – create/maintain port destination
WE11- DELETE IDocs
RSEXARCD—report name for deletion program for archived IDocs
RBDAPP01-- report name for selecting INBOUND Processing of IDocs Ready for Transfer
RBDAGAIN—report name for processing OUTBOUND IDocs with Errors Again.
RSRFCPIN —report name for  RFC Connection Test.
RBDAGAI2 – report name for reprocess IDocs after INBOUND ALE Error
RBDAGAIE—report name for reprocessing of edited IDocs.
RSEOUT00—report name for process all selected IDocs (EDI)

CREATE OUTBOUND

Source system:
SE11—Create ZTABLE_IDOC_TEST
First, we shall create our table for sending its data to another system.






WE31—Create Segment
Assign name and (F5) Create new segment.
Select the fields you need to transport via IDocs.
Save.






WE30—Creating Basic IDoc Type
Assign a name and (F5) Create a Basic IDoc Type.
(Shift-F6) or Create again. On the next screen you give your segment name to bound them each other.
Select Minimum and maximum number.
Ok, then it seems like this. (Ctrl-S) Save





WE81—Creation Message Type.
(Ctrl-F4) or Change -> Display,
 New Entries.
Assign a name for new message Type.
Save.

WE82—Bound a relation between Message Type and Basic IDOC Type
(Ctrl-F4) or Change -> Display,
New Entries.
Write our Message type and Basic Type names here.
Save.




BD64—Create Distribution Model.
(Ctrl-F4) or Change -> Display,
Edit->Create Model View
Give Names.

Select Model we created,
Edit-> Add Message Type.
Sender and Receiver is to be fulled correctly.

Put our own  message type name.
Save.
Environment-> Generate Profile
And partner profile generated.


Edit-> Model View -> Distribute--  For distribute created Model View.







Then Model View Created.
Now we can check the partner profile for our message type.
WE20- Display profiles.
Our Message Type is set in the Outbound section.




 SE38—Write to report program for creating IDOC control records then transferring it to destination system.
REPORT z_idoc_test.
Run report program.








Then check the IDocs from WE02











CREATE INBOUND


WE57- Assign Function Module to Logical Message:
(Ctrl-F4) or Change -> Display,
New Entries.
Write our Function Name,
Select our Message type and Basic Type,
Direction is Inbound.

Save.

BD51- Assign Method for Written Function Module
(Ctrl-F4) or Change -> Display,
New Entries.
Write Function Name
Select 2 for Input T (Inbound)
Save.



WE42- Creating process Code
(Ctrl-F4) or Change -> Display,
New Entries.
Assign a name for process.
Click left part of screen on “logical message”
Assign our Message Type to process.

BD64- Generating Model View
Select Model View, which you created in source system. 
Environment-> Generate Profile
And partner profile generated.

WE20- For cheking profile detail.
Select destination source and check if you can see your message type in Inbound section.





Now everything is set.
Run Z_IDOC_TEST from R2D. And create IDOC, send it to R1D system.


WE02-Check IDoc in source for Outbox. (R2D)






WE02-Check IDoc in destination for Inbox. (R1D)




*---------------------------------------------------------------------*
*Report  Z_IDOC_TEST
*---------------------------------------------------------------------*

REPORT z_idoc_test.

TABLES: ztable_idoc_test.

DATA : s_ctrl_rec LIKE edidc, "Idoc Control Record
       s_zsegment 
LIKE zsegment_test. "CUSTOMER Header Data

DATA : t_ztable_idoc_test LIKE ztable_idoc_test 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_TEST'.
CONSTANTS: c_idoctp LIKE edidc-idoctp VALUE 'ZBASICTYPE_IDOC_TEST'.
*** Selection Screen
SELECT-OPTIONS : s_bukrs FOR ztable_idoc_test-bukrs OBLIGATORY.
PARAMETERS : c_mestyp LIKE edidc-mestyp DEFAULT 'ZMESSAGE_TYPE_IDOC_TEST',
c_rcvprt 
LIKE edidc-rcvprt DEFAULT 'LS', "Partner type of receiver
c_logsys 
LIKE edidc-rcvprn DEFAULT 'R1DCLNT030',
c_rcvpor 
like edidc-rcvpor default 'R1DCLNT030',
c_sndprn 
like edidc-sndprn default 'R2DCLNT030',
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
* <-- nbsp="" p2="" span="" text="">
*----------------------------------------------------------------------*
FORM generate_data_records .
  
SELECT * FROM ztable_idoc_test
  
INTO TABLE t_ztable_idoc_test
  
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
* <-- nbsp="" p2="" span="" 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
* <-- nbsp="" p2="" span="" 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
* <-- nbsp="" p2="" span="" text="">
*----------------------------------------------------------------------*
FORM arrange_data_records .

  
SORT t_ztable_idoc_test BY bukrs.

  
LOOP AT t_ztable_idoc_test.
    s_zsegment
-mandt = t_ztable_idoc_test-mandt.
    s_zsegment
-bukrs = t_ztable_idoc_test-bukrs.
    s_zsegment
-zeile = t_ztable_idoc_test-zeile.
    t_edidd
-segnam = c_zshstuseg.
    t_edidd
-sdata = s_zsegment.
    
APPEND t_edidd.
    
CLEAR t_edidd.
  
ENDLOOP.
ENDFORM. " ARRANGE_DATA_RECORDS