Tip

Converting an internal SAP table into text with a delimiter

Very often as developers, we are required to write programs that read data based on some business logic, then download. Usually this kind of requirement is handled using functions DOWNLOAD, WS_DOWNLOAD or GUI_DOWNLOAD. This feature has few drawbacks -- fixed length files, only tab/no delimited files, formats of date, quantity and currency fields.

All the above limitations can be very easily overcome by using the function SAP_CONVERT_TO_TEX_FORMAT. This function module will take any internal table as input and convert the data accordingly, using various formatting options defined at data element level, and it will give you the output in text format. In addition, this function will make use of any delimiter you want.

    Requires Free Membership to View

The program below demonstrates the above functionality. Here, we are reading data from table EKKO and downloading the data as '|' delimited file.

Editor's note: This tip works on SAP versions 4.6 or higher.
 

REPORT y_ss_test_ekko .
 
* To hold selection data
DATA: i_ekko TYPE STANDARD TABLE OF ekko.
* To hold converted text data
DATA: i_text(4096) TYPE c OCCURS 0.
 
* Selection Screen
PARAMETERS: p_ebeln LIKE ekko-ebeln.
 
* Select data into an ITAB based on the selection Criteria 
SELECT * FROM  ekko
         INTO  TABLE i_ekko
         WHERE ebeln = p_ebeln.
 
* Process further only if found some data 
IF NOT i_ekko[] IS INITIAL.
 
* Convert data in internal table to a delimited text data
  CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
       EXPORTING
            i_field_seperator    = '|'
       TABLES
            i_tab_sap_data       = i_ekko
       CHANGING
            i_tab_converted_data = i_text
       EXCEPTIONS
            conversion_failed    = 1
            OTHERS               = 2.
  IF sy-subrc <> 0.
    WRITE: / 'Program failed to Convert data.'.
  ELSE.
 
*   Download convert data to Presentation Server
    CALL FUNCTION 'DOWNLOAD'
         TABLES
              data_tab = i_text
         EXCEPTIONS
              OTHERS   = 8.
    IF sy-subrc <> 0.
      WRITE: / 'Program failed to download data.'.
    ENDIF.
  ENDIF.
ENDIF.

This was first published in February 2006

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.