2006 Apr 24 10:36 AM
Hi All,
Im currently using the fm MASTER_IDOC_DISTRIBUTE, is there anyone here with the code on how and what needs to be populated in its parameters?
Thanks,
Kenny
2006 Apr 24 10:46 AM
the pupose of the fn module is to generate Communication idocs from master idocs.
communication idocs: means if there is one sender and 2 receivers, then 1 master idoc and 2 communication idocs will be generated.
so, the parameters to be passed are
1. master idoc control records(declare a structure of type EDIDC and fill control records)
2. master idoc data records(dclare an internal table of type EDIDD and fill data records)
it exports
communication idoc control records(declare an internal table of type EDIDC and pass, the fn module will return values to the table)
example:
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = P_EDI_HEAD
TABLES
COMMUNICATION_IDOC_CONTROL = P_T_DOCNUM
MASTER_IDOC_DATA = P_PXT_IDOC_DATA
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 01
ERROR_WRITING_IDOC_STATUS = 02
ERROR_IN_IDOC_DATA = 03
SENDING_LOGICAL_SYSTEM_UNKNOWN = 04
OTHERS = 05.
IF SY-SUBRC = 0.
IF PI_PROTOCOLL = YES.
Erzeugung erfolgreich: --> t_docnum gefüllt
Erzeugung nicht ok : --> t_docnum nur Kopfzeile da
LOOP AT P_T_DOCNUM.
ADD 1 TO H_ZAEHLER.
ADD 1 TO P_KOMMUN_COUNT.
ADD 1 TO P_KOMMUN_COUNT_SNG. "40C
WRITE: /6 P_T_DOCNUM-DOCNUM COLOR COL_NORMAL,
25 'Segmentanzahl'(004),
P_PX_SEGMENT_COUNTER COLOR COL_NORMAL,
50 'für Zielsystem'(003),
P_T_DOCNUM-RCVPRN COLOR COL_NORMAL,
75 'for idoc ZCOND_A'.
ENDLOOP.
Message was edited by: Hymavathi Oruganti
2006 Apr 24 10:44 AM
Here is the code and the required parameters to pass
DATA: Begin of imara occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
mbrsh like mara-mbrsh,
meins(3) type c,
end of imara.
data: begin of imakt occurs 0,
maktx like makt-maktx,
end of imakt.
DATA: wamas_con LIKE edidc,
imas_data LIKE edidd OCCURS 0 WITH HEADER LINE,
icom_con LIKE edidc OCCURS 0 WITH HEADER LINE.
PARAMETERS: e_matnr LIKE mara-matnr,
e_msgtyp LIKE edidc-mestyp,
e_rcvprn LIKE edidc-rcvprn.
retrive app. data from DB
SELECT matnr mtart mbrsh meins FROM mara INTO TABLE imara WHERE
matnr = e_matnr.
SELECT maktx FROM makt INTO TABLE imakt WHERE
matnr = e_matnr.
*Master idoc control record
wamas_con-rcvprt = 'LS'.
wamas_con-rcvprn = e_rcvprn.
wamas_con-idoctp = 'YMATMAS1'.
wamas_con-mestyp = e_msgtyp.
master idoc data records
LOOP AT imara.
imas_data-segnam = 'Y1MARA'.
move imara to imas_data-sdata .
APPEND imas_data.
ENDLOOP.
LOOP AT imakt.
imas_data-segnam = 'Y1MAKT'.
imas_data-sdata = imakt.
APPEND imas_data.
ENDLOOP.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = wamas_con
OBJ_TYPE = ''
CHNUM = ''
TABLES
communication_idoc_control = icom_con
master_idoc_data = imas_data
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.
ENDIF.
COMMIT WORK.
Pls.assign the points if u satisfy with the answer
Regards
Eswar
2006 Apr 24 10:46 AM
the pupose of the fn module is to generate Communication idocs from master idocs.
communication idocs: means if there is one sender and 2 receivers, then 1 master idoc and 2 communication idocs will be generated.
so, the parameters to be passed are
1. master idoc control records(declare a structure of type EDIDC and fill control records)
2. master idoc data records(dclare an internal table of type EDIDD and fill data records)
it exports
communication idoc control records(declare an internal table of type EDIDC and pass, the fn module will return values to the table)
example:
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = P_EDI_HEAD
TABLES
COMMUNICATION_IDOC_CONTROL = P_T_DOCNUM
MASTER_IDOC_DATA = P_PXT_IDOC_DATA
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 01
ERROR_WRITING_IDOC_STATUS = 02
ERROR_IN_IDOC_DATA = 03
SENDING_LOGICAL_SYSTEM_UNKNOWN = 04
OTHERS = 05.
IF SY-SUBRC = 0.
IF PI_PROTOCOLL = YES.
Erzeugung erfolgreich: --> t_docnum gefüllt
Erzeugung nicht ok : --> t_docnum nur Kopfzeile da
LOOP AT P_T_DOCNUM.
ADD 1 TO H_ZAEHLER.
ADD 1 TO P_KOMMUN_COUNT.
ADD 1 TO P_KOMMUN_COUNT_SNG. "40C
WRITE: /6 P_T_DOCNUM-DOCNUM COLOR COL_NORMAL,
25 'Segmentanzahl'(004),
P_PX_SEGMENT_COUNTER COLOR COL_NORMAL,
50 'für Zielsystem'(003),
P_T_DOCNUM-RCVPRN COLOR COL_NORMAL,
75 'for idoc ZCOND_A'.
ENDLOOP.
Message was edited by: Hymavathi Oruganti
2006 Apr 24 10:53 AM
Hi Kenny,
The said function module is used to generate Outbound Idocs.
For the same, we need to call the function module in the manner shown below ::
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = ls_idoc_cntrl
OBJ_TYPE = ''
CHNUM = ''
TABLES
communication_idoc_control = lit_comm_idoc_cntrl
master_idoc_data = xt_idoc_data
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5
.
Here, the first exporting parameter is the control record.
You need to give the Sender port, the receiver port, the idoc type, part no of recipient, partner no of sender and logical system.
In the data record, you pass the idoc data which is populated in a structure of the same type as the idoc.
Do let me know in case you have any further doubts. Let me know if any further clarification is needed.
Regards,
Ameya
2006 Apr 24 11:27 AM
Hi,
Refer this code:
[code----
REPORT ZPSR0001 MESSAGE-ID ZPS01.
*****************************************************************
Table Declarations *
*****************************************************************
TABLES: ZPS001.
*****************************************************************
Internal Table Declarations *
*****************************************************************
DATA: BEGIN OF GT_ZPS001 OCCURS 0.
INCLUDE STRUCTURE ZPS001.
DATA :END OF GT_ZPS001.
DATA: BEGIN OF GT_ZCO001 OCCURS 0.
INCLUDE STRUCTURE ZCO001.
DATA :END OF GT_ZCO001.
DATA: BEGIN OF GT_EDIDC OCCURS 0.
INCLUDE STRUCTURE EDIDC.
DATA :END OF GT_EDIDC.
DATA: BEGIN OF GT_EDIDC1 OCCURS 0.
INCLUDE STRUCTURE EDIDC.
DATA :END OF GT_EDIDC1.
DATA: BEGIN OF GT_EDIDD OCCURS 0.
INCLUDE STRUCTURE EDIDD.
DATA :END OF GT_EDIDD.
DATA : BEGIN OF GT_Z1ZPSOBJLOC OCCURS 0.
INCLUDE STRUCTURE Z1ZPSOBJLOC.
DATA : END OF GT_Z1ZPSOBJLOC.
*****************************************************************
Work area Declarations *
*****************************************************************
DATA : WA_ZPS001 LIKE ZPS001,
WA_Z1ZPSOBJLOC LIKE Z1ZPSOBJLOC,
WA_EDIDD LIKE GT_EDIDD OCCURS 0 WITH HEADER LINE.
*****************************************************************
Constants Declarations *
*****************************************************************
CONSTANTS: C_N TYPE C VALUE 'N',
C_L TYPE C VALUE 'L',
C_M TYPE C VALUE 'M',
C_1 TYPE C VALUE '1',
C_SEG(12) TYPE C VALUE 'Z1ZPSOBJLOC',
C_MESTYP(11) TYPE C VALUE 'ZPSOBJLOC',
C_IDOCTP(19) TYPE C VALUE 'Z_PSIDOC_IOBJLOC01'.
*****************************************************************
SELECTION SCREEN *
*****************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_ZRUNDT FOR ZPS001-ZRUNDT.
SELECTION-SCREEN END OF BLOCK B1.
*****************************************************************
START OF SELECTION *
*****************************************************************
START-OF-SELECTION.
CHECK FOR RUNNING DATE VALUE
IF S_ZRUNDT[] IS INITIAL.
SELECT SINGLE * FROM ZPS001
INTO WA_ZPS001.
IF SY-SUBRC = 0.
SELECT * FROM ZCO001
INTO TABLE GT_ZCO001
WHERE ZCREATEDATE GE WA_ZPS001-ZRUNDT
AND ZCREATETIME > WA_ZPS001-ZRUNTIME.
ELSE.
SELECT * FROM ZCO001
INTO TABLE GT_ZCO001.
ENDIF.
ELSE.
SELECT * FROM ZCO001
INTO TABLE GT_ZCO001
WHERE ZCREATEDATE IN S_ZRUNDT.
ENDIF.
Populate fields in IDOC
IF GT_ZCO001[] IS NOT INITIAL.
PERFORM POP_FIELDS.
ELSE.
ZPS001-ZPROGNAME = SY-REPID.
ZPS001-ZRUNDT = SY-DATUM.
ZPS001-ZRUNTIME = SY-UZEIT.
ZPS001-ZUSER = SY-UNAME.
MODIFY ZPS001.
EXIT.
ENDIF.
END-OF-SELECTION.
PERFORM BUILD_CONTROL_RECORD.
PERFORM BUILD_DATA_RECORD.
Modify Run History Table.
ZPS001-ZPROGNAME = SY-REPID.
ZPS001-ZRUNDT = SY-DATUM.
ZPS001-ZRUNTIME = SY-UZEIT.
ZPS001-ZUSER = SY-UNAME.
MODIFY ZPS001.
&----
*& Form built_control_record
&----
Control Record
FORM BUILD_CONTROL_RECORD .
GT_EDIDC-MESTYP = C_MESTYP.
GT_EDIDC-IDOCTP = C_IDOCTP.
GT_EDIDC-DIRECT = C_1.
APPEND GT_EDIDC.
ENDFORM. " built_control_record
&----
*& Form built_data_record
&----
Data record
FORM BUILD_DATA_RECORD .
LOOP AT GT_Z1ZPSOBJLOC INTO WA_Z1ZPSOBJLOC.
GT_EDIDD-MANDT = SY-MANDT.
GT_EDIDD-SEGNAM = C_SEG.
GT_EDIDD-SDATA = WA_Z1ZPSOBJLOC.
APPEND GT_EDIDD .
PERFORM DISTRIBUTE_DATA.
ENDLOOP.
ENDFORM. " built_data_record
&----
*& Form distribute_data
&----
Distribute Data
FORM DISTRIBUTE_DATA .
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = GT_EDIDC
TABLES
COMMUNICATION_IDOC_CONTROL = GT_EDIDC1
MASTER_IDOC_DATA = GT_EDIDD
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 1
ERROR_WRITING_IDOC_STATUS = 2
ERROR_IN_IDOC_DATA = 3
SENDING_LOGICAL_SYSTEM_UNKNOWN = 4
OTHERS = 5.
CASE SY-SUBRC.
WHEN 1.
MESSAGE E004.
WHEN 2.
MESSAGE E005.
WHEN 3.
MESSAGE E006.
WHEN 4.
MESSAGE E007.
WHEN 5.
MESSAGE E008.
WHEN OTHERS.
Do Nothing
ENDCASE.
COMMIT WORK.
Clear IDOC data internal table after use
CLEAR GT_EDIDD.
REFRESH GT_EDIDD.
ENDFORM. " distribute_data
&----
*& Form pop_fields_IDOC_N
&----
FORM POP_FIELDS_IDOC_N .
MOVE GT_ZCO001-MANDT TO GT_Z1ZPSOBJLOC-MANDT.
MOVE GT_ZCO001-ZCNTRY TO GT_Z1ZPSOBJLOC-ZCNTRY.
MOVE GT_ZCO001-ZOLOC TO GT_Z1ZPSOBJLOC-ZOLOC.
MOVE GT_ZCO001-ZOLOC20 TO GT_Z1ZPSOBJLOC-ZOLOC20.
MOVE GT_ZCO001-ZOLOC40 TO GT_Z1ZPSOBJLOC-ZOLOC40.
MOVE GT_ZCO001-ZAWSYS TO GT_Z1ZPSOBJLOC-ZAWSYS.
MOVE GT_ZCO001-ZSTREET TO GT_Z1ZPSOBJLOC-ZSTREET.
MOVE GT_ZCO001-ZPOSTAL_CODE TO GT_Z1ZPSOBJLOC-ZPOSTAL_CODE.
MOVE GT_ZCO001-ZCITY TO GT_Z1ZPSOBJLOC-ZCITY.
MOVE GT_ZCO001-ZREF2 TO GT_Z1ZPSOBJLOC-ZREF2.
MOVE GT_ZCO001-ZREF3 TO GT_Z1ZPSOBJLOC-ZREF3.
MOVE GT_ZCO001-ZREF4 TO GT_Z1ZPSOBJLOC-ZREF4.
APPEND GT_Z1ZPSOBJLOC.
ENDFORM. " pop_fields_IDOC_N
&----
*& Form pop_fields_idoc_L
&----
FORM POP_FIELDS_IDOC_L .
MOVE GT_ZCO001-MANDT TO GT_Z1ZPSOBJLOC-MANDT.
MOVE GT_ZCO001-ZCNTRY TO GT_Z1ZPSOBJLOC-ZCNTRY.
MOVE GT_ZCO001-ZOLOC TO GT_Z1ZPSOBJLOC-ZOLOC.
MOVE GT_ZCO001-ZOLOC20 TO GT_Z1ZPSOBJLOC-ZOLOC20.
MOVE GT_ZCO001-ZOLOC40 TO GT_Z1ZPSOBJLOC-ZOLOC40.
MOVE GT_ZCO001-ZAWSYS TO GT_Z1ZPSOBJLOC-ZAWSYS.
MOVE GT_ZCO001-ZSTREET TO GT_Z1ZPSOBJLOC-ZSTREET.
MOVE GT_ZCO001-ZOBJ_SIGN TO GT_Z1ZPSOBJLOC-ZOBJ_SIGN.
MOVE GT_ZCO001-ZREF1 TO GT_Z1ZPSOBJLOC-ZREF1.
MOVE GT_ZCO001-ZREF4 TO GT_Z1ZPSOBJLOC-ZREF4.
MOVE GT_ZCO001-ZNOTE1 TO GT_Z1ZPSOBJLOC-ZNOTE1.
MOVE GT_ZCO001-ZNOTE2 TO GT_Z1ZPSOBJLOC-ZNOTE2.
APPEND GT_Z1ZPSOBJLOC.
ENDFORM. " pop_fields_idoc_L
&----
*& Form pop_fields_idoc_M
&----
FORM POP_FIELDS_IDOC_M .
MOVE-CORRESPONDING GT_ZCO001 TO GT_Z1ZPSOBJLOC.
APPEND GT_Z1ZPSOBJLOC.
ENDFORM. " pop_fields_idoc_M
&----
*& Form pop_fields
&----
FORM POP_FIELDS .
LOOP AT GT_ZCO001.
Node number starting with 'N'
CASE GT_ZCO001-ZOLOC+0(1).
WHEN C_N.
PERFORM POP_FIELDS_IDOC_N.
Node number starting with 'L'
WHEN C_L.
PERFORM POP_FIELDS_IDOC_L.
Node number starting with 'M'
WHEN C_M.
PERFORM POP_FIELDS_IDOC_M.
WHEN OTHERS.
Do Nothing
ENDCASE.
ENDLOOP.
ENDFORM. " pop_fields
Regards,
Gayathri
2006 May 03 8:43 AM
Hi All,
If I want to generate an inbound IDOC from a text file, how do i go about this? I can't use master_idoc_distribute since its for outbound idocs. What other function module can i use to generate inbound idocs? Please provide codes if you have.
thanks,
kenny
2006 May 04 9:57 PM
Hi Kenny,
You can use Program RSEINB00 to process a file into inbound IDOC. The file needs to be on your application server.
Alternatively, FM IDOC_INBOUND_FROM_FILE can be used for the same.
I would suggest using the program to process the IDOC.
Plz reward in case you find solution helpful.
Cheers,
Vikram