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: 

data from itab to be store in text file in desktop

Former Member
0 Kudos

hi

i am tyring to store the data from itab into a text file in desktop,but its now owrking.

i am using open dataset statment,but no where data is storing.My code:

TYPES : BEGIN OF ST_DEMO,

REG_NO(10) TYPE C,

NAME(20) TYPE C,

ADDR(20) TYPE C,

END OF ST_DEMO.

DATA : WA_DEMO TYPE ST_DEMO,

IT_DEMO TYPE TABLE OF ST_DEMO,

L_FNAME TYPE dxfile-filename .

PARAMETERS: P_FNAME(128) TYPE C DEFAULT '\usr\sap\put\vipin.txt' OBLIGATORY.

L_FNAME = P_FNAME.

***

WA_DEMO-REG_NO = '100001'.

WA_DEMO-NAME = 'ANAND'.

WA_DEMO-ADDR = 'NAGARKOVIL'.

APPEND WA_DEMO TO IT_DEMO.

OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' .

LOOP AT IT_DEMO INTO WA_DEMO.

IF SY-SUBRC = 0.

TRANSFER WA_DEMO TO L_FNAME.

WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR.

ENDIF.

ENDLOOP.

close DATASET L_FNAME.

please tell me where is the prob?I wan to schedule it for background job.

regds

vipin

6 REPLIES 6

Former Member

former_member184619
Active Contributor
0 Kudos

hi Vipin,

This will download the file on Application server under the specified directory.

Check tcode AL11 for the same to check the file.

To download on desktop check FM GUI_Download.

Sachin

0 Kudos

hi

i have checked in al11,but no where the txt file is storing in any DIR.

how to locate it?Please tell

regds

Former Member

former_member184619
Active Contributor
0 Kudos

I think the directory you are using is not specified in AL11...

It is of type /usr/sap/<system ID>/put/filename..

You can dobule click on directory DIR_PUT in your case .. but first check the address in front of DIR_PUT and use the same in your code..

Regards,

Sachin

Former Member
0 Kudos

hi

here is the code for : "data from itab to be store in text file in desktop"

TABLES: vbak.    " standard table

*----------------------------------------------------------------------*
*                           Type Pools                                 *
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*                     Global Structure Definitions                     *
*----------------------------------------------------------------------*
*-- Structure to hold data from table CE1MCK2
TYPES: BEGIN OF tp_itab1,
       vbeln LIKE vbap-vbeln,
       posnr LIKE vbap-posnr,
       werks LIKE vbap-werks,
       lgort LIKE vbap-lgort,
       END OF tp_itab1.

*-- Data Declaration
DATA: t_itab1 TYPE TABLE OF tp_itab1.
DATA : i_fieldcat TYPE slis_t_fieldcat_alv.

*----------------------------------------------------------------------*
*                    Selection  Screen                                 *
*----------------------------------------------------------------------*
*--Sales document-block
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF  BLOCK b1.

*--Display option - block
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
PARAMETERS: alv_list RADIOBUTTON GROUP g1,
            alv_grid RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF  BLOCK b2.

*file download - block
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t03.
PARAMETERS: topc AS CHECKBOX,
            p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF  BLOCK b3.

*---------------------------------------------------------------------*
*                      Initialization.                                *
*---------------------------------------------------------------------*


*---------------------------------------------------------------------*
*                      At Selection Screen                            *
*---------------------------------------------------------------------*


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
    EXPORTING
      dynpfield_filename = 'P_FILE'
      dyname             = sy-cprog
      dynumb             = sy-dynnr
      filetype           = 'P'      "P-->Physical
      location           = 'P'     "P Presentation Srever
      server             = space.

AT SELECTION-SCREEN ON s_vbeln.
  PERFORM vbeln_validate.


*----------------------------------------------------------------------*
*                           Start Of Selection                         *
*----------------------------------------------------------------------*
START-OF-SELECTION.

*-- Fetching all the required data into the internal table
  PERFORM select_data.

*----------------------------------------------------------------------*
*                           End Of Selection                           *
*----------------------------------------------------------------------*
END-OF-SELECTION.

  IF t_itab1[] IS NOT INITIAL.
    IF topc IS NOT INITIAL.

      PERFORM download.
      MESSAGE 'Data Download Completed' TYPE 'S'.
    ENDIF.
    PERFORM display.
  ELSE.
    MESSAGE 'No Records Found' TYPE 'I'.
  ENDIF.

*----------------------------------------------------------------------*
*                           Top Of Page Event                          *
*----------------------------------------------------------------------*
TOP-OF-PAGE.

*&---------------------------------------------------------------------*
*& Form           :      select_data
*&---------------------------------------------------------------------*
* Description     : Fetching all the data into the internal tables
*----------------------------------------------------------------------*
*  parameters    :  none
*
*----------------------------------------------------------------------*
FORM select_data .
  SELECT vbeln
     posnr
     werks
     lgort
     INTO CORRESPONDING  FIELDS OF TABLE t_itab1
     FROM vbap
     WHERE  vbeln IN s_vbeln.
  IF sy-subrc <> 0.
    MESSAGE 'Enter The Valid Sales Document Number'(t04) TYPE 'I'.
    EXIT.
  ENDIF.
ENDFORM.                    " select_data



*&---------------------------------------------------------------------*
*& Form        : display
*&---------------------------------------------------------------------*
*  decription  : to display data in given format
*----------------------------------------------------------------------*
* parameters   :  none
*----------------------------------------------------------------------*
FORM display .

  IF alv_list = 'X'.
    PERFORM build_fieldcat TABLES i_fieldcat[]
                           USING :
*-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
   'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
   'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
   'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
   'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.



    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
*        i_callback_pf_status_set = c_pf_status
        i_callback_user_command  = 'USER_COMMAND '
*        it_events                = t_alv_events[]
        it_fieldcat              = i_fieldcat[]
      TABLES
        t_outtab                 = t_itab1[]
      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.

  ENDIF.

  IF alv_grid = 'X'.

    PERFORM build_fieldcat TABLES i_fieldcat[]
                             USING :
*-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
     'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
     'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
     'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
     'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.


    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
*        i_callback_pf_status_set = c_pf_status
        i_callback_user_command  = 'USER_COMMAND '
        it_fieldcat              = i_fieldcat
      TABLES
        t_outtab                 = t_itab1[]

    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.


  ENDIF.

ENDFORM.                    " display
*&---------------------------------------------------------------------*
*& Form        : vbeln_validate
*&---------------------------------------------------------------------*
*  description : to validate sales document number
*----------------------------------------------------------------------*
* parameters   :  none
*
*----------------------------------------------------------------------*
FORM vbeln_validate .
  DATA: l_vbeln TYPE vbak-vbeln.
  SELECT SINGLE vbeln
    FROM vbak
    INTO l_vbeln
    WHERE vbeln IN s_vbeln.
  IF sy-subrc NE 0.
    MESSAGE 'ENTER THE VALID SALES DOCUMENT NO:' TYPE 'I'.
    EXIT.
  ENDIF.

ENDFORM.                    " vbeln_validate




*&---------------------------------------------------------------------*
*& Form       :build_fieldcat
*&---------------------------------------------------------------------*
* Description : This routine fills field-catalogue
*----------------------------------------------------------------------*
*  Prameters  : none
*----------------------------------------------------------------------*
FORM build_fieldcat TABLES  fpt_fieldcat TYPE slis_t_fieldcat_alv
                    USING   fp_field     TYPE slis_fieldname
                            fp_table     TYPE slis_tabname
                            fp_length    TYPE dd03p-outputlen
                            fp_ref_tab   TYPE dd03p-tabname
                            fp_ref_fld   TYPE dd03p-fieldname
                            fp_seltext   TYPE dd03p-scrtext_l
                            fp_col_pos   TYPE sy-cucol.


*-- Local data declaration
  DATA:   wl_fieldcat TYPE slis_fieldcat_alv.

*-- Clear WorkArea

  wl_fieldcat-fieldname       = fp_field.
  wl_fieldcat-tabname         = fp_table.
  wl_fieldcat-outputlen       = fp_length.
  wl_fieldcat-ref_tabname     = fp_ref_tab.
  wl_fieldcat-ref_fieldname   = fp_ref_fld.
  wl_fieldcat-seltext_l       = fp_seltext.
  wl_fieldcat-col_pos         = fp_col_pos.


*-- Update Field Catalog Table
  APPEND wl_fieldcat  TO  fpt_fieldcat.
ENDFORM.                    "build_fieldcat
*&---------------------------------------------------------------------*
*& Form        : download
*&---------------------------------------------------------------------*
*  description : To Download The Data
*----------------------------------------------------------------------*
*  Parameters  :  none
*----------------------------------------------------------------------*
FORM download .

  DATA: l_file TYPE string.

  l_file = p_file.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = l_file
      filetype                = 'ASC'
    TABLES
      data_tab                = t_itab1
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6.
  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.                    " download

hope it will help you

regards

rahul