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

BDC,DATASET

Former Member
0 Likes
606

how to handle files in application server by using opendata sets

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
580

Hi,

Hope this could be helpful..

FORM f_upload_appfile TABLES gi_lbox_chkrec USING p_afile.

*open the file to which data is to be sent

OPEN DATASET p_ifile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

READ DATASET p_ifile INTO gw_lbox_chkrec.

IF sy-subrc = 0.

APPEND gw_lbox_chkrec TO gi_lbox_chkrec.

CLEAR: gw_lbox_chkrec.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET p_ifile.

IF sy-subrc <> 0.

MESSAGE i170(yfi) . " 'Error in closing the file'.

LEAVE LIST-PROCESSING.

ENDIF.

ELSE.

MESSAGE i169(yfi). "Error in opening the file'.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " f_upload_appfile

-Mohan

4 REPLIES 4
Read only

Former Member
0 Likes
581

Hi,

Hope this could be helpful..

FORM f_upload_appfile TABLES gi_lbox_chkrec USING p_afile.

*open the file to which data is to be sent

OPEN DATASET p_ifile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

READ DATASET p_ifile INTO gw_lbox_chkrec.

IF sy-subrc = 0.

APPEND gw_lbox_chkrec TO gi_lbox_chkrec.

CLEAR: gw_lbox_chkrec.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET p_ifile.

IF sy-subrc <> 0.

MESSAGE i170(yfi) . " 'Error in closing the file'.

LEAVE LIST-PROCESSING.

ENDIF.

ELSE.

MESSAGE i169(yfi). "Error in opening the file'.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " f_upload_appfile

-Mohan

Read only

Former Member
0 Likes
580

Hi Raju,

what do u need exactly?

normally for keeping the files in the Application server you can use the following code..

REPORT ZMURALI_DS_UPLOAD.

CONSTANTS: C_FILE(20) VALUE '.\MURALI123.TXT'.

DATA: V_MSG(100).

DATA: BEGIN OF ITAB OCCURS 0,

MATNR(18),

WERKS(4),

LGORT(4),

END OF ITAB.

data :itab1 like itab occurs 0 with header line.

ITAB-MATNR = 'ABC123'.

ITAB-WERKS = '1000'.

ITAB-LGORT = '0001'.

APPEND ITAB.

CLEAR ITAB.

ITAB-MATNR = 'ABC456'.

ITAB-WERKS = '1001'.

ITAB-LGORT = '0002'.

APPEND ITAB.

CLEAR ITAB.

ITAB-MATNR = 'ABC789'.

ITAB-WERKS = '1002'.

ITAB-LGORT = '0003'.

APPEND ITAB.

CLEAR ITAB.

ITAB-MATNR = 'ABC101'.

ITAB-WERKS = '1003'.

ITAB-LGORT = '0004'.

APPEND ITAB.

CLEAR ITAB.

OPEN DATASET C_FILE FOR input

IN TEXT MODE

ENCODING DEFAULT

MESSAGE V_MSG.

IF SY-SUBRC NE 0.

WRITE:/'NO FILE'.

EXIT.

ENDIF.

do.

read dataset c_file into itab1.

if sy-subrc eq 0.

append itab1.

else.

exit.

endif.

enddo.

CLOSE DATASET C_FILE.

Read only

Former Member
0 Likes
580

You can try this

DATA: v_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

OPEN DATASET v_file FOR INPUT IN TEXT MODE.

IF sy-subrc NE 0.

MESSAGE 'Error opening file' TYPE 'E'.

ENDIF.

DO.

  • Reads each line of file individually

READ DATASET v_file INTO <WORK_AREA>.

  • Perform processing here

  • .....

ENDDO.

Regards

Kathirvel

Read only

Former Member
0 Likes
580