Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

out bound idoc creation urgent!!!!!!!!!!!!

Former Member
0 Kudos

Hi experts,

I am given a task to create an out bound IDOC which would be input to TIBCO, which must be triggered every time Good issue transaction is completed by either VT02N or VL02N transaction up pressing SAVE.

IDOC is to have fields from Customize tables apart from standard SAP tables, so was asked to create an own IDOC ( eg: Z--Idoc).

Please tell me how to create the idoc, and also the method to trigger it and how to populate the IDOC ( program etc).

Use full inputs would be promtly rewarded.

Regards,

Ram.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

In order to create an outbound IDOC we need to follow the below steps.

WE31 - Create Segment (then release it)

WE30 - Create Idoc (then release it)

WE81 - Create Message class

WE82 - Assign the message type with basic IDOC type

WE21 - Define Ports (If not already defined)

WE20 - Partner Profiles (Assign Message Type in the outbound parameters of receiving partner)

Now the program for sending IDoc.

REPORT zdemo_idoc.

**********************Data Declaration**********************

DATA: i_vbak TYPE TABLE OF [Segment Name]

w_vbak TYPE [Segment Name],

w_edidc TYPE edidc, [Workarea for Control Records]

w_edidd TYPE edidd, [Workarea for Data Records]

i_edidd TYPE TABLE OF edidd, [Internal table for Data Records]

t_idoc_comm_control TYPE edidc OCCURS 0 WITH HEADER LINE.

**********************Select Statements**********************

SELECT vbeln

ernam

kunnr

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE i_vbak

WHERE vbeln = '0000000012'.

**********************Control Records************************

w_edidc-rcvprt = 'LS'. [Partner Type of Receiver]

w_edidc-rcvpor = [Receiver port (SAP System, EDI subsystem)]

w_edidc-rcvprn = [Partner Number of Recipient]

w_edidc-mestyp = [Message Type]

w_edidc-doctyp = [IDoc Type]

***********************Data Records***************************

  • Move data records from internal table to the edidd structure.

LOOP AT i_vbak INTO w_vbak.

w_edidd-segnam = [Segment Name].

w_edidd-segnum = 1.

w_edidd-sdata = w_vbak.

w_edidd-hlevel = 1.

APPEND w_edidd TO i_edidd.

CLEAR w_edidd.

ENDLOOP.

**********************Send the IDOC***************************

  • Function Module to send the IDOC to the receiving port.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = w_edidc

TABLES

communication_idoc_control = t_idoc_comm_control

master_idoc_data = i_edidd

EXCEPTIONS

error_in_idoc_control = 1

error_writing_idoc_status = 2

error_in_idoc_data = 3

sending_logical_system_unknown = 4

OTHERS = 5.

COMMIT WORK. [Important statement for outbound IDOC.]

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

WRITE 😕 'Operation Unsuccessful'.

ELSE.

WRITE 😕 'operation successful'.

ENDIF.

Now about triggering the IDoc from VT02N or VL02N, you need to do the NACE settings which will a output type assigned to your program which will trigger the IDoc when you save it.

And I guess TIBCO is a middle ware to do conversion which will have certain Mapping rules to map the fields from your IDoc with the Endusers fields.

Do ask is any help required as I have worked on TIBCO.

Reward if helpful

Regards,

Arati.

4 REPLIES 4

Former Member
0 Kudos

Sample code in the below:

REPORT zhefrn_idoc_extract_fi LINE-SIZE 160.

*----

-


  • Purpose

  • -------

  • This program extracts FI postings and create IDOCs

*

  • Description

  • -----------

  • An IDOC of type ACC_GL_POSTING01 is created from the extracted

  • FI-data.

*

*- Extract data from BKPF and BSEG

*

*- Build the IDOC control record. Use structure EDIDC.

*

*- Build and internal table of structure EDIDD with IDOC segments.

  • EDIDD contains some keyfields, but the data segment field is simply

  • one string, as EDIDD is used for all type of IDOC’s. To simplify the

  • process of building this string, use the SAP datastructures with the

  • same name as the segment. E.g for segment E1BPACHE08 use structure

  • E1BPACHE08.

*

*- Use function module MASTER_IDOC_DISTRIBUTE to create the IDOC’s.

  • Remember to commit.

