Skip to end of metadata
Go to start of metadata

List of all pages

Pages at first level

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT zdownload_file.
DATA: BEGIN OF itab OCCURS 0,
  field1 TYPE char9,
  field2 TYPE char2,
  field3 TYPE char2,
END OF itab.
DATA: output(100) TYPE c.

PARAMETERS:  p_file TYPE localfile .

START-OF-SELECTION.
  itab-field1 = 'name1'.
  itab-field2 = '11'.
  itab-field3 = '23' .
  APPEND itab .
  itab-field1 = 'name2'.
  itab-field2 = '41'.
  itab-field3 = '53' .
  APPEND itab .
  itab-field1 = 'name3'.
  itab-field2 = '53'.
  itab-field3 = '87' .
  APPEND itab .

  OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .
  LOOP AT itab.
    CONCATENATE itab-field1
                itab-field2
                itab-field3
        INTO output
        SEPARATED BY ','.
    TRANSFER output TO p_file.
  ENDLOOP.
  CLOSE DATASET p_file.

Program for writing into application server from Internal table

REPORT  z_opendataset_output.
*--------------------------------------------------------------------------------------*
* variable declaration
*--------------------------------------------------------------------------------------*
DATA:  w_file(80)    TYPE c ,
       w_count       TYPE i VALUE 0,
       w_log(310)    TYPE c.
*-----------------------------------------------------------------------------------*
*   internal table declarations
*----------------------------------------------------------------------------------*
DATA: BEGIN OF it_log OCCURS 0,
       w_vbeln    LIKE vbap-vbeln,   "Sales Document
       w_posnr(6)   ,                         " Sales Document Item
       w_matnr(18)  ,                       " material no
       w_cname(30)  ,                     " characteristic name
       w_ovalue(90) ,                     " old value of characteristic
       w_nvalue(90) ,                      " new value of characteristic
      END OF it_log .
*-----work area for the table
DATA: wa_it_log LIKE LINE OF it_log.
*---------------------------------------------------------------------------------------*
*         selection screen
*--------------------------------------------------------------------------------------*
PARAMETERS: p_file  TYPE ibipparms-path.
*---------------------------------------------------------------------------------------*
*         start of selection
*--------------------------------------------------------------------------------------*
START-OF-SELECTION .
*----this is for the file upload
  PERFORM log_file_upload.
*---------------------------------------------------------------------------------------*
*         file upload
*--------------------------------------------------------------------------------------*
FORM log_file_upload .
  DATA: l_msg(80)   TYPE c,
        l_name(200) TYPE c,
        l_ext(5)    TYPE c,
        l_file(300) TYPE c.

  MOVE p_file TO w_file.
*----get the count  of lines in the table
  DESCRIBE TABLE it_log LINES w_count.
  IF NOT w_count IS INITIAL.
    OPEN DATASET w_log
                   FOR OUTPUT IN TEXT MODE
                   ENCODING DEFAULT.
    IF sy-subrc <> 0.
      WRITE:/ 'Error in opening file'.
    ELSE.
*----Setting header
      wa_it_log-w_vbeln   = 'Order'.
      wa_it_log-w_posnr   = 'Item'.
      wa_it_log-w_matnr   = 'Material'.
      wa_it_log-w_cname   = 'Char Name'.
      wa_it_log-w_ovalue  = 'Old Value'.
      wa_it_log-w_nvalue  = 'New Value'.
      TRANSFER wa_it_log TO w_log.
      MOVE: sy-uline(255)
          TO wa_it_log.
      TRANSFER wa_it_log TO w_log.
      MOVE: '   '
            TO wa_it_log.
      TRANSFER wa_it_log TO w_log.
      LOOP AT it_log.
        CLEAR wa_it_log.
        wa_it_log-w_vbeln   = it_log-w_vbeln.
        wa_it_log-w_posnr   = it_log-w_posnr.
        wa_it_log-w_matnr   = it_log-w_matnr.
        wa_it_log-w_cname   = it_log-w_cname.
        wa_it_log-w_ovalue  = it_log-w_ovalue.
        wa_it_log-w_nvalue  = it_log-w_nvalue.
        TRANSFER wa_it_log TO w_log.
        CLEAR w_excel_string.
      ENDLOOP.
*---text-307 'log file saved successfully to :'
      CONCATENATE text-307 w_log INTO l_msg SEPARATED BY space.
      MESSAGE l_msg TYPE 'S'.
    ENDIF.
  ENDIF.
ENDFORM.                    " log_file_upload
 


Declare input and output file parameters on selection screen


Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
SELECTION-SCREEN BEGIN OF BLOCK block01
                WITH FRAME TITLE text-001.     "File Path
PARAMETERS: p_file LIKE  rlgrap-filename OBLIGATORY ,  "INPUT FILE PATH
            p_path LIKE rlgrap-filename OBLIGATORY .   "Output file path



Providing F4 help for File path


Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
**Providing F4 help for user to enter file name
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_file
    IMPORTING
      serverfile       = p_file
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE e009(zz) WITH p_file.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
**Providing F4 help for user to enter file name
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_path
    IMPORTING
      serverfile       = p_path
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE e009(zz) WITH p_path.
  ENDIF.


 To read a file from Application server


Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA : lv_str(50) TYPE c.

*Read the data from application server
OPEN DATASET p_file FOR INPUT IN TEXT  MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
  MESSAGE e009(zz) WITH p_file.

ENDIF.
DO.
**Writing the data into internal table
  READ DATASET p_file INTO lv_str.
  IF sy-subrc = 0.
    SPLIT lv_str AT '#' INTO   gwa_file-f1
                               gwa_file-f2
                               gwa_file-f3
                               gwa_file-f4
                               gwa_file-f5
    append gwa_file to it_file.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET p_file.


To Upload file back to application server


Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA : lv_filename TYPE rlgrap-filename,
*       lv_file(60) TYPE c,
        lv_string(100) TYPE c ,
        c_con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

CONCATENATE p_path c_filename INTO lv_filename.



* Writing the file to the Application server
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
  MESSAGE e009(zz) WITH lv_filename.
ENDIF.

LOOP AT it_final INTO gwa_final.
  CONCATENATE gwa_file-f1
                               gwa_file-f2
                               gwa_file-f3
                               gwa_file-f4
                               gwa_file-f5
              INTO lv_string SEPARATED BY c_con_tab.

  TRANSFER lv_string   TO lv_filename.
ENDLOOP.

CLOSE DATASET lv_filename.


*To Open the file from application server :
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
  MESSAGE e009(message CLASS ) WITH p_file.  " Displaying an error message when file is not opened
ENDIF.
DO.
*  to read the data from file to a string
  READ DATASET p_file INTO lv_str.
  IF sy-subrc = 0.
    SPLIT lv_str AT '#' INTO gwa_file-country_code.
    gwa_file-f1 gwa_file-f2 gwa_file-f3 gwa_file-f4 .
    APPEND gwa_file TO it_file.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET p_file.
 

Applies to:

This document applies to SAP ECC 6.0, SAP Netweaver 2004s. For more information, visit the ABAP homepage.

Summary

This program is used to perform file operation such as Delete\ upload\ download from application server. There is no standard transaction to delete file from application server. So this sample code can be useful when someone wants to delete a file from application server.

Author: Sourabh Batwara        

Company: Cognizant Technology Solution        

Submitted: 1st December 2010

Author Bio: 

Sourabh Batwara is working in Cognizant technology solution as a SAP Consultant. He has 4.5 years of experience in SAP. 

Description

While working with file interface we have to delete, upload or download files from application server. but for deletion, there is no standard transaction available in SAP.  This program will help to delete file from application server.  

Selection screen shots

Upload File:

Download File

Delete File


Program Code

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*-----------------------------------------------------------------------
* Program Name : ZSB_FILE_OPERATION
* Creation date : 01.12.2010
* Description : This Test program is used to perform file
* operation on application server such as delete/upload/download.
*-----------------------------------------------------------------------
REPORT zsb_file_operation.
*----------------------------------------------------------------------*
* DATA DECLEARATION *
*----------------------------------------------------------------------*
* boolean constants for function-parameters and other objects
TYPE-POOLS: esp1.
* Boolean values
TYPES: boolean TYPE esp1_boolean.
DATA: p_file(128), " File path
      lv_ans, " Popup answer
      lv_flag LIKE bapistdtyp-boolean.
CONSTANTS : c_yes TYPE c VALUE '1',
            c_no TYPE c VALUE '0',
            c_upload(4) TYPE c VALUE 'CG3Z',
            c_dnload(4) TYPE c VALUE 'CG3Y',
            c_x TYPE c VALUE 'X',
            c_j TYPE c VALUE 'J',
            c_n TYPE c VALUE 'N',
            true TYPE boolean VALUE esp1_true.
*----------------------------------------------------------------------*
* SELECTION SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS :  r_upload RADIOBUTTON GROUP rb1 USER-COMMAND del DEFAULT 'X', " Upload file
              r_dnload RADIOBUTTON GROUP rb1, " Download file
              r_delete RADIOBUTTON GROUP rb1. " Delete file
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_dir LIKE rlgrap-filename MODIF ID del, " Dir Path
            p_file1 LIKE rlgrap-filename MODIF ID del. " Path name
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_local LIKE rcgfiletr-ftfront MODIF ID up, " Dir Path
            p_path LIKE rcgfiletr-ftappl MODIF ID up, " Path name
            p_over AS CHECKBOX MODIF ID up. " Overwrite
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path1 LIKE rcgfiletr-ftappl MODIF ID dn, " Path name
            p_local1 LIKE rcgfiletr-ftfront MODIF ID dn, " Dir Path
            p_over1 AS CHECKBOX MODIF ID dn.
SELECTION-SCREEN END OF BLOCK b4.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN OUTPUT *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-group1 = 'DEL'.
      IF r_delete = c_x.
        screen-invisible = c_no .
        screen-active = c_yes .
      ELSE.
        screen-invisible = c_yes .
        screen-active = c_no .
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
    IF screen-group1 = 'UP'.
      IF r_upload = c_x.
        screen-invisible = c_no .
        screen-active = c_yes .
      ELSE.
        screen-invisible = c_yes .
        screen-active = c_no .
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
    IF screen-group1 = 'DN'.
      IF r_dnload = c_x.
        screen-invisible = c_no .
        screen-active = c_yes .
      ELSE.
        screen-invisible = c_yes .
        screen-active = c_no .
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN ON VALUE REQUEST *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_LOCAL'
    IMPORTING
      file_name  = p_local.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local1.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_LOCAL1'
    IMPORTING
      file_name  = p_local1.
*----------------------------------------------------------------------*
* START OF SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  IF r_upload = c_x.
    PERFORM file_upload.
  ELSEIF r_dnload = c_x.
    PERFORM file_dnload.
  ELSE.
    PERFORM file_delete.
  ENDIF.
*&---------------------------------------------------------------------*
*& Form FILE_UPLOAD
*&---------------------------------------------------------------------*
* Form to upload file from frontend to application server
*----------------------------------------------------------------------*
FORM file_upload .
  CLEAR lv_flag.
  IF p_over = c_x.
    lv_flag = 1.
  ENDIF.
  CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
    EXPORTING
      i_file_front_end   = p_local
      i_file_appl        = p_path
      i_file_overwrite   = lv_flag
    EXCEPTIONS
      fe_file_not_exists = 1
      fe_file_read_error = 2
      ap_no_authority    = 3
      ap_file_open_error = 4
      ap_file_exists     = 5.
  CASE sy-subrc.
    WHEN '0'.
      MESSAGE s899(bd) WITH 'File uploaded successfully'.
    WHEN '1'.
      MESSAGE e899(bd) WITH 'File does not exist'.
    WHEN '2'.
      MESSAGE e899(bd) WITH 'Error in file reading'.
    WHEN '3'.
      MESSAGE e899(bd) WITH 'Authorization Error'.
    WHEN '5'.
* file already exists, ask if file can be overwritten
      CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE'
        IMPORTING
          e_flg_continue = lv_flag
        EXCEPTIONS
          OTHERS         = 1.
      IF sy-subrc = 0 AND
      lv_flag = true.
        CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
          EXPORTING
            i_file_front_end = p_local
            i_file_appl      = p_path
            i_file_overwrite = lv_flag.
        IF sy-subrc IS INITIAL.
          MESSAGE s899(bd) WITH 'File uploaded successfully'.
        ENDIF.
      ENDIF.
  ENDCASE.
ENDFORM. " FILE_UPLOAD
*&---------------------------------------------------------------------*
*& Form FILE_DNLOAD
*&---------------------------------------------------------------------*
* Form to download the file from application server to frontend
*----------------------------------------------------------------------*
FORM file_dnload .
  CLEAR lv_flag.
  IF p_over1 = c_x.
    lv_flag = 1.
  ENDIF.
  CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
    EXPORTING
      i_file_front_end   = p_local1
      i_file_appl        = p_path1
      i_file_overwrite   = lv_flag
    EXCEPTIONS
      fe_file_open_error = 1
      fe_file_exists     = 2
      ap_no_authority    = 4.
  CASE sy-subrc.
    WHEN '0'.
      MESSAGE s899(bd) WITH 'File downloaded successfully'.
    WHEN '1'.
      MESSAGE e899(bd) WITH 'Error while opening file'.
    WHEN '2'.
* file already exists, ask if file can be overwritten
      CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE'
        IMPORTING
          e_flg_continue = lv_flag
        EXCEPTIONS
          OTHERS         = 1.
      IF sy-subrc = 0 AND
      lv_flag = true.
        CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
          EXPORTING
            i_file_front_end = p_local1
            i_file_appl      = p_path1
            i_file_overwrite = lv_flag.
        IF sy-subrc IS INITIAL.
          MESSAGE s899(bd) WITH 'File downloaded successfully'.
        ENDIF.
      ENDIF.
    WHEN '4'.
      MESSAGE e899(bd) WITH 'Authorization Error'.
  ENDCASE.
ENDFORM. " FILE_DNLOAD
*----------------------------------------------------------------------*
* Form FILE_DELETE *
*----------------------------------------------------------------------*
* Form to delete file from application server *
*----------------------------------------------------------------------*
FORM file_delete .
* File path
  CONCATENATE p_dir p_file1 INTO p_file.
* Check file exists
  OPEN DATASET p_file FOR INPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    MESSAGE e899(bd) WITH p_file 'does not exist'.
    EXIT.
  ELSE.
* Popup window
    CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
      EXPORTING
        defaultoption = c_n
        textline1     = p_file
        titel         = 'Are you sure to delete this file?'
      IMPORTING
        answer        = lv_ans
      EXCEPTIONS
        OTHERS        = 1.
  ENDIF.
  CLOSE DATASET p_file.
  IF lv_ans EQ c_j.
* Delete file
    DELETE DATASET p_file.
    IF sy-subrc NE 0.
      MESSAGE e899(bd) WITH 'Invalid file name' p_file.
    ELSE.
      CLOSE DATASET p_file.
      MESSAGE s899(bd) WITH p_dir p_file1 'has been deleted'.
    ENDIF.
  ENDIF.
ENDFORM. " FILE_DELETE
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT zdelete.
*----------------------------------------------------------------------*
* Delete a file on the application server.
*----------------------------------------------------------------------*
PARAMETERS: p_dir LIKE rlgrap-filename
                  DEFAULT '/usr/sap/trans/',
            p_file1 LIKE rlgrap-filename.

DATA: p_file(128).
DATA: w_ans.

START-OF-SELECTION.
  CONCATENATE p_dir p_file1 INTO p_file.
*----------------------------------------------------------------------*
* check file exists
*----------------------------------------------------------------------*
  OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc NE 0.
    MESSAGE e899(bd) WITH p_file 'DOES NOT EXIST'.
    EXIT.
  ELSE.

    CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
      EXPORTING
        defaultoption = 'N'
        textline1     = p_dir
        textline2     = p_file1
        titel         = 'ARE YOU SURE YOU WANT TO DELETE'
      IMPORTING
        answer        = w_ans
      EXCEPTIONS
        OTHERS        = 1.

  ENDIF.
  CLOSE DATASET p_file.
  CHECK w_ans = 'J'.
*----------------------------------------------------------------------*
* delete
*----------------------------------------------------------------------*

  DELETE DATASET p_file.

  IF sy-subrc NE 0.
    MESSAGE e899(bd) WITH 'INVALID FILE NAME' p_file.
  ELSE.
    CLOSE DATASET p_file.
    MESSAGE i899(bd) WITH p_dir p_file1 'DELETED SUCCESFULLY'.
  ENDIF.


Output:-

*Enter the Directory name & File Name *







*Press F8*

*Press Enter*

 
*Go to Transcation AL11 ->Double Click on DIR_TEMP-> You can find the List of file*

*Before Deleting the File*

 
 *After Deleting the File*

  

When you access sequential files on the application server using the following statements

  • OPEN DATASET
  • READ DATASET
  • TRANSFER
  • DELETE DATASET

the system automatically checks the user’s authorization against the authorization object S_DATASET. Based on the User Role and Authorizations the above activities will be possible.

Hence the developers must check the authorization in ABAP program before accessing the file using the function module AUTHORITY_CHECK_DATASET.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zshiva_itab_to_xml_app_server.
TYPE-POOLS: ixml.

TYPES: BEGIN OF xml_line,
        data(256) TYPE x,
       END OF xml_line.

DATA fname(30) VALUE 'D:\XML\shiva.XML'.

DATA: l_ixml            TYPE REF TO if_ixml,
      l_streamfactory   TYPE REF TO if_ixml_stream_factory,
      l_ostream         TYPE REF TO if_ixml_ostream,
      l_renderer        TYPE REF TO if_ixml_renderer,
      l_document        TYPE REF TO if_ixml_document.

DATA: l_element_flights TYPE REF TO if_ixml_element,
      l_element_airline TYPE REF TO if_ixml_element,
      l_element_flight  TYPE REF TO if_ixml_element,
      l_element_from    TYPE REF TO if_ixml_element,
      l_element_to      TYPE REF TO if_ixml_element,
      l_element_dummy   TYPE REF TO if_ixml_element,
      l_value           TYPE string.

DATA: l_xml_table       TYPE TABLE OF xml_line,
      rec TYPE xml_line,
      l_xml_size        TYPE i,
      l_rc              TYPE i.

DATA: lt_spfli          TYPE TABLE OF spfli.
DATA: l_spfli           TYPE spfli.

START-OF-SELECTION.
*   Fill the internal table
  SELECT * FROM spfli INTO TABLE lt_spfli.

*   Sort internal table
  SORT lt_spfli BY carrid.

*   Start filling xml dom object from internal table
  LOOP AT lt_spfli INTO l_spfli.

    AT FIRST.
*       Creating a ixml factory
      l_ixml = cl_ixml=>create( ).
*       Creating the dom object model
      l_document = l_ixml->create_document( ).
*       Fill root node with value flights
      l_element_flights  = l_document->create_simple_element(
                  name = 'flights'
                  parent = l_document ).
    ENDAT.

    AT NEW carrid.
*       Create element 'airline' as child of 'flights'
      l_element_airline  = l_document->create_simple_element(
                  name = 'airline'
                  parent = l_element_flights  ).

*       Create attribute 'code' of node 'airline'
      l_value = l_spfli-carrid.
      l_rc = l_element_airline->set_attribute( name = 'code' value = l_value ).

*       Create attribute 'name' of node 'airline'
      SELECT SINGLE carrname FROM scarr INTO l_value WHERE carrid EQ l_spfli-carrid.
      l_rc = l_element_airline->set_attribute( name = 'name' value = l_value ).

    ENDAT.

    AT NEW connid.
*       Create element 'flight' as child of 'airline'
      l_element_flight  = l_document->create_simple_element(
                  name = 'flight'
                  parent = l_element_airline  ).

*       Create attribute 'number' of node 'flight'
      l_value = l_spfli-connid.
      l_rc = l_element_flight->set_attribute( name = 'number' value = l_value ).

    ENDAT.

*     Create element 'from' as child of 'flight'
    CONCATENATE l_spfli-cityfrom ',' l_spfli-countryfr INTO l_value.
    l_element_from  = l_document->create_simple_element(
                name = 'from'
                value = l_value
                parent = l_element_flight  ).

*     Create attribute 'airport' of node 'from'
    l_value = l_spfli-airpfrom.
    l_rc = l_element_from->set_attribute( name = 'airport' value = l_value ).

*     Create element 'to' as child of 'flight'
    CONCATENATE l_spfli-cityto ',' l_spfli-countryto INTO l_value.
    l_element_to  = l_document->create_simple_element(
                name = 'to'
                value = l_value
                parent = l_element_flight  ).

*     Create attribute 'airport' of node 'from'
    l_value = l_spfli-airpto.
    l_rc = l_element_to->set_attribute( name = 'airport' value = l_value ).

*     Create element 'departure' as child of 'flight'
    l_value = l_spfli-deptime.
    l_element_dummy  = l_document->create_simple_element(
                name = 'departure'
                value = l_value
                parent = l_element_flight ).

*     Create element 'arrival' as child of 'flight'
    l_value = l_spfli-arrtime.
    l_element_dummy  = l_document->create_simple_element(
                name = 'arrival'
                value = l_value
                parent = l_element_flight ).

*     Create element 'type' as child of 'flight'
    CASE l_spfli-fltype.
      WHEN 'X'.
        l_value = 'Charter'.
      WHEN OTHERS.
        l_value = 'Scheduled'.
    ENDCASE.
    l_element_dummy  = l_document->create_simple_element(
                name = 'type'
                value = l_value
                parent = l_element_flight ).
  ENDLOOP.
  IF sy-subrc NE 0.
    MESSAGE 'No data into db table ''spfli'', please run program ''SAPBC_DATA_GENERATOR'' with transaction ''SA38''' TYPE 'E'.
  ENDIF.

*   Creating a stream factory
  l_streamfactory = l_ixml->create_stream_factory( ).
*   Connect internal XML table to stream factory
  l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).

*   Rendering the document
  l_renderer = l_ixml->create_renderer( ostream  = l_ostream
                                        document = l_document ).
  l_rc = l_renderer->render( ).

*   Saving the XML document
  l_xml_size = l_ostream->get_num_written_raw( ).
*

  OPEN DATASET fname FOR OUTPUT
    IN BINARY MODE.
  IF sy-subrc EQ 0.

    LOOP AT l_xml_table INTO rec.
      TRANSFER rec TO fname.
    ENDLOOP.
    CLOSE DATASET fname.
  ENDIF.

Author: Vivek Priyadarshi
Submitted: 06/17/2015
Related Links:

  • <link>

Description I recently worked on a requirement where a functionality was required to get the modification date of a file on application server and make some decisions based on the same. In this blog, I will discussed a simple technique to get this information for any file stored on the application server. This code resembles the logic in function module EPS_GET_FILE_ATTRIBUTES with minor adjustments (mostly for the modification date property).

/* your snippet */

 
 *----------------------------------------------------------------------*
*       CLASS lcl_file_property DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_file_property DEFINITION FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    TYPES:
    BEGIN OF ty_file_property ,
          dirname(75) TYPE c, " name of directory. (possibly truncated.)
          name(75)    TYPE c, " name of entry. (possibly truncated.)
          type(10)    TYPE c, " type of entry.
          len(8)      TYPE p DECIMALS 0, " length in bytes.
          owner(8)    TYPE c, " owner of the entry.
          mtime(10)   TYPE p DECIMALS 0, " last modification date, seconds since 1970
          mdate       TYPE datum,
          mode(9)     TYPE c, " like "rwx-r-x--x": protection mode.
          errno(3)    TYPE c,
          errmsg(40)  TYPE c,
        END OF ty_file_property.
    DATA: directory_name  TYPE line,
          file_property   TYPE ty_file_property,
          file_property_t TYPE STANDARD TABLE OF ty_file_property.
    DATA: lv_mgr_user    TYPE as4user,
          lv_eps_subdir  TYPE epsf-epssubdir.
    DATA: lt_dir_list    TYPE STANDARD TABLE OF epsfili,
          dir_list       LIKE LINE OF lt_dir_list,
          file_counter   TYPE epsf-epsfilsiz,
          error_counter  TYPE  epsf-epsfilsiz,
          lv_unix_path   TYPE char255.
    DATA: lt_sections TYPE stringtab,
          lv_section  TYPE string,
          lv_filename TYPE epsf-epsfilnam,
          lv_rows     TYPE i.
    METHODS: constructor
                    IMPORTING
                        directory_path TYPE char255,
        get_file_properties RETURNING value(properties) TYPE ty_file_property.

  PRIVATE SECTION.
    CONSTANTS:  gc_secs_in_day TYPE i VALUE 86400.
    METHODS: calculate_modification_date
              IMPORTING property TYPE ty_file_property
              RETURNING value(mod_date) TYPE datum.
ENDCLASS.                    "lcl_file_property DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_file_property IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_file_property IMPLEMENTATION.

  METHOD constructor.
    directory_name = directory_path.
*--- Split path to get the file name
    SPLIT directory_name AT '/' INTO TABLE lt_sections.
    lv_rows = lines( lt_sections ).

    READ TABLE lt_sections INTO  lv_section INDEX lv_rows.
    CHECK sy-subrc EQ 0.
    lv_filename = lv_section.

*----- Remove filename from directory path
    REPLACE FIRST OCCURRENCE OF lv_section IN directory_name WITH space.
    CONDENSE directory_name.
  ENDMETHOD.                    "constructor

  METHOD get_file_properties.

* get directory listing
    CALL 'C_DIR_READ_FINISH'                  " just to be sure
          ID 'ERRNO'  FIELD file_property-errno
          ID 'ERRMSG' FIELD file_property-errmsg.

    CALL 'C_DIR_READ_START'
          ID 'DIR'    FIELD directory_name
          ID 'FILE'   FIELD lv_filename
          ID 'ERRNO'  FIELD file_property-errno
          ID 'ERRMSG' FIELD file_property-errmsg.
    IF sy-subrc <> 0.
***      RAISE EXCEPTION TYPE zcx_unix_file_base
***        EXPORTING
***          textid    = zcx_unix_file_base=>read_directory_failed
***          unix_path = lv_unix_path.
      MESSAGE 'Error during reading content of directory path' TYPE 'E'.
    ENDIF.

    REFRESH lt_dir_list.
    CLEAR file_counter.
    CLEAR error_counter.
    DO.
      CLEAR file_property.
      CLEAR dir_list.
      CALL 'C_DIR_READ_NEXT'
            ID 'TYPE'   FIELD file_property-type
            ID 'NAME'   FIELD file_property-name
            ID 'LEN'    FIELD file_property-len
            ID 'OWNER'  FIELD file_property-owner
            ID 'MTIME'  FIELD file_property-mtime
            ID 'MODE'   FIELD file_property-mode
            ID 'ERRNO'  FIELD file_property-errno
            ID 'ERRMSG' FIELD file_property-errmsg.

