Home > SAP Tips > ABAP/Java developer tips > Converting an internal SAP table into text with a delimiter
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ABAP/JAVA DEVELOPER TIPS

Converting an internal SAP table into text with a delimiter


Sumant Sura
02.15.2006
Rating: -4.09- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

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.

Code

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. 

Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ABAP/Java developer tips
Select Text fields: Case-insensitive
Finding BADIs you can use
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects
Find a BADI in a minute
Top 10 SAP tips of 2007
How to transport an SAP query in R/3 4.6x
How to switch off message determination in BAPI_PO_CREATE1

SAP ABAP
Is SAP BI knowledge advantageous to an ABAP user?
An ABAP user wants to learn XI
Select Text fields: Case-insensitive
Finding BADIs you can use
Is ABAP knowledge necessary for SAP BI?
Quiz: SAP ABAP development
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects
SAP ABAP Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
ABAP  (SearchSAP.com)
ABAP Objects  (SearchSAP.com)
ABAP Workbench  (SearchSAP.com)
BAPI  (SearchSAP.com)
CATT  (SearchSAP.com)
R/3 Repository  (SearchSAP.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.

HomeNewsTopicsBlogsTipsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts