Q

Creating a purchase order with an XML file

How do I post an XML file into SAP for creating a purchase order, and how do I upload an XML file to the IDoc and send it to the external system?

1. How do I post an XML file into SAP for creating a purchase order?
2. How do I upload an XML file to the IDoc and send it to the external system?
1. Basically you simply have to convert the XML file into the proper IDoc format. There are many ways to achieve this. One solution would be to convert it externally to SAP, e.g. via VB Script or with an XSLT transformation. Or you use the built in SAP functions for importing an IDoc from an XML stream.

2. Uploading a file is either done via GUI_UPLOAD or via the usual way of reading a file from the application server

(Open dataset. Read dataset) But what do you mean by "send to external system"? Do you want to convert an IDoc into XML? Then you simply define an XML port with WE21 to send the IDoc out.

Here is an example of code that loads an XML from file and posts it as an IDoc. Please keep in mind that the XML has to be in its canonical format as described in the interface repository: ifr.sap.com (choose the template of the desired IDoc from there as an example).

*
data: data_tab type table of char1024.
data: XML_STREAM type string.
*
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = 'D:test.xml'
*   FILETYPE                      = 'ASC'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = DATA_TAB
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
CALL FUNCTION 'CONVERT_TABLE_TO_STRING'
  EXPORTING
    I_TABLINE_LENGTH       = '1024'
  IMPORTING
    E_STRING               = XML_STREAM
  TABLES
    IT_TABLE               = DATA_TAB[].
*
write: / xml_stream color col_total.
data: CONTENT_LENGTH type string.
data: CONTENT_TYPE type string.
data: REMOTE_ADDR type string.
*

CALL FUNCTION 'IDOC_INBOUND_XML_VIA_HTTP'
  EXPORTING
    XML_STREAM                      = XML_STREAM
    CONTENT_LENGTH                  = content_type
    CONTENT_TYPE                    = content_type
    REMOTE_ADDR                     = remote_addr
 EXCEPTIONS
   NO_IDOCS_SAVED                  = 1
   TAG_ERROR                       = 2
   NO_DATA_RECEIVED                = 3
   NO_IDOCS_RECEIVED               = 4
   SEGMENT_ERROR                   = 5
   IDOC_WAS_SEND_SECOND_TIME       = 6
   OTHERS                          = 7
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write: / sy-subrc color COL_NEGATIVE.
ENDIF.
This was first published in April 2005

Dig deeper on SAP interface technologies

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close