SAP R/3 ABAP
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Program to list the contents of an IDOC



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces |
View previous topic :: View next topic  
Author Message
vga




Age: 49
Joined: 04 Oct 2007
Posts: 1218
Location:

PostPosted: Sat Nov 29, 2008 4:59 pm    Post subject: Program to list the contents of an IDOC Reply with quote

With the next report we will be able to display the contents of an IDOC and then save it to file.
Just run the program with the number of IDOC and then it is listed the contents, we can save a file from the menu list -> Record / Send -> File ...

Code:

REPORT Z_DISPLAY_IDOC LINE-SIZE 275.

DATA: 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.

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,
      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.

START-OF-SELECTION.
  PERFORM READ_IDOC.
  PERFORM PROCESS_IDOC.

END-OF-SELECTION.

*&*
*&      Form  read_idoc
*&*
*       text
*-*
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
*&*
*       text
*-*
FORM PROCESS_IDOC.
  PERFORM READ_IDOC_STRUCTURE.
  PERFORM DISPLAY_DATA_RECORDS.
ENDFORM.                    process_idoc

*&*
*&      Form  display_data_records
*&*
*       text
*-*
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(50),
        TMP_STR(15),
        TMP_STR3(15),
        SEG_REPEATS TYPE I VALUE 0,
        TMP_STR2(15),
        TAB_CR(2) TYPE C 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.
    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.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    display_data_records

*&*
*&      Form  read_idoc_structure
*&*
*       text
*-*
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
*       IMPORTING
*            IDOC_TYPE            = idoctype
       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
Back to top
View user's profile Send private message Blog
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.