*

  • Important: This program can not handle multiple documents, so all

  • postings must have the same key (Company code, currency code,

  • postingdate, document date) so that they can be posted in the same

  • document. *If the program should handle multiple documents, data

  • should be split *according to the key, and an IDOC created for each

  • document.

*

*----

-


  • Standard types

*----

-


TABLES:

bkpf, "Accounting Document header

bseg. "Accounting Document Segment

  • TEDS1. "IDoc status values

*----

-


  • Standard types

*----

-


TYPES:

BEGIN OF st_bkpf,

bukrs LIKE bkpf-bukrs,

belnr LIKE bkpf-belnr,

gjahr LIKE bkpf-gjahr,

blart LIKE bkpf-blart,

bldat LIKE bkpf-bldat,

budat LIKE bkpf-budat,

monat LIKE bkpf-monat,

waers LIKE bkpf-waers,

END OF st_bkpf,

BEGIN OF st_extract,

bukrs LIKE bkpf-bukrs,

belnr LIKE bkpf-belnr,

gjahr LIKE bkpf-gjahr,

blart LIKE bkpf-blart,

bldat LIKE bkpf-bldat,

budat LIKE bkpf-budat,

monat LIKE bkpf-monat,

waers LIKE bkpf-waers,

hkont LIKE bseg-hkont,

bschl LIKE bseg-bschl,

shkzg LIKE bseg-shkzg, "Debit/credit indicator

dmbtr LIKE bseg-dmbtr,

wrbtr LIKE bseg-wrbtr,

dmbe2 LIKE bseg-dmbe2,

END OF st_extract.

*----

-


  • Table types

*----

-


TYPES: tt_bkpf TYPE STANDARD TABLE OF st_bkpf,

tt_extract TYPE STANDARD TABLE OF st_extract,

tt_edidd TYPE STANDARD TABLE OF edidd,

tt_edidc TYPE STANDARD TABLE OF edidc.

*----

-


  • Internal tables

*----

-


DATA:

  • G/L Doc header

gi_bkpf TYPE tt_bkpf,

  • G/L extracted data

gi_extract TYPE tt_extract,

  • IDOC segment data

gi_edidd TYPE tt_edidd,

  • Return table

gi_communication_idoc_control TYPE tt_edidc.

*----

-


  • Global variables

*----

-


DATA:

  • WA for internal tables

g_bkpf TYPE st_bkpf,

g_extract TYPE st_extract,

g_edidd LIKE edidd,

*-- IDOC structures:

  • IDOC control record

g_idoc_control_record LIKE edidc,

  • G/L document header

g_e1bpache08 LIKE e1bpache08,

  • G/L Account Line Items

g_e1bpacgl08 LIKE e1bpacgl08,

  • Line Item Currency Fields

g_e1bpaccr08 LIKE e1bpaccr08,

  • Return table from MASTER_IDOC_DISTRIBUTE

g_communication_idoc_control LIKE edidc.

*----

-


  • Selection screen

*----

-


SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME.

SELECT-OPTIONS: a_bukrs FOR bkpf-bukrs,

a_budat FOR bkpf-budat,

a_hkont FOR bseg-hkont,

a_usnam FOR bkpf-usnam DEFAULT 'WMHEFRN'.

PARAMETERS: p_create AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK 1.

SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME.

  • IDOC control record - Receiver

PARAMETERS:

p_rcvpor LIKE edidc-rcvpor DEFAULT 'PORT-HFN', "Rec. Port

p_rcvprn LIKE edidc-rcvprn DEFAULT 'WMHEFRN', "Rec. Partn. number

p_rcvprt LIKE edidc-rcvprt DEFAULT 'US', "Rec. Partn. type.

p_rcvpfc LIKE edidc-sndpfc DEFAULT '§§'. "Partner function

SELECTION-SCREEN END OF BLOCK 2.

SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME.

  • IDOC control record - Sender

PARAMETERS:

p_sndpor LIKE edidc-sndpor DEFAULT 'SAPC46', "Send. Port

p_sndprn LIKE edidc-sndprn DEFAULT 'WMHEFRN', "Send. Partn.number

p_sndprt LIKE edidc-sndprt DEFAULT 'US'. "Send. Partn. type.

  • p_sndpfc LIKE edidc-sndpfc DEFAULT '§P'. "Send. Partn. funct.

SELECTION-SCREEN END OF BLOCK 3.

*----

-


  • Start of selection

*----

-


START-OF-SELECTION.

PERFORM initialize.

PERFORM extract_data.

PERFORM build_idoc_control_record.

PERFORM build_idoc_segments.

IF p_create = 'X'.

PERFORM create_idocs.

ENDIF.

PERFORM write_report.

*&----


*

*& Form INITIALIZE

*&----


*

FORM initialize.

REFRESH: gi_bkpf,

gi_extract,

gi_edidd.

CLEAR: g_idoc_control_record.

ENDFORM. " INITIALIZE

*&----


*

*& Form EXTRACT_DATA

*&----


*

  • Extract FI postings to internal table gi_extract

*----

-


FORM extract_data.

  • Read BKPF

SELECT bukrs

belnr

gjahr

blart

bldat

budat

monat

waers

FROM bkpf

APPENDING CORRESPONDING FIELDS OF TABLE gi_bkpf

WHERE bukrs IN a_bukrs AND

budat IN a_budat AND

usnam IN a_usnam.

LOOP AT gi_bkpf INTO g_bkpf.

SELECT hkont

bschl

shkzg

dmbtr

wrbtr

dmbe2

FROM bseg

INTO CORRESPONDING FIELDS OF g_extract

WHERE bukrs = g_bkpf-bukrs AND

belnr = g_bkpf-belnr AND

gjahr = g_bkpf-gjahr.

MOVE-CORRESPONDING g_bkpf TO g_extract.

APPEND g_extract TO gi_extract.

CLEAR g_extract.

ENDSELECT.

ENDLOOP.

SORT gi_extract BY belnr.

ENDFORM. " EXTRACT_DATA

*&----


*

*& Form WRITE_REPORT

*&----


*

  • Writes a report showing the selected data, and generated IDOCs

  • and errors

*----


*

FORM write_report.

WRITE: / 'Extracted data' COLOR COL_GROUP INTENSIFIED ON.

LOOP AT gi_extract INTO g_extract.

AT NEW belnr.

SKIP 1.

FORMAT COLOR COL_GROUP INTENSIFIED ON.

WRITE: 'Document', g_extract-belnr.

FORMAT RESET.

NEW-LINE.

ENDAT.

WRITE: /

g_extract-bukrs,

g_extract-belnr,

g_extract-gjahr,

g_extract-blart,

g_extract-bldat,

g_extract-budat,

g_extract-monat,

g_extract-waers,

g_extract-hkont,

g_extract-bschl,

g_extract-shkzg,

g_extract-dmbtr,

g_extract-wrbtr,

g_extract-dmbe2.

ENDLOOP.

  • Write generated IDOCS

ULINE.

SKIP 2.

WRITE: / 'Generated IDOCs' COLOR COL_GROUP INTENSIFIED ON.

WRITE: / g_idoc_control_record.

LOOP AT gi_edidd INTO g_edidd.

WRITE: / g_edidd-segnam(10) COLOR COL_KEY, g_edidd-sdata(140).

ENDLOOP.

  • Write staus codes returned from function module MASTER_IDOC_DISTRIBUTE

IF p_create = 'X'.

ULINE.

SKIP 2.

WRITE: / 'Returncoides from function module MASTER_IDOC_DISTRIBUTE'

COLOR COL_GROUP INTENSIFIED ON.

LOOP AT gi_communication_idoc_control INTO

g_communication_idoc_control.

  • Find error message

  • select single

  • from TEDS1

WRITE: / g_communication_idoc_control-docnum,

g_communication_idoc_control-status.

ENDLOOP.

ENDIF.

ENDFORM. " WRITE_REPORT

*&----


*

*& Form BUILD_IDOC_CONTROL_RECORD

*&----


*

*

  • The IDOC control record contains message type, port and

  • partnerinformation

*----

-


FORM build_idoc_control_record.

g_idoc_control_record-mestyp = 'ACC_GL_POSTING'. "Message type

g_idoc_control_record-idoctp = 'ACC_GL_POSTING01'. "IDOC type

  • Receiver

g_idoc_control_record-rcvpor = p_rcvpor. "Port

g_idoc_control_record-rcvprn = p_rcvprn. "Partner number

g_idoc_control_record-rcvprt = p_rcvprt. "Partner type

g_idoc_control_record-rcvpfc = p_rcvpfc. "Partner function

  • Sender

g_idoc_control_record-sndpor = p_sndpor. "Port

g_idoc_control_record-sndprn = p_sndprn. "Partner number

