Professional Documents
Culture Documents
Log In
Register
About Us
How to Contribute
Welcome Guest
SDN Community
BPX Community
BusinessObjects
University Alliances
SAP EcoHub
Home
Forums
Wiki
Blogs
Articles
eLearning
Downloads
Code Exchange
Career Center
Events
InnoCentive
Idea Place
Description : This code sample is meant for the developers who are looking for a prototype of a report program for editing (modifying) Id
useful for editing any Idoc with repeated incorrect values in the segment fields .It is just an atempt to develop a reusable report which ca
of Idocs and incorporate conditional edit in the Idoc with all the possible validations which I can think ofJ.It is a prototype and whoever s
to address the specific needs of the project. Report can also be tuned for its performance for better results.
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 2 of 7
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 3 of 7
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM open_idoc_to_edit .
PERFORM change_data.
PERFORM change_data_segments.
PERFORM change_control_record.
PERFORM close_idoc.
END-OF-SELECTION.
*----------------------------------------------------------------------*
* SUB-ROUTINES *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form open_idoc_to_edit
*&---------------------------------------------------------------------*
* Subroutine to open the Idoc for editing
*----------------------------------------------------------------------*
FORM open_idoc_to_edit.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
EXPORTING
document_number = p_docnum
IMPORTING
idoc_control = itab_edidc
TABLES
idoc_data = itab_edidd
EXCEPTIONS
document_foreign_lock =1
document_not_exist =2
document_not_open =3
status_is_unable_for_changing = 4
OTHERS = 5.
CASE sy-subrc.
WHEN 0.
*Validation on segment level
IF p_elmnt1 NE space AND p_val1 EQ space
OR p_elmnt1 EQ space AND p_val1 NE space.
WRITE / text-006.
STOP.
ENDIF.
READ TABLE itab_edidd WITH KEY segnam = p_sgmnt
TRANSPORTING NO FIELDS.
IF NOT sy-subrc IS INITIAL.
MESSAGE s102 WITH p_sgmnt p_docnum.
STOP.
ELSE.
EXIT.
ENDIF.
WHEN OTHERS.
MESSAGE s113 .
STOP.
ENDCASE.
ENDFORM. " open_idoc_to_edit
*&---------------------------------------------------------------------
*& Form change_data *
*&---------------------------------------------------------------------
*Subroutine performs following steps *
*1. Selection of data structure from table dd03l for the segment *
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 4 of 7
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 5 of 7
ENDIF.
* If comparison values are provided then check the value in the
* corresponding field before editing
IF p_elmnt1 NE space AND p_val1 NE space.
LOOP AT itab_edidd WHERE segnam = p_sgmnt.
<dyn_wa> = itab_edidd-sdata.
ASSIGN COMPONENT p_elmnt1 OF STRUCTURE <dyn_wa> TO <dyn_var2> .
IF <dyn_var2> = p_val1.
ASSIGN COMPONENT p_elmnt OF STRUCTURE <dyn_wa> TO <dyn_var1> .
<dyn_var1> = p_val.
itab_edidd-sdata = <dyn_wa>.
MODIFY itab_edidd.
ENDIF.
ENDLOOP.
ELSE.
* If comparison values are not provided then edit directly
LOOP AT itab_edidd WHERE segnam = p_sgmnt.
<dyn_wa> = itab_edidd-sdata.
ASSIGN COMPONENT p_elmnt OF STRUCTURE <dyn_wa> TO <dyn_var1> .
<dyn_var1> = p_val.
itab_edidd-sdata = <dyn_wa>.
MODIFY itab_edidd.
ENDLOOP.
ENDIF.
ENDFORM. " change_data
*&---------------------------------------------------------------------
*& Form change_data_segments *
*&---------------------------------------------------------------------
* Subroutine to change the data segments *
*----------------------------------------------------------------------
FORM change_data_segments.
CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'
TABLES
idoc_changed_data_range = itab_edidd
EXCEPTIONS
idoc_not_open =1
data_record_not_exist = 2
OTHERS = 3.
CASE sy-subrc.
WHEN 0.
EXIT.
WHEN OTHERS.
MESSAGE s113 .
STOP.
ENDCASE.
ENDFORM. " change_data_segments
*&---------------------------------------------------------------------
*& Form change_control_record *
*&---------------------------------------------------------------------
*Subroutine to change the control record *
*----------------------------------------------------------------------
FORM change_control_record.
CALL FUNCTION 'EDI_CHANGE_CONTROL_RECORD'
EXPORTING
idoc_changed_control = itab_edidc
EXCEPTIONS
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 6 of 7
idoc_not_open =1
direction_change_not_allowed = 2
OTHERS = 3.
CASE sy-subrc.
WHEN 0.
EXIT.
WHEN OTHERS.
MESSAGE s113 .
STOP.
ENDCASE.
ENDFORM. " change_control_record
*&---------------------------------------------------------------------
*& Form close_Idoc *
*&---------------------------------------------------------------------
*Subroutine to close the Idoc after edit *
*----------------------------------------------------------------------
FORM close_idoc.
CLEAR itab_edids40.
*steps for updating idoc status
itab_edids40-docnum = p_docnum.
itab_edids40-status = '51'.
itab_edids40-repid = sy-repid.
itab_edids40-tabnam = 'EDI_DS'.
itab_edids40-mandt = sy-mandt.
itab_edids40-stamqu = 'SAP'.
itab_edids40-stamid = 'B1'.
itab_edids40-stamno = '999'.
itab_edids40-stapa1 = 'values changed to '.
itab_edids40-stapa2 = p_val.
itab_edids40-logdat = sy-datum.
itab_edids40-logtim = sy-uzeit.
APPEND itab_edids40.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
EXPORTING
document_number = p_docnum
do_commit = 'X'
do_update = 'X'
write_all_status = 'X'
TABLES
status_records = itab_edids40
EXCEPTIONS
idoc_not_open =1
db_error =2
OTHERS = 3.
CASE sy-subrc.
WHEN 0.
WRITE : / 'IDOC number ', p_docnum ,' edited' .
EXIT.
WHEN OTHERS.
MESSAGE s113.
STOP.
ENDCASE.
ENDFORM. " close_Idoc
1) Selection Texts :-
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010
SAP Community Network Wiki - Code Gallery - Reusable Code for Editing Idoc Page 7 of 7
2) Text Symbols :-
Labels
idoc
Comments (2)
http://wiki.sdn.sap.com/wiki/display/Snippets/Reusable+Code+for+Editing+Idoc 15/12/2010