(转)ABOUT NAST RSNAST00
谈旺
2023-12-01
Check this one The simplest way to create IDocs, is to write an ABAP. The individual ABAP can either be a triggering ABAP which runs at certain events, e.g. every night, or it can be an ABAP which does the complete IDoc creation from scratch. Triggering ABAPA triggering ABAP would simply try to determine which IDocs need sending and call the appropriate IDoc creation routines.ABAP creates the whole IDocYou may also imagine the ABAP to do all the job. As this is mostly reinventing the wheel, it is not really recommended and should be reserved to situation, where the other solution do not provide an appropriate mean.1.1 NAST Messages Based Outbound IDocsYou can use the R/3 message concept to trigger IDocs the same way as you trigger SAPscript printing.One of the key tables in R/3 is the table NAST. This table records reminders written by applications. Those reminders are called messages. Applications write messages to NAST, which will be processed by a message handlerEvery time when an applications sees the necessity to pass information to a third party. a message is written to NAST. A message handler will eventually check the entries in the table and cause an appropriate action. EDI uses the same mechanism as printingThe concept of NAST messages has originally been designed for triggering SAPscript printing. The very same mechanism is used for IDocs, where the IDoc processor replaces the print task, as an IDoc is only the paperless form of a printed document.Condition technique can mostly be usedThe messages are usually be created using the condition technique, a mechanism available to all major R/3 applications.Printing, EDI and ALE use the same triggerThe conditions are set up the same way for any output media. So you may define a condition for printing a document and then just change the output media from printer to IDoc/EDI or ALE. Figure 1: Communicating with message via table NASTNAST messages are created by application by calling function module MESSAGINGCreating NAST messages is a standard functionality in most of the SAP core applications. Those applications - e.g. VA01, ME21 - perform calls to the central function module MESSAGING of group V61B. The function module uses customizing entries, mainly those of the tables T681* to T685*.NAST contains object key, sender and receiverA NAST output message is stored as a single record in the table NAST. The record stores all information that is necessary to create an IDoc. This includes mainly an object key to identify the processed object and application to the message handler and the sender and receiver information.Programs RSNAST00 and RSNASTED provide versatile subroutines for NAST processing The messages are typically processed byFORM ENTRY in PROGRAM RSNAST00.If we are dealing with printing or faxing andFORM EDI_PROCESSING in PROGRAM RSNASTED.If we are dealing with IDocsFORM ALE_PROCESSING in PROGRAM RSNASTED.If we are dealing with ALE.The following piece of code does principally the same thing as RSNAST00 does and makes full use of all customizing settings for message handling.FORM einzelnachricht IN PROGRAM RSNAST00TABLES: NAST.SELECT * FROM NAST ...PERFORM einzelnachricht IN PROGRAM RSNAST00Programs are customized in table TNAPRThe processing routine for the respective media and message is customized in the table TNAPR. This table records the name of a FORM routine, which processes the message for the chosen media and the name of an ABAP where this FORM is found.1.2 The RSNAST00 ABAP The ABAP RSNAST00 is the standard ABAP, which is used to collect unprocessed NAST message and to execute the assigned action.RSNAST00 is the standard batch collector for messagesRSNAST00 can be executed as a collector batch run, that eventually looks for unprocessed IDocs. The usual way of doing that is to define a batch-run job with transaction SM37. This job has to be set for periodic processing and start a program that triggers the IDoc re-sending. RSNAST00 processes only messages of a certain statusCave! RSNAST00 will only look for IDocs which are set to NAST-VSZTP = '1' or '2' (Time of processing). VSZPT = '3' or '4' is ignored by RSNAST00.For batch execution a selection variant is requiredStart RSNAST00 in the foreground first and find the parameters that match your required selection criteria. Save them as a VARIANT and then define the periodic batch job using the variant.If RSNAST00 does not meet 100% your needs you can create an own program similar to RSNAST00. The only requirement for this program are two steps: Read the NAST entry to process into structure NAST tables nast.data: subrc like sy-subrc.....select from NAST where ....... then call FORM einzelnachricht(rsnast00) to process the record PERFORM einzelnachricht(rsnast00) USING subrc. 1.3 Sending IDocs Via RSNASTEDStandard R/3 provides you with powerful routines, to trigger, prepare and send out IDocs in a controlled way. There are only a few rare cases, where you do not want to send IDocs the standard way.The ABAP RSNAST00 is the standard routine to send IDocs from entries in the message control. This program can be called directly, from a batch routine with variant or you can call the FORM einzelnachricht_screen(RSNAST00) from any other program, while having the structure NAST correctly filled with all necessary information.RSNAST00 determines if it is IDoc or SAPscript etc.If there is an entry in table NAST, RSNAST00 looks up the associated processing routine in table TNAPR. If it is to send an IDoc with standard means, this will usually be the routine RSNASTED(EDI_PROCESSING) or RSNASTED(ALE_PROCESSING) in the case of ALE distribution.RSNASTED processes IDocsRSNASTED itself determines the associated IDoc outbound function module, executes it to fill the EDIDx tables and passes the prepared IDoc to the port.You can call the standard processing routines from any ABAP, by executing the following call to the routine. You only have to make sure that the structure NAST is declared with the tables statement in the calling routine and that you fill at least the key part and the routine (TNAPR) information before.TABLES NAST.NAST-MANDT = SY-MANDT.NAST-KSCHL = 'ZEDIK'.NAST-KAPPL = 'V1'.NAST-OBJKY = '0012345678'.NAST-PARNR = 'D012345678'.PERFORM einzelnachricht_screen(RSNAST00).Calling einzelnachricht_screen determines how the message is processed. If you want to force the IDoc-processing you can call it directly:TNAPR-PROGN = ''.TNAPR-ROUTN = 'ENTRY'.PERFORM edi_processing(RSNASTED).1.4 Sending IDocs Via RSNAST00Here is the principle flow how RSNAST00 processes messages for IDocs. Figure 2: Process logic of RSNAST00 ABAP1.5 Workflow Based Outbound IDocsUnfortunately, there are application that do not create messages. This is especially true for master data applications. However, most applications fire a workflow event during update, which can easily be used to trigger the IDoc distribution.SWE_EVENT_CREATEMany SAP R/3 applications issue a call to the function SWE_EVENT_CREATE during update. This function module ignites a simple workflow event. Workflow is a call to a function moduleTechnically a workflow event is a timed call to a function module, which takes the issuing event as the key to process a subsequent action.Applications with change documents always trigger workflow eventsIf an application writes regular change documents (ger.: Änderungsbelege) to the database, it will issue automatically a workflow event. This event is triggered from within the function CHANGEDOCUMENT_CLOSE. The change document workflow event is always triggered, independent of the case whether a change document is actually written.Workflow coupling can be done by utility functionsIn order to make use of the workflow for IDoc processing, you do not have to go through the cumbersome workflow design procedure as it is described in the workflow documentation. For the mentioned purpose, you can register the workflow handler from the menu, which says Event Coupling from the BALD transaction.Workflow cannot easily be restartedTriggering the IDoc from a workflow event has a disadvantage: if the IDoc has to be repeated for some reason, the event cannot be repeated easily. This is due to the nature of a workflow event, which is triggered usually from a precedent action. Therefore you have to find an own way how to make sure that the IDoc is actually generated, even in the case of an error. Practically this is not a very big problem for IDocs. In most cases the creation of the IDoc will always take place. If there is a problem, then the IDoc would be stored in the IDoc base with a respective status. It will shown in transaction WE05 and can be resend from there.