g_idoc_control_record-sndprt = p_sndprt. "Partner type

  • g_idoc_control_record-sndpfc = p_sndpfc. "Partner function

ENDFORM. " BUILD_IDOC_CONTROL_RECORD

*&----


*

*& Form BUILD_IDOC_SEGMENTS

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM build_idoc_segments.

DATA: l_transdate(8) TYPE c,

l_itemnr TYPE i.

CLEAR l_itemnr.

LOOP AT gi_extract INTO g_extract.

  • Build data - The structures from the underlying BAPI are used to

  • simplify thje work of building the data part of the IDOC

*-- Document header segment E1BPACHE08

*-- The document header should only be generated in the first loop

CLEAR g_edidd.

IF sy-tabix = 1.

CLEAR g_e1bpache08.

g_edidd-segnam = 'E1BPACHE08'.

g_edidd-segnum = 1.

g_e1bpache08-obj_type = 'BKPFI'.

g_e1bpache08-obj_key = '127387347'.

g_e1bpache08-obj_sys = 'APOCLNT800'.

g_e1bpache08-username = 'WMHEFRN'.

g_e1bpache08-header_txt = 'Humle er godt'.

g_e1bpache08-comp_code = g_extract-bukrs.

g_e1bpache08-fisc_year = g_extract-gjahr.

g_e1bpache08-doc_date = g_extract-budat.

g_e1bpache08-pstng_date = g_extract-bldat.

g_e1bpache08-trans_date = sy-datum.

g_e1bpache08-fis_period = g_extract-monat.

g_e1bpache08-doc_type = 'SA'.

MOVE g_e1bpache08 TO g_edidd-sdata.

APPEND g_edidd TO gi_edidd.

ENDIF.

*-- Line item segment E1BPACGL08

CLEAR g_e1bpacgl08.

CLEAR g_edidd.

l_itemnr = l_itemnr + 1.

g_edidd-segnam = 'E1BPACGL08'.

g_edidd-segnum = 2.

g_e1bpacgl08-itemno_acc = l_itemnr.

g_e1bpacgl08-gl_account = g_extract-hkont.

g_e1bpacgl08-pstng_date = g_extract-bldat.

g_e1bpacgl08-item_text = 'Halli Hallo'.

MOVE g_e1bpacgl08 TO g_edidd-sdata.

APPEND g_edidd TO gi_edidd.

*-- Line Item Currency Fields segment E1BPACCR08

CLEAR g_e1bpaccr08.

CLEAR g_edidd.

g_edidd-segnam = 'E1BPACCR08'.

g_edidd-segnum = 3.

g_e1bpaccr08-itemno_acc = l_itemnr.

g_e1bpaccr08-curr_type = '00'.

g_e1bpaccr08-currency = g_extract-waers.

IF g_extract-shkzg = 'H'.

g_extract-dmbtr = g_extract-dmbtr * -1.

ENDIF.

CALL FUNCTION 'CURRENCY_AMOUNT_IDOC_TO_SAP'

EXPORTING

currency = g_extract-waers

idoc_amount = g_extract-dmbtr

IMPORTING

sap_amount = g_e1bpaccr08-amt_doccur.

MOVE g_e1bpaccr08 TO g_edidd-sdata.

APPEND g_edidd TO gi_edidd.

ENDLOOP.

SORT gi_edidd BY segnum.

LOOP AT gi_edidd INTO g_edidd.

g_edidd-segnum = sy-tabix.

MODIFY gi_edidd FROM g_edidd.

ENDLOOP.

SORT gi_edidd BY segnum.

ENDFORM. " BUILD_IDOC_SEGMENTS

*&----


*

*& Form CREATE_IDOCS

*&----


*

  • Create IDOCS

*----


*

FORM create_idocs.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = g_idoc_control_record

TABLES

communication_idoc_control = gi_communication_idoc_control

master_idoc_data = gi_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 'I' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

  • Remember to commit !

COMMIT WORK.

ENDIF.

ENDFORM. " CREATE_IDOCS

Process outbound IDOCs

Process the outbound IDOCs using program RSEOUT00. The program can be executed from SE38. The IDOC should now have status code 03 Data passed to port OK.

Create inbound IDOCs

The inbound IDOC can be created from the outbound IDOC using transaction WE12 Modification of Outbound file Triggering inbound Procg. The name of the target file is not important, but it must not have the same name as the source file.

Note that the program returns an error, but an inpund IDOC is created.

