‎2012 Jun 06 9:50 AM
Hi,
I am trying to read an excel file that is present in the app server.
Have downloaded the file from the SAP content server into an internal table using the FM BAPI_DOCUMENT_GETDETAIL2,
and also the FM SCMS_R3DB_GET (this gets the data in binary form in the internal table data_bin)
Now I need this in regular text in an internal table, so I can manipulate and use the data,
I am also able to download this data into the app server as an xls file. But not sure how to read it , would be great if it can be read as a string.
Appreciate any input, to either convert the data_bin in the FM SCMS_R3DB_GET , or read an excel file from the app server.
Thank you
Lalitha
‎2012 Jun 06 10:00 AM
Hi,
you can read the file from the application server by using the statements
open dataset, read dataset and close dataset.
Regards,
Anvesh
‎2012 Jun 06 10:14 AM
Hi,
Try this
OPEN DATASET 'file name' FOR INTPUT IN BINARY MODE ENCODING DEFAULT.
DO.
READ DATASET
IF SY-SUBRC NE 0.
EXIT.
ELSE.
Fill to Internal table.
ENDIF.
ENDDO.
CLOSE DATASET.
Thanks&Regards,
Shankar Darbha
‎2012 Jun 06 10:44 AM
Hi Lalitha i use this code to get the file data in string format and it is met with your problem i hope.
Thanks.
TYPES : BEGIN OF T_MAT,
MATNR(18) TYPE C,
MTART(4) TYPE C,
MBRSH(1) TYPE C,
MEINS(3) TYPE C,
END OF T_MAT.
TYPES : TT_MAT TYPE STANDARD TABLE OF T_MAT.
DATA : LW_MAT TYPE T_MAT,
LT_MAT TYPE TT_MAT.
DATA : V_DSN(100) TYPE C.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM WRITE_FILE_ON_APPL_SVR.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR MTART MBRSH MEINS FROM MARA
INTO TABLE LT_MAT
UP TO 3 ROWS.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form write_file_on_appl_svr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_FILE_ON_APPL_SVR .
V_DSN = '/usr/sap/LID/DVEBMGS00/work/material.txt'.
OPEN DATASET V_DSN FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
IF SY-SUBRC EQ 0.
LOOP AT LT_MAT INTO LW_MAT.
TRANSFER LW_MAT TO V_DSN.
CLEAR LW_MAT.
ENDLOOP.
WRITE : / 'File created ' , v_dsn.
ELSE.
WRITE : / 'File could not open'.
ENDIF.
CLOSE DATASET V_DSN.
ENDFORM.