Business Scenario:
This is one of the real life implementation scenarios where the data was to come in the XML format, needed to be posted as a IDoc and then after some postings in the SAP, it was required to be converted into the Baan format text file which had some fields in pipe delimited format.Sounds Interesting!
Technical Scenario:
The process had to be totally automated and three parties involved were customer who was sending the data in XML format , SAP (running on WAS 6.2) system which was receiving it and carrying out business transactions and Vendor who was getting the Baan format file.
Now, the data which was coming in the XML format from customer was the PO information which was required to be posted as a Sales Order, subsequently creating a purchase order in SAP system and then sending it to the vendor in the text file BAAN format. Further it was required that a order acknowledgement file coming from the vendor in the BAAN format, was required to be posted as order response in SAP system, further sending the same file in the XML format to the customer.
How-to-guide.....
Plunge into the waters,the swimming automatically comes!! That's what happened!
Simple steps..
XML format for posting the orders: This XML format was created by using the third party tool where we downloaded the XML schema for the "ORDERS05" IDoc type (Transaction WE60). Generated the XML file and removed the non-mandatory, non-required fields which was not required.
Create a service (Transaction: SICF) to create the link where the XML was being posted. The service had a class handler CL_HTTP_IDOC_XML_REQUEST. This SAP standard handler which passes the IDoc to ALE layer and sends a response back to the sender of the HTTP request "IDoc-XML-inbound ok" ,If the IDoc was created .
Otherwise, in case of any other error , it was HTTP 408/409 error. Here we did some customization, as our user wanted the XML error to be returned. We copied the standard handler to a "Z" and in the IF_HTTP_EXTENSION interface of the handler, wherever 408/409 error was returned changed it to the customized XML message. Do not forget to give the background user in the service!!
The process was required to be automatic, trigger to create a sales order and then purchase order in the SAP system.
In the partner profile configuration, for the inbound orders message, normally the process code for standard sales order creation is "ORDE" for creating the sales order.
But here we needed to trigger the creation of the purchase order as well in SAP , and also at the same time creating the BAAN text file to be sent across to the vendor.
Steps:
1. Create a custom 'Z' function module (interface is the same as that of standard) , which calls the standard 'IDOC_INPUT_ORDERS' to create the Sales order and also the BAPI_PO_CREATE to create the purchase order (values required to create the PO taken in from the IDoc posted).
In the same function module a logic could be written to create the BAAN pipe delimited text file.This logic is the ABAP code which creates the pipe delimited BAAN text file.
2. Assign the function module in ALE attributes using the transaction BD51.
3. Assign the function module to the message type and the application object using transaction WE57.
4. Create the inbound process code and attach this function module to this process code using transaction WE42 , the parameters being the same as that of the standard "ORDE".
5. The file created for the vendor was stored on the application server .As external FTP was not allowed from the application server, a separate servlet code was written to run on the server in DMZ zone , which would run the thread, to check if any file was formed on application server and as soon as it was, the file was read by that program and sent to the vendor's FTP address.
The snippet of the code for the 'Z' function module is :
| FUNCTION ZSD_FUNC_ORDERSPOSTING. *"--------------------------------------------------------- *"*"Global 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 *" VALUE(DOCUMENT_NUMBER) LIKE VBAK-VBELN *" TABLES *" IDOC_CONTRL STRUCTURE EDIDC *" IDOC_DATA STRUCTURE EDIDD *" IDOC_STATUS STRUCTURE BDIDOCSTAT *" RETURN_VARIABLES STRUCTURE BDWFRETVAR *" SERIALIZATION_INFO STRUCTURE BDI_SER *" EDI_TEXT STRUCTURE EDIORDTXT1 OPTIONAL *" EDI_TEXT_LINES STRUCTURE EDIORDTXT2 OPTIONAL *"----------- DATA: L_SALES_ORDNO LIKE EKKO-EBELN, L_FILENAME TYPE STRING, L_RANGE TYPE I OCCURS 0 WITH HEADER LINE, L_INDEX TYPE I, L_FROM TYPE I, L_TO TYPE I, L_TEMP TYPE I. GET TIME. CONCATENATE 'C:\PO_FILE\' SY-DATUM SY-UZEIT '.TXT' INTO L_FILENAME. *** call the standard function module*** CALL FUNCTION 'IDOC_INPUT_ORDERS' EXPORTING INPUT_METHOD = INPUT_METHOD MASS_PROCESSING = MASS_PROCESSING IMPORTING DOCUMENT_NUMBER = L_SALES_ORDNO TABLES IDOC_CONTRL = IDOC_CONTRL IDOC_DATA = IDOC_DATA IDOC_STATUS = IDOC_STATUS RETURN_VARIABLES = RETURN_VARIABLES SERIALIZATION_INFO = SERIALIZATION_INFO . **** TO create PO take in DATA**** IF L_SALES_ORDNO IS NOT INITIAL. * PO Header Details *** EXTRACT THE DOCUMENT DATE LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDK02' AND HLEVEL = '02'. *IDOC_DATA-SDATA offset 44. W_PO_HEADER-DOC_DATE = IDOC_DATA-SDATA+44(8). ENDLOOP. LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDK14' AND HLEVEL = '02'. W_PO_HEADER-DOC_TYPE = 'P470'. *** EXTRACT THE PURCHASING ORGANIZATION IF IDOC_DATA-SDATA(3) = '014'. * IDOC_DATA-SDATA OFFSET 3. IF IDOC_DATA-SDATA+3(35) <> ''. W_PO_HEADER-PURCH_ORG = IDOC_DATA-SDATA+3(35). ELSE. W_PO_HEADER-PURCH_ORG = '0470'. ENDIF. ELSE. W_PO_HEADER-PURCH_ORG = '0470'. ENDIF. *** EXTRACT THE SALES ORGANIZATION IF IDOC_DATA-SDATA(3) = '008'. L_ORG = IDOC_DATA-SDATA+3(35). ENDIF. *** HARD CODE THE PURCHASING GROUP IF IDOC_DATA-SDATA(3) = '009'. * IDOC_DATA-SDATA OFFSET 3. IF W_PO_HEADER-PUR_GROUP <> ''. W_PO_HEADER-PUR_GROUP = IDOC_DATA-SDATA+3(35). ELSE. *** PUT A DEFAULT VALUE FOR PURCHASING GROUP IF IT IS EMPTY W_PO_HEADER-PUR_GROUP = '06F'. ENDIF. ELSE. ** PUT A DEFAULT VALUE FOR PURCHASING GROUP IF IT IS EMPTY W_PO_HEADER-PUR_GROUP = '06F'. ENDIF. ENDLOOP. *** EXTRACT THE VENDOR INFORMATION LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDKA1' . IF IDOC_DATA-SDATA(3) = 'LF'. ****RETREIVE THE VENDOR CODE W_PO_HEADER-VENDOR = IDOC_DATA-SDATA(17). ELSE. ****PUT THE DEFAULT FOR VENDOR W_PO_HEADER-VENDOR = '0000034422'. ENDIF. L_BUSPARTNER = W_PO_HEADER-VENDOR. ENDLOOP. APPEND W_PO_HEADER. DATA : L_POITEM TYPE EDI1082_A. LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDP01' . L_RANGE = SY-TABIX. APPEND L_RANGE. CLEAR L_RANGE. ENDLOOP. DESCRIBE TABLE IDOC_DATA LINES L_RANGE. APPEND L_RANGE. CLEAR L_RANGE. * PO items details LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDP01' . *** EXTRACT THE PO ITEM NUMBER W_PO_ITEMS-PO_ITEM = IDOC_DATA-SDATA(6). "PO_ITEM L_POITEM = IDOC_DATA-SDATA(6). W_PO_ITEMS-NET_PRICE = IDOC_DATA-SDATA+78(18). **-Added now - PO quantity: total of all sched. lines for *display purposes W_PO_ITEMS-DISP_QUAN = IDOC_DATA-SDATA+11(15). L_TEMP = L_INDEX = L_INDEX + 1. READ TABLE L_RANGE INDEX L_INDEX. L_FROM = L_RANGE. L_TEMP = L_TEMP + 1. READ TABLE L_RANGE INDEX L_TEMP. L_TO = L_RANGE. *PO_ITEM_SCHEDULES LOOP AT IDOC_DATA FROM L_FROM TO L_TO WHERE SEGNAM = 'E1EDP20'. W_PO_ITEM_SCHEDULES-PO_ITEM = L_POITEM. "PO_ITEM * PO_ITEM_QUANTITY W_PO_ITEM_SCHEDULES-QUANTITY = IDOC_DATA-SDATA(15). * IDOC_DATA-SDATA OFFSET 30. * ITEM DELIVERY DATE W_PO_ITEM_SCHEDULES-DELIV_DATE = IDOC_DATA-SDATA+30(8). APPEND W_PO_ITEM_SCHEDULES. CLEAR W_PO_ITEM_SCHEDULES. ENDLOOP. CLEAR L_POITEM. *** EXTRACT THE PLANT NUMBER * IDOC_DATA-SDATA OFFSET 311. W_PO_ITEMS-PLANT = IDOC_DATA-SDATA+311(4). IF W_PO_ITEMS-PLANT = ''. * HARD CODE THE VALUES W_PO_ITEMS-PLANT = '0470'. ENDIF. *** EXTRACT THE PO MATERIAL LOOP AT IDOC_DATA WHERE SEGNAM = 'E1EDP19'. W_PO_ITEMS-MATERIAL = IDOC_DATA-SDATA+3(35). W_PO_ITEMS-PUR_MAT = IDOC_DATA-SDATA+3(35). ENDLOOP. W_PO_ITEMS-ACKN_REQD = 'X'. APPEND W_PO_ITEMS. CLEAR W_PO_ITEMS. ENDLOOP. ***** * Calling function BAPI_PO_CREATE TO CREATE PURCHASE ORDER ***** CALL FUNCTION 'BAPI_PO_CREATE' EXPORTING PO_HEADER = W_PO_HEADER SKIP_ITEMS_WITH_ERROR = 'X' IMPORTING PURCHASEORDER = W_PURCHASEORDER TABLES PO_ITEMS = W_PO_ITEMS PO_ITEM_SCHEDULES = W_PO_ITEM_SCHEDULES RETURN = W_RETURN PO_LIMITS = W_PO_LIMITS PO_CONTRACT_LIMITS = W_PO_CONTRACT_LIMITS PO_SERVICES = W_PO_SERVICES PO_SRV_ACCASS_VALUES = W_PO_SRV_ACCASS_VALUES PO_SERVICES_TEXT = W_PO_SERVICES_TEXT PO_BUSINESS_PARTNER = W_PO_BUSINESS_PARTNER EXTENSIONIN = W_EXTENSIONIN POADDRDELIVERY = W_POADDRDELIVERY . ENDIF. *IF PURCHASE ORDER HAS BEEN CREATED THEN DOWNLOAD BAAN FORMAT FILE. IF W_PURCHASEORDER IS NOT INITIAL. < code to create a text file in BAAN format and download it at application server> ENDIF. |