Source and Sender

The source file must have the same name and path as the outbound file in the partner profile. In this example it is created in the TMP directory which seem to exist in the root directory.

Recipient

Process inbound IDOCs

The inbound IDOC should now have staus code 64. Use program RBDAPP01 to process the inbound IDOC.

Please give me reward points If it is useful.

Thanks

Murali Poli

Former Member
0 Kudos

Hi Ram,

Check the previous post (by Murali Poli) on how to <b>fill</b> an IDOC. Though as u asked - u can't use a report, try output types (search them in IMG). There u can connect a processing block (a form) to be triggered.

To create a new Z--IDOC press WEDI in main menu, then open the Development branch. U have to follow the 1st 4 trans.(we31- create your segments, we30 - create and IDOC containing the segments, we81 - create message type, we82 - connect the message type to the IDOC u created). Then open the outbound processing and use we41 to connect a FM to your new mess.type/IDOC. The FM should contain whatever needs to be processed in the IDOC.

Pls reward if helps.

Igal

Former Member
0 Kudos

Firstly try to seach for a enhancement which you can use to trigger the idoc ..

-creating a zmessage type,idoc,segments..

the post by Igal Anav is quite impressive.. just follow..it..

terms explaination..

<b>segments..</b> it is just like a structure.. which can hold data (generally from 1 table)

<b>Idoc</b>. : Idoc is a bundle of one or more segments.. they can be related child (dependent) or parallel..

<b>Message type</b> : its a combination of various combination along with IDOC.. (most of the communication in ALE use Message type to indicate what kind of data is communicated..)

an message type can contain various records of a single or muntiple idoc..

Former Member
0 Kudos

Hi,

In order to create an outbound IDOC we need to follow the below steps.

WE31 - Create Segment (then release it)

WE30 - Create Idoc (then release it)

WE81 - Create Message class

WE82 - Assign the message type with basic IDOC type

WE21 - Define Ports (If not already defined)

WE20 - Partner Profiles (Assign Message Type in the outbound parameters of receiving partner)

Now the program for sending IDoc.

REPORT zdemo_idoc.

**********************Data Declaration**********************

DATA: i_vbak TYPE TABLE OF [Segment Name]

w_vbak TYPE [Segment Name],

w_edidc TYPE edidc, [Workarea for Control Records]

w_edidd TYPE edidd, [Workarea for Data Records]

i_edidd TYPE TABLE OF edidd, [Internal table for Data Records]

t_idoc_comm_control TYPE edidc OCCURS 0 WITH HEADER LINE.

**********************Select Statements**********************

SELECT vbeln

ernam

kunnr

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE i_vbak

WHERE vbeln = '0000000012'.

**********************Control Records************************

w_edidc-rcvprt = 'LS'. [Partner Type of Receiver]

w_edidc-rcvpor = [Receiver port (SAP System, EDI subsystem)]

w_edidc-rcvprn = [Partner Number of Recipient]

w_edidc-mestyp = [Message Type]

w_edidc-doctyp = [IDoc Type]

***********************Data Records***************************

  • Move data records from internal table to the edidd structure.

LOOP AT i_vbak INTO w_vbak.

w_edidd-segnam = [Segment Name].

w_edidd-segnum = 1.

w_edidd-sdata = w_vbak.

w_edidd-hlevel = 1.

APPEND w_edidd TO i_edidd.

CLEAR w_edidd.

ENDLOOP.

**********************Send the IDOC***************************

  • Function Module to send the IDOC to the receiving port.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = w_edidc

TABLES

communication_idoc_control = t_idoc_comm_control

master_idoc_data = i_edidd

EXCEPTIONS

error_in_idoc_control = 1

error_writing_idoc_status = 2

error_in_idoc_data = 3

sending_logical_system_unknown = 4

OTHERS = 5.

COMMIT WORK. [Important statement for outbound IDOC.]

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

WRITE 😕 'Operation Unsuccessful'.

ELSE.

WRITE 😕 'operation successful'.

ENDIF.

Now about triggering the IDoc from VT02N or VL02N, you need to do the NACE settings which will a output type assigned to your program which will trigger the IDoc when you save it.

And I guess TIBCO is a middle ware to do conversion which will have certain Mapping rules to map the fields from your IDoc with the Endusers fields.

Do ask is any help required as I have worked on TIBCO.

Reward if helpful

Regards,

Arati.