‎2008 Mar 07 5:36 AM
code required for how to upload to application server and download it from application server using open dataset and closedataset.
‎2008 Mar 07 5:40 AM
Hi,
DATA FNAME(60) VALUE 'myfile'.---Application server file name
DATA: TEXT1(4) VALUE '1234 ',
TEXT2(8) VALUE '12345678',
TEXT3(2),
LENG TYPE I.
For writing
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.
TRANSFER: TEXT1 TO FNAME,
TEXT2 TO FNAME.
CLOSE DATASET FNAME.
For Reading
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO 2 TIMES.
READ DATASET FNAME INTO TEXT3 LENGTH LENG.
WRITE: / TEXT3, LENG.
ENDDO.
CLOSE DATASET FNAME.
To get the application server file goto tcdoe AL11
‎2008 Mar 07 5:41 AM
Hi,
You can use this code for downloading file to application server.
form download_file_appl_server.
open dataset p_dlf2 for output
in text mode encoding default .
if sy-subrc ne 0.
message:i005 with text-415 text-407.
endif.
loop at i_final into wa_final.
transfer wa_final to p_dlf2.
endloop.
close dataset p_dlf2.
endform. " OPENDATA_CLOSE
Where p_dlf2 is the application server file path.
Hope this will Help
Regards
Shibin
Edited by: Shibin on Mar 7, 2008 6:42 AM
‎2008 Mar 07 5:41 AM
Hi,
Use the below statements.
OPEN DATASET : open application server file in OUTPUT, INPUT(read) & APPEND modes.
READ DATASET : Read records from file when it is opened in read mode (INPUT MODE).
TRANSFER : write data to the file when opened in Output & Append mode.
CLOSE DATASET : Close the application server file.
‎2008 Mar 07 5:42 AM
* Audit file read from application server
FORM check_phys_file USING p_file TYPE any.
DATA: l_str(300) TYPE c.
CLEAR l_str.
OPEN DATASET p_file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
READ DATASET p_file INTO l_str.
CLOSE DATASET p_file.
ENDFORM. " check_phys_file
* Audit file download in application server
OPEN DATASET p_ofile_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
CLEAR: wa_local.
LOOP AT p_local_table INTO wa_local.
TRANSFER wa_local TO p_ofile_file.
CLEAR: wa_local.
ENDLOOP.
CLOSE DATASET p_ofile_file.
ELSE.
‎2008 Mar 07 5:47 AM
hi
good
pls check this code
EXCEL to INTERNAL table and then to APPLICATION SEVER
&----
*& Report ZSD_EXCEL_INT_APP
*&
&----
*&
*&
&----
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
start-of-selection.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
thanks
mrutyun^
‎2008 Mar 07 6:27 AM
Hello bharath,
Check out this code:
EPORT Z_CRM_REP_SCORE100 no standard page heading message-id zmsgap.
*&---------------------------------------------------------------------*
*& Type Declaration
*&---------------------------------------------------------------------*
Types: Begin of t_file,
BPEXT type BU_BPEXT, "External Number of Business Partner
NAME_FIRST type BU_NAMEP_F, "First Name
NAME_LAST type BU_NAMEP_L, "Last Name
CITY1 type AD_CITY1, "City
COUNTRY type AD_COMCTRY, "Country
TEL_NUMBER type AD_TLNMBR1, "Telephone Number
End of t_file.
Types: Begin of t_but000, "External Number of Business Partner
PARTNER type BU_PARTNER,
BPEXT type BU_BPEXT,
NAME_FIRST type BU_NAMEP_F, "First Name
NAME_LAST type BU_NAMEP_L, "Last Name
PERSNUMBER type AD_PERSNUM, "Person Number
ADDRCOMM type BU_ADDRCOMM, "Address Number
end of t_but000.
Types: Begin of t_adr2,
ADDRNUMBER type AD_ADDRNUM, "Address Number
PERSNUMBER type AD_PERSNUM, "Person Number
COUNTRY type AD_COMCTRY, "Country
TEL_NUMBER type AD_TLNMBR, "Telephone Number
End of t_adr2.
Types: Begin of t_adrc,
ADDRNUMBER type AD_ADDRNUM, "Address Number
CITY1 type AD_CITY1, "City
End of t_adrc.
*&---------------------------------------------------------------------*
*& Internal tables and Work Areas Declaration
*&---------------------------------------------------------------------*
Data: it_file type standard table of t_file,
wa_file type t_file,
it_sapdata type standard table of t_file,
wa_sapdata type t_file,
it_output type standard table of t_file,
wa_output type t_file,
it_but000 type standard table of t_but000,
wa_but000 type t_but000,
it_adr2 type standard table of t_adr2,
wa_adr2 type t_adr2,
it_adrc type standard table of t_adrc,
wa_adrc type t_adrc.
*Variable Declaration for file path
Data:gv_path type SAPB-SAPPFAD value 'C:\FILE.TXT',
gv_path1 type string value 'file1.txt'.
*Variable Declaration for index.
Data: gv_tabix type sy-tabix.
*Variable Declaration for Line selection.
Data: v_fieldname type BUT000-BPEXT,
v_fieldvalue type BU_BPEXT.
*Calling subroutine to create flat file in application server.
Perform f_file_to_server.
*Calling subroutine to fetch values from flat file into an internal table.
Perform f_dataset.
*&---------------------------------------------------------------------*
*& Event Start-of-Selection.
*&---------------------------------------------------------------------*
Start-of-Selection.
*Calling subroutine to fetch values from table BUT000 into an internal table.
Perform f_select_but000.
*Calling subroutine to fetch values from table ADR2 into an internal table.
Perform f_select_adr2.
*Calling subroutine to fetch values from table ADRC into an internal table.
Perform f_select_adrc.
*&---------------------------------------------------------------------*
*& Event End-of-Selection.
*&---------------------------------------------------------------------*
End-of-Selection.
*Calling subroutine to fill an internal table with SAP data.
Perform f_fill_sapdata.
*Calling subroutine to compare the values between I_SAPDATA and I_FILE.
Perform f_compare.
*&---------------------------------------------------------------------*
*& Event At Line Selection.
*&---------------------------------------------------------------------*
At Line-Selection.
*Checking for list index.
Case sy-lsind.
*When list index is 1.
When '1'.
*Get the value of external number and apss it to the field value..
Get Cursor Field v_fieldname value v_fieldvalue.
*Passing field value to field name.
wa_sapdata-BPEXT = v_fieldvalue.
If v_fieldname = 'WA_SAPDATA-BPEXT'.
*Taking only that value whose External Number exist in the internal table IT_BUT000.
Read Table it_but000 into wa_but000 with key BPEXT = v_fieldvalue binary search.
*Checking if value exist.
If sy-subrc eq 0.
*If it exists then call BP transaction to change the values for that particualr BP according to Aries data.
Set Parameter id 'BPA' FIELD WA_BUT000-partner.
Call Transaction 'BP' and skip first screen..
Endif. "End of Sy-subrc check.
Endif.
Endcase.
*&---------------------------------------------------------------------*
*& Form f_file_to_server
*&---------------------------------------------------------------------*
* This module is used to create flat file in application server
* by using function module ARCHIVFILE_CLIENT_TO_SERVER .
*----------------------------------------------------------------------*
FORM f_file_to_server .
*Calling function module to create flat file in application server.
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
EXPORTING
PATH = GV_PATH
TARGETPATH = 'FILE1.TXT '
EXCEPTIONS
ERROR_FILE = 1
OTHERS = 2.
*checking if file is created successfully
IF SY-SUBRC <> 0.
*If file is not created then display a message.
Message E009.
ENDIF. "End of Sy-subrc check.
ENDFORM. " f_file_to_server
*&---------------------------------------------------------------------*
*& Form f_dataset
*&---------------------------------------------------------------------*
* This module is used to fetch values from flat file,stored in
* application server, into an internal table it_file.
*----------------------------------------------------------------------*
FORM f_dataset .
*Opening file from application server.
Open dataset gv_path1 for input in text mode encoding default.
*Reading the file.
While sy-subrc eq 0.
Read dataset gv_path1 into wa_file.
Append wa_file to it_file.
Clear wa_file.
Endwhile.
*closing the file in application server.
Close dataset gv_path1.
ENDFORM. " f_dataset
*&---------------------------------------------------------------------*
*& Form f_select_but000
*&---------------------------------------------------------------------*
* This module is used to select values from table BUT000 into an
* internal table i_but000.
*----------------------------------------------------------------------*
FORM f_select_but000 .
*Selecting values from table BUT000.
Select PARTNER
BPEXT
NAME_FIRST
NAME_LAST
PERSNUMBER
ADDRCOMM
From but000 into table it_but000
where TYPE = '1'
and BPEXT ne ''
and ADDRCOMM ne ''.
*Checking if values are fetched in the internal table.
If sy-subrc eq 0.
sort it_but000 by BPEXT PERSNUMBER .
Endif. " End of Sy-subrc check.
ENDFORM. " f_select_but000
*&---------------------------------------------------------------------*
*& Form f_select_adr2
*&---------------------------------------------------------------------*
* This module is used to select values from table ADR2 into an
* internal table i_adr2 corresponding to the values in i_but000.
*----------------------------------------------------------------------*
FORM f_select_adr2 .
*Checking if internal table i_but000 is not empty.
If not it_but000[] is initial.
*Selecting values from table ADR2.
Select ADDRNUMBER
PERSNUMBER
COUNTRY
TEL_NUMBER
into table it_adr2
from adr2
for all entries in it_but000
where PERSNUMBER = it_but000-PERSNUMBER.
*Checking if values are fetched in the internal table.
If sy-subrc eq 0.
sort it_adr2 by ADDRNUMBER. " End of Sy-subrc check.
Endif.
Endif. "End of internal table check.
ENDFORM. " f_select_adr2
*&---------------------------------------------------------------------*
*& Form f_select_adrc
*&---------------------------------------------------------------------*
* This module is used to select values from table ADRC into an
* internal table i_adrc on the basis of values in i_adr2.
*----------------------------------------------------------------------*
FORM f_select_adrc .
*Checking if internal table i_but000 is not empty.
If not it_adr2[] is initial.
*Selecting values from table ADRC.
Select ADDRNUMBER
CITY1
from adrc
into table it_adrc
for all entries in it_adr2
where ADDRNUMBER = it_adr2-ADDRNUMBER.
*Checking if values are fetched in the internal table.
If sy-subrc eq 0.
sort it_adrc by ADDRNUMBER. " End of Sy-subrc check.
Endif.
Endif. "End of internal table check.
ENDFORM. " f_select_adrc
*&---------------------------------------------------------------------*
*& Form f_fill_sapdata
*&---------------------------------------------------------------------*
* This module is used to fill values in internal table i_sapdata
* with the values selected from BUT000,ADRC and ADR2.
*----------------------------------------------------------------------*
FORM f_fill_sapdata .
*Checking if internal table it_but000 is not empty.
If not it_but000[] is initial.
Loop at it_but000 into wa_but000.
*Filling the values of internal table IT_BUT000 into workarea of IT_SAPDATA.
wa_sapdata-BPEXT = wa_but000-BPEXT.
wa_sapdata-NAME_FIRST = wa_but000-NAME_FIRST.
wa_sapdata-NAME_LAST = wa_but000-NAME_LAST.
*Taking only those values whose Person Number exist in the internal table IT_ADR2.
Read table it_adr2 into wa_adr2 with key PERSNUMBER = wa_but000-PERSNUMBER Binary Search.
*If value exists then populate those values in work area of IT_SAPDATA.
If sy-subrc eq 0.
wa_sapdata-COUNTRY = wa_adr2-COUNTRY.
wa_sapdata-TEL_NUMBER = wa_adr2-TEL_NUMBER .
*Taking only those values whose Address Number exist in the internal table I_ADRC.
Read table it_adrc into wa_adrc with key ADDRNUMBER = wa_adr2-ADDRNUMBER Binary Search.
*If value exists then populate that value in work area of I_SAPDATA.
If sy-subrc eq 0.
wa_sapdata-CITY1 = wa_adrc-CITY1.
Endif. "End of Sy-subrc Check.
Endif. "End of Sy-subrc Check.
*Inserting workarea of sapdata into its internal table.
Append wa_sapdata to it_sapdata.
*Clearing all workareas.
Clear: wa_adrc,wa_adr2,wa_sapdata.
Endloop.
Endif. "End of internal table check.
*Clearing workarea.
Clear wa_but000.
ENDFORM. " f_fill_sapdata
*&---------------------------------------------------------------------*
*& Form f_compare
*&---------------------------------------------------------------------*
* This module is used to compare values between the Aries data
* and SAP data and display those values which are different.
*----------------------------------------------------------------------*
FORM f_compare .
*Checking if internal table it_sapdata is not empty.
If not it_sapdata[] is initial.
Loop at it_sapdata into wa_sapdata.
*Taking only those values whose External Number exist in the internal table IT_FILE.
Read table it_file into wa_file with key BPEXT = wa_sapdata-BPEXT.
*Comparing the workareas of two internal tables
If wa_sapdata ne wa_file.
*Checking if values of work area donot match then write the header.
Write: / sy-uline(120).
Format color 1.
Write: /1 'External Number' Centered.
Format Hotspot on.
Write: 17 wa_sapdata-BPEXT.
Format Hotspot off.
Write: 47 sy-vline,
48 'Aries data' Centered,
80 sy-vline,
81 'SAP data' Centered,
120 sy-vline.
WRITE: / sy-uline(120).
*Checking if first name in the aries data and SAP data does not match.
If wa_sapdata-NAME_FIRST ne wa_file-NAME_FIRST.
*If it doesnt match then display it using subroutine.
Perform f_write using 'First Name' wa_file-NAME_FIRST wa_sapdata-NAME_FIRST.
Endif. " End of Sy-subrc check.
*Checking if last name in the aries data and SAP data does not match.
If wa_sapdata-NAME_LAST ne wa_file-NAME_LAST.
*If it doesnt match then display it using subroutine.
Perform f_write using 'Last Name' wa_file-NAME_LAST wa_sapdata-NAME_LAST.
Endif. " End of Sy-subrc check.
*Checking if city in the aries data and SAP data does not match.
If wa_sapdata-CITY1 ne wa_file-CITY1.
*If it doesnt match then display it using subroutine.
Perform f_write using 'City' wa_file-CITY1 wa_sapdata-CITY1.
Endif. " End of Sy-subrc check.
*Checking if country in the aries data and SAP data does not match.
If wa_sapdata-COUNTRY ne wa_file-COUNTRY.
*If it doesnt match then display it using subroutine.
Perform f_write using 'Country' wa_file-COUNTRY wa_sapdata-COUNTRY.
Endif. " End of Sy-subrc check.
*Checking if phone number in the aries data and SAP data does not match.
If wa_sapdata-TEL_NUMBER ne wa_file-TEL_NUMBER.
*If it doesnt match then display it using subroutine.
Perform f_write using 'Phone Number' wa_file-TEL_NUMBER wa_sapdata-TEL_NUMBER.
Endif. " End of Sy-subrc check.
Endif. "End of Equality check.
Endloop.
*Clearing workareas.
Clear: wa_sapdata, wa_file.
Endif. "End of internal table check.
ENDFORM. " f_compare
*&---------------------------------------------------------------------*
*& Form f_write
*&---------------------------------------------------------------------*
* This module is used to display the field names which has been
* changed in SAP from Aries data.
*----------------------------------------------------------------------*
* -->P_field_name text
* -->P_Aries_data text
* -->P_SAP_data text
*----------------------------------------------------------------------*
FORM f_write USING VALUE(P_field_name)
VALUE(P_Aries_data)
VALUE(P_SAP_data).
Format color 2.
Write : /1 P_field_name,
47 sy-vline.
Format color off.
Write: 48 P_Aries_data,
80 sy-vline,
81 P_SAP_data,
120 sy-vline.
WRITE: / sy-uline(120).
ENDFORM. " f_write
Please reward points if helpful.
Regards,
Aditi