‎2013 Jun 06 6:56 PM
Hi Experts,
I have never worked on the file download upload onto application server.
now i have a requirement like the report selection screen has 2 fields and email field ( where the user should be able to enter multiple rows ) on the selection screen .
Hence based on the two selection screen field couple of records needs to be picked up from KNKK table.. now this content should be downloaded as below into a flat file on the application server.
VERSION;10.1
EMAIL;RESPONSE;abc@email.com
ADD;SALARYFEED;Field1.1;Field1.2;Field1.3
ADD;SALARYFEED;Field2.1;Field2.2;Field2.3
ADD;SALARYFEED;Field3.1;Field3.2;Field3.3
ADD;SALARYFEED;Field4.1;Field4.2;Field4.3
I dont understand how to achieve this..
I have couple of doubts now..
1) when it is said download file onto the application server.. what exactly it means..
i am now selecting the data into an internal table and now i am looping the table and transferring the content into the filepath .. it is throwing run time error with the below exception..
Kindly guide what needs to be done
Thanks and Regards,
Swarnadeepta
‎2013 Jun 06 8:04 PM
Hi,
could you past your code where you made your OPEN DATASET ?
regards
Fred
‎2013 Jun 06 9:24 PM
Hi please find the below code ,
START-OF-SELECTION.
perform select_data.
if gt_knkk is NOT initial.
perform save_file.
endif.
FORM select_data .
SELECT kunnr
kkber
klimk
knkli
skfor FROM knkk INTO TABLE gt_knkk
WHERE kkber IN s_area
AND knkli IN s_accnt.
ENDFORM. " SELECT_DATA
FORM save_file .
DATA : lv_data TYPE string,
lv_file LIKE gv_file,
lv_name TYPE string VALUE 'test.txt',
lv_email TYPE string,
lv_knkli TYPE char20,
lv_klimk TYPE char20,
lv_skfor TYPE char20.
DATA : lc_add TYPE char10 VALUE 'ADD',
lc_mod TYPE char10 VALUE 'MODIFY',
lc_del TYPE char10 VALUE 'DELETE'.
gv_file = 'QR1\SAP_HR\ST\AR\'.
CONCATENATE gv_file lv_name INTO gv_file.
IF rb_add = 'X'.
OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
TRANSFER 'VERSION : 10.1' TO gv_file.
CONCATENATE 'EMAIL RESPONSE' s_email-low INTO lv_email.
TRANSFER lv_email TO gv_file.
LOOP AT gt_knkk INTO gs_knkk.
lv_klimk = gs_knkk-klimk.
lv_knkli = gs_knkk-knkli.
lv_skfor = gs_knkk-skfor.
CONCATENATE lc_add
'SALARYFEED'
lv_klimk
lv_knkli
lv_skfor
INTO lv_data SEPARATED BY ';'.
TRANSFER lv_data TO gv_file.
CLEAR : gs_knkk,lv_klimk,lv_knkli,lv_skfor.
ENDLOOP.
CLOSE DATASET lv_file.
ENDIF.
ENDFORM. " SAVE_FILE
‎2013 Jun 07 12:50 AM
Hi,
I think it will be OPEN DATASET FOR INPUT..
Cheers,
Arindam
‎2013 Jun 07 6:49 AM
Hi Swarnadeepta,
To download the file into the application server, there are three steps to be followed.
To open the file use the below statement.
Step1: OPEN DATASET <file name> FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
To write into the file use.
Step2: TRANSFER name TO <file name>.
Dont forget to close the file once it is transferred.
Step3: CLOSE DATASET <file name>.
‎2013 Jun 07 6:53 AM
Arindam Mondal wrote:
Hi,
I think it will be OPEN DATASET FOR INPUT..
Cheers,
Arindam
Wrong.
‎2013 Jun 07 7:20 AM
Hi Swarnadeepta,
You are getting this error because you haven't closed your file.
check your close dataset statement.It should be gv_file not lv_file.
Thanks & Regards
Shravan
‎2013 Jun 06 8:45 PM
Hi Padhi,
Check the following SAP help document on Files; For writing file you should open the file in OUTPUT mode, check and correct that as per help document;
http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3c7f358411d1829f0000e829fbfe/content.htm
Hope this helps.
Regards,
Karthik
‎2013 Jun 07 4:24 AM
Hi,
Some of the points to be taken care while writing file to an application server,
1) Make sure that you are giving correct file path.
2) You must have the authorization to read/write files in AL11.
Hope this helps,
~Athreya
‎2013 Jun 07 7:24 AM
‎2013 Jun 07 10:18 AM
‎2013 Jun 07 10:27 AM
Hi Padhi,
Go through the below code to upload the data to Application server,
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TO_APPLN_SERVER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_to_appln_server.
DATA: lt_out TYPE TABLE OF string,
lv_out(5000) TYPE c,
lv_get(100) TYPE c,
lv_get1(100) TYPE c.
FIELD-SYMBOLS: <fs> TYPE ANY. "CCheck
"PERFORM it_move_data.
PERFORM fieldinfo_get.
IF gt_app[] IS NOT INITIAL.
LOOP AT gt_app INTO gwa_app. "This is your final table which has data
CLEAR: lv_out.
DO.
CLEAR lv_get.
ASSIGN COMPONENT sy-index OF STRUCTURE gwa_app TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1. "To avoid 1st column check box and MANDT
lv_out = <fs>.
ELSE.
lv_get = <fs>.
CONCATENATE lv_out
lv_get
INTO lv_out SEPARATED BY gv_tab.
ENDIF.
ENDDO.
APPEND lv_out TO lt_out.
ENDLOOP.
IF p_app CA '.'.
CLEAR gv_ap_path.
lv_get1 = p_app. "Here you should pass your application server path
CLEAR lv_get1+0(16)."for my scenario's i do some thing
CONDENSE lv_get1 NO-GAPS.
CONCATENATE gv_path lv_get1 INTO gv_ap_path.
ELSE.
MESSAGE s001(zgen) WITH text-044.
ENDIF.
OPEN DATASET gv_ap_path FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
IF sy-subrc <> 0.
MESSAGE text-009 TYPE 'I' DISPLAY LIKE 'W'.
* MESSAGE s001(zgen) WITH text-009
* gv_ap_path. ""#EC * "CCheck
CLOSE DATASET gv_ap_path.
EXIT.
ELSE.
TRANSFER gv_header TO gv_ap_path.
LOOP AT lt_out INTO lv_out.
TRANSFER lv_out TO gv_ap_path.
ENDLOOP.
ENDIF.
ENDIF.
MESSAGE s001(zgen) WITH text-040.
CLOSE DATASET gv_ap_path.
ENDFORM. " DOWNLOAD_TO_APPLN_SERVER
*&---------------------------------------------------------------------*
*& Form FIELDINFO_GET Here you will pass the each field header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fieldinfo_get .
TYPES text TYPE c LENGTH 50.
DATA: lt_text TYPE TABLE OF text.
APPEND text-010 TO lt_text.
APPEND text-011 TO lt_text.
APPEND text-012 TO lt_text.
APPEND text-013 TO lt_text.
APPEND text-014 TO lt_text.
APPEND text-015 TO lt_text.
APPEND text-016 TO lt_text.
APPEND text-017 TO lt_text.
APPEND text-018 TO lt_text.
APPEND text-019 TO lt_text.
APPEND text-020 TO lt_text.
APPEND text-021 TO lt_text.
APPEND text-022 TO lt_text.
APPEND text-023 TO lt_text.
APPEND text-024 TO lt_text.
APPEND text-025 TO lt_text.
APPEND text-026 TO lt_text.
APPEND text-027 TO lt_text.
APPEND text-028 TO lt_text.
APPEND text-029 TO lt_text.
APPEND text-030 TO lt_text.
APPEND text-031 TO lt_text.
APPEND text-032 TO lt_text.
APPEND text-033 TO lt_text.
APPEND text-034 TO lt_text.
APPEND text-035 TO lt_text.
APPEND text-036 TO lt_text.
APPEND text-037 TO lt_text.
CONCATENATE LINES OF lt_text INTO gv_header SEPARATED BY gv_tab.
ENDFORM. " FIELDINFO_GET
I hope this will helpful to you.
Be careful while passing the application server path because that is case sensitive,
1 Small letter should be in small
2 Capital letter should be in Caps
Don't forget the above conditions,
Warm Regards,
John.
‎2013 Jun 07 12:33 PM
Hi ..
I am now able to download the file but everything is coming as one line..
VERSION;10.1EMAIL;RESPONSE;abc@email.com;pqr@mail.comADD;SALARYFEED;Field1.1;Field1.2;Field1.3
How to transfer the lines one by one.. like below..
VERSION;10.1
EMAIL;RESPONSE;abc@email.com;pqr@mail.com
ADD;SALARYFEED;Field1.1;Field1.2;Field1.3
ADD;SALARYFEED;Field2.1;Field2.2;Field2.3
ADD;SALARYFEED;Field3.1;Field3.2;Field3.3
ADD;SALARYFEED;Field4.1;Field4.2;Field4.3
Thanks and Regards,
Swarnadeepta
‎2013 Jun 07 12:49 PM
Hi Swarna,
Use transfer dataset inside loop...endloop to transfer line by line.
‎2013 Jun 07 12:58 PM
But that should be printed once only..
i am transferring Version 10.1 to <filepath>
then transferring email address to <filepath>.
then looping the content of the itab and transferring the content to <filepath>
This is how it is done right ?
Regards,
Swarna
‎2013 Jun 10 10:50 AM
Hi Swarnadeepta,
OPEN DATASET lv_file.
LOOP AT <Your Itable as itab> INTO <Your Work area as wa>.
at new wa-emailid.
wa1-version = wa-version
wa1-mailid = wa-emailid.
endat.
Here you can pass the other data as per your condition.
TRANSFER <wa1> TO <file path>.
CLEAR Everything here.
ENDLOOP.
CLOSE DATASET lv_file.
I hope this will solve your problem.
Warm Regards,
John.
‎2013 Jun 10 11:13 AM
Hi,
The error 'CX_SY_FILE_OPEN_MODE' means that the program failed to open the file at the specified filepath. the probable reasons could be wrong file path or missing authorization. Check for sy-subrc after the open dataset statement.
Thanks,
Neha
‎2013 Jun 20 3:41 PM
Yes .. It was related to the file opening .. the program was not able to find the exact file path.. hence it was throwing the above dump .
Thanks ..
Swarnadeepta.
‎2013 Jun 20 3:54 PM
Sorry i got to be late in replying the post. I solved the issue..
till my last post i was facing the issue that everything was coming in one line but it gt resolved by using
OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH WINDOWS LINEFEED .
the underlined key word has to be added to the above open dataset statement as an end marker..
Hope people facing the same problem like mine , may get a solution from this .
Thanks all for posting various solutions..,
Regards,
Swarnadeepta.