Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CHECK THIS PROGRAM

Former Member
0 Likes
792

HAI,

I HAVE WRITHEN ONE PROGRAM FOR WRITE DATA IN APPLICATION SERVER USING OPEN DATASET AND ONCE'S AGAIN I AM READING FROM APPLICATION SERVER. BUT IT IS NOT WORKING .PLEASE CORRECT IT.

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

OPEN DATASET 'C:\SAMPLE.TXT' FOR OUTPUT IN TEXT MODE ENCODING

DEFAULT.

LOOP AT TMARA.

TRANSFER TMARA-MATNR TO 'C:\SAMPLE.TXT'.

ENDLOOP.

CLOSE DATASET 'C:\SAMPLE.TXT'.

CLEAR TMARA[].

OPEN DATASET 'C:\SAMPLE.TXT' FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

LOOP AT TMARA.

READ DATASET 'C:\SAMPLE.TXT' INTO TMARA-MATNR.

WRITE 😕 TMARA-MATNR.

ENDLOOP.

CLOSE DATASET 'C:\SAMPLE.TXT'.

THANK YOU

ASHOK KUMAR

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
764

Why are you writing it, then reading what you wrote? Why not just loop at the internal table and write from it?

Also, why, are you using the open dataset? Why not just use the gui_download funtion module? You can try the below.

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\SAMPLE.TXT'

tables

data_tab = tmara.

CLEAR TMARA.

LOOP AT TMARA.

WRITE 😕 TMARA-MATNR.

ENDLOOP.

8 REPLIES 8
Read only

Former Member
0 Likes
764

Hi

You are not at all READING the data from DATASET

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

OPEN DATASET 'C:\SAMPLE.TXT' FOR OUTPUT IN TEXT MODE ENCODING

DEFAULT.

LOOP AT TMARA.

TRANSFER TMARA-MATNR TO 'C:\SAMPLE.TXT'.

ENDLOOP.

CLOSE DATASET 'C:\SAMPLE.TXT'.

CLEAR TMARA[].

OPEN DATASET 'C:\SAMPLE.TXT' FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

<b>DO.

READ DATASET 'C:\SAMPLE.TXT' INTO TMARA.

APPEND TMARA.

ENDDO.

CLOSE DATASET 'C:\SAMPLE.TXT'.

LOOP AT TMARA.

WRITE 😕 TMARA-MATNR.

ENDLOOP.</b>

SEE NOW. IT WORKS NOW.

Reward points if useful

Regards

Anji

Read only

0 Likes
764

HAI,

IS IT POSSIBLE ONLY FOR CHARACTER BECAUSE I GOT SHORT DUMP.

HOW CAN I WRITE INTEGER.

ASHOK

Read only

0 Likes
764

what are you trying to do ?

you have called open data set, and that means u are trying to do something with a file in application server.

and then you are passing path 'C:\SAMPLE.TXT' ... this is a path in presentation server, right ??

what are you trying to acheive... ? if u really want to write something to application server... give a path over there... (use AL11 to see application server files )..

else, if from 'C:\SAMPLE.TXT' ..use gui_upload

Read only

Former Member
0 Likes
765

Why are you writing it, then reading what you wrote? Why not just loop at the internal table and write from it?

Also, why, are you using the open dataset? Why not just use the gui_download funtion module? You can try the below.

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\SAMPLE.TXT'

tables

data_tab = tmara.

CLEAR TMARA.

LOOP AT TMARA.

WRITE 😕 TMARA-MATNR.

ENDLOOP.

Read only

Former Member
0 Likes
764

Try this

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

OPEN DATASET 'C:\SAMPLE.TXT' FOR OUTPUT IN TEXT MODE ENCODING

DEFAULT.

LOOP AT TMARA.

TRANSFER TMARA-MATNR TO 'C:\SAMPLE.TXT'.

ENDLOOP.

CLOSE DATASET 'C:\SAMPLE.TXT'.

CLEAR TMARA.

Refresh TMARA.

OPEN DATASET 'C:\SAMPLE.TXT' FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

<b>While sy-subrc = 0.

WRITE 😕 TMARA-MATNR.

READ DATASET 'C:\SAMPLE.TXT' INTO TMARA-MATNR.

ENDwhile.</b>

CLOSE DATASET 'C:\SAMPLE.TXT'.

Read only

Former Member
0 Likes
764

Hi,

Here is the Solution, The Internal table should have only charecter fields if the Unicode checkbox is clicked, the below Program will run if the Unicode checkbox is unchecked. you can uncheck in the program Attributes

