09-24-2008 3:59 PM
Hi All,
I want to download data to application server from a table with few condition.The problem is that there are around 450,000 records and 55 fields and the avg length of the field is 15 char.The system is SAP 4.0 B and the environment is unix.Basically it has to be done for archieving data.
If anybody can provide me the code, it will be great.
Thanks in advance,
Harsh
09-25-2008 1:50 PM
Hi,
The storage capacity of internal table is limited by the memory of the server. The system you mentioned here will put severe restrictions on the size of the internal table. You have to get data up to some records at a time. For this use statement SELECT ______ UP TO ROWS n _______ and fill the internal table. now download the file using FM: GUI_DOWNLOAD. Now put the file into your application server using
FM: ARCHIVFILE_CLIENT_TO_SERVER.
I hope this helps.
Regards,
Jeet K Bhatt
09-24-2008 4:04 PM
Please check this thread
https://forums.sdn.sap.com/search.jspa?threadID=&q=openANDdatasetANDtransfer&objID=f50&dateRange=all&numResults=15
a®
09-25-2008 6:04 AM
Hi,
But the thing is that how to deal with 4.5 lac records.Because I think we cant take this much record at once in an internal table and we have to break table,transfer ,refresh and break.But dont know how to do that.
Thnks,
Harsh
09-25-2008 10:45 AM
hi,
for this you can use Function module : "GUI_DOWNLOAD"
sample code of FM :
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.
detailed sample code of saving internal table data in application server is here:
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
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 u
regards
rahul
09-25-2008 1:13 PM
09-25-2008 1:50 PM
Hi,
The storage capacity of internal table is limited by the memory of the server. The system you mentioned here will put severe restrictions on the size of the internal table. You have to get data up to some records at a time. For this use statement SELECT ______ UP TO ROWS n _______ and fill the internal table. now download the file using FM: GUI_DOWNLOAD. Now put the file into your application server using
FM: ARCHIVFILE_CLIENT_TO_SERVER.
I hope this helps.
Regards,
Jeet K Bhatt