Application Development 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: 

Open dataset......

kiran_k8
Active Contributor
0 Kudos

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.

1 ACCEPTED SOLUTION

kiran_k8
Active Contributor
0 Kudos

Hi Folks,

I had done some changes to the code and placed in the same thread(first one with code).Kindly go through the highlighted part of the code.

If I had given the path name as

<b>DATA : file(50) VALUE 'E:\userdata\labelfiles\XXX\bar'.</b>

It is saying <b>file could not be opened.

If I use the path name as below

<b>DATA : file(50) VALUE 'C:\labelfile'.</b>

it is not showing any error and going through the execution process.

Kindly throw some light on this.

Thanks,

K.Kiran.

30 REPLIES 30

Former Member
0 Kudos

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

0 Kudos

Mino,

Kindly check the highlighted part of the code.

If sy-subrc <> 0 WRITE "FILE COULD NOT BE OPENED.It is not stopping at this point,doesn't that mean that file is OPEN.Kindly let me know.

Thanks,

K.Kiran.

0 Kudos

Sai,

The syntax changes that you have done "open dataset dsn for output" is resulting in error.

I think it should be "open dataset dsn for output in text mode econding default"

Thanks,

K.Kiran.

0 Kudos

Hi Kiran,

Nope it worked fine for me here in a 4.6c system. Actually it showed me a syntax error that there shd be something like TYPE,, FILTER,, etc after the mode. so i removed that part. And there was a warning that sy-repid shd not be passed directly. These are the two changes that i've made. Which system have u written this program ? I mean ECC or 46c ? Please let me know i'll try this once again. I've also got an .XLS download of this program's output.

Regards,

Sai

0 Kudos

Hi Folks,

Looking forward to SDN experts replies.

Thanks,

K.Kiran.

0 Kudos

Kiran,

Got the solution... if you see in the debug mode the file is going to be created at location 'C:\labelfiles0000.PJ' which is filled in variable dsn.

However the command OPEN/CLOSE DATASET n TRANSFER are used to write into the Application Server directories (as seen in AL11) not the desktop as in the case you are trying to do.

Hence the failure.

PS: It shud solve your query.

Regards.

0 Kudos

Mino,

Yes you are right.

'C:\labelfiles0000.PJ' in variable dsn.

I don't have authorisation to AL11.

Kindly let me what changes needs to be done.

Thanks,

K.Kiran.

0 Kudos

Can u view the Application dataset in AL11 Tcode, generally the application path generally starts with '
' in your case its C: thats what confuses me. One more thing can u try this code also:

OPEN DATASET dsn FOR APPENDING IN TEXT MODE ENCODING DEFAULT
                                       WITH WINDOWS LINEFEED.
  IF sy-subrc <> 0.
    LEAVE TO LIST-PROCESSING.
    WRITE:/ 'FILE COULD NOT BE OPENED'.
    EXIT.
  ENDIF.

Hope That Helps

Anirban M.

0 Kudos

Hi Kiran