REPORT ZOPENDATASET.

TABLES MARA.

DATA TMARA LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT MATNR

UP TO 20 ROWS

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE TMARA.

OPEN DATASET 'C:\SAMPLE.TXT' FOR OUTPUT IN TEXT MODE ENCODING

DEFAULT.

LOOP AT TMARA.

TRANSFER TMARA-MATNR TO 'C:\SAMPLE.TXT'.

ENDLOOP.

CLOSE DATASET 'C:\SAMPLE.TXT'.

CLEAR TMARA[].

OPEN DATASET 'C:\SAMPLE.TXT' FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

<b>DO

READ DATASET 'C:\SAMPLE.TXT' INTO TMARA-MATNR.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE 😕 TMARA-MATNR.

ENDDO.</b>

CLOSE DATASET 'C:\SAMPLE.TXT'.

Read only

Former Member
0 Likes
764

Hi Ashok,

It appears to me that you are using the OPEN DATASET, TRANSFER / READ DATASET and CLOSE DATASET statements to read and write data from and to your PC (Presentation Layer). This is not possible. The above statements are used to read and write data from and to the Application Layer (you can view the file structure using transaction AL11). To read a file from the PC (Presentation Layer) you use function module GUI_UPLOAD and to write data to the PC (Presentation Layer) you use function module GUI_DOWNLOAD.

You need to do one of the two things:

1) Use a valid file path from the application server (See transaction AL11) and replace 'C:\SAMPLE.TXT' with this path (the rest of your program will remain the same).

OR

2) Use GUI_UPLOAD (to read data from 'C:\SAMPLE.TXT' ) and GUI_DOWNLOAD (to write data to 'C:\SAMPLE.TXT') instead of the OPEN DATASET, TRANSFER / READ DATASET and CLOSE DATASET statements.

Please let me know if this helps you.

Regards,

Mark

Read only

Former Member
0 Likes
764

hi try this one it works

&----


*& Form SUB_GET_FILEPATH

&----


text

-


--> p1 text

<-- p2 text

-


FORM SUB_GET_FILEPATH .

GFILE = 'D:\SAP_INT\INBOUND\INBOX'. "Path

ENDFORM. " SUB_GET_FILEPATH

&----


*& Form SUB_GET_FILE

&----


text

-


--> p1 text

<-- p2 text

-


FORM SUB_GET_FILE .

DATA: P_FDIR(200) TYPE C.

DATA: IT_FILEDIR1 TYPE STANDARD TABLE OF TY_FILEDIR WITH HEADER LINE.

P_FDIR = GFILE.

CALL FUNCTION 'RZL_READ_DIR_LOCAL'

EXPORTING

NAME = P_FDIR

TABLES

FILE_TBL = IT_FILEDIR.

REFRESH : IT_FILEDIR1.

LOOP AT IT_FILEDIR.

IF IT_FILEDIR-NAME(4) = 'ZINC' OR IT_FILEDIR-NAME(4) = 'zinc'.

MOVE IT_FILEDIR-NAME TO IT_FILEDIR1-NAME.

APPEND IT_FILEDIR1.

ENDIF.

ENDLOOP.

IF IT_FILEDIR1[] IS INITIAL.

STOP.

ENDIF.

LOOP AT IT_FILEDIR1.

REFRESH: I_TAB.

CLEAR: I_TAB.

NAME = IT_FILEDIR1-NAME.

CONCATENATE: GFILE '\' NAME INTO G_FILE.

OPEN DATASET G_FILE FOR INPUT IN TEXT MODE

ENCODING DEFAULT

IGNORING CONVERSION ERRORS.

IF SY-SUBRC EQ 0.

CONCATENATE 'FILENAME : ' G_FILE INTO I_MSG1.

APPEND I_MSG1.

DO.

READ DATASET G_FILE INTO RECORD.

IF SY-SUBRC = 0.

SPLIT RECORD AT ',' INTO I_TAB-BUKRS I_TAB-EBELN

I_TAB-BLDAT I_TAB-XBLNR I_TAB-LIFNR I_TAB-AMOUNT

I_TAB-CURR I_TAB-BUSAREA

I_TAB-BKTXT I_TAB-DMBTR I_TAB-MENGE I_TAB-SRNO.

MOVE-CORRESPONDING I_TAB TO I_TAB1.

ELSE.

EXIT.

ENDIF.

APPEND I_TAB1.

CLEAR: I_TAB, I_TAB1.

ENDDO.

ENDIF.

CLOSE DATASET G_FILE.