Google Search - Blog...........

ABAP - Report Program To Display Contents Of IDOC Using Function Module IDOC_READ_COMPLETELY.

*----------------------------------------------------------------------*

* reprot name : ZDISPLAY *

* reprot date : 22/10/2008 *

* description : here is an example program for dislaying the contents *

* of given idoc in a report . if you check the check box *

* in the selection screen then it will download the data *

* into a spread sheet *

*----------------------------------------------------------------------*

REPORT zdisplay LINE-SIZE 275.





TYPE-POOLS : ledid.



DATA: struct_type TYPE ledid_struct_type ,

idoc_struct TYPE ledid_t_idoc_struct,

segments TYPE ledid_t_segment,

segment_struct TYPE ledid_t_segment_struct,

idoc_control LIKE edidc,

number_of_data_records LIKE sy-dbcnt,

number_of_status_records LIKE sy-dbcnt,



int_edids LIKE edids OCCURS 0 WITH HEADER LINE,

int_edidd LIKE edidd OCCURS 0 WITH HEADER LINE,

excel_tab(2000) OCCURS 0 WITH HEADER LINE.





PARAMETER: docnum LIKE edidc-docnum OBLIGATORY, ""Idoc Number

sap_rel LIKE sy-saprl DEFAULT sy-saprl OBLIGATORY,

pi_ver LIKE edi_verrec-version DEFAULT '3'

OBLIGATORY,

d_excel AS CHECKBOX DEFAULT 'X'. ""Download ?



START-OF-SELECTION.



PERFORM read_idoc.



PERFORM process_idoc.



IF d_excel = 'X'.

PERFORM download_to_excel.

ENDIF.



END-OF-SELECTION.



*&---------------------------------------------------------------------*

*& Form read_idoc

*----------------------------------------------------------------------*

FORM read_idoc.



CALL FUNCTION 'IDOC_READ_COMPLETELY'

EXPORTING

document_number = docnum

IMPORTING

idoc_control = idoc_control

number_of_data_records = number_of_data_records

number_of_status_records = number_of_status_records

TABLES

int_edids = int_edids

int_edidd = int_edidd

EXCEPTIONS

document_not_exist = 1

document_number_invalid = 2

OTHERS = 3.

IF sy-subrc <> 0.

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

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

ENDIF.



ENDFORM. "" read_idoc



*&---------------------------------------------------------------------*

*& Form process_idoc

*----------------------------------------------------------------------*

FORM process_idoc.



PERFORM read_idoc_structure.



PERFORM display_data_records.



ENDFORM. "" process_idoc



*&---------------------------------------------------------------------*

*& Form display_data_records

*----------------------------------------------------------------------*

FORM display_data_records.



DATA: pe_seg_header LIKE edi_sapi01,

segname LIKE edi_iapi12-segmenttyp,

prev_segname LIKE edi_iapi12-segmenttyp VALUE ' ',

pt_fields2 LIKE edi_iapi12 OCCURS 0 WITH HEADER LINE,

pt_fvalues2 LIKE edi_iapi14 OCCURS 0 WITH HEADER LINE,

byte_first TYPE i,

byte_last TYPE i,

field_val type char50,

tmp_str type char15,

tmp_str3 type char15,

seg_repeats TYPE i VALUE 0,

tmp_str2 type char15,

tab_cr(1) TYPE x VALUE '09',

tot_ctr TYPE i VALUE 0,

ctr TYPE i VALUE 0,

msg(40) TYPE c.



DATA: idoc_struct_wa TYPE ledid_idoc_struct.



SORT int_edidd BY segnum.



DESCRIBE TABLE int_edidd LINES tot_ctr.



LOOP AT int_edidd.



MOVE int_edidd-segnam TO segname.



CLEAR msg.



CONCATENATE 'Reading segment ' segname

INTO msg SEPARATED BY space.



IF tot_ctr <> 0.

ctr = ( 100 * sy-tabix ) / tot_ctr.

ENDIF.



CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

percentage = ctr

text = msg.

ADD 1 TO seg_repeats.

CLEAR tmp_str2.

IF int_edidd-segnam <> prev_segname.

seg_repeats = 1.

CLEAR: pe_seg_header,

pt_fields2,

pt_fvalues2.



REFRESH: pt_fields2,

pt_fvalues2.



CALL FUNCTION 'SEGMENT_READ_COMPLETE'

EXPORTING

pi_segtyp = segname

pi_release = sap_rel

pi_version = pi_ver

IMPORTING

pe_header = pe_seg_header

TABLES

pt_fields = pt_fields2

pt_fvalues = pt_fvalues2

EXCEPTIONS

segment_unknown = 1

segment_structure_unknown = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

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

ENDIF.



prev_segname = int_edidd-segnam.



ENDIF.



READ TABLE idoc_struct INTO idoc_struct_wa WITH KEY

segment_type = int_edidd-segnam.



IF sy-subrc = 0.

IF idoc_struct_wa-syntax_attrib-mustfl = 'X'.

tmp_str = 'Mandatory'. ""Mandatory

ELSE.

tmp_str = 'Optional'. ""Optional

ENDIF.



IF idoc_struct_wa-segment_type_attrib-qualifier = 'X'.

tmp_str3 = 'Qualified'.

ELSE.

tmp_str3 = 'Non-Qualified'.

ENDIF.



SHIFT idoc_struct_wa-syntax_attrib-occmax

