Application Development and Automation 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: 
Read only

IDOC_QUERY

Former Member
0 Likes
561

Hi..

My requirement is that , I am processing an IDOC, and I am validating some conditions in the segments of the IDOC.

I want to display an error message, if any of the conditions in any of the segments doesnt match with the required one.

The error message, should come in red status with the text displayed on it just like any standard SAP IDOC error occurs.

So, basically I want to show the error message as shown by Standard SAP programs in case of any mismatch.

Please tell me how shall I proceed for every segment(As tehre is a check in almost every segment of my IDOC)

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
520

Hi Subhash,

In standard IDOC error display process, error messages are logged into status table IDOC_STATUS.

whenever you are validation some segment and if it is not valid, move the error data to idoc_status table.

declare idoc_status table like :

IDOC_STATUS TYPE STRUCTURE BDIDOCSTAT.

Move IDOC to the status table with status '51', type 'E' and relevant error message.

Code snippet will be like below :

loop at idoc_data where docnum eq idoc_contrl-docnum.

case idoc_data-segnam.

*- Header record

when 'Z1ORDACK3HDR'.

move idoc_data-sdata to z1ordack3hdr.

if z1ordack3hdr is initial.

idoc_status-docnum = idoc_contrl-docnum.

idoc_status-status = '51'.

idoc_status-msgty = 'E'.

idoc_status-msgid = 'ZV'.

idoc_status-msgno = '00'.

idoc_status-msgv1 = 'Header data missing!'.

append idoc_status.

endif.

Cheers,

Vikram

Pls reward for helpful replies!!

4 REPLIES 4
Read only

ashok_kumar24
Contributor
0 Likes
520

Hi subhash soni ,

Check out this custom Function Module

Schedule it on the inbound system

FUNCTION Z_IDOC_INPUT_EMPREP.

*"----


""Local interface:

*" IMPORTING

*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD

*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC

*" EXPORTING

*" VALUE(WORKFLOW_RESULT) LIKE BDWFAP_PAR-RESULT

*" VALUE(APPLICATION_VARIABLE) LIKE BDWFAP_PAR-APPL_VAR

*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK

*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS

*" TABLES

*" IDOC_CONTRL STRUCTURE EDIDC

*" IDOC_DATA STRUCTURE EDIDD

*" IDOC_STATUS STRUCTURE BDIDOCSTAT

*" RETURN_VARIABLES STRUCTURE BDWFRETVAR

*" SERIALIZATION_INFO STRUCTURE BDI_SER

*" EXCEPTIONS

*" WRONG_FUNCTION_CALLED

*"----


----


  • Database Tables

----


TABLES: ZAK_EMPLIST.

----


  • Include programs

----


INCLUDE MBDCONWF.

----


  • Data Declarations

----


*--- Employee Header -IDOC

DATA: FS_EMPHDR_DATA LIKE Z1RKMSG.

*--- Employee Details -IDOC

DATA: FS_EMPDET_DATA LIKE Z1RKMSG1.

*--- Employee Header - application data

DATA: FS_APP_EMPHDR LIKE ZAK_EMPLIST.

*--- Employee Details - application data

DATA: FS_APP_EMPDET LIKE ZAK_EMPLIST.

----


  • Program Logic

----


*---Initialize Work Flow Result

WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.

*--- Check whether the correct message was passed to us

IF IDOC_CONTRL-MESTYP NE 'ZRKMSG'.

RAISE WRONG_FUNCTION_CALLED.

ENDIF.

*--- Clear application buffers before reading a new record

CLEAR FS_APP_EMPDET.

CLEAR FS_APP_EMPHDR.

  • REFRESH FS_APP_EMPDET.

  • REFRESH FS_APP_EMPDET.

*--- Process all records and pass them on to application buffers

LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.

CASE IDOC_DATA-SEGNAM.

WHEN 'Z1RKMSG'. " Employee Header

FS_EMPHDR_DATA = IDOC_DATA-SDATA.

MOVE-CORRESPONDING FS_EMPHDR_DATA TO FS_APP_EMPHDR.

WHEN 'Z1RKMSG1'. " Employee Details

FS_EMPDET_DATA = IDOC_DATA-SDATA.

MOVE-CORRESPONDING FS_EMPDET_DATA TO FS_APP_EMPDET.

ENDCASE.

ENDLOOP.

*--- If data is ok

SELECT * FROM ZAK_EMPLIST WHERE ENUMBER = FS_APP_EMPHDR.

IF SY-SUBRC NE 0.

INSERT INTO ZAK_EMPLIST VALUES FS_APP_EMPHDR.

INSERT INTO ZAK_EMPLIST VALUES FS_APP_EMPDET.

ELSE.

UPDATE ZAK_EMPLIST FROM FS_APP_EMPHDR.

UPDATE ZAK_EMPLIST FROM FS_APP_EMPDET.

ENDIF.

ENDSELECT.

IF SY-SUBRC EQ 0.

*--- Populate Return variables for success

RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

RETURN_VARIABLES-WF_PARAM = 'Appl_Objects'.

RETURN_VARIABLES-DOC_NUMBER = FS_APP_EMPHDR-ENUMBER.

APPEND RETURN_VARIABLES.

*--- Add Status Reocrds indicating success

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '53'.

IDOC_STATUS-MSGTY = 'I'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '006'.

IDOC_STATUS-MSGV1 = FS_APP_EMPHDR-ENUMBER.

APPEND IDOC_STATUS.

ELSE.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

*--- Add status record indicating failure in updating

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '007'.

IDOC_STATUS-MSGV1 = FS_APP_EMPHDR-ENUMBER.

APPEND IDOC_STATUS.

ENDIF.

ENDLOOP.

ENDFUNCTION.

Good Luck and Reward me for the same

Thanks

Ashok

Read only

0 Likes
520

Hi Ashok

Thanks a lot..

Can we also use structure BDCMSGCOLL(Collecting messages in the SAP System) to collect messages instead of structure BDWFRETVAR keeping all other things constant?

Read only

0 Likes
520

Subhash,

In order to show the error in a IDOC, you will have to update the status record always like the one shown in the post. BDCMSGCOLL deals with BDC and NOT with IDOC's/

Regards,

Ravi

Note :Please mark the helpful answers

Read only

Former Member
0 Likes
521

Hi Subhash,

In standard IDOC error display process, error messages are logged into status table IDOC_STATUS.

whenever you are validation some segment and if it is not valid, move the error data to idoc_status table.

declare idoc_status table like :

IDOC_STATUS TYPE STRUCTURE BDIDOCSTAT.

Move IDOC to the status table with status '51', type 'E' and relevant error message.

Code snippet will be like below :

loop at idoc_data where docnum eq idoc_contrl-docnum.

case idoc_data-segnam.

*- Header record

when 'Z1ORDACK3HDR'.

move idoc_data-sdata to z1ordack3hdr.

if z1ordack3hdr is initial.

idoc_status-docnum = idoc_contrl-docnum.

idoc_status-status = '51'.

idoc_status-msgty = 'E'.

idoc_status-msgid = 'ZV'.

idoc_status-msgno = '00'.

idoc_status-msgv1 = 'Header data missing!'.

append idoc_status.

endif.

Cheers,

Vikram

Pls reward for helpful replies!!