Recently has some enhancement works on Intercompany billing with standard output type RD04 which will create output which type is 'Invoice Receipt MM' and generate an inbound IDoc 'INVOIC' to create an accounting document. I write down the basic processing which deeply integrated with IDoc and hopes it could help if someone faces the same. But actually, it'll work as a warm-up for me to recall memory when dealing with potential
subsequent issues~ : D
1. About RD04 output
After Intercompany billing been saved and go to Header->output to check the output processing log at VF03 with the Intercompany billing number. Btw, one
wiki document explains the whole setting related to RD04 very well.
The process logs contain key details with driver program 'RSNASTED', the routine name 'EDI_PROCESSING' ( both are standard and can check at RD04 output setting by NACU as well), and the inbound Idoc number.
Go to WE05 with the Idoc number to check RD04 generated IDoc details which provide the generated accounting document number at status '53'.
Go to WE20 using the above Idoc attributes like partner No., partner type, port, basic type, and message type, then get the key Function Module: IDOC_INPUT_INVOIC_FI which is the inbound handler. (Although using customized process code here, still it's standard FM).
2. About Inbound FM ‘IDOC_INPUT_INVOIC_FI’
The main FM for 'IDOC_INPUT_INVOIC_FI' is
'PROCESS_IDOC_INVOIC_FI' which contains a single FM: 'zwischenstr_zuordnen_invoic01' which will post accounting document using the BDC method. That's why we can re-run this Idoc inbounding process by SE19 and debug this in the front end like a pure BDC session.
The enhancement for this FM is 'FEDI0001', there're several FM user exits available. From my understanding, the two categories here for EDI processing:
- 'MM-EDI' is MM involved could be Invoice Verification related Accounting posting;
- 'FI-EDI' is the only pure FI Accounting Document posting.
I'd like to use 'CALL
CUSTOMER-FUNCTION' to search at this include program LIEDIF4S, then find out user exit '101' against FM: 'EXIT_SAPLIEDI_101' which can be used to manipulate the data before accounting document posting.
Then just modify the internal table 'document_data' contents inside the include program ZXF06U06 will achieve any data replacement you want for account document posting.
The table 'DOCUMENT_DATA' been populated line after line at the major loop per Idoc segments like e1edk01.
The contents inside table 'beleg_daten' which against DOCUMENT_DATA look like this:
Exactly the same as the BDC sessions' data for FNAM and FVAL! For example, if need to update the order number by using field BSEG-AUFNR(may not good idea~), will get an error like below during posting cause store as BSEG-AUFNR doesn't mean the field at BDC input screen use the same~
Check the correct field at the FB03 screen or you can ask the function to help to record one BDC session by SHDB if not sure where it's.
Search 'COBL-AUFNR' inside the main program of the FM, will find routine: fill_user_exit_kontierungen impact the value of COBL-AUFNR.
By using the where-used list, get another user exit: EXIT_SAPLIEDI_002 (FI-EDI: Invoice Receipt - Determine Add. Acct Assignm. per Line Item). Just add custom code at include ZXF06U02 will do.
The above process is inbound for posting account documents, sometimes maybe it's better to modify the IDoc segment contents before it's been generated. Then we need to check its preceding procedure which is Idoc generation during RD04 output controlled by FM: IDOC_OUTPUT_INVOIC_IV_MM.
3. About IDoc Filling FM: IDOC_OUTPUT_INVOIC_IV_MM
The main routine to populate segment fields is 'FUELLEN_IDOC_INTTAB' which contains several sub-routine to populate per Idoc segment.
Search interested segments structure name to identify the routine name, then search text 'customer_function' to identify its user exit FM. Below is the user exit for E1EDP01.
Will find FM like 'EXIT_SAPLVEDF_002' which maps to '002' of enhancement 'LVEDF001' for Customer Enhancement in Data Segments Billing Document Output. Then do the custom code to manipulate the segment filling process.
About Debug Idoc related to RD04
Reprocess existed inbound Idoc by BD87 will not generate new IDoc but WE19 will do, so BD87 can't debug the Idoc when been processed successfully. Only possible for traffic light with yellow or red color. WE19 will be better than BD87 for this case.
To test the inbound process FM: ‘IDOC_INPUT_INVOIC_FI’, just use SE19 with Inbound FM and check the box of 'Call in debugging mode'. And do remember to tick in foreground mode which will be very convenient with data the per-screen just like the BDC session.
A good watch-point for trace changes of document fields is BELEG_DATEN-FVAL:
To test the RD04 Idoc filling FM: IDOC_OUTPUT_INVOIC_IV_MM, one easiest way is using the program RSNAST0D.
One tip about G/L account replacement:
- If you want to change the G/L account before IDoc been generated, using the included program 'ZXEDFU02' of FM: 'EXIT_SAPLVEDF_002'.
- But be cautious that the system will validate this new G/L account again using table T076I and change it to another G/L account if no maintenance entry for your G/L account.
- If that is the case, then have to use included program 'ZXF06U06' of FM: 'EXIT_SAPLIEDI_101' to manipulate the value of the G/L account after Idoc been generated and wait for system validation completed and before the document been posted.
- You can use the parameter field 'IDOC_DATA_INDEX' to monitor changes inside the internal table 'DOCUMENT_DATA' and DOCUMENT_LINE to separate various account items with posting keys BSEG-BSCHL!