Dump on OPEN DATASET ; TRANSFER stmt
p_name is the file name parameter
FORM APPL_TRAN.
file = p_name.
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
CLEAR wa_final.
Loop through the internal table which has the ECC data and transfer it to the file.
LOOP AT it_final into wa_final.
TRANSFER wa_final to file.
CLEAR wa_final.
ENDLOOP.
*Close the file.
CLOSE DATASET file.
ENDIF.
ENDFORM. "APPL_TRAN
I'm getting a short dump when the stmt TRANSFER is executed.
The Error Analysis is as follows:
For the statement
"TRANSFER f TO ..."
only character-type data objects are supported at the argument position
"f".
In this case. the operand "f" has the non-character-type "TY_ECC2". The
current program is a Unicode program. In the Unicode context, the type
'X' or structures containing not only character-type components are
regarded as non-character-type.
Can someone please help me in this regard.
Thanks,
FS
hi,
ur internal table it_final declaration is like this
data : begin of it_final occurs 0,
matnr(18),
werks(4),
end of it_final.
in this situation ur statement
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
works then u wont get any dump in transfer statement.
so u replace
OPEN DATASET file FOR OUTPUT IN BINARY MODE .
it works.
regards
siva
Similar Messages
-
Data transfer error open dataset files
hi,
When i try to create a excel or text in my application server using open dataset.
i.e
l_filename type rlgrap-filename value '/tmp/down.txt'.
I got a short dump during the run time
i got the output and put into an internal table.
the following code has been used.
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
if r_ucomm = 'confirm' .
OPEN DATASET l_fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT it_out INTO wa_out.
IF sy-subrc = 0.
TRANSFER wa_out TO l_filename.
ENDIF.
ENDLOOP.
endform.
during the execution i hv a button alv grid outpu. when i click the button the file should be transferred.
but NO authorization to open the file "/tmp/down.txt".
and the error is pointed in the opendataset line.
Please tell me where i am wrong . and help me in resoving this.Try this..instead of moving field by field into the file 1st convert all he fields to a character stream..and then move that steam to file. Ex:
loop at internal table into l_h_tbl_file.
concatenate l_h_tbl_file-f1 l_h_tbl_file-f2 l_h_tbl_file-f3
l_h_tbl_file-f4 l_h_tbl_file-f5 into g_string.
TRANSFER g_string TO fu_wk_get_file.
endloop. -
hi guys,
I am getting OPEN DATASET SHORTDUMP using below code.
can somebody suggest me alteration of code..
Dump says error in READ statement.
DATA : BEGIN OF IT_EDIT OCCURS 0,
CNO(5) TYPE C,
DATE(8) TYPE C,
VENDOR(10) TYPE C,
MATERIAL(18) TYPE C,
STARTDT(8) TYPE C,
ENDDT(8) TYPE C,
QUANTITY(13) TYPE N,
END OF IT_EDIT.
OPEN DATASET P_INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
IF NOT SY-SUBRC IS INITIAL.
EXIT.
ELSE.
<b> READ DATASET P_OUFILE INTO IT_EDIT.</b>
APPEND IT_EDIT.
ENDIF.
ENDDO.
CLOSE DATASET P_OUFILE.
Regards
Chandra.hi,
pls chk this sample code.
report zfiles_0001.
Parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt',
d2 type localfile default '/usr/sap/TST/SYS/Data2.txt'.
data: itab type table of string.
data: wa type string.
start-of-selection.
Read file
open dataset d1 for input in text mode.
if sy-subrc = 0.
do.
read dataset d1 into wa.
if sy-subrc <> 0.
exit.
endif.
append wa to itab.
enddo.
endif.
close dataset d1.
Copy to new file
open dataset d2 for output in text mode.
loop at itab into wa.
transfer wa to d2.
endloop.
close dataset d2.
Delete the first
delete dataset d1.
regards
anver
if hlpful pls mark points -
Hi all,
I open Dataset in Text Mode with default encoding and trying to transfer data from an internal table to TEXT file in application server.
But my internal table has 1 numeric field, so while transfering i am getting error stating: "cannot write Non-chracter field".
So, is there any way to write Non-character fields also using same OPEN Dataset and TRANSFER Statements.
Help will be rewarded.
SachinHi Saching..
As per UNICODE We cannot transfer Numeric fields to file .
So We must convert the Record to Character format.
This is the Modified code. Changes are in BOLD.
TABLES: ZSACHIN_STUDENT.
PARAMETERS:
OUTFILE(20) DEFAULT 'sachin_test.txt'
LOWER CASE.
TYPES: BEGIN OF st_student,
ID TYPE ZSACHIN_STUDENT-ID,
NAME TYPE ZSACHIN_STUDENT-NAME,
ADDRESS TYPE ZSACHIN_STUDENT-ADDRESS,
STATE TYPE ZSACHIN_STUDENT-STATE,
CITY TYPE ZSACHIN_STUDENT-CITY,
STATUS TYPE ZSACHIN_STUDENT-STATUS,
END OF st_student.
DATA : it_student TYPE STANDARD TABLE OF st_student,
it_student_wa TYPE st_student.
<b>DATA: V_RECORD(200) TYPE C.</b>
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE encoding default.
IF sy-subrc <> 0.
message e001(z_error).
endif.
SELECT * FROM ZSACHIN_STUDENT INTO
CORRESPONDING FIELDS OF TABLE it_student.
<b>LOOP AT it_student INTO it_student_wa.
<b>CONCATENATE IT_student_wa-name
IT_student_wa-address
IT_student_wa-state
IT_student_wa-city
IT_student_wa-status
INTO V_RECORD
SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
TRANSFER V_RECORD TO OUTFILE.</b>
ENDLOOP.</b>
CLOSE DATASET OUTFILE.
Here SEPARATED BY is for generating TAB delimiter .
<b>Reward if Helpful</b> -
File transfer Open dataset CSV file Problem
Hi Experts,
I have an issue in transferring Korean characters to a .CSV file using open dataset.
data : c_file(200) TYPE c value '
INTERFACES\In\test8.CSV'.
I have tried
open dataset c_file for output LEGACY TEXT MODE CODE PAGE '4103'.
open dataset c_file for output in TEXT MODE ENCODING NON-UNICODE.
open dataset c_file for output in TEXT MODE ENCODING Default.
Nothing is working.
But to download to the presentation server the below code is working. How can the same be achieved for uploading the file to application server.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = 'D:/test123.xls'
filetype = 'ASC'
write_field_separator = 'X'
dat_mode = 'X'
codepage = '4103'
write_bom = 'X'
CHANGING
data_tab = t_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.Hi,
I would recommend to use OPEN DATASET ... ENCODING UTF-8 ...
If your excel version is unable to open this format, you can convert from 4110 to 4103 with report RSCP_CONVERT_FILE.
Please also have a look at
File upload: Special character
Best regards,
Nils Buerckel -
Regarding Transfer statement in OPEN DATASET
Hi All,
I am calling call transformation statement twice in my program and creating 2 xml files.
One as lv_xml_string
Second one as lv_xml_string1.
When i transferred the first xml file using open dataset to the application server its coming fine.
When i am trying to send the second one it is appending to the first one.
I want output 2 files not as single one.
Can anyone suggest me what to do?
ThanksThanks for the reply.
I did that but i cannot see the first file. It is writing the second file.
I need 2 xml files in the output
Any other advice please? -
OPEN DATASET FILENAME FOR OUTPUT.
HI,
While doing unicode enable inECC6.0 FOLLOWING ERROR IS COMING.hOW IT WILL BE RESOLVED.
oPEN DATASET physname FOR OUTPUT.Hello,
For opendataset u need to add the below coding.
open dataset 'filename' for output in text mode encoding default. ( Based on ur filetype)
binary mode encoding default
if it not a unicode system then non unicoding must be added.
N.B
In the Transfer stmt the data types apart from CNDT will result dump.
So please ensure that all are of CNDT types.
With Regards,
Sumodh.P -
How to open a pdf file using OPEN DATASET
Im trying to convert a pdf into binary format. So im trying to read the contents of the pdf into a XSTRING. Using the FM 'SCMS_XSTRING_TO_BINARY' i can convert the XSTRING to binary format.
How to open a pdf file using OPEN DATASET and transfer its contents in a XSTRING variable.
What i've tried is....
DATA: f_name type string value 'C:\rep_output_pdf.pdf',
x1 type xstring,
LT_DATA TYPE STANDARD TABLE OF X255.
OPEN DATASET f_name FOR input IN BINARY MODE.
READ DATASET f_name INTO x1.
CLOSE DATASET f_name.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = x1
TABLES
BINARY_TAB = LT_DATA.
Im getting a short dump .
Short text: The file is not open.
Plz help me out.Hello Rajesh,
You are trying to do use OPEN DATASET with a local file. NOT POSSIBLE
You have to have the file in the app server to use OPEN DATASET.
BR,
Suhas -
Open dataset in ECC 6.0 passes AUTHORITY_CHECK but still fails to download
Hello Gurus,
I'm having trouble getting open dataset to work in ECC 6.0.
I've tried using encoding utf-8 and default plus an authority check.
The program doesn't abap dump, but nothing happens.
Am I doing something wrong?
DATA: my_full_path_auth LIKE authb-filename .
my_full_path_auth = 'c:\temp\inv_coverage_by_material.txt'.
MESSAGE i001(zstd) WITH 'converting itab to characters'.
REFRESH ta_by_part_number_ascii.
LOOP AT pta_out INTO ts_by_part_number .
MOVE-CORRESPONDING ts_by_part_number
TO ts_by_part_number_ascii.
APPEND ts_by_part_number_ascii TO ta_by_part_number_ascii.
ENDLOOP.
MESSAGE i001(zstd) WITH 'convertion complete'.
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
* PROGRAM =
activity = 'WRITE'
filename = my_full_path_auth
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3 .
IF sy-subrc <> 0.
MESSAGE i001(zstd) WITH 'authority check failed'.
ELSE.
MESSAGE i001(zstd) WITH 'authority check PASSED'.
ENDIF.
OPEN DATASET my_full_path FOR OUTPUT
IN TEXT MODE ENCODING DEFAULT .
LOOP AT ta_by_part_number_ascii INTO ts_by_part_number_ascii .
TRANSFER ts_by_part_number_ascii TO my_full_path.
ENDLOOP.
CLOSE DATASET my_full_path.Ahhh. I forgot that the file is saved on the app server.
New question:
I was trying to do a download of an internal table in batch mode. The GUI_DOWNLOAD function won't work for that.
What do people do to download a file to the presentation server?
Moderator message - Please limit yourself to one question per thread. That makes it easier for others to find solutions to their similar problems.
So please close this one and ask a new question
Edited by: Rob Burbank on Apr 14, 2009 1:12 PM -
CG3Z working not open dataset for output
Hi,
I am trying to upload data into the application server for which m using the OPEN DATASET statement. My file name is as follows in lowercase.
p_file = '/usr/upi/out/test_20100220.dat'. TYPE c.
While trying to execute this i am getting a short dump 'DATASET_NOT OPEN'.
I tried to upload a file through tcode CG3Z with the same file path and its working fine whereas through the below code its not working at all.
open DATASET w_filename_unix for INPUT in TEXT MODE ENCODING DEFAULT.
LOOP AT i_fieldnames INTO wa_fieldnames.
TRANSFER wa_fieldnames TO w_filename_unix.
ENDLOOP.
LOOP AT i_output INTO wa_output.
TRANSFER wa_output TO w_filename_unix.
ENDLOOP.
if sy-subrc NE 0.
WRITE: 'Error'.
ENDIF.
CLOSE DATASET w_filename_unix.
Please help.
Regards herwin..hii,
Why is it W_filename...??? it should be p_file ...... after opendataset... -
Fetch excel file from app. server using open dataset...
Hello Experts,
Our functional consultant is asking me if it possible to get an excel file from the
application server file using OPEN dataset and in background mode? If yes, Please tell me on how to do this.
Thank you guys and take care!Hi Viraylab,
to download this the procedure:
you can use the FM 'EXCEL_OLE_STANDARD_DAT ' for this purpose.
this FM 'EXCEL_OLE_STANDARD_DAT' can be used to start Excel with a new sheet and transfer data from an internal table to the sheet.
Here are some of the parameters:
file_name: Name and path of the Excel worksheet file e.g. ?C:TEMPZTEST?
data_tab: Name of the internal table that should be uploaded to Exvcel
fieldnames: Internal tabel with column headers
How to build the field names table:
data: begin of i_fieldnames occurs 20,
field(60), end of i_fieldnames.
i_fieldnames-field = ?This is column 1?. append i_fieldnames-field.
i_fieldnames-field = ?This is column 2?. append i_fieldnames-field.
to upload follow this:
OPEN DATASET dsn FOR INPUT IN BINARY MODE.
DO.
READ DATASET dsn INTO itab-field.
IF sy-subrc = 0.
APPEND itab.
ELSE.
EXIT.
ENDIF.
ENDDO.
[/code]Rob
or Try this function module.
FILE_READ_AND_CONVERT_SAP_DATA
pass 'XLS' to I_FILEFORMAT..
Dont forgot to Reward me points .....All the very best....
Regards,
Sreenivasa sarma K. -
Open dataset and close dataset
Hi
I need to write log file in fileshare.
I am using the following FM to create the file.
Z_FILE_OPEN_OUT_UNICODE'
I have following qns
1. do i need to use open dataset and close dataset stmts, even I create the files with the FM?Hi,
you can fill in the name of the FM in transaction SE37, then click 'Display' and look at the source code and the 'Tables' tab.
It's a custom build FM, so you might have to look at the import parameters it needs... ( Tab 'Import' and 'Tables' ).
To answer your question, as the name of the FM suggests it will write the file for you, so no open/close dataset. Please doublecheck tab 'Source code' and you might find these statements there...
hope that helps,
Rolf -
Open dataset......
Hi Folks,
I am trying to get some data using Open dataset.The program is not showing any errors and executing fine,but I was not able to find the data that I am going to get using OPEN DATASET.Where will I be able to see the data.In the given path there is no file downloaded.Kindly let me know.
run the program
enter some data in the blank fields of the alv
save it
now double click on the qty1 field in the alv.
Thanks,
K.Kiran.
REPORT zlabel.
TYPE-POOLS:slis,icon.
TABLES:makt.
*Declarations for ALV
DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA:itfieldcat1 TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA:itprintparams TYPE slis_print_alv.
DATA:itrepid TYPE sy-repid.
itrepid = sy-repid.
DATA:itevent TYPE slis_t_event.
DATA:itlistheader TYPE slis_t_listheader.
DATA:walistheader LIKE LINE OF itlistheader.
DATA:itlayout TYPE slis_layout_alv.
DATA:top TYPE slis_formname.
DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA : grid TYPE REF TO cl_gui_alv_grid.
*Declaration for DSN
<b>DATA : file(50) VALUE 'E:\userdata\labelfiles'.</b>
DATA : dsn(150).
DATA : dsn1(100).
DATA : n1(4) TYPE n.
*Declarations for Internal tables.
DATA:BEGIN OF imakt OCCURS 0,
matnr LIKE makt-matnr,
spras LIKE makt-spras,
maktx LIKE makt-maktx,
label1(03) TYPE c,
qty1(03) TYPE c,
label2(03) TYPE c,
qty2(03) TYPE c,
END OF imakt.
DATA:ITFINAL LIKE imakt OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:matnr FOR makt-matnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM getdata.
IF sy-subrc = 0.
PERFORM alv.
ELSE.
STOP.
ENDIF.
*& Form getdata
text
FORM getdata.
SELECT matnr
spras
maktx
FROM makt
INTO CORRESPONDING FIELDS OF TABLE imakt
WHERE spras = sy-langu.
ENDFORM. "getdata
*& Form ALV
text
FORM alv.
DEFINE m_fieldcat.
itfieldcat-fieldname = &1.
itfieldcat-col_pos = &2.
itfieldcat-seltext_l = &3.
itfieldcat-do_sum = &4.
itfieldcat-outputlen = &5.
itfieldcat-edit = &6.
append itfieldcat to itfieldcat.
clear itfieldcat.
END-OF-DEFINITION.
m_fieldcat 'MATNR' '' 'MATERIAL No' '' 18 ''.
m_fieldcat 'SPRAS' '' 'Language' '' 02 ''.
m_fieldcat 'MAKTX' '' 'Description' '' 40 ''.
m_fieldcat 'LABEL1' '' 'LABEL1' '' 12 'X'.
m_fieldcat 'QTY1' '' 'QTY1' '' 12 'X'.
m_fieldcat 'LABEL2' '' 'LABEL2' '' 12 'X'.
m_fieldcat 'QTY2' '' 'QTY2' '' 12 'X'.
itlayout-zebra = 'X'.
itlayout-colwidth_optimize = 'X'.
itlayout-no_subtotals = ' '.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = itlayout
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'LIST1'
i_callback_top_of_page = 'TOP'
it_fieldcat = itfieldcat[]
i_save = 'X'
is_variant = ITVARIANT
it_events = itevent[]
is_print = itprintparams
it_sort = itsort[]
TABLES
t_outtab = imakt
EXCEPTIONS
program_error = 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.
CLEAR itfieldcat.
ENDFORM. "ALV
*& Form list1
text
-->R_UCOMM text
-->RS_SELFIELDtext
FORM list1 USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN 'EXIT'.
STOP.
ENDCASE.
CLEAR itfieldcat1.
REFRESH itfieldcat1.
DEFINE k_fieldcat.
itfieldcat1-fieldname = &1.
itfieldcat1-col_pos = &2.
itfieldcat1-seltext_l = &3.
itfieldcat1-outputlen = &4.
append itfieldcat1 to itfieldcat1.
clear itfieldcat1.
END-OF-DEFINITION.
k_fieldcat 'MATNR' '' 'MATERIAL No' 18 .
k_fieldcat 'SPRAS' '' 'Language' 02 .
k_fieldcat 'MAKTX' '' 'Description' 40 .
k_fieldcat 'LABEL1' '' 'LABEL1' 12 .
k_fieldcat 'QTY1' '' 'QTY1' 12 .
k_fieldcat 'LABEL2' '' 'LABEL2' 12 .
k_fieldcat 'QTY2' '' 'QTY2' 12 .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = itlayout
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'LIST2'
i_callback_top_of_page = 'TOP'
it_fieldcat = itfieldcat1[]
i_save = 'X'
is_variant = ITVARIANT
it_events = itevent[]
is_print = itprintparams
it_sort = itsort[]
TABLES
t_outtab = imakt
EXCEPTIONS
program_error = 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.
CLEAR:itfieldcat1,itfieldcat.
ENDFORM. "list1
*& Form list2
text
-->R_UCOMM text
-->RS_SELFIELDtext
FORM list2 USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
IF rs_selfield-fieldname = 'QTY1'.
LOOP AT IMAKT.
<b>CONCATENATE file n1 '.PJ' INTO dsn.</b>
<b> PERFORM DSN.</b>
CLEAR DSN.
N1 = N1 + 1.
ENDLOOP.
ENDIF.
ENDCASE.
ENDFORM. "list2
*& Form top
text
FORM top.
DATA:title(70) TYPE c.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = itevent
EXCEPTIONS
LIST_TYPE_WRONG = 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.
title = 'LABEL'.
walistheader-typ = 'H'.
walistheader-info = title.
APPEND walistheader TO itlistheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = itlistheader
I_LOGO = ''.
I_END_OF_LIST_GRID =
CLEAR itlistheader.
ENDFORM. "TOP
*& Form DSN
text
--> p1 text
<-- p2 text
<b>form DSN .</b>
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
<b>LEAVE TO LIST-PROCESSING</b>
<b>WRITE:/ 'FILE COULD NOT BE OPENED'.</b>
EXIT.
ENDIF.
MOVE-CORRESPONDING IMAKT TO ITFINAL.
APPEND ITFINAL.
TRANSFER 'MDA.LBL' TO dsn.
TRANSFER '1' TO dsn.
TRANSFER: ITFINAL-MATNR TO DSN,
ITFINAL-SPRAS TO DSN,
ITFINAL-MAKTX TO DSN,
ITFINAL-LABEL1 TO DSN,
ITFINAL-QTY1 TO DSN,
ITFINAL-LABEL2 TO DSN,
ITFINAL-QTY2 TO DSN.
<b>if sy-subrc <> 0.</b>
write:/ 'Check your code'.
endif.
CLOSE DATASET DSN.
ENDFORM.Hi Kiran,
To my understanding your file is not being created cause you have not passed a location for your file to be put. Refer to my below code you see how its done.
If you need more info let me know.
TYPES DECLARATIONS *
*Data type for Accounting Document Header Table
TYPES: BEGIN OF gt_bkpf,
bukrs TYPE bkpf-bukrs, "Company Code
belnr TYPE bkpf-belnr, "Accounting Document Number
gjahr TYPE bkpf-gjahr, "Fiscal Year
budat TYPE bkpf-budat, "Posting Date
END OF gt_bkpf.
*Data type for Accounting Document Segment Table
TYPES: BEGIN OF gt_bseg,
bukrs TYPE bkpf-bukrs, "Company Code
belnr TYPE bkpf-belnr, "Accounting Document Number
gjahr TYPE bkpf-gjahr, "Fiscal Year
buzei TYPE bseg-buzei , "Line Item
shkzg TYPE bseg-shkzg , "Debit/Credit Indicator
wrbtr TYPE bseg-wrbtr , "Amount in document currency
kostl TYPE bseg-kostl , "Cost Center
aufnr TYPE bseg-aufnr , "Project / Order Number
hkont TYPE bseg-hkont , "General Ledger Account Key
prctr TYPE bseg-prctr , "Profit Center
segment TYPE bseg-segment, "Segment
END OF gt_bseg.
*Data type for Posting Summary Table of given file format
TYPES: BEGIN OF gt_posting_summary,
effective_date(10) TYPE c, "Date of last tuesday
company_code(4) TYPE c, "Company Code
gl_key(6) TYPE c, "General Ledger Account Key
cost_centre(10) TYPE c, "Cost Center
profit_centre(10) TYPE c, "Profit Center
project(12) TYPE c, "Order Number
segment(10) TYPE c, "Segment for Segmental Reporting
amount(16) TYPE c, "Amount with minor denomination & debit/credit indicator
END OF gt_posting_summary.
INTERNAL TABLE DECLARATIONS *
DATA:
*Internal table for Accounting Document Header Table
gi_bkpf TYPE STANDARD TABLE OF gt_bkpf,
*Internal table for Accounting Document Segment Table
gi_bseg TYPE STANDARD TABLE OF gt_bseg,
*Internal table for Posting Summary Table of given file format
gi_posting_summary TYPE STANDARD TABLE OF gt_posting_summary.
RANGES DECLARATIONS *
DATA:
*Building ranges table for last saturday to current date
gr_date TYPE RANGE OF sy-datum.
WORK AREA DECLARATIONS *
DATA:
*Work area for Accounting Document Segment Table
gwa_bseg TYPE gt_bseg,
*Work area for Accounting Document Segment Table
gwa_bkpf TYPE gt_bkpf,
*Work area for Posting Summary Table of given file format
gwa_posting_summary TYPE gt_posting_summary,
*Work area for ranges table for last saturday to current date
gwa_date LIKE LINE OF gr_date.
GLOBAL VARIABLE DECLARATIONS *
DATA: gv_to_date TYPE sy-datum,
gv_from_date TYPE sy-datum,
gv_effective_date(10) TYPE c,
gv_posting_amount(16) TYPE c,
gv_file_name TYPE string,
gv_server_file_name TYPE fileextern,
gv_suspense_accnt TYPE hkont,
gv_amount TYPE wrbtr.
GLOBAL CONSTANT DECLARATIONS *
DATA: gc_x TYPE c VALUE 'X',
gc_s TYPE bseg-shkzg VALUE 'S',
gc_h TYPE bseg-shkzg VALUE 'H',
gc_i TYPE tvarv-sign VALUE 'I',
gc_bt TYPE tvarv-opti VALUE 'BT',
gc_ys TYPE bkpf-blart VALUE 'YS',
gc_zfii0431 TYPE filepath-pathintern VALUE 'ZFII0431',
gc_debit TYPE c VALUE '+',
gc_credit TYPE c VALUE '-',
gc_dot TYPE c VALUE '.',
gc_suspense_key TYPE zglkey VALUE 'SUSPENSE_GL_ACCOUNT'.
Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECTION-SCREEN SKIP 1.
*Accounting Document type for eSFA postings
PARAMETERS : p_ys TYPE bkpf-blart DEFAULT gc_ys.
SELECTION-SCREEN SKIP 1.
*Logical Path of file to be downloaded on Application Server
PARAMETERS : p_l_path TYPE filepath-pathintern DEFAULT gc_zfii0431.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
SELECT-OPTIONS : s_date FOR sy-datum .
SELECTION-SCREEN END OF BLOCK b2.
ON LOAD EVENT - Occurs only once, when the program is loaded *
LOAD-OF-PROGRAM.
************************MAIN PROGRAM************************
START-OF-SELECTION - start of database access *
START-OF-SELECTION.
Clear all global variables
PERFORM clear_memory.
Routine for calulating date of Last Saturday and Current Tuesday
PERFORM calculate_posting_dates.
Routine to select posted G/L records from database
PERFORM posting_record_selection.
Routine to compile posting summary table
PERFORM build_posting_summary.
Routine to make filename as eSFA_GL_CandC_YYYYMMDD.txt
PERFORM build_file_name.
Routine for compile physical path of file on Appln. Server
from logical path and desired filename.
PERFORM get_physical_path USING p_l_path
gv_file_name
gc_x
CHANGING gv_server_file_name.
Routine to download file on application server
PERFORM download_on_application_server.
**************************INCLUDES***************************
INCLUDE zfi_get_physical_path.
INCLUDE zfi_file_status_change.
*************************SUBROUTINES*************************
*& Form calculate_posting_dates
Routine for calulating date of Last Saturday and Current Tuesday
FORM calculate_posting_dates .
DATA: lv_monday TYPE sy-datum.
*Get the first day of the week.
CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
EXPORTING
date_in = sy-datum
IMPORTING
date_out = lv_monday.
*Calculate the to date (saturday)
gv_to_date = lv_monday - 2.
*Calculate the from date (sunday)
gv_from_date = lv_monday - 8.
IF s_date-low IS NOT INITIAL.
gv_from_date = s_date-low.
ENDIF.
IF s_date-high IS NOT INITIAL.
gv_to_date = s_date-high.
ENDIF.
ENDFORM. " calculate_posting_dates
*& Form build_posting_summary
Routine for processing posting summary data table & compile
in given output file table
FORM build_posting_summary .
DATA : lv_kostl TYPE kostl,
lv_amount TYPE wrbtr,
lv_amount_str TYPE wrbtr.
DATA : li_posting_summary TYPE TABLE OF gt_posting_summary.
DATA : lwa_posting_summary TYPE gt_posting_summary.
LOOP AT gi_bseg INTO gwa_bseg.
READ TABLE gi_bkpf INTO gwa_bkpf
WITH KEY bukrs = gwa_bseg-bukrs
belnr = gwa_bseg-belnr
gjahr = gwa_bseg-gjahr.
Routine to calcualte effective date in format YYYY-MM-DD
PERFORM calculate_effective_date.
gwa_posting_summary-effective_date = gv_effective_date.
gwa_posting_summary-company_code = gwa_bseg-bukrs.
gwa_posting_summary-gl_key = gwa_bseg-hkont+4(6).
gwa_posting_summary-cost_centre = gwa_bseg-kostl.
gwa_posting_summary-profit_centre = gwa_bseg-prctr.
gwa_posting_summary-project = gwa_bseg-aufnr.
gwa_posting_summary-segment = gwa_bseg-segment.
Remove the derived fields created in SAP while posting
IF gwa_bseg-kostl IS NOT INITIAL OR
gwa_bseg-aufnr IS NOT INITIAL.
CLEAR: gwa_posting_summary-profit_centre,
gwa_posting_summary-segment.
ENDIF.
IF gwa_bseg-aufnr IS NOT INITIAL.
Substitution for internal order to costcenter for document type 'YS'
SELECT SINGLE cost_centre
INTO lv_kostl
FROM ztfi_sub_costctr
WHERE internal_order = gwa_bseg-aufnr.
IF sy-subrc = 0.
gwa_posting_summary-cost_centre = lv_kostl.
CLEAR gwa_posting_summary-project.
ENDIF.
ENDIF.
IF gwa_bseg-shkzg = gc_h.
gwa_bseg-wrbtr = gwa_bseg-wrbtr * -1.
gwa_posting_summary-amount = gwa_bseg-wrbtr.
ELSE.
gwa_posting_summary-amount = gwa_bseg-wrbtr.
ENDIF.
APPEND gwa_posting_summary TO gi_posting_summary.
CLEAR gwa_posting_summary.
CLEAR gwa_bseg.
ENDLOOP. "LOOP AT gi_bseg INTO gwa_bseg
Sort to find the summary
SORT gi_posting_summary BY company_code
gl_key
cost_centre
profit_centre
project
segment.
*Summarise amount for unique entries
LOOP AT gi_posting_summary INTO gwa_posting_summary.
lv_amount_str = gwa_posting_summary-amount.
lv_amount = lv_amount + lv_amount_str.
AT END OF segment.
gv_amount = lv_amount.
PERFORM calculate_amount.
gwa_posting_summary-amount = gv_posting_amount.
APPEND gwa_posting_summary TO li_posting_summary.
CLEAR lv_amount.
ENDAT.
ENDLOOP.
*Copy the summarised table back to summary table
gi_posting_summary = li_posting_summary.
ENDFORM. " build_posting_summary
*& Form calculate_effective_date
Routine to calcualte effective date in format YYYY-MM-DD
FORM calculate_effective_date .
DATA: lv_date(8) TYPE c,
lv_yyyy(4) TYPE c,
lv_mm(2) TYPE c,
lv_dd(2) TYPE c,
lv_effective_date(10) TYPE c.
DATA: lc_dash TYPE c VALUE '-'.
lv_date = gv_to_date.
lv_yyyy = lv_date+0(4).
lv_mm = lv_date+4(2).
lv_dd = lv_date+6(2).
CONCATENATE lv_yyyy
lc_dash
lv_mm
lc_dash
lv_dd
INTO lv_effective_date.
gv_effective_date = lv_effective_date.
ENDFORM. " calculate_effective_date
*& Form posting_record_selection
Routine to select posted G/L records from database
FORM posting_record_selection .
gwa_date-sign = gc_i.
gwa_date-option = gc_bt.
gwa_date-low = gv_from_date.
gwa_date-high = gv_to_date.
APPEND gwa_date TO gr_date.
*Get the suspese GL accout number from ZTFI_SIXPARTKEY table.
SELECT SINGLE gl_account
FROM ztfi_sixpartkey
INTO gv_suspense_accnt
WHERE sixpartkey = gc_suspense_key .
IF sy-subrc IS INITIAL.
Selection of records (other than suspended acc. no. 999999) posted
between last saturday and current tuesday where document type is 'YS'
SELECT bukrs "Company Code
belnr "Accounting Document Number
gjahr "Fiscal Year
budat "Posting Date
FROM bkpf
INTO TABLE gi_bkpf
WHERE blart EQ p_ys
AND budat IN gr_date. "Change - MV - 16.04.2007 - FCDK902208
AND cpudt IN gr_date.
IF sy-subrc IS NOT INITIAL.
WRITE / 'No records for current posting period, file not created.'(m03).
ELSEIF sy-subrc IS INITIAL.
READ TABLE gi_bkpf INTO gwa_bkpf INDEX 1.
IF sy-subrc = 0.
PERFORM calculate_effective_date.
ENDIF.
Selection of details of all records selected in above table
SELECT bukrs "Company Code
belnr "Document Number
gjahr "fiscal year
buzei "Line Item
shkzg "Debit/Credit Indicator
wrbtr "Amount in document currency
kostl "Cost Center
aufnr "Project / Order Number
hkont "General Ledger Account Key
prctr "Profit Center
segment "Segment
FROM bseg
INTO TABLE gi_bseg
FOR ALL ENTRIES IN gi_bkpf
WHERE bukrs = gi_bkpf-bukrs
AND belnr = gi_bkpf-belnr
AND gjahr = gi_bkpf-gjahr
AND hkont <> gv_suspense_accnt.
IF sy-subrc IS NOT INITIAL.
WRITE / 'No records Found, file not created.'(002).
ENDIF.
ENDIF.
ELSE.
WRITE / 'Suspense GL account is not maintained in sixpart key look up table'(001).
ENDIF.
ENDFORM. " posting_record_selection
*& Form calculate_amount
Routine to concancate amouunt and debit/credit indicator
FORM calculate_amount .
DATA: lv_amount(15) TYPE c,
lv_amount_1(12) TYPE c,
lv_amount_2(2) TYPE c,
lv_debit_credit TYPE c.
IF gv_amount <= 0.
lv_debit_credit = gc_credit.
gv_amount = gv_amount * -1.
ELSE.
lv_debit_credit = gc_debit.
ENDIF.
lv_amount = gv_amount.
SPLIT lv_amount AT gc_dot
INTO lv_amount_1
lv_amount_2.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_amount_1
IMPORTING
output = lv_amount_1.
CONCATENATE lv_amount_1
lv_amount_2
INTO lv_amount
SEPARATED BY gc_dot.
CONCATENATE lv_debit_credit lv_amount INTO gv_posting_amount.
ENDFORM. " calculate_amount
*& Form build_file_name
Routine to make filename as eSFA_GL_CandC_YYYYMMDD.txt
FORM build_file_name .
DATA: lv_date(8) TYPE c,
lv_file_name TYPE string.
DATA: lc_file_prefix(14) TYPE c VALUE 'eSFA_GL_CandC_',
lc_file_suffix(4) TYPE c VALUE '.txt'.
lv_date = gv_to_date.
CONCATENATE lc_file_prefix lv_date lc_file_suffix INTO lv_file_name.
gv_file_name = lv_file_name.
ENDFORM. " build_file_name
*& Form download_on_application_server
Routine to download file on application server
FORM download_on_application_server.
DATA : lv_command TYPE string,
lv_lines TYPE i.
lv_command = 'ZFII0431'.
File should be downloaded only if it is not empty
IF gi_bseg IS NOT INITIAL.
Open file for output in text mode
OPEN DATASET gv_server_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc IS NOT INITIAL.
WRITE / 'File could not be open.'(m01).
EXIT.
ENDIF. "IF sy-subrc IS NOT INITIAL
DESCRIBE TABLE gi_posting_summary LINES lv_lines.
LOOP AT gi_posting_summary INTO gwa_posting_summary.
IF sy-tabix <> lv_lines.
Transfer data to application server
TRANSFER gwa_posting_summary TO gv_server_file_name.
ELSE.
Transfer data to application server with out end of line
TRANSFER gwa_posting_summary TO gv_server_file_name NO END OF LINE.
ENDIF.
ENDLOOP. " LOOP AT gi_posting_summary INTO gwa_posting_summary
Close file for output in text mode
CLOSE DATASET gv_server_file_name.
IF sy-subrc IS NOT INITIAL.
WRITE / 'File could not be close.'(m02).
EXIT.
ELSEIF sy-subrc IS INITIAL.
WRITE : / 'File Name:', gv_file_name .
WRITE : / 'File Downloaded to Application Server successfully.'(m04).
Call the OS command to run Shell script.
PERFORM change_file_status USING lv_command.
ENDIF.
ENDIF.
ENDFORM. " download_on_application_server
*& Form clear_memory
Clear all global variables
FORM clear_memory .
REFRESH: gi_bkpf ,
gi_bseg ,
gi_posting_summary.
REFRESH: gr_date.
CLEAR: gwa_bseg ,
gwa_posting_summary,
gwa_date .
CLEAR: gv_from_date ,
gv_to_date ,
gv_effective_date ,
gv_posting_amount ,
gv_file_name ,
gv_server_file_name.
ENDFORM. " clear_memory
***INCLUDE ZFI_GET_PHYSICAL_PATH .
*& Form get_physical_path
Routine for compile physical path of file on Appln. Server
from logical path and desired filename.
-->P_P_L_PATH text
-->P_GV_FILE_NAME text
-->P_GC_OK text
<--P_GV_SERVER_FILE_NAME text
FORM get_physical_path USING p_p_l_path TYPE any
p_gv_file_name TYPE any
p_gc_ok TYPE any
CHANGING p_gv_server_file_name TYPE any.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
client = sy-mandt
logical_path = p_p_l_path
operating_system = sy-opsys
file_name = p_gv_file_name
eleminate_blanks = p_gc_ok
IMPORTING
file_name_with_path = p_gv_server_file_name
EXCEPTIONS
path_not_found = 1
missing_parameter = 2
operating_system_not_found = 3
file_system_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " get_physical_path -
Dear All,
I am trying to upload a text file in application server. But I am getting the run time error which says-
" For the statement
"TRANSFER f TO ..."
only character-type data objects are supported at the argument position
"f".
In this case. the operand "f" has the non-character-type "u". The
current program is a Unicode program. In the Unicode context, the type
'X' or structures containing not only character-type components are
regarded as non-character-type."
If I remove the quantity fields then the error does not happen. But I have to take quantity fields also. Plz tell me what to do. My code is,
DATA FILENAME like rlgrap-filename VALUE 'MIGO_VALUE.txt'.
TABLES VBAK.
DATA D_MSG_TEXT(50).
DATA : BEGIN OF it_mseg OCCURS 0,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
matnr TYPE mseg-matnr,
* erfmg TYPE mseg-erfmg,
werks TYPE mseg-werks,
lgort TYPE mseg-lgort,
END OF it_mseg.
DATA wa LIKE it_mseg.
SELECT mblnr mjahr matnr werks lgort FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_mseg WHERE bwart = '101'.
SORT it_mseg BY mblnr.
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
MESSAGE D_MSG_TEXT.
if sy-subrc eq 0.
message 'File created succesfully in SAP System'(002) type 'S'.
endif.
IF SY-SUBRC NE 0.
WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
EXIT.
ENDIF.
* Transferring Data
LOOP AT it_mseg INTO wa.
TRANSFER wa to filename.
ENDLOOP.
* Closing the File
CLOSE DATASET FILENAME.
Thanks,
Tripod.Thanks Sri for your help. I tried to apply the logic, but the error i am getting here is -
"IT_MSEG-ERFMG" must be a character-like data object (data type C, N,D, T, or STRING) STRING).
Same case here, if I remove ERFMG field, i do not get such error.
data ld_string type string.
LOOP AT it_mseg INTO wa.
CONCATENATE it_mseg-mblnr it_mseg-mjahr it_mseg-matnr it_mseg-erfmg it_mseg-werks it_mseg-lgort INTO ld_string.
endloop.
With regards,
Tripod. -
Problem writing file ANSI to UTF-8. OPEN DATASET FOR OUTPUT IN TEXT MODE
Hello everybody,
My report needs to create a file in ANSI so I am using this sentence: * "OPEN DATASET p_dir_a FOR OUTPUT IN TEXT MODE ENCODING DEFAULT."* almost all charters in the file are well generating excepting for this two: ( Á ) & ( Í ) because SAP assigns the same code to both characters ( Ã? ) = 'xC3' which is not correct, the right code should be ( Á ) = 'xC1' ( Í ) = 'xCD' respectively
from this string = ( ÁÉÍÓÚáéíóúàèìòùÀÈÌÒÙ ) only those two characters are wrong converted.
Also I tray to catch a conversion error with this sentence:
TRY.
TRANSFER <field> TO p_dir_a NO END OF LINE.
CATCH cx_sy_conversion_codepage.
MESSAGE 'error' type 'I'.
ENDTRY.
but never enters in it.
Does anyone know where I can configure SAP to SET this value correctly?
Thanks for your help.was a server problem, not SAP
Maybe you are looking for
-
I recently downloaded mysql Connector for my project. However, I have problems setting it up. When I run my program, It gives me a class not defined error. System.out.println("Registering Driver..."); Class.forName("com.mysql.jdbc.Driv
-
Firefox 4.ob10 Mac: The "Save Tabs?" does not appear when quitting FF
I have disabled all extentions, add-ons, started up in Safe Mode or tried any other suggestions placed on the forum, but still, tabs are not saved. I don't find a "enable" or "disable Save Tabs" in the preferences As suggested, in the profile folder
-
Using jQuery UI in a timeline trigger
I am successfully using jQuery in timeline triggers, but something is going wrong when I try to use jQuery UI. I am loading jquery-ui-1.9.2.custom.js and jquery-ui-1.9.2.custom.css using yepnope in the creationComplete event for the stage object ("Sy
-
I need to select and upload a image and corresponding url from an external website using file upload control in MVC4. Please help Latheesh K Contact No:+91-9747369936
-
Mac storage is supposed to be 500gb but its only 399
can somone help me with this issue?(see the picture) Where did that 100gigs go?How do i get it back?