Ask your Basis consultant to give to access to AL11 (he'll attach the role to access AL11 to your user id).

Then you can select the directory name in your variable dsn (eg: dsn = F:\usr\sap\EC1\DVEBMGS00\work\YOURFILENAME) and the file will get downloaded to that path.

To view to the file you can use transaction SXDA_TOOLS to get the file on ur desktop to view it correctly.

PS: Since this solves your query please mark this question answered.

Regards.

0 Kudos

Mino,

So you mean to say everything is correct except the file name.As I told you I don't have authorisation to AL11 as well as SXDA_TOOLS.

In such a case how can i check whether the program is working fine or not.?

Can't we download it to our desktop by giving the path as C:\labelfiles.txt?

Let me know what is Application server.

Thanks,

K.Kiran.

0 Kudos

Sai,

I am in 4.7 and there is no error with respect to the program name passed to the alv as sy-repid but the moment I change the open dataset syntax as per your code it is throwing an error.I was just wondering how you got the data dowloaded into XLS.

Thanks,

K.Kiran.

Former Member
0 Kudos

Hi Kiran,

Please try this code. I've made some changes to the code. Please check if this works. Please revert back if i have made any mistakes.

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

data : file(50) value 'C:\labelfiles'.

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 = ' '.

data : i_repid type sy-repid.

i_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = i_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 .

data : i_repid type sy-repid.

i_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = i_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.

concatenate file n1 '.PJ' into dsn.

perform dsn.

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

----


form dsn .

open dataset dsn for output.

if sy-subrc <> 0.

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.

if sy-subrc <> 0.

write:/ 'Check your code'.

endif.

close dataset dsn.

endform.

Regards,

Sai

Former Member
0 Kudos

Hi,

If you're program executed properly and you want to get the file

then use TCODE - CG3Y to download the file to local machine

from the application server.

Regards,

Samson Rodrigues.

kiran_k8
Active Contributor
0 Kudos

Hi Folks,

I had done some changes to the code and placed in the same thread(first one with code).Kindly go through the highlighted part of the code.

If I had given the path name as

<b>DATA : file(50) VALUE 'E:\userdata\labelfiles\XXX\bar'.</b>

It is saying <b>file could not be opened.

If I use the path name as below

<b>DATA : file(50) VALUE 'C:\labelfile'.</b>

it is not showing any error and going through the execution process.

Kindly throw some light on this.

Thanks,

K.Kiran.

Former Member
0 Kudos

Hi Kiran,

You said

<i>DATA : file(50) VALUE 'E:\userdata\labelfiles\CIPL\bar'.

It is saying file could not be opened.</i>

Probably this Drive or those folders don't exist in your application server.

Since C drive does not give u any error, try TCODE CG3Y, it will give

you the default path where you can store the file,

use this path to create your file,

it shows something like this

example

C:\usr\sap\<server ID>\SYS\global\<filename>

put your file name there, it should work, until you get access

to AL11 transaction and see what all folders are available.

Regards,

Samson Rodrigues.

kiran_k8
Active Contributor
0 Kudos

Sam,

When I go cg3y

it is showing the source file as E:\usr\sap\CQD\SYS\global\substanc.When I change it to what I have given in program i.e C:\labelfile

it is showing a pop up message

cannot open file C:\labelfile no such file or directory.

Thanks,

K.Kiran.

0 Kudos

Hi Kiran,

Run this program

You will get a popup

If it shows the same path as the parameter in the popup, that means the directory exists

else, in your case, it would show E:\ if the directory userdata doesnt exist

We use the application server mainly when we want to write data in a background program to a file

This is because when we run a program in background, it has no access to your local PC (presentation server)


*&---------------------------------------------------------------------*
*& Report  ZKRIS_FINDDIRECTORIES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZKRIS_FINDDIRECTORIES.

  parameters: p_path like DXFIELDS-LONGPATH
    default 'E:userdatalabelfilesXXXbar'.

  data: lv_opath like dxfields-longpath.
  data: ev_server_name like btctgtsrvr-srvname,
        server_name like msxxlist-name.
  call 'C_SAPGPARAM'
  id 'NAME' field 'rdisp/myname'
  id 'VALUE' field ev_server_name.
  if sy-subrc <> 0.
    clear ev_server_name.
  endif.

  call function 'F4_DXFILENAME_TOPRECURSION'
   exporting
     i_location_flag       = 'X'
     i_server              = server_name
     i_path                = p_path
   importing

      o_path                = lv_opath  .

   write:/ lv_opath.

kiran_k8
Active Contributor
0 Kudos

Kirs,

Simpley Superb Code Buddy.It is indeed showing a list of my files with date and lenght etc stuff.Now how to see the actual data.

But one thing,my path is like this E:\userdata\labelfiles.

When I run this program it is showing a list of files with the name given in path,after closing that window

it is showing as E:\userdata.

Does that mean there is a drive E with a folder userdata but not my file labelfiles?

Long live Kris Donald.

Thanks a ton,

K.Kiran.

0 Kudos

well.. to see the data, the file would need to be written in the first place

using that above program, find a suitable directory in your system which exists

then write your file to that directory using your same program (don't forget to add a filename to the directory name)

you can later download the file using CG3Y transaction

Former Member
0 Kudos

Hi Kiran,

One reason you cannot see your file is because it seems you have not given an extension to it like <file.txt> hence the failure at path E:\userdata\labelfiles.

Try giving the path as E:\userdata\labelfiles.txt

Let me know the outcome.

Regards,

-Mino.

0 Kudos

This program shows only directories

If it shows E:\userdata, it means that the directory E:\userdata exists in your system

(you would also be able to see E:\userdata on the top left corner under the word 'Directory' in your popup)

so you would be able to create and write to a file named E:\userdata\labelfiles1.nj <b>if you have write access to that folder</b>

In your case, it is quite possible that you do not have access to that folder

so then, write the file to any available folder (i think you mentioned earlier that C:\labelfile works)

then use transaction CG3Y to download the file to your desktop

kiran_k8
Active Contributor
0 Kudos

Kris,

Yes you are rigjht.I have a directory E:\userdata wherein I will be able to write the data and indeed I was able to see the data too using CG3Y.The program what you gave is quite helpful.Thanks once again.

K.Kiran.

former_member223537
Active Contributor
0 Kudos

Hi Kiran,

You are trying to open a file which is on Presentation Server through Open Dataset.

Open Dataset deals only with the files placed on Application Server.

Transaction CG3Y & CG3Z are used to upload/download files from application/Presentation server.

Place the file in application server & pass the correct path. The code should work.

<b>Use GUI_DOWNLOAD/GUI_UPLOAD if you want to deal with files placed on Presentation server.</b>

Best regards,

Prashant

Message was edited by:

Prashant Patil

0 Kudos

Prashanth,

Thanks Prashanth.Can you please let me know how a presentation server differs from Application server in this context.If possible kindly given me an example in this context.

Thanks,

K.Kiran.

former_member223537
Active Contributor
0 Kudos

Hi Kiran,

<b>Presentation Server</b> is the Presentation Layer in R/3 architecture i.e Windows in our case.

The presentation components are responsible for the interaction between the R/3 System and the user, and for desktop component integration (such as word processing and spreadsheets).

<b>Application server is</b> the APplication Layer in R/3 architecture

The application layer consists of one or more application servers and a message server. Each application server contains a set of services used to run the R/3 System. Theoretically, you only need one application server to run an R/3 System. In practice, the services are distributed across more than one application server. This means that not all application servers will provide the full range of services. The message server is responsible for communication between the application servers. It passes requests from one application server to another within the system. It also contains information about application server groups and the current load balancing within them. It uses this information to choose an appropriate server when a user logs onto the system.

refer this link for architecture diagram which will clear you doubts:

http://www.erpgenie.com/sap/basis/

Best regards,

Prashant

0 Kudos

Prashanth,

As it is showing the file is not opened, is it possible to create a file in the application server thorugh coding.

Thanks,

K.Kiran.

0 Kudos

Hi Kiran,

the statement

<b>open dataset file for output in text mode encoding default.</b>

will create and open the file automatically, if the specified path exists

and only if you have access rights to create files on that folder.

If the file already exists then it will be overwritten.

Regards,

Samson Rodrigues.

0 Kudos

Sam,

Can you please let me know when we will go for this Application server concept.

Thanks,

K.Kiran.

0 Kudos

Kiran,

Assume you have a scenario, wherein you have to execute a program and

store the output in a file, now if this program takes 6 - 8 hours to execute

then no foreground program would be able to run that long.

Hence, we schedule the job in background.

Now in background mode when we try to write to a file,

it can only be written to the application server.

Thus, later when you check the job overview and find that your job has completed

you can download the files to local machine or whatever....

Regards,

Samson Rodrigues.

former_member223537
Active Contributor
0 Kudos

Hi Kiran,

Yes its possible to create a file on application server through ABAP coding.

Here is a sample program:

The path wont be C:\ ... You can check the path through AL11 or CG3Y/CG3Z transaction you can get a fair idea about the path.

DATA: file TYPE string VALUE `G:\usr\sap\trans\flights.dat`,

wa TYPE spfli.

FIELD-SYMBOLS TYPE x.

OPEN DATASET file FOR OUTPUT IN BINARY MODE.

SELECT *

FROM spfli

INTO wa.

ASSIGN wa TO CASTING.

TRANSFER TO file.

ENDSELECT.

CLOSE DATASET file.

Best regards,

Prashant