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,
Pavan
Hi 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
Similar Messages
-
Pass the internal table with different structures to the class module
Hi ,
I have created a class method to fill up the data in XML format. the method can be called from various programs with internal table with different structures. I want to pass it as dynamic How can I do that.
I tried to declare that as type any.
but not working.
regards,
MadhuriHi,
You could work with data reference.
Use GET REFERENCE OF itab INTO data_ref for passing the internal table to your method, and dereference it within the method with ASSIGN statement...
DATA: lr_data TYPE REF TO data.
GET REFERENCE OF itab INTO lr_data.
CALL METHOD meth EXPORTING pr_data = lr_data.
METHOD meth.
FIELD-SYMBOLS <fs> TYPE ANY TABLE
ASSIGN pr_data->* TO <fs>.
ENDMETHOD.
Kr,
Manu. -
Upload data to an internal table with Services of the Table Tool
Hi,
I'm trying to upload data to an internal table with the table with the new abap debugger but I can see the option in Services of the Table Tool. I see the information in this sap link and also I saw some screen shot in other pages.
http://help.sap.com/saphelp_nw70ehp2/helpdata/en/49/2db60934e414d0e10000000a42189b/content.htm
Is this option depends the SAP version or the patch version or I need to configure the debugger?Hi,
I used the statement
SPLIT i_file AT '|' INTO TABLE It_file.
But it is overwriting each row but not appending to the internal table while passing do and enddo.
Actually my requirement is download the pipe delimited text file and sent an XLS attachment to the
distribution mail id's.
I know sending the mails by using the FM.
But I need all data from the file line by line and pass to the Mail sending function module.
Can you help me in acheiving this.
Regards
Jay -
Two internal tables with different structures
Hi Experts,
I Have two internal tables.
Table 1 structure:
Name
Age
Table 2 structure :
Name
age
branch
Now the table 1 has some 5 data's and table 2 is empty.
First i want to move that 5 data's from table 1 to table 2.
Then the branch field is same for all records. its stored in a separate field called 'Branch'.
finallay i need to move that branch to internal table 2 for all records.
So the Table 2 should has five records and each record should have the branch.Its like,
Name Age Branch
name1 10 ECE
name2 10 ECE
I didnt use with header line for both tables. In function module i declared as table parameter.
Please give me a logic.
Helps will be appreciated.Since the structure of yur both internal table is different so you can't use ITAB1[] = ITAB2[] statements.
In this case you have to loop on first table then move data into second table and appned data into second table.
Declare work area for both table with like line of statement as follows
data: wa_itab1 like line of itab1,
wa_itab2 like line of itab2.
Loop at ita1 into wa_itab1.
wa_itab2-name = wa_itab1-name.
wa_itab2-age = wa_itab1-age.
wa_itab2-branch = 'ECE'.
append wa_itab to itab2.
clear wa_itab1, wa_itab2.
endloop.
Hope this will solve your problem. -
Validate the data in the internal table with the date in selection screen
Hi all,
I want to validate the data in the internal table and get only the records with the input date in the selection screen.
The date is in the select options and please let me know how to get the records only if it satisfies the input date in the selection screen.
Regards,
ShalemFor Ex.
SELECT-OPTIONS: S_DATE FOR VBAK-VDATU
If you want to read one INTERNAL TABLE record
READ TABLE it_tab(internal table name) WHERE vdatu(date field name in the internal table) = s_date
If you want to move more then one
LOOP AT it_tab WHERE vdatu = s_date.
Take the field values in another table and append it. then end loop.
you will get the records which only have the date in select option..
If you want detail code give me internal table name and select option name i will write you the code.
regards
Yuvaram -
How to fetch the data to the internal table with out using mandt
Hi all,
Iam giving my code please observer... and give me the reasonable solution.
t_mar LIKE STANDARD TABLE OF z_mar.
SELECT mandt
werks " Plant
lifnr " Vendor
FROM z_mar
INTO TABLE t_mar
where sal = 2000.
By removing MANDT from select query, it is going to dump.
ex:
SELECT
werks " Plant
lifnr " Vendor
FROM z_mar
INTO TABLE t_mar
where sal = 2000.
> Now it is going to dump ( here i removed the mandt field ).
Please give me a solution to fetch the data by removing mandt in select statement, with out chaning the internal table structure.
Thanks,
Ravihi Ravi,
i also had to avoid move-corresponding and the following is what i did...its extra work and goes around but it will
do the needed work..............
t_mar LIKE STANDARD TABLE OF z_mar.
SELECT *
FROM z_mar
INTO TABLE t_mar
where sal = 2000.
the above gets you all the fields ...but if you still want to narrow it down to just two fields
*****Declaring structure with 2 fields
data:begin of fs_data.
data:werks type z_mar-werks,
lifnr type z_mar-lifnr ,
data:end of fs_data.
*******internal table of above
data:int_data like fs_data occurs 0 with headerline.
*****moving the only 2 required fields
loop at t_mar.
t_mar-werks = int_data-werks.
t_mar-lifnr = int_data-lifnr.
append int_data.
endloop.
Hope you found it useful...
Regards
Bx -
Migrating CMP EJB mapped to SQL Server table with identity column from WL
Hi,
I want to migrate an application from Weblogic to SAP Netweaver 2004s (7.0). We had successfully migrated this application to an earlier version of Netweaver. I have a number of CMP EJBs which are mapped to SQL Server tables with the PK as identity columns(autogenerated by SQL Server). I am having difficulty mapping the same in persistant.xml. This scenario works perfectly well in Weblogic and worked by using ejb-pk in an earlier version of Netweaver.
Please let me know how to proceed.
-SekharI suspect it is the security as specified in the message. E.g .your DBA set the ID columns so no user can override values in it.
And I suggest you 1st put the data into a staging table, then push it to the destination, this does not resolve the issue, but ensures better processing.
Arthur
MyBlog
Twitter -
How to migrate data fSQL server 2005 Tables with image column To ORACLE 11g
Hi ....
I am in the middle of migrating our database from sqlserver 2005 version to ORACLE 11g instance, and i'm facing a problem when trying to load data into one of the oracle table which has blob column and some more. The data file was extracted from sql server 2005 table which has image column and some more. All other columns are sinking with the migration as expected but the image column is not getting loaded into oralce blob.
I tried loading data using sqlloader.
Is there any other way to migrate data directly between these two versions of database?. Pls help...
Edited by: user13310523 on 21-Jun-2010 23:48Welcome to the forum,
Hi,
To link Oracle with SQL Server follow this steps:
1-Install Oracle ODBC drivers on the server (your local Oracle database) that will access the remote SQL Server database using the database link.
2. Setup the ODBC connection on the local Oracle database using the Windows ODBC Data Source Administrator
3. Test the ODBC drivers to ensure that connectivity is made to the SQL Server database.
4. Ensure that your global_names parameter is set to False.
5. Configure the Oracle Heterogeneous services by creating an initodbc.ora file within the Oracle database.
7. Modify the Listener.ora file.
SID_NAME is the DSN for the remote database.
ORACLE_HOME is the actual Oracle home file path.
PROGRAM tells Oracle to use heterogeneous services.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME=Cas30C) -- Enter the DSN on this line
(ORACLE_HOME = c:\oracle10gdb) -- Enter your Oracle home on this line
(PROGRAM = hsodbc) ) )
8. Modify the Tnsnames.ora file. This is the Oracle database installation accessed by the users to connect to the ODBC drivers
(DESCRIPTION=
(ADDRESS_LIST=
(Address=(PROTOCOL=TCP)
(HOST=
-- (Server x)
(PORT=1521))) -- Enter the port on which the server x Oracle installation
-- is listening
(CONNECT_DATA=(SID=Cas30c)) - Enter the DSN name
(HS=OK) -- Enter this value. It tells Oracle to use hetergeneous services
9. Reload the listener on local Oracle database
10. Create a database link on the local Oracle installation that accesses the heterogeneous connection, which, in turn, connect to SQL Server.
11. Run a SQL Server Select statement from the Oracle installation using the database link
Thanks
BelMan :) -
Migrating a table with BLOB column from one db to another
Hello everybody,
I have two databases D1 and D2. Each database contains table T1 (same structure in both databases). T has a BLOB column and is populated in D1. I have to move all the data from T database D1 into T database D2.
D1 and D2 are located on different machines. T in D1 is a huge table (milions of records). What is the best solution to migrate the T data between the 2 databases?
Any help will be appreciated.
Thank you in advance.
danielaDepending on the version of the database you have, you could use transportable tablespaces.
http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96524/c04space.htm#9370 -
Insert into a table with unique columns from another table.
There are two tables,
STG_DATA
ORDER_NO DIR_CUST_IND
1002 DNA
1005 GEN
1005
1008 NULL
1001 NULL
1001 NULL
1006 NULL
1000 ZZZ
1001 ZZZ
FACT_DATA
ORDER_NO DIR_CUST_IND
1005 NULL
1006 NULL
1008 NULL
I need to insert only unique [ORDER_NO] from STG_DATA to FACT_DATA with corresponding [DIR_CUST_IND]. Though STG_DATA has multiple rows with same ORDER_NO, I need to insert only one of that it can be any record.
SarvanCREATE TABLE #Level(ORDER_NO INT, DIR_CUST_IND CHAR(3))
INSERT #Level
SELECT 1002,'DNA' UNION
SELECT 1005,'GEN' UNION
SELECT 1005,NULL UNION
SELECT 1008,NULL UNION
SELECT 1001,NULL UNION
SELECT 1001,NULL UNION
SELECT 1006,NULL UNION
SELECT 1000,'ZZZ' UNION
SELECT 1001,'ZZZ'
SELECT ORDER_NO,DIR_CUST_IND
FROM( SELECT ROW_NUMBER()OVER(PARTITION BY ORDER_NO ORDER BY ORDER_NO) RowNum,*
FROM #Level)A
WHERE RowNum=1
I hope this would give you enough idea. All you have to do is just write insert statement.
Next time please post DDL & DML.
Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
The climb is all there is. -
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 -
Header data and item data into same internal table
Hi Experts,
I WANT TO KNOW THE LOGIC TO POPULATE HEADER DATA AND ITEM DATA INTO SAME INTERNAL TABLE AND AGAIN DOWNLOAD THE SAME TO EXCEL FILE .Output file should be displayed like this format
Header1 rectyp ,hdnum ,sbank ,bankl ,accnr , paytp , crda ,iso.
Item1 : rectyp ,valut ,cknum ,amount,bankl,accnr,pdate,bnktc.
Item2 : rectyp ,valut ,cknum ,amount,bankl,accnr,pdate,bnktc.
Header2: rectyp ,hdnum ,sbank ,bankl ,accnr , paytp , crda ,iso.
Item1 : rectyp ,valut ,cknum ,amount,bankl,accnr,pdate,bnktc.
Thanks
Moderator message: Please do not use all upper case in the future.
Edited by: Thomas Zloch on May 12, 2010 3:10 PMHi,
for example we have 3 internal tables
1> it_header 2>it_items 3>it_final (which contains all the header and item fields)
once it_header it_items are filled
loop at it_items.
read table it_header with key xyz = it_item-xyz.
if sy-subrc = 0.
here move all the header fields to it_final like below.
it_final -xfield = it_header-xfield.
endif.
here move all the item fields to it_final like below.
it_final -yfield = it_item-yfield.
append it_final.
clear it_final.
endloop.
now header and item fileds will be fillled in it_item -
Downloading different internal table data in a single excel with diff tabs.
Hi gurs,
I have 4 internal tables with me i can able to display in 4 different excel sheets using CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
But my requirement is i want to download 4 internal table in single excel sheets with different tabs. please send the code if u have.
Thanks and regards.Hi,
If you want to display the content of 4 internal table in different sheets of same workbook then go through below code,
DATA : EXCEL TYPE OLE2_OBJECT,
WORKBOOKS TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT,
CELLS TYPE OLE2_OBJECT,
SHEET TYPE OLE2_OBJECT,
FONT TYPE OLE2_OBJECT,
H_COM1 TYPE OLE2_OBJECT,
F TYPE RLGRAP-FILENAME,
FILEP TYPE DRAW-FILEP,
G_FILE_DEST TYPE STRING,
G_FILE_TEMP TYPE STRING,
G_SYSUBRC TYPE SY-SUBRC,
G_FILE_SRC TYPE DRAW-FILEP.
START THE EXCEL APPLICATION
CREATE OBJECT excel 'EXCEL.APPLICATION'.
CALL METHOD OF excel 'WORKBOOKS' = workbooks.
SET PROPERTY OF excel 'VISIBLE' = 0.
CALL METHOD OF workbooks 'OPEN' EXPORTING
#1 = filep.
For Sheet1
CALL METHOD OF excel 'Worksheets' = sheet
EXPORTING #1 = 1.
CALL METHOD OF sheet 'Activate'.
FREE OBJECT sheet.
CALL METHOD OF excel 'CELLS' = cells
EXPORTING #1 = 1
#2 = 15.
SET PROPERTY OF cells 'VALUE' = <value>
CALL METHOD OF cells 'FONT' = font.
SET PROPERTY OF font 'SIZE' = '20'.
FREE OBJECT cells.
For Sheet2
CALL METHOD OF excel 'Worksheets' = sheet
EXPORTING #1 = 2.
CALL METHOD OF sheet 'Activate'.
FREE OBJECT sheet.
CALL METHOD OF excel 'CELLS' = cells
EXPORTING #1 = 1
#2 = 6.
SET PROPERTY OF cells 'VALUE' = 'XYZ'.
CALL METHOD OF cells 'FONT' = font.
SET PROPERTY OF font 'SIZE' = '20'.
GET PROPERTY OF excel 'ACTIVESHEET' = sheet.
CALL METHOD OF sheet 'SAVEAS' EXPORTING
#1 = <destination file path where you want to store>
#2 = 1.
CALL METHOD OF workbooks 'CLOSE'.
CALL METHOD OF excel 'QUIT'.
FREE OBJECT excel.
Thanks!
Brunda
'Reward if useful'. -
How to insert data from different internal table into a data base table
hi all,
I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal tables.can some one tell me how to do this?
in short i want to do something like the foll:
INSERT INTO ZMIS_CODES-CODE VALUE '1'.
*INSERT INTO ZMIS_CODES-COL1 VALUE DATA_MTD-AUFNR .(zmis_codes is the db table and data_mtd is the int.table)REPORT ZINSERT.
tables kna1.
data: itab LIKE KNA1.
data lv_kUNAG LIKE KNA1-KUNNR.
lv_kuNAG = '0000010223'.
ITAB-kuNNR = lv_kuNAG.
ITAB-name1 = 'XYZ'.
INSERT INTO KNA1 VALUES ITAB.
IF SY-SUBRC = 0.
WRITE:/ 'SUCCESS'.
ELSE.
WRITE:/ 'FAILED'.
ENDIF.
Here lv_kunag is ref to kna1 kunnr passed in different name
In internal table .
Try and let me know if this logic dint work. -
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
Maybe you are looking for
-
My 5800 touch screen is not working properly.
Hi, Frequently my 5800 touch screen is not working. Some times I am unable to use the screen. It's just hung. The call, menu and disconnect buttons only work during this time. Can any please let me know what might be the problem.? Thanks in advance,
-
I am trying to connect to a TRIP database (a product from Tietoenator). They offer a JDBC driver which I have already used in java applications. So I can confirm that it works. What makes that driver perhaps a bit special is that it needs 3 other jar
-
Select planning level for forecast caluculation manually
Dear all, In S&OP on HANA we would like to run the forecast on a more aggregated level than the base planning level. The base planning level in the input/output key figure of the forecast profile is supposed to be lower than the level which should be
-
Hi, Can we split PR according to delivery schedule. Secondly does auto closing of PR/PO is possible within a stipulated time frame?
-
What is the reason that reason wont sync
I load up a redrum, make a pattern and hit run and it plays thru fine till the end of the loop point in logic then on return to start of the loop it won't continue to cycle in my redrum... i see the little scrolling light stop on the redrum.????\ ple