*   handle files > 2147483647 byte (int 4) - hen 9.9.2004
      IF file_property-len > 2147483647.
        dir_list-size  = -99.
      ELSE.
        dir_list-size  = file_property-len.
      ENDIF.
      dir_list-name = file_property-name.
      IF sy-subrc = 0.
        IF file_property-type(1) = 'f' OR              " regular file
           file_property-type(1) = 'F'.
          ADD 1 TO file_counter.
          dir_list-rc   = 0.
          APPEND dir_list TO lt_dir_list.
          file_property-mdate = me->calculate_modification_date( file_property ).
          APPEND file_property TO file_property_t.
        ENDIF.
      ELSEIF sy-subrc = 1.
        EXIT.
      ELSE.
        IF error_counter > 1000.
          CALL 'C_DIR_READ_FINISH'
                ID 'ERRNO'  FIELD file_property-errno
                ID 'ERRMSG' FIELD file_property-errmsg.
***        RAISE EXCEPTION TYPE zcx_unix_file_base
***          EXPORTING
***            textid = zcx_unix_file_base=>too_many_read_errors.
          MESSAGE 'Too many read errors' TYPE 'E'.
        ENDIF.
        ADD 1 TO error_counter.
        dir_list-rc  = 18.
        APPEND dir_list TO lt_dir_list.
        file_property-mdate = me->calculate_modification_date( file_property ).
        APPEND file_property TO file_property_t.
      ENDIF.
    ENDDO.

    CALL 'C_DIR_READ_FINISH'
          ID 'ERRNO'  FIELD file_property-errno
          ID 'ERRMSG' FIELD file_property-errmsg.

    IF file_counter > 0.
      SORT lt_dir_list BY name ASCENDING.
      READ TABLE file_property_t INTO file_property INDEX 1.
      CHECK sy-subrc EQ 0.
      properties = file_property.
    ELSE.
***      RAISE EXCEPTION TYPE zcx_unix_file_base
***        EXPORTING
***          textid = zcx_unix_file_base=>empty_directory_list.
      MESSAGE 'Directory list is empty' TYPE 'E'.
    ENDIF.

    properties = file_property.

  ENDMETHOD.                    "get_file_properties


  METHOD calculate_modification_date.
    DATA: lv_days TYPE p LENGTH 10 DECIMALS 4,
          lv_seconds TYPE p LENGTH 10 DECIMALS 0,
          lv_date    TYPE sy-datum VALUE '19691231'.

    CHECK NOT property-mtime IS INITIAL.
*-----   1 Day = 86400 Seconds
*-----   Get number of days from seconds
    lv_seconds = property-mtime.
    lv_days =   lv_seconds / me->gc_secs_in_day.
    lv_date = lv_date + lv_days.

    mod_date  = lv_date.
  ENDMETHOD.                    "calculate_modification_date

ENDCLASS.                    "lcl_file_property IMPLEMENTATION 

Naresh
Dec 10 2007

Description: ABAP code for retrieving list of files contained within specific Application server directory(SAP). 

*&---------------------------------------------------------------------*
*& Report  ZDIRFILES                                                   *
*&---------------------------------------------------------------------*
REPORT  ZDIRFILES    .

PARAMETER: p_fdir            type pfeflnamel DEFAULT '/usr/sap/tmp'.

data: begin of it_filedir occurs 10.
        include structure salfldir.
data: end of it_filedir.

************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
  call function 'RZL_READ_DIR_LOCAL'
       exporting
            name     = p_fdir
       tables
            file_tbl = it_filedir.

* List of files are contained within table it_filedir
  loop at it_filedir.
    write: / it_filedir-NAME.
  endloop.


To get an F4 help of the application server directories:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
PARAMETERS : p_dir TYPE char30 LOWER CASE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR  p_dir.

  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_dir
    IMPORTING
      serverfile       = p_dir
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.

  • No labels