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: 

How to read datas from IDOC

Former Member
0 Kudos

Hi experts,

I am new to IDOC.I want to retrive data from IDOC and display it in list. How to read data from an IDOC? I have the IDOC number and also the header and item segments.

Help me to read an IDOC and display values...

Thanks&Regards,

Karthik.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

If you know the Idoc no you can use the following function module to read the Idoc data.

Data:p_docnum LIKE EDIDC-DOCNUM,

s_edidc LIKE EDIDC,

itab_edidd type table of EDIDD with header line.

CALL FUNCTION 'IDOC_READ_COMPLETELY'

EXPORTING

document_number = p_docnum

IMPORTING

idoc_control = s_edidc

TABLES

int_edidd = itab_edidd

EXCEPTIONS

document_not_exist = 1

document_number_invalid = 2

OTHERS = 3.

Regards,

Savitha

6 REPLIES 6

GauthamV
Active Contributor
0 Kudos

hi,

use these tables.

EDIDD

EDIDS

EDIDC.

also you can get idoc details from we02,we05 transactions.

Former Member
0 Kudos

hi gautham,

Thanks for ur immediate reply.You have mentioned three tables in this from which table I can receive the actual data.

Thanks&Regards,

karthik.

GauthamV
Active Contributor
0 Kudos

hi,

3 tables has there own functionalities.

one displays data records,other status records and other control records.

use them accordingly depending on your requirement.

Former Member
0 Kudos

Hi,

Thanks for ur frequent reply...Can you please list out the INVOIC idoc structures & fields?

Thanks

Former Member
0 Kudos

Hi,

check this sample program which takes idocnumber as input and downloads the idoc details as text file..

&----


*& Report ZCAMES_IDOC_DISPLAY *

*& *

&----


*& *

*& *

&----


REPORT ZCAMES_IDOC_DISPLAY .

************************************************************************

*eject

************************************************************************

  • Includes

************************************************************************

************************************************************************

  • tables

************************************************************************

*Tables : edidc.

************************************************************************

  • Parameters and Selection Options

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP 1.

PARAMETERS: p_idoc TYPE edidc-docnum OBLIGATORY," idoc number

p_crec AS CHECKBOX DEFAULT 'X'." checkbox for control record

SELECTION-SCREEN SKIP 1.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN END OF BLOCK b1.

***********************************************************************

  • Types

***********************************************************************

types : begin of t_sdata_itab,

sdata type edi_dd-sdata,

end of t_sdata_itab.

**********************************************************************

*Internal Table and Work Area Declaration

***********************************************************************

data : i_sdata_itab type standard table of t_sdata_itab,

i_sdata_itab_line like line of i_sdata_itab,

i_tcode type tstc-tcode.

DATA: i_idoc_control TYPE standard TABLE OF edidc,

i_idoc_control_line LIKE LINE OF i_idoc_control,

i_idoc_data TYPE standard TABLE OF edidd.

**********************************************************************

  • Initialization Event

***********************************************************************

INITIALIZATION.

***********************************************************************

  • At Selection-Screen Event

***********************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'FILENAME'

IMPORTING

file_name = p_file.

AT SELECTION-SCREEN ON p_idoc.

i_idoc_control_line-docnum = p_idoc.

APPEND i_idoc_control_line TO i_idoc_control.

SELECT * FROM edidc

UP TO 1 ROWS

INTO TABLE i_idoc_control

WHERE docnum EQ p_idoc.

IF sy-subrc NE 0.

MESSAGE e208(00) WITH 'Idoc is either Invalid or is Empty'(002).

ENDIF.

***********************************************************************

  • Start Of Selection Event

***********************************************************************

START-OF-SELECTION.

  • Make sure that app is only executed in online mode.

CHECK sy-batch NE 'X'.

PERFORM grab_idoc_data.

PERFORM download_idoc_to_pc.

*&----


*

*& Form grab_idoc_data

*&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM grab_idoc_data.

DATA: i_control_40 TYPE edi_dc40,

i_conv_edidd40 TYPE standard TABLE OF edi_dd40,

i_conv_edidd40_line LIKE LINE OF i_conv_edidd40.

CALL FUNCTION 'ALE_FTCH_DATA_SEGMENTS_OF_IDOC'

TABLES

t_idoc_control = i_idoc_control

t_idoc_data = i_idoc_data.

IF p_crec EQ 'X'.

READ TABLE i_idoc_control INTO i_idoc_control_line INDEX 1.

CALL FUNCTION 'IDOC_CONTROL_OUTBOUND_CONVERT'

EXPORTING

control_record = i_idoc_control_line

port_version = '3'

IMPORTING

control_40 = i_control_40

EXCEPTIONS

conversion_error = 1

OTHERS = 2.

IF sy-subrc EQ 0.

MOVE i_control_40 TO i_sdata_itab_line.

APPEND i_sdata_itab_line TO i_sdata_itab.

ENDIF.

ENDIF.

CALL FUNCTION 'IDOC_DATA_OUTBOUND_CONVERT'

EXPORTING

docnum = p_idoc

segrelease = space

refresh_table = 'Y'

TABLES

i_edidd = i_idoc_data

conv_edidd40 = i_conv_edidd40

EXCEPTIONS

conversion_error = 1

OTHERS = 2.

IF sy-subrc EQ 0.

LOOP AT i_conv_edidd40 INTO i_conv_edidd40_line.

MOVE i_conv_edidd40_line TO i_sdata_itab_line.

APPEND i_sdata_itab_line TO i_sdata_itab.

ENDLOOP.

ENDIF.

ENDFORM. " grab_idoc_data

*&----


*

*& Form download_idoc_to_pc

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM download_idoc_to_pc.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = p_file

filetype = 'ASC'

TABLES

data_tab = i_sdata_itab.

ENDFORM. " download_idoc_to_p

Former Member
0 Kudos

Hi,

If you know the Idoc no you can use the following function module to read the Idoc data.

Data:p_docnum LIKE EDIDC-DOCNUM,

s_edidc LIKE EDIDC,

itab_edidd type table of EDIDD with header line.

CALL FUNCTION 'IDOC_READ_COMPLETELY'

EXPORTING

document_number = p_docnum

IMPORTING

idoc_control = s_edidc

TABLES

int_edidd = itab_edidd

EXCEPTIONS

document_not_exist = 1

document_number_invalid = 2

OTHERS = 3.

Regards,

Savitha