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: 

i want program for idocs....

Former Member
0 Kudos
85

i want program for idocs....

dont give links pls....

pls dont give an routine example........

i want one real time scenario......

pls give one program source code for one real time scenario.....

thanks & regards,

Arjun

3 REPLIES 3

jaideeps
Advisor
Advisor
0 Kudos
48

hi,

chk out all the links...

https://www.sdn.sap.com/irj/sdn/advancedsearch?query=idoc%20example&cat=sdn_all

thanks

jaideep

*reward points if useful..

Former Member
0 Kudos
48

Hi

Here is sample code , understand the code and apply with ur requirement

pls reward is it's worth

First u have to fill the Control structure

SELECT RCVPRN RCVPRT RCVPOR MESTYP IDOCTYP

INTO TABLE IT_EDP13

FROM EDP13.

SORT IT_EDP13 BY MESTYP IDOCTYP.

READ TABLE IT_EDP13 INTO IS_EDP13 WITH KEY MESTYP = C_MESTYP

IDOCTYP = C_IDOCTP BINARY SEARCH.

IF SY-SUBRC EQ 0.

IS_EDIDC-MESTYP = YMM_ST_FBD_101_102. (Message type)

IS_EDIDC-IDOCTP = YMM_ST_FBD. (idoc Name eg :Matmas like)

IS_EDIDC-RCVPOR = IS_EDP13-RCVPOR. (Partner Number of Recipient)

IS_EDIDC-RCVPRN = IS_EDP13-RCVPRN. (Partner Type of receiver)

IS_EDIDC-RCVPRT = IS_EDP13-RCVPRT. (Partner function of recipient)

ENDIF.

Next Fill The data structure

SORT IT_MSEG BY MBLNR ZEILE.

IF NOT IT_MKPF[] IS INITIAL.

LOOP AT IT_MKPF INTO IS_MKPF.

READ TABLE IT_IDOCTRACK INTO IS_IDOCTRACK WITH KEY MBLNR = IS_MKPF-MBLNR.

IF SY-SUBRC NE 0.

IS_YMATDOCHDR-MBLNR = IS_MKPF-MBLNR.

IS_YMATDOCHDR-BUDAT = IS_MKPF-BUDAT.

IS_YMATDOCHDR-XBLNR = IS_MKPF-XBLNR.

IS_EDIDD-SEGNAM = YMATDOCHDR. (Header segmant )

IS_EDIDD-SDATA = IS_YMATDOCHDR.

IS_EDIDD-HLEVEL = '2'.

APPEND IS_EDIDD TO IT_EDIDD.

CLEAR : IS_YMATDOCHDR,IS_EDIDD.

LOOP AT IT_MSEG INTO IS_MSEG WHERE MBLNR = IS_MKPF-MBLNR.

IS_YMATDOCITEM-MBLNR = IS_MSEG-MBLNR.

IS_YMATDOCITEM-ZEILE = IS_MSEG-ZEILE.

IS_YMATDOCITEM-MATNR = IS_MSEG-MATNR.

IS_YMATDOCITEM-WERKS = IS_MSEG-WERKS.

IS_YMATDOCITEM-CHARG = IS_MSEG-CHARG.

IS_YMATDOCITEM-MENGE = IS_MSEG-MENGE.

IS_YMATDOCITEM-SHKZG = IS_MSEG-SHKZG.

IS_EDIDD-SEGNAM = YMATDOCITEM. ( child segmant )

IS_EDIDD-SDATA = IS_YMATDOCITEM.

IS_EDIDD-HLEVEL = '3'.

APPEND IS_EDIDD TO IT_EDIDD.

CLEAR : IS_YMATDOCHDR,IS_EDIDD.

ENDLOOP.

ENDIF .

ENDLOOP.

ENDIF.

Next Create IDOC with FM

REFRESH IT_EDIDC.

IF NOT IT_EDIDD[] IS INITIAL.

  • Creation of communication idoc

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

MASTER_IDOC_CONTROL = IS_EDIDC

TABLES

COMMUNICATION_IDOC_CONTROL = IT_EDIDC

MASTER_IDOC_DATA = IT_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 NE 0.

W_SUBRC = SY-SUBRC.

LEAVE LIST-PROCESSING.

ELSE.

COMMIT WORK.

endif .

Former Member
0 Kudos
48

Hi,

&----


*& Report ZZ_Program_To_Create_Idoc

&----


report zz_program_to_create_idoc .

tables: ekko,ekpo.

selection-screen skip 3.

selection-screen begin of block b1 with frame title titl.

selection-screen skip.

select-options s_ebeln for ekko-ebeln.

selection-screen skip.

selection-screen end of block b1.

data: header_segment_name like edidd-segnam value 'Z1EKKO',

item_segment_name like edidd-segnam value 'Z1EKPO',

idoc_name like edidc-idoctp value 'Z19838IDOC1'.

data: header_segment_data like z1ekko,

item_segment_data like z1ekpo.

data: control_record like edidc.

data: messagetyp like edmsg-msgtyp value 'ZZ9838MESG1'.

data: i_communication like edidc occurs 0 with header line,

i_data like edidd occurs 0 with header line.

data: begin of i_ekko occurs 0,

ebeln like ekko-ebeln,

aedat like ekko-aedat,

bukrs like ekko-bukrs,

bsart like ekko-bsart,

lifnr like ekko-lifnr,

end of i_ekko.

data: begin of i_ekpo occurs 0,

ebelp like ekpo-ebelp,

matnr like ekpo-matnr,

menge like ekpo-menge,

meins like ekpo-meins,

netpr like ekpo-netpr,

end of i_ekpo.

start-of-selection.

select ebeln aedat bukrs bsart lifnr from ekko

into table i_ekko where ebeln in s_ebeln.

select ebelp

matnr

menge

meins

netpr

from ekpo

into table i_ekpo

where ebeln in s_ebeln.

control_record-mestyp = messagetyp.

control_record-rcvprt = 'LS'.

control_record-idoctp = idoc_name.

control_record-rcvprn = '0MART800'.

loop at i_ekko.

header_segment_data-ebeln = i_ekko-ebeln.

header_segment_data-aedat = i_ekko-aedat.

header_segment_data-bukrs = i_ekko-bukrs.

header_segment_data-bsart = i_ekko-bsart.

header_segment_data-lifnr = i_ekko-lifnr.

i_data-segnam = header_segment_name.

i_data-sdata = header_segment_data.

append i_data.

select ebelp

matnr

menge

meins

netpr

from ekpo

into table i_ekpo

where ebeln = i_ekko-ebeln.

loop at i_ekpo.

item_segment_data-ebelp = i_ekpo-ebelp.

item_segment_data-matnr = i_ekpo-matnr.

item_segment_data-menge = i_ekpo-menge.

item_segment_data-meins = i_ekpo-meins.

item_segment_data-netpr = i_ekpo-netpr.

i_data-segnam = item_segment_name.

i_data-sdata = item_segment_data.

append i_data.

endloop.

clear i_ekpo.

refresh i_ekpo.

endloop.

call function 'MASTER_IDOC_DISTRIBUTE'

exporting

master_idoc_control = control_record

  • OBJ_TYPE = ''

  • CHNUM = ''

tables

communication_idoc_control = i_communication

master_idoc_data = i_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.

else.

loop at i_communication.

write: 'IDOC GENERATED', i_communication-docnum.

endloop.

commit work.

endif.

initialization.

titl = 'ENTER THE PURCHASE ORDER NUMBER'.

Regards,

Bhaskar