Call function 'Download' using different internal tables
Hi everyone!
i declare 10 different internal tables, with the same structure but different data.
i need to create 10 different files (one from each internal table)
i dont want to call 10 times the function download.
is there someway to put a variable name(that refeer to my internal table)
something like this.
PERFORM Create_file USING mytable.
PERFORM Create_file USING mytable2.
PERFORM Create_file USING mytable3.
PERFORM Create_file USING etc....
FORM create_file USING table.
DATA: file(128),
zcancel(1).
archivo = 'c:\loans.dat'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = ' '
codepage = ' '
filemask_all = ' '
filemask_mask = ' '
filemask_text = ' '
filename = file
filetype = 'dat'
filetype_no_change = ' '
filetype_no_show = ' '
item = ' '
mode = ' '
wk1_n_format = ' '
wk1_n_size = ' '
wk1_t_format = ' '
wk1_t_size = ' '
IMPORTING
cancel = zcancel
TABLES
data_tab = <b>TABLE</b>
EXCEPTIONS
invalid_filesize = 01
invalid_table_width = 02
invalid_type = 03
no_batch = 04
unknown_error = 05.
ENDFORM.
Hi,
Check this example..
It download t_mara1 & t_mara2..Modify the code according to your requirement..
DATA: t_mara1 LIKE mara OCCURS 0 WITH HEADER LINE.
DATA: t_mara2 LIKE mara OCCURS 0 WITH HEADER LINE.
DATA: v_filename LIKE rlgrap-filename.
DATA: v_char5(5).
FIELD-SYMBOLS: <fs> TYPE table.
DATA: v_variable(30).
DO 2 TIMES.
CLEAR: v_filename.
v_char5 = sy-index.
SHIFT v_char5 LEFT DELETING LEADING space.
CONDENSE v_char5.
CONCATENATE 'C:\TEST' v_char5 '.TXT' INTO v_filename.
CONCATENATE 'T_MARA' v_char5 '[]' INTO v_variable.
ASSIGN (v_variable) TO <fs>.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = v_filename
filetype = 'DAT'
TABLES
data_tab = <fs>
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
customer_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDDO.
Thanks,
Naren
Similar Messages
-
Senarious for using different internal table types
please give scenarios for using different internal table types?
Refer to the following.
Internal table types
This section describes how to define internal tables locally in a program. You can also define internal tables globally as data types in the ABAP Dictionary.
Like all local data types in programs , you define internal tables using the TYPES statement. If you do not refer to an existing table type using the TYPE or LIKE addition, you can use the TYPES statement to construct a new local internal table in your program.
TYPES <t> TYPE|LIKE <tabkind> OF <linetype> [WITH <key>]
[INITIAL SIZE <n>].
After TYPE or LIKE, there is no reference to an existing data type. Instead, the type constructor occurs:
<tabkind> OF <linetype> [WITH <key>]
The type constructor defines the table type <tabkind>, the line type <linetype>, and the key <key> of the internal table <t>.
You can, if you wish, allocate an initial amount of memory to the internal table using the INITIAL SIZE addition.
Table type
You can specify the table type <tabkind> as follows:
Generic table types
INDEX TABLE
For creating a generic table type with index access.
ANY TABLE
For creating a fully-generic table type.
Data types defined using generic types can currently only be used for field symbols and for interface parameters in procedures . The generic type INDEX TABLE includes standard tables and sorted tables. These are the two table types for which index access is allowed. You cannot pass hashed tables to field symbols or interface parameters defined in this way. The generic type ANY TABLE can represent any table. You can pass tables of all three types to field symbols and interface parameters defined in this way. However, these field symbols and parameters will then only allow operations that are possible for all tables, that is, index operations are not allowed.
Fully-Specified Table Types
STANDARD TABLE or TABLE
For creating standard tables.
SORTED TABLE
For creating sorted tables.
HASHED TABLE
For creating hashed tables.
Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
Line type
For the line type <linetype>, you can specify:
Any data type if you are using the TYPE addition. This can be a predefined ABAP type, a local type in the program, or a data type from the ABAP Dictionary. If you specify any of the generic elementary types C, N, P, or X, any attributes that you fail to specify (field length, number of decimal places) are automatically filled with the default values. You cannot specify any other generic types.
Any data object recognized within the program at that point if you are using the LIKE addition. The line type adopts the fully-specified data type of the data object to which you refer. Except for within classes, you can still use the LIKE addition to refer to database tables and structures in the ABAP Dictionary (for compatibility reasons).
All of the lines in the internal table have the fully-specified technical attributes of the specified data type.
Key
You can specify the key <key> of an internal table as follows:
[UNIQUE|NON-UNIQUE] KEY <col1> ... <col n>
In tables with a structured line type, all of the components <coli> belong to the key as long as they are not internal tables or references, and do not contain internal tables or references. Key fields can be nested structures. The substructures are expanded component by component when you access the table using the key. The system follows the sequence of the key fields.
[UNIQUE|NON-UNIQUE] KEY TABLE LINE
If a table has an elementary line type (C, D, F, I, N, P, T, X), you can define the entire line as the key. If you try this for a table whose line type is itself a table, a syntax error occurs. If a table has a structured line type, it is possible to specify the entire line as the key. However, you should remember that this is often not suitable.
[UNIQUE|NON-UNIQUE] DEFAULT KEY
This declares the fields of the default key as the key fields. If the table has a structured line type, the default key contains all non-numeric columns of the internal table that are not and do not contain references or internal tables. If the table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
Specifying a key is optional. If you do not specify a key, the system defines a table type with an arbitrary key. You can only use this to define the types of field symbols and the interface parameters of procedures . For exceptions, refer to Special Features of Standard Tables.
The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:
You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.
You must always specify the UNIQUE option when you create a hashed table.
Initial Memory Requirement
You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following addition:
INITIAL SIZE <n>
This size does not belong to the data type of the internal table, and does not affect the type check. You can use the above addition to reserve memory space for <n> table lines when you declare the table object.
When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each are then allocated.
You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The space occupied, depending on the line width, is 16 <= <n> <= 100.
It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and need to allocate exactly that amount of memory (exception: Appending table lines to ranked lists). This can be particularly important for deep-structured internal tables where the inner table only has a few entries (less than 5, for example).
To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB.
Examples
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
The program defines a table type ITAB. It is a sorted table, with line type of the structure LINE and a unique key of the component COLUMN1.
TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
TYPES: BEGIN OF DEEPLINE,
FIELD TYPE C,
TABLE1 TYPE VECTOR,
TABLE2 TYPE ITAB,
END OF DEEPLINE.
TYPES DEEPTABLE TYPE STANDARD TABLE OF DEEPLINE
WITH DEFAULT KEY.
The program defines a table type VECTOR with type hashed table, the elementary line type I and a unique key of the entire table line. The second table type is the same as in the previous example. The structure DEEPLINE contains the internal table as a component. The table type DEEPTABLE has the line type DEEPLINE. Therefore, the elements of this internal table are themselves internal tables. The key is the default key - in this case the column FIELD. The key is non-unique, since the table is a standard table.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm -
How to use an internal table of a calling program in to a called program
Hi Experts,
I am calling a report in another report through SUBMIT .
I want to use the internal table of calling prog into
called prog but problem is i have to do it without exporting to memory id and importing it.
Plz provide me any soln..Check for more information on SUBMIT
[http://www.sapdevelopment.co.uk/reporting/rep_submit.htm] -
DATA UPLOAD into 5 Different Internal Tables !!!
Hi ABAPers,
I have data in 5 different TABS of an Excel Sheet.
I have to UPLOAD this data in these different TABS to 5 different Internal tables.
Can any one give me a solution to this ???take data from all internal tabels into final internal table.....and proceed in below way......
fill ur inetnal table and call call the below form DOWNLOAD_TO_EXCEL, This Form is displaying an internal table it_outtab
Move data from it_outtab to it_excel
it_excel will contain all the charecter fields
DATA : BEGIN OF IT_EXCEL OCCURS 0,
FLD1(32),
FLD2(32),
FLD3(32),
FLD4(32),
FLD5(32),
FLD6(32),
FLD7(32),
FLD8(32),
FLD9(32),
FLD10(32),
FLD11(32),
FLD12(32),
FLD13(32),
FLD14(32),
FLD15(32),
FLD16(32),
FLD17(32),
FLD18(32),
FLD19(32),
FLD20(32),
FLD21(32),
END OF IT_EXCEL.
FORM DOWNLOAD_TO_EXCEL.
PERFORM GET_FILE_NAME .
CLEAR IT_EXCEL.
REFRESH IT_EXCEL.
IF NOT FNAME IS INITIAL .
PERFORM POPULATE_HEADER_DETAIL.
LOOP AT IT_OUTTAB.
IT_EXCEL-FLD1 = IT_OUTTAB-BANFN.
IT_EXCEL-FLD2 = IT_OUTTAB-BNFPO.
IT_EXCEL-FLD3 = IT_OUTTAB-EBELN.
IT_EXCEL-FLD4 = IT_OUTTAB-EBELP.
IT_EXCEL-FLD5 = IT_OUTTAB-STYLE.
IT_EXCEL-FLD6 = IT_OUTTAB-SKU.
IT_EXCEL-FLD7 = IT_OUTTAB-LP_COLOR.
IT_EXCEL-FLD8 = IT_OUTTAB-MAKTX.
IT_EXCEL-FLD9 = IT_OUTTAB-CURR_PRICE.
IF NOT IT_OUTTAB-VALID_FROM IS INITIAL.
CONCATENATE IT_OUTTAB-VALID_FROM+4(2) '/'
IT_OUTTAB-VALID_FROM+6(2) '/'
IT_OUTTAB-VALID_FROM(4) INTO IT_EXCEL-FLD10.
ENDIF.
IF NOT IT_OUTTAB-VALID_TO IS INITIAL.
CONCATENATE IT_OUTTAB-VALID_TO+4(2) '/'
IT_OUTTAB-VALID_TO+6(2) '/'
IT_OUTTAB-VALID_TO(4) INTO IT_EXCEL-FLD11.
ENDIF.
IT_EXCEL-FLD12 = IT_OUTTAB-FUT_PRICE.
IT_EXCEL-FLD13 = IT_OUTTAB-FAC_PRICE.
IF NOT IT_OUTTAB-FAC_VALID_FROM IS INITIAL.
CONCATENATE IT_OUTTAB-FAC_VALID_FROM+4(2) '/'
IT_OUTTAB-FAC_VALID_FROM+6(2) '/'
IT_OUTTAB-FAC_VALID_FROM(4) INTO IT_EXCEL-FLD14.
ENDIF.
IF NOT IT_OUTTAB-FAC_VALID_TO IS INITIAL.
CONCATENATE IT_OUTTAB-FAC_VALID_TO+4(2) '/'
IT_OUTTAB-FAC_VALID_TO+6(2) '/'
IT_OUTTAB-FAC_VALID_TO(4) INTO IT_EXCEL-FLD15.
ENDIF.
IT_EXCEL-FLD16 = IT_OUTTAB-JPN_PRICE.
IT_EXCEL-FLD17 = IT_OUTTAB-EAN11_1.
IT_EXCEL-FLD18 = IT_OUTTAB-EAN11_2.
IT_EXCEL-FLD19 = IT_OUTTAB-HANG_TAG_STAT.
IT_EXCEL-FLD20 = IT_OUTTAB-LABEL_STAT.
IT_EXCEL-FLD21 = IT_OUTTAB-CJI_STAT.
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
ENDLOOP.
CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'
EXPORTING
CHECK_VERSION = ' '
DATA_NAME = FNAME
DATA_PATH_FLAG = ''
DATA_TYPE = 'DAT'
DATA_BIN_FILE_SIZE =
MACRO_NAME = ' '
MACRO_PATH_FLAG = 'E'
FORCE_START = ' '
WAIT = ''
IMPORTING
WINID =
TABLES
DATA_TAB = IT_EXCEL
EXCEPTIONS
NO_BATCH = 1
EXCEL_NOT_INSTALLED = 2
WRONG_VERSION = 3
INTERNAL_ERROR = 4
INVALID_TYPE = 5
CANCELLED = 6
DOWNLOAD_ERROR = 7
OTHERS = 8
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. " DOWNLOAD_TO_EXCEL
FORM GET_FILE_NAME.
DATA: TMP_FILENAME LIKE RLGRAP-FILENAME,
GLOBAL_FILEMASK_ALL(80),
GLOBAL_FILEMASK_MASK(20), GLOBAL_FILEMASK_TEXT(20),
GLOBAL_DOWNLOAD_PATH LIKE RLGRAP-FILENAME,
DEF_PATH LIKE RLGRAP-FILENAME,
FIELDLN TYPE I,
MODE TYPE C,
TMP_MASK LIKE GLOBAL_FILEMASK_ALL.
FIELD-SYMBOLS: .
IF GLOBAL_FILEMASK_MASK IS INITIAL.
TMP_MASK = ',.,..'.
ELSE.
TMP_MASK = ','.
WRITE GLOBAL_FILEMASK_TEXT TO TMP_MASK+1.
WRITE ',' TO TMP_MASK+21.
WRITE GLOBAL_FILEMASK_MASK TO TMP_MASK+22.
WRITE '.' TO TMP_MASK+42.
CONDENSE TMP_MASK NO-GAPS.
ENDIF.
IF NOT GLOBAL_FILEMASK_ALL IS INITIAL.
TMP_MASK = GLOBAL_FILEMASK_ALL.
ENDIF.
FIELDLN = STRLEN( DEF_PATH ) - 1.
ASSIGN DEF_PATH+FIELDLN(1) TO .
ENDIF.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = FNAME "rlgrap-filename
DEF_PATH = DEF_PATH
MASK = TMP_MASK
MODE = MODE
TITLE = ' '
IMPORTING
FILENAME = FNAME
RC =
EXCEPTIONS
INV_WINSYS = 01
NO_BATCH = 02
SELECTION_CANCEL = 03
SELECTION_ERROR = 04.
IF SY-SUBRC = 0.
FNAME = TMP_FILENAME.
ELSE.
ENDIF.
ENDFORM. " GET_FILE_NAME
FORM POPULATE_HEADER_DETAIL.
IT_EXCEL-FLD8 = 'S U D H E E R'.
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
IT_EXCEL-FLD1 = 'Price Validation Report'.
IT_EXCEL-FLD14 = 'Page'.
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
IT_EXCEL-FLD1 = 'Vendor Number/Name'.
IT_EXCEL-FLD3 = 'Plan Month'.
IT_EXCEL-FLD4 = 'Effective In-store-Date'.
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
IT_EXCEL-FLD1 = VENDOR_NAME.
IT_EXCEL-FLD3 = P_BEDNR.
IT_EXCEL-FLD4 = P_EFF_DT.
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
sudheer start
APPEND IT_EXCEL.
IT_EXCEL-FLD1 = 'PR'.
IT_EXCEL-FLD2 = 'Line'.
IT_EXCEL-FLD3 = 'PO'.
IT_EXCEL-FLD4 = 'PO Line'.
IT_EXCEL-FLD5 = 'Style'.
IT_EXCEL-FLD6 = 'SKU'.
IT_EXCEL-FLD7 = 'Long Color'.
IT_EXCEL-FLD8 = 'Material Description'.
IT_EXCEL-FLD9 = 'Current Price'.
IT_EXCEL-FLD10 = 'validity'.
IT_EXCEL-FLD11 = 'Period'.
IT_EXCEL-FLD12 = 'Future Price'.
IT_EXCEL-FLD13 = 'Factory Price'.
IT_EXCEL-FLD14 = 'Validity'.
IT_EXCEL-FLD15 = 'Period'.
IT_EXCEL-FLD16 = 'Japan Price'.
IT_EXCEL-FLD17 = 'First UPC'.
IT_EXCEL-FLD18 = 'Factory UPC'.
IT_EXCEL-FLD19 = 'Hang Tag Status'.
IT_EXCEL-FLD20 = 'Label Status'.
IT_EXCEL-FLD21 = 'CJI Label Status'.
*sudheer end
APPEND IT_EXCEL.
CLEAR IT_EXCEL.
ENDFORM. " POPULATE_HEADER_DETAIL
Check these links for sample code :
http://www.sapdevelopment.co.uk/ms/ms_excel.htm
please check this example:
FORM download.
DATA: lh_file1 TYPE rlgrap-filename,
lh_file2 TYPE rlgrap-filename,
lh_file3 TYPE rlgrap-filename,
lh_datda(1).
CLEAR: lh_file1, lh_file2, lh_file3.
Download neue Daten
CONCATENATE xh_pfad 'Datafile materialmaster new ' sy-datum(4)
sy-datum4(2) sy-datum6(2) sy-uzeit '.xls' INTO lh_file1.
working area
DATA: index TYPE i,
lh_col TYPE i.
FIELD-SYMBOLS: .
SORT xt_bmm00 BY matnr.
SORT xt_bmmh1 BY matnr.
SORT xt_bmmh4 BY matnr.
SORT xt_bmmh7 BY matnr.
IF NOT xt_bmm00[] IS INITIAL.
MOVE 'X' TO lh_datda.
DO 4 TIMES.
CASE sy-index.
WHEN 1.
CREATE OBJECT lh_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF lh_excel 'Visible' = 1 .
GET PROPERTY OF lh_excel 'Workbooks' = lh_workbooks .
GET PROPERTY OF lh_workbooks 'Application' = lh_application .
SET PROPERTY OF lh_application 'SheetsInNewWorkbook' = 1 .
CALL METHOD OF lh_workbooks 'Add' = lh_workbook .
CALL METHOD OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Item' = lh_sheet
EXPORTING #1 = sy-index .
SET PROPERTY OF lh_sheet 'NAME' = 'BMMH7'.
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S005'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_bmmh7.
index = sy-tabix + 1.
DO 4 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_bmmh7 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
WHEN 2.
GET PROPERTY OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Add' = lh_newsheet .
SET PROPERTY OF lh_newsheet 'Name' = 'BMMH4'.
CALL METHOD OF lh_excel 'WorkSheets' = lh_activesheet
EXPORTING #1 = 'BMMH4'.
CALL METHOD OF lh_activesheet 'Activate' .
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S004'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_bmmh4.
index = sy-tabix + 1.
DO 4 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_bmmh4 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
WHEN 3.
GET PROPERTY OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Add' = lh_newsheet .
SET PROPERTY OF lh_newsheet 'Name' = 'BMMH1'.
CALL METHOD OF lh_excel 'WorkSheets' = lh_activesheet
EXPORTING #1 = 'BMMH1'.
CALL METHOD OF lh_activesheet 'Activate' .
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S003'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
Die folgende Abfrage ist notwendig, weil der Namensraum ZZ...
in der Struktur nicht erlaubt ist, aber im Excel-Sheet als
Überschrift gebraucht wird.
IF xt_ftab-fieldname = 'SPIRIDON'.
MOVE 'ZZSSN' TO xt_ftab-fieldname.
ENDIF.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_bmmh1.
index = sy-tabix + 1.
DO 72 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_bmmh1 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
WHEN 4.
GET PROPERTY OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Add' = lh_newsheet .
SET PROPERTY OF lh_newsheet 'Name' = 'BMM00'.
CALL METHOD OF lh_excel 'WorkSheets' = lh_activesheet
EXPORTING #1 = 'BMM00'.
CALL METHOD OF lh_activesheet 'Activate' .
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S002'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_bmm00.
index = sy-tabix + 1.
DO 21 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_bmm00 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
ENDCASE.
ENDDO.
CALL METHOD OF lh_workbook 'SAVEAS'
EXPORTING #1 = lh_file1.
CALL METHOD OF lh_excel 'QUIT'.
FREE OBJECT: lh_cells, lh_sheet, lh_sheets, lh_application,
lh_workbook, lh_workbooks, lh_excel,
lh_chart, lh_activesheet.
ENDIF.
Download geänderter Materialstammdaten
CONCATENATE xh_pfad 'Datafile materialmaster change ' sy-datum(4)
sy-datum4(2) sy-datum6(2) sy-uzeit '.xls' INTO lh_file2.
IF NOT xt_emmh1[] IS INITIAL.
MOVE 'X' TO lh_datda.
DO 2 TIMES.
CALL METHOD OF lh_sheets 'Item' = lh_sheet
EXPORTING #1 = sy-index .
CASE sy-index.
WHEN 1.
CREATE OBJECT lh_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF lh_excel 'Visible' = 1 .
GET PROPERTY OF lh_excel 'Workbooks' = lh_workbooks .
GET PROPERTY OF lh_workbooks 'Application' = lh_application .
SET PROPERTY OF lh_application 'SheetsInNewWorkbook' = 1 .
CALL METHOD OF lh_workbooks 'Add' = lh_workbook .
CALL METHOD OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Item' = lh_sheet
EXPORTING #1 = sy-index .
SET PROPERTY OF lh_sheet 'NAME' = 'BMMH7'.
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S005'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_emmh7.
index = sy-tabix + 1.
DO 4 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_emmh7 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
WHEN 2.
GET PROPERTY OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Add' = lh_newsheet .
SET PROPERTY OF lh_newsheet 'Name' = 'BMMH1'.
CALL METHOD OF lh_excel 'WorkSheets' = lh_activesheet
EXPORTING #1 = 'BMMH1'.
CALL METHOD OF lh_activesheet 'Activate' .
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S003'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
Die folgende Abfrage ist notwendig, weil der Namensraum ZZ...
in der Struktur nicht erlaubt ist, aber im Excel-Sheet als
Überschrift gebraucht wird.
IF xt_ftab-fieldname = 'SPIRIDON'.
MOVE 'ZZSSN' TO xt_ftab-fieldname.
ENDIF.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_emmh1.
index = sy-tabix + 1.
DO 72 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_emmh1 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
ENDCASE.
ENDDO.
CALL METHOD OF lh_workbook 'SAVEAS'
EXPORTING #1 = lh_file2.
CALL METHOD OF lh_excel 'QUIT'.
FREE OBJECT: lh_cells, lh_sheet, lh_sheets, lh_application,
lh_workbook, lh_workbooks, lh_excel,
lh_chart, lh_activesheet.
ENDIF.
Download geänderter Texte
CONCATENATE xh_pfad 'Datafile materialmaster change PO ' sy-datum(4)
sy-datum4(2) sy-datum6(2) sy-uzeit '.xls' INTO lh_file3.
IF NOT xt_tmmh7[] IS INITIAL.
CLEAR: lh_cells, lh_sheet, lh_sheets, lh_application,
lh_workbook, lh_workbooks, lh_excel,
lh_chart, lh_activesheet.
MOVE 'X' TO lh_datda.
CREATE OBJECT lh_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF lh_excel 'Visible' = 1 .
GET PROPERTY OF lh_excel 'Workbooks' = lh_workbooks .
GET PROPERTY OF lh_workbooks 'Application' = lh_application .
SET PROPERTY OF lh_application 'SheetsInNewWorkbook' = 1 .
CALL METHOD OF lh_workbooks 'Add' = lh_workbook .
CALL METHOD OF lh_workbook 'Sheets' = lh_sheets .
CALL METHOD OF lh_sheets 'Item' = lh_sheet
EXPORTING #1 = 1 .
SET PROPERTY OF lh_sheet 'NAME' = 'BMMH7'.
Überschrift erstellen
CLEAR xt_ftab.
REFRESH xt_ftab.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
tabname = '/SIE/TS_MM01S005'
withtext = ' '
only = 'T'
TABLES
fieldtab = xt_ftab
EXCEPTIONS
OTHERS = 1.
CLEAR lh_col.
LOOP AT xt_ftab.
ADD 1 TO lh_col.
PERFORM fill_cell
USING 1 lh_col xt_ftab-fieldname lh_excel lh_cells.
ENDLOOP.
LOOP AT xt_tmmh7.
index = sy-tabix + 1.
DO 4 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE xt_tmmh7 TO lh_excel lh_cells.
ENDIF.
ENDDO.
ENDLOOP.
CALL METHOD OF lh_workbook 'SAVEAS'
EXPORTING #1 = lh_file3.
CALL METHOD OF lh_excel 'QUIT'.
FREE OBJECT: lh_cells, lh_sheet, lh_sheets, lh_application,
lh_workbook, lh_workbooks, lh_excel,
lh_chart, lh_activesheet.
ENDIF.
IF lh_datda NE 'X'.
MESSAGE i016.
ENDIF.
ENDFORM. " download
FORM fill_cell USING p_i
value
p_customer_cell1
h_excel
h_cells.
CALL METHOD OF h_excel 'Cells' = h_cells EXPORTING #1 = p_i #2 = value.
SET PROPERTY OF lh_cells 'Numberformat' = '@'.
SET PROPERTY OF h_cells 'Value' = p_customer_cell1.
ENDFORM. " fill_cell -
Download data from internal table to flat file.
I need to download the data from Internal table to Flat file. can any one suggest how to do it? i suppose WS_Download OR GUI_DOWNLOAD.
but if it is please guide me how to use this.
is thre any other F.M. please provide the information.
Thanks in advanceHi,
Try this,
* File download, uses older techniques but achieves a perfectly
* acceptable solution which also allows the user to append data to
* an existing file.
PARAMETERS: p_file like rlgrap-filename.
* Internal table to store export data
DATA: begin of it_excelfile occurs 0,
row(500) type c,
end of it_excelfile.
DATA: rc TYPE sy-ucomm,
ld_answer TYPE c.
CALL FUNCTION 'WS_QUERY'
EXPORTING
query = 'FE' "File Exist?
filename = p_file
IMPORTING
return = rc.
IF rc NE 0. "If File alread exists
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
text_question = 'File Already exists!!'
text_button_1 = 'Replace'
* ICON_BUTTON_1 = ' '
text_button_2 = 'New name'
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
IMPORTING
answer = ld_answer
* TABLES
* PARAMETER =
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
* Option 1: Overwrite
IF ld_answer EQ '1'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = p_file "File Name
filetype = 'ASC'
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_excelfile "Data table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE i003(zp) WITH
'There was an error during Excel file creation'(200).
exit. "Causes short dump if removed and excel document was open
ENDIF.
* Option 2: New name.
ELSEIF ld_answer EQ '2'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = p_file "File name
filetype = 'ASC' "File type
* col_select = 'X' "COL_SELECT
* col_selectmask = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
* "COL_SELECTMASK
filetype_no_show = 'X' "Show file type selection?
* IMPORTING
* act_filename = filename_dat
TABLES
data_tab = it_excelfile "Data table
* fieldnames =
EXCEPTIONS
file_open_error = 01
file_write_error = 02
invalid_filesize = 03
invalid_table_width = 04
invalid_type = 05
no_batch = 06
unknown_error = 07.
ENDIF.
ELSE. "File does not alread exist.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = p_file "File name
filetype = 'ASC' "File type
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_excelfile "Data table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE i003(zp) WITH
'There was an error during Excel file creation'(200).
exit. "Causes short dump if removed and excel document was open
ENDIF.
ENDIF.
Regards,
Raghav -
Problem disalying alv using dynamic internal table
Hi All,
I have 4 radiobutton for each radiobutton there is one internaltable to be displayed in alv.
My requirement is intead of calling the function module reuse_alv_grid_display everytime for
each of the internal table I want to create a dynamic internal tble for the function module.
My question is how to create a dynamic internal table which will hold the fields & data of
different interna table when diffrent radiobuttons are checked.
Areciate your time to help.
Thank you very much.Hi follow following logic:
field-symbols: <i_table> type standard table.
when rb1 is checked.
assign itab1 to <i_table>.
perform alv_disp using <i_table>
when rb2 is checked.
assign itab2 to <i_table>.
perform alv_disp using <i_table>
when rb3 is checked.
assign itab3 to <i_table>.
perform alv_disp using <i_table>
when rb4 is checked.
assign itab4 to <i_table>.
perform alv_disp using <i_table>
<<<<<<<<<<form alv_disp
form alv_disp using p_i_table type standard table.
perform create fieldcatelog changing i_fc
call the fm and pass the table p_i_table and i_fc
<<<<<<<<<< form create fieldcaelog
here create field catelog ..either by fm reuse_alv_fieldcatelog_merge ...in this just pass the structure name based on the radiobutton
hope its useful -
How to use dynamic internal table when using gui_upload?
Hi Experts,
my scenario is like i have header data, item data and serial numbers.
so with respect to the quantity in unit of measure ,there will be number of serial numbers..
i have declared the dynamic internal table,but i am not getting the logic to change the structure accordingly with respect to the flat file entries..
is it possible to do or its not possible....any suggestion!!!!i have declared like this....
TYPES: BEGIN OF ty_final,
bldat TYPE string, "Document Date
budat TYPE string, "Psting Date
bktxt TYPE string, "Document Header Text
werks TYPE string, "Plant
lgort TYPE string, "Storage Location
matnr TYPE string, "Material Number
erfmg TYPE string, "Quantity in Unit Of Entry
anln1 TYPE string, "Asset Number
anln2 TYPE string, "Asset Subnumber
sernr TYPE string, "serial Number
END OF ty_final.
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
FIELD-SYMBOLS : <fs_final> TYPE table.
ASSIGN it_final TO <fs_final>.
after this i called gui upload and passed internal table it_final..
but i have to change the internal table structure dynamically before the upload function.so that it will match with the flat file...
Regards
KarthickThere are at least two approaches you can use to change/generate new dynamic-structured table. Either with [RTTI + RTTS|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] or using [CL_ALV_TABLE_CREATE|http://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create] . In this one just determine fieldcatalog of current table and change it accordingly, then regenarate table.
There are plenty of examples in SCN for this. You should not face difficulties applying this.
Regards
Marcin -
How to populate field catalogue fields in ALV using dynamic internal table
Hi All,
Please let me know how to populate field catalogue fields in ALV using dynamic internal table.
I have created <dyn_table> using code below.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = g_t_ifc
it_fieldcatalog = g_t_fieldcat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
Now this <dyn_table> has fields like idoc no.,creation date ,
segment field 1, segment field 2 etc..Now idoc no.,creation date are static fields from table EDIDC. And segment field 1, segment field 2 etc are dynamic fields from table EDSAPPL.
In my ALV report I am getting the final layout properly but I am unable to move values to corresponding fields in the final layout shown.Please let me know how to populate these fields from different tables.
I tried this way but its not working.
SORT g_t_edid4 BY docnum.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
<dyn_wa> = g_r_edid4-sdata.
MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.You have to assign each field to field symbol and then assign the value to that field symbol and asssign that field symbol to workarea field symbol.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'SDATA' OF STRUCTURE <DYN_WA> TO <DYN_FLD>.
<DYN_FLD> = g_r_edid4-sdata.
" <dyn_wa> = g_r_edid4-sdata.
" Assign each fields like this.
" MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
" MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
Regards,
Naimesh Patel -
Downloading data from internal table to xls file leading zeros are not disp
Hai abap gurus,
when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
Ex:
<b>ECC Code.</b>
045234
88567
098456
but output is giving like this:
45234
88567
98456
how to get the actual values.....
plz help me in this matter.Dear Kiran,
Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
Then use the function module to download the content of the internal table to the excel file.
Regards,
Abir
Don't forget to Reward Points * -
BADI cant use an internal table with header line
hi,
In BADI, we cant use an internal table with header line, and I am calling a function module which requires internal table as import parameter, now, the table I am passing is without a header line, So how to solve this problem ?You can use a type and then create an internal table of that type.
types :
begin of t_<example>
*field list
end of t_<example>
data :
gt_<table> type standard table of t_<example>
pass this to the FM -
How to use the internal table of the submitted program
Hi,
In the main program i have submitted a program and that program is running successfully and data is populated in to it_final, now i want to use this data populated internal table it_final in my main program.
Thanks,
Sudhakar.Hi,Mathew,
*& Report ZMB51 *
REPORT ZMB51 .
DATA LIST_TAB TYPE TABLE OF ABAPLIST.
DATA: BEGIN OF olist OCCURS 0,
filler1(1500) TYPE c,
END OF olist.
submit <b>RM07DOCS</b> EXPORTING LIST TO MEMORY
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = LIST_TAB
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
LIST_INDEX = -1
TABLES
LISTASCI = oLIST
LISTOBJECT = LIST_TAB
EXCEPTIONS
EMPTY_LIST = 1
LIST_INDEX_INVALID = 2
OTHERS = 3.
BREAK-POINT.
write:/ sy-subrc.
ENDIF.
OLIST will contain the report output that you have executed but you need to tweak this internal table so that it can be used for further processing.The current example will get you MB51 output into OLIST,so change the program name to your program name at the SUBMIT statement and then try.
K.Kiran. -
Create Table Control using Dynamic Internal Table.
Hi,
I have requirement in which I will create a Dynamic Internal Table and then I need to create a Table Control Using that Internal Table. Now this can't be done using Screen Editor as it requires a pre-defined internal table or a DDIC Object.
Please Help.This should be correct answer(I am not author of code below):
REPORT ztablemaintace NO STANDARD PAGE HEADING.
TYPE-POOLS: rsds.
DATA: is_x030l TYPE x030l,
it_dfies TYPE TABLE OF dfies,
is_dfies TYPE dfies,
it_fdiff TYPE TABLE OF field_dif,
is_fdiff TYPE field_dif.
DATA: w_selid TYPE rsdynsel-selid,
it_tables TYPE TABLE OF rsdstabs,
is_tables TYPE rsdstabs,
it_fields TYPE TABLE OF rsdsfields,
it_expr TYPE rsds_texpr,
it_ranges TYPE rsds_trange,
it_where TYPE rsds_twhere,
is_where TYPE rsds_where,
w_active TYPE i.
DATA: it_content TYPE REF TO data,
it_modif TYPE REF TO data,
it_fcat TYPE lvc_t_fcat.
DATA: w_okcode TYPE sy-ucomm.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE,
<ntab> TYPE STANDARD TABLE.
* Macros
DEFINE table_error.
message e398(00) with 'Table' p_table &1.
END-OF-DEFINITION.
DEFINE fixed_val.
is_fdiff-fieldname = is_dfies-fieldname.
is_fdiff-fixed_val = &1.
is_fdiff-no_input = 'X'.
append is_fdiff to it_fdiff.
END-OF-DEFINITION.
* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: p_table TYPE tabname OBLIGATORY "table
MEMORY ID dtb
MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: BEGIN OF LINE,
PUSHBUTTON 33(20) selopt USER-COMMAND sel,
COMMENT 55(15) selcnt,
END OF LINE.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_rows TYPE i. "rows
SELECTION-SCREEN: END OF BLOCK b01,
SKIP,
BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: p_displ TYPE c AS CHECKBOX. "display
SELECTION-SCREEN: END OF BLOCK b02.
* Initialization
INITIALIZATION.
MOVE '@4G@ Filter records' TO selopt.
* PBO
AT SELECTION-SCREEN OUTPUT.
IF w_active IS INITIAL.
CLEAR: selcnt.
ELSE.
WRITE w_active TO selcnt LEFT-JUSTIFIED.
ENDIF.
* PAI
AT SELECTION-SCREEN.
IF p_table NE is_x030l-tabname.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
tabname = p_table
IMPORTING
x030l_wa = is_x030l
TABLES
dfies_tab = it_dfies
EXCEPTIONS
OTHERS = 1.
IF is_x030l IS INITIAL.
table_error 'does not exist or is not active'.
ELSEIF is_x030l-tabtype NE 'T'.
table_error 'is not selectable'.
* ELSEIF is_x030l-align NE 0.
* table_error 'has alignment - cannot continue'.
ENDIF.
* Default values for system fields
REFRESH: it_fdiff.
is_fdiff-tabname = p_table.
LOOP AT it_dfies INTO is_dfies.
IF is_dfies-datatype = 'CLNT'.
fixed_val sy-mandt.
ELSEIF is_dfies-rollname = 'ERDAT'
OR is_dfies-rollname = 'ERSDA'
OR is_dfies-rollname = 'AEDAT'
OR is_dfies-rollname = 'LAEDA'.
fixed_val sy-datum.
ELSEIF is_dfies-rollname = 'ERTIM'
OR is_dfies-rollname = 'AETIM'.
fixed_val sy-uzeit.
ELSEIF is_dfies-rollname = 'ERNAM'
OR is_dfies-rollname = 'AENAM'.
fixed_val sy-uname.
ENDIF.
CALL FUNCTION '/SAPDMC/DATAELEMENT_GET_TEXTS'
EXPORTING
name = is_dfies-rollname
IMPORTING
text_middle = is_dfies-reptext
EXCEPTIONS
not_found = 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.
MODIFY it_dfies FROM is_dfies.
ENDLOOP.
* Prepare free selection on table
REFRESH it_tables.
is_tables-prim_tab = p_table.
APPEND is_tables TO it_tables.
CLEAR: w_selid.
ENDIF.
IF sy-ucomm = 'SEL'.
IF w_selid IS INITIAL.
* Init free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = it_expr
IMPORTING
selection_id = w_selid
expressions = it_expr
TABLES
tables_tab = it_tables
EXCEPTIONS
OTHERS = 1.
ENDIF.
* Display free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = w_selid
title = 'Selection'
status = 1
as_window = 'X'
IMPORTING
expressions = it_expr
field_ranges = it_ranges
number_of_active_fields = w_active
TABLES
fields_tab = it_fields
EXCEPTIONS
OTHERS = 1.
ENDIF.
* Start of processing
START-OF-SELECTION.
PERFORM f_create_table USING p_table.
PERFORM f_select_table.
PERFORM f_display_table.
* FORM f_create_table *
FORM f_create_table USING in_tabname.
FIELD-SYMBOLS: <fcat> TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = in_tabname
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
* Complete field catalog
LOOP AT it_fcat ASSIGNING <fcat>.
<fcat>-tabname = in_tabname.
ENDLOOP.
CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
ELSE.
WRITE: 'Error building field catalog'.
STOP.
ENDIF.
* Create dynamic table for data
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_content.
IF sy-subrc = 0.
ASSIGN it_content->* TO <itab>.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.
* Create dynamic table for modif
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_modif.
IF sy-subrc = 0.
ASSIGN it_modif->* TO <ntab>.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.
ENDFORM. "f_create_table
* FORM f_select_table *
FORM f_select_table.
IF w_active = 0.
SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <itab>
UP TO p_rows ROWS.
ELSE.
* Selection with parameters
CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
EXPORTING
field_ranges = it_ranges
IMPORTING
where_clauses = it_where.
READ TABLE it_where INTO is_where WITH KEY tablename = p_table.
SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <itab>
UP TO p_rows ROWS
WHERE (is_where-where_tab).
ENDIF.
IF sy-dbcnt = 0.
WRITE: 'No record selected'.
STOP.
ENDIF.
ENDFORM. "f_select_table
* FORM f_display_table *
FORM f_display_table.
DATA: l_answer TYPE c,
l_eflag TYPE c.
CLEAR: w_okcode.
REFRESH: <ntab>.
* Display table contents
CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
EXPORTING
header = p_table
tabname = p_table
display_only = p_displ
endless = 'X'
no_button = space
IMPORTING
okcode = w_okcode
TABLES
* nametab = it_dfies
table = <itab>
* fielddif = it_fdiff
modif_table = <ntab>
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
IF p_displ IS INITIAL AND w_okcode = 'SAVE'.
* Confirm update
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = p_table
text_question = 'Do you want to update table ?'
default_button = '2'
display_cancel_button = ' '
IMPORTING
answer = l_answer
EXCEPTIONS
OTHERS = 1.
IF l_answer = '1'.
* Apply modifications
IF NOT <ntab>[] IS INITIAL.
PERFORM f_add_system USING space.
MODIFY (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
l_eflag = 'X'.
ENDIF.
ENDIF.
* Apply deletions
IF l_eflag IS INITIAL.
REFRESH: <ntab>.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
deleted_data = <ntab>
EXCEPTIONS
OTHERS = 1.
IF NOT <ntab>[] IS INITIAL.
DELETE (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
* Apply creations
IF l_eflag IS INITIAL.
REFRESH: <ntab>.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
new_data = <ntab>
EXCEPTIONS
OTHERS = 1.
IF NOT <ntab>[] IS INITIAL.
PERFORM f_add_system USING 'X'.
INSERT (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
IF l_eflag IS INITIAL.
COMMIT WORK.
MESSAGE s261(53).
ELSE.
MESSAGE s075(3i).
PERFORM f_select_table.
ENDIF.
ENDIF.
* Display table again
PERFORM f_display_table.
ENDIF.
ENDIF.
ENDFORM. "f_display_table
* FORM f_add_system *
FORM f_add_system USING new TYPE c.
FIELD-SYMBOLS: <irec> TYPE ANY,
<upd> TYPE ANY.
LOOP AT it_fdiff INTO is_fdiff.
READ TABLE it_dfies INTO is_dfies
WITH KEY fieldname = is_fdiff-fieldname.
LOOP AT <ntab> ASSIGNING <irec>.
ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE <irec> TO <upd>.
IF is_dfies-datatype = 'CLNT'.
<upd> = sy-mandt.
ELSE.
CASE is_dfies-rollname.
WHEN 'AENAM'.
<upd> = sy-uname.
WHEN 'AEDAT' OR 'LAEDA'.
<upd> = sy-datum.
WHEN 'AETIM'.
<upd> = sy-uzeit.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. "f_add_system -
Passing data to different internal tables with different columns from a comma delimited file
Hi,
I have a program wherein we upload a comma delimited file and based on the region( we have drop down in the selection screen to pick the region). Based on the region, the data from the file is passed to internal table. For region A, we have 10 columns and for region B we have 9 columns.
There is a split statement (split at comma) used to break the data into different columns.
I need to add hard error messages if the no. of columns in the uploaded file are incorrect. For example, if the uploaded file is of type region A, then the uploaded file should be split into 10 columns. If the file contains lesser or more columns thenan error message should be added. Similar is the case with region B.
I do not want to remove the existing split statement(existing code). Is there a way I can exactly pass the data into the internal table accurately? I have gone through some posts where in they have made use of the method cl_alv_table_create=>create_dynamic_table by passing the field catalog. But I cannot use this as I have two different internal tables to be populated based on the region. Appreciate help on this.
Thanks,
PavanHi Abhishek,
I have no issues with the rows. I have a file with format like a1,b1,c1,d1,e1, the file should be uploaded and split at comma. So far its fine. After this, if the file is related to region A say Asia, then it should have 5 fields( as an example). So, all the 5 values a1,b1..e1 will be passed to 5 fields of itab1.
I also have region B( say Europe) whose file will have only 4 fields. So, file is of the form a2,b2,c2,d2. Again data is split at comma and passed to itab2.
If some one loads file related to Asia and the file has only 4 fields then the data would be incorrect. Similar is the case when someone tries to load Europe file with 5 fields related data. To avoid this, I want to validate the data uploaded. For this, I want to count the no. of fields (seperated by comma). If no. of fields is 5 then the file is related to Asia or if no. of fields is 4 then it is Europe file.
Well, the no. of commas is nothing but no. of fields - 1. If the file is of the form a1,b1..e1 then I can say like if no. of commas = 4 then it is File Asia.But I am not sure how to write a code for this.Please advise.
Thanks,
Pavan -
What are the advantages of using an internal table with workarea
Hi,
can anyone tell me
What are the advantages of using an internal table with workarea
over an internal table with header line?
thnks in adv
regards
nagiHI,
Internal tables are a standard data type object which exists only during the runtime of the program. They are used to perform table calculations on subsets of database tables and for re-organising the contents of database tables according to users need.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm
<b>Difference between Work Area and Header Line</b>
While adding or retrieving records to / from internal table we have to keep the record temporarily.
The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
e.g.
data: begin of itab occurs 10,
ab type c,
cd type i,
end of itab. " this table will have the header line.
data: wa_itab like itab. " explicit work area for itab
data: itab1 like itab occurs 10. " table is without header line.
The header line is a field string with the same structure as a row of the body, but it can only hold a single row.
It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table
1) The difference between
whih header line and with out heater line of internal table.
ex:-
a) Data : itab like mara occurs 0 with header line.
b) Data: itab like mara occurs 0.
-While adding or retrieving records to / from internal table we have to keep the record temporarily.
-The area where this record is kept is called as work area for the internal table.
-The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
-Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
a) Data : itab like mara occurs 0 with header line.
table is with header line
b) Data: itab like mara occurs 0.
table is without header line
2)work area / field string and internal table
which one is prefarable for good performance any why ?
-The header line is a field string with the same structure as a row of the body, but it can only hold a single row , whereas internal table can have more than one record.
In short u can define a workarea of an internal table which means that area must have the same structure as that of internal table and can have one record only.
Example code:
data: begin of itab occurs 10,
ab type c,
cd type i,
end of itab. " this table will have the header line.
data: wa_itab like itab. " explicit work area for itab
data: itab1 like itab occurs 10. " table is without header line.
Regards,
Padmam. -
How to join fields from different internal tables and display into one int
hai i have one doubt...
how to join fields from different internal tables and display into one internal table..
if anybody know the ans for this qus tell me......hii
you can read data as per condition and then can join in one internal table using READ and APPEND statement..refer to following code.
SELECT bwkey " Valuation Area
bukrs " Company Code
FROM t001k
INTO TABLE i_t001k
WHERE bukrs IN s_bukrs.
IF sy-subrc EQ 0.
SELECT bwkey " Valuation Area
werks " Plant
FROM t001w
INTO TABLE i_t001w
FOR ALL ENTRIES IN i_t001k
WHERE bwkey = i_t001k-bwkey
AND werks IN s_werks.
IF sy-subrc EQ 0.
LOOP AT i_output INTO wa_output.
READ TABLE i_t001w INTO wa_t001w WITH KEY werks = wa_output-werks.
READ TABLE i_t001k INTO wa_t001k WITH KEY bwkey = wa_t001w-bwkey.
wa_output-bukrs = wa_t001k-bukrs.
MODIFY i_output FROM wa_output.
CLEAR wa_output.
ENDLOOP. " LOOP AT i_output
ENDIF. " IF sy-subrc EQ 0
regards
twinkal
Maybe you are looking for
-
FDM Data import from EBS failed via FDMEE after roll back the 11.1.2.3.500 patch . Getting below error message in ERPI Adapter log. *** clsGetFinData.fExecuteDataRule @ 2/18/2015 5:36:17 AM *** PeriodKey = 5/31/2013 12:00:00 AM PriorPeriodKey = 4/30/
-
An E4200 "MegaThread" - FAQ, Issues, How to, etc
Hi Cisco Community! I've taken it on myself to make a kind of "mega-thread" for the E4200, because I see that there are a bunch of questions scattered around the forum, and (perhaps it's just me personally) I'd love to see things grouped together as
-
Quick Tip: How to create a fillable PDF form | Acrobat X Tips & Tricks | Adobe TV
This quick tip explains the steps and some of the terms you'll encounter when you create a fillable PDF form using an existing PDF document in Acrobat X Std. or Pro. http://adobe.ly/GJAUgk
-
Can't get to ringtone "buy" icon
This may be a stupid question, but my screen cuts off the left side of the ringtone purchase page where the "Buy" ringtone icon is. I can't seem to move the page or resize the screen to get to it! Any help out there? Thanks!
-
Is MSI Z87-G45 compatible with Be Quiet Dark Rock 3 and TridentX ?
Hello, I have a MSI Z87-G45 and 2 DDR3 TridentX (from 40 mm tall without heatspreader to 53mm with it) in dual channel mode. I'd like to mount a Be Quiet Dark Rock 3 with rear air extraction, front heatsink fan, and my DDR3 in dual channel mode (slot