LEFT DELETING LEADING '0'.

MOVE seg_repeats TO tmp_str2.



CONDENSE: idoc_struct_wa-syntax_attrib-occmax, tmp_str2.



CONCATENATE tmp_str2 'of' idoc_struct_wa-syntax_attrib-occmax

INTO tmp_str2 SEPARATED BY space.



WRITE :/ idoc_struct_wa-segment_type,

tmp_str,

tmp_str3,

tmp_str2,

idoc_struct_wa-syntax_attrib-hlevel,

idoc_struct_wa-segment_type_attrib-plast,

idoc_struct_wa-segment_type_attrib-descrp.



IF d_excel = 'X'.

CONCATENATE 'Segment Name' tab_cr

'Mand / Opt ' tab_cr

'Qual / non-Qual' tab_cr

'Seq of Max' tab_cr

'Level' tab_cr

'Owner' tab_cr

'Description'

INTO excel_tab.

APPEND excel_tab.

CONCATENATE idoc_struct_wa-segment_type tab_cr

tmp_str tab_cr

tmp_str3 tab_cr

tmp_str2 tab_cr

idoc_struct_wa-syntax_attrib-hlevel tab_cr

idoc_struct_wa-segment_type_attrib-plast tab_cr

idoc_struct_wa-segment_type_attrib-descrp

INTO excel_tab.

APPEND excel_tab.

CONCATENATE tab_cr

'Field Nma' tab_cr

'Type' tab_cr

'Length' tab_cr

'Byte From' tab_cr

'Byte To' tab_cr

'Description' tab_cr

'Value' tab_cr

'Qualifier Meaning'

INTO excel_tab.

APPEND excel_tab.

ENDIF.

ENDIF.



SORT pt_fields2 BY field_pos.



byte_first = 0.



LOOP AT pt_fields2.

CLEAR: field_val.

byte_last = pt_fields2-extlen.

WRITE int_edidd-sdata+byte_first(byte_last) TO

field_val LEFT-JUSTIFIED.

SHIFT pt_fields2-extlen LEFT DELETING LEADING '0'.

SHIFT pt_fields2-byte_first LEFT DELETING LEADING '0'.

SHIFT pt_fields2-byte_last LEFT DELETING LEADING '0'.

WRITE:/ ' ', pt_fields2-fieldname,

pt_fields2-datatype,

pt_fields2-extlen,

pt_fields2-byte_first ,

pt_fields2-byte_last,

pt_fields2-descrp,

field_val.

READ TABLE pt_fvalues2 WITH KEY fieldname = pt_fields2-fieldname

fldvalue_l = field_val.

ADD byte_last TO byte_first.

IF sy-subrc = 0.

WRITE : pt_fvalues2-descrp.

ELSE.

CLEAR pt_fvalues2-descrp.

ENDIF.

IF d_excel = 'X'.

CONCATENATE tab_cr pt_fields2-fieldname tab_cr

pt_fields2-datatype tab_cr

pt_fields2-extlen tab_cr

pt_fields2-byte_first tab_cr

pt_fields2-byte_last tab_cr

pt_fields2-descrp tab_cr

field_val tab_cr

pt_fvalues2-descrp

INTO excel_tab.

APPEND excel_tab.

ENDIF.

ENDLOOP.

ENDLOOP.

ENDFORM. "" display_data_records



*&---------------------------------------------------------------------*

*& Form read_idoc_structure

*----------------------------------------------------------------------*

FORM read_idoc_structure.

DATA: idoctype TYPE ledid_idoctype.



IF NOT idoc_control-cimtyp IS INITIAL.

struct_type = 'E'. ""Extended

idoctype = idoc_control-cimtyp.

ELSE.

struct_type = 'B'. ""Basic

idoctype = idoc_control-idoctp.

ENDIF.



CALL FUNCTION 'IDOC_TYPE_COMPLETE_READ'

EXPORTING

release = sap_rel

struct_type = struct_type

idoctype = idoctype

version = pi_ver

TABLES

idoc_struct = idoc_struct

segments = segments

segment_struct = segment_struct

EXCEPTIONS

idoctype_unknown = 1

idocstruct_unknown = 2

segment_data_missing = 3

illegal_struct_type = 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.



ENDFORM. "" read_idoc_structure



*&---------------------------------------------------------------------*

*& Form download_to_excel

*----------------------------------------------------------------------*

FORM download_to_excel.

DATA: name LIKE rlgrap-filename.



SHIFT docnum LEFT DELETING LEADING '0'.

CONCATENATE docnum '-' idoc_control-idoctp '.xls'

INTO name.



CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'

EXPORTING

data_name = name

data_type = 'ASC'

wait = ' '

TABLES

data_tab = excel_tab

EXCEPTIONS

no_batch = 1

excel_not_installed = 2

wrong_version = 3

internal_error = 4

invalid_type = 5

cancelled = 6

download_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

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

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

ENDIF.



ENDFORM. "" download_to_excel

2 comments:

  1. Thanks for sharing your thoughts about build muscle.
    Regards

    Here is my web site; No2 maximus review

    ReplyDelete
  2. Please let me know if you're looking for a article writer for your weblog. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I'd really like to write some
    content for your blog in exchange for a link back to mine.

    Please send me an e-mail if interested. Regards!

    Here is my web site :: Lipo Slim Reviews *http://liposlimblog.net/*

    ReplyDelete