Program to upload csv file to internal table and insert into database table
Hi I'm writing a program where I need to upload a csv file into an internal table using gui_upload, but i also need this program to insert the data into my custom database table using the split command. Anybody have any samples to help, its urgent!
Hi,
Check this table may be it will give u an hint...
REPORT z_table_upload LINE-SIZE 255.
Data
DATA: it_dd03p TYPE TABLE OF dd03p,
is_dd03p TYPE dd03p.
DATA: it_rdata TYPE TABLE OF text1024,
is_rdata TYPE text1024.
DATA: it_fields TYPE TABLE OF fieldname.
DATA: it_file TYPE REF TO data,
is_file TYPE REF TO data.
DATA: w_error TYPE text132.
Macros
DEFINE write_error.
concatenate 'Error: table'
p_table
&1
&2
into w_error
separated by space.
condense w_error.
write: / w_error.
stop.
END-OF-DEFINITION.
Field symbols
FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
<data> TYPE ANY,
<fs> TYPE ANY.
Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
PARAMETERS: p_file TYPE localfile DEFAULT 'C:\temp\' OBLIGATORY,
p_separ TYPE c DEFAULT ';' OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b01.
SELECTION-SCREEN: BEGIN OF BLOCK b02 WITH FRAME TITLE text-b02.
PARAMETERS: p_table TYPE tabname OBLIGATORY
MEMORY ID dtb
MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: END OF BLOCK b02.
SELECTION-SCREEN: BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
PARAMETERS: p_create TYPE c AS CHECKBOX.
SELECTION-SCREEN: END OF BLOCK b03,
SKIP.
SELECTION-SCREEN: BEGIN OF BLOCK b04 WITH FRAME TITLE text-b04.
PARAMETERS: p_nodb RADIOBUTTON GROUP g1 DEFAULT 'X'
USER-COMMAND rg1,
p_save RADIOBUTTON GROUP g1,
p_dele RADIOBUTTON GROUP g1.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_test TYPE c AS CHECKBOX,
p_list TYPE c AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN: END OF BLOCK b04.
At selection screen
AT SELECTION-SCREEN.
IF sy-ucomm = 'RG1'.
IF p_nodb IS INITIAL.
p_test = 'X'.
ENDIF.
ENDIF.
At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
Start of selection
START-OF-SELECTION.
PERFORM f_table_definition USING p_table.
PERFORM f_upload_data USING p_file.
PERFORM f_prepare_table USING p_table.
PERFORM f_process_data.
IF p_nodb IS INITIAL.
PERFORM f_modify_table.
ENDIF.
IF p_list = 'X'.
PERFORM f_list_records.
ENDIF.
End of selection
END-OF-SELECTION.
FORM f_table_definition *
--> VALUE(IN_TABLE) *
FORM f_table_definition USING value(in_table).
DATA: l_tname TYPE tabname,
l_state TYPE ddgotstate,
l_dd02v TYPE dd02v.
l_tname = in_table.
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = l_tname
IMPORTING
gotstate = l_state
dd02v_wa = l_dd02v
TABLES
dd03p_tab = it_dd03p
EXCEPTIONS
illegal_input = 1
OTHERS = 2.
IF l_state NE 'A'.
write_error 'does not exist or is not active' space.
ENDIF.
IF l_dd02v-tabclass NE 'TRANSP' AND
l_dd02v-tabclass NE 'CLUSTER'.
write_error 'is type' l_dd02v-tabclass.
ENDIF.
ENDFORM.
FORM f_prepare_table *
--> VALUE(IN_TABLE) *
FORM f_prepare_table USING value(in_table).
DATA: l_tname TYPE tabname,
lt_ftab TYPE lvc_t_fcat.
l_tname = in_table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = l_tname
CHANGING
ct_fieldcat = lt_ftab
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
WRITE: / 'Error while building field catalog'.
STOP.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_ftab
IMPORTING
ep_table = it_file.
ASSIGN it_file->* TO <table>.
CREATE DATA is_file LIKE LINE OF <table>.
ASSIGN is_file->* TO <data>.
ENDFORM.
FORM f_upload_data *
--> VALUE(IN_FILE) *
FORM f_upload_data USING value(in_file).
DATA: l_file TYPE string,
l_ltext TYPE string.
DATA: l_lengt TYPE i,
l_field TYPE fieldname.
DATA: l_missk TYPE c.
l_file = in_file.
l_lengt = strlen( in_file ).
FORMAT INTENSIFIED ON.
WRITE: / 'Reading file', in_file(l_lengt).
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
TABLES
data_tab = it_rdata
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
WRITE: /3 'Error uploading', l_file.
STOP.
ENDIF.
File not empty
DESCRIBE TABLE it_rdata LINES sy-tmaxl.
IF sy-tmaxl = 0.
WRITE: /3 'File', l_file, 'is empty'.
STOP.
ELSE.
WRITE: '-', sy-tmaxl, 'rows read'.
ENDIF.
File header on first row
READ TABLE it_rdata INTO is_rdata INDEX 1.
l_ltext = is_rdata.
WHILE l_ltext CS p_separ.
SPLIT l_ltext AT p_separ INTO l_field l_ltext.
APPEND l_field TO it_fields.
ENDWHILE.
IF sy-subrc = 0.
l_field = l_ltext.
APPEND l_field TO it_fields.
ENDIF.
Check all key fields are present
SKIP.
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Key fields'.
FORMAT RESET.
LOOP AT it_dd03p INTO is_dd03p WHERE NOT keyflag IS initial.
WRITE: /3 is_dd03p-fieldname.
READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
FORMAT COLOR COL_POSITIVE.
WRITE: 'ok'.
FORMAT RESET.
ELSEIF is_dd03p-datatype NE 'CLNT'.
FORMAT COLOR COL_NEGATIVE.
WRITE: 'error'.
FORMAT RESET.
l_missk = 'X'.
ENDIF.
ENDLOOP.
Log other fields
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Other fields'.
FORMAT RESET.
LOOP AT it_dd03p INTO is_dd03p WHERE keyflag IS initial.
WRITE: /3 is_dd03p-fieldname.
READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: 'X'.
ENDIF.
ENDLOOP.
Missing key field
IF l_missk = 'X'.
SKIP.
WRITE: /3 'Missing key fields - no further processing'.
STOP.
ENDIF.
ENDFORM.
FORM f_process_data *
FORM f_process_data.
DATA: l_ltext TYPE string,
l_stext TYPE text40,
l_field TYPE fieldname,
l_datat TYPE c.
LOOP AT it_rdata INTO is_rdata FROM 2.
l_ltext = is_rdata.
LOOP AT it_fields INTO l_field.
ASSIGN COMPONENT l_field OF STRUCTURE <data> TO <fs>.
IF sy-subrc = 0.
Field value comes from file, determine conversion
DESCRIBE FIELD <fs> TYPE l_datat.
CASE l_datat.
WHEN 'N'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
WRITE l_stext TO <fs> RIGHT-JUSTIFIED.
OVERLAY <fs> WITH '0000000000000000'. "max 16
WHEN 'P'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING ',.'.
<fs> = l_stext.
WHEN 'F'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING ',.'.
<fs> = l_stext.
WHEN 'D'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING '/.-.'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = l_stext
IMPORTING
date_internal = <fs>
EXCEPTIONS
OTHERS = 1.
WHEN 'T'.
CALL FUNCTION 'CONVERT_TIME_INPUT'
EXPORTING
input = l_stext
IMPORTING
output = <fs>
EXCEPTIONS
OTHERS = 1.
WHEN OTHERS.
SPLIT l_ltext AT p_separ INTO <fs> l_ltext.
ENDCASE.
ELSE.
SHIFT l_ltext UP TO p_separ.
SHIFT l_ltext.
ENDIF.
ENDLOOP.
IF NOT <data> IS INITIAL.
LOOP AT it_dd03p INTO is_dd03p WHERE datatype = 'CLNT'.
This field is mandant
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-mandt.
ENDLOOP.
IF p_create = 'X'.
IF is_dd03p-rollname = 'ERDAT'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-datum.
ENDIF.
IF is_dd03p-rollname = 'ERZET'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uzeit.
ENDIF.
IF is_dd03p-rollname = 'ERNAM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uname.
ENDIF.
ENDIF.
IF is_dd03p-rollname = 'AEDAT'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-datum.
ENDIF.
IF is_dd03p-rollname = 'AETIM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uzeit.
ENDIF.
IF is_dd03p-rollname = 'AENAM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uname.
ENDIF.
APPEND <data> TO <table>.
ENDIF.
ENDLOOP.
ENDFORM.
FORM f_modify_table *
FORM f_modify_table.
SKIP.
IF p_save = 'X'.
MODIFY (p_table) FROM TABLE <table>.
ELSEIF p_dele = 'X'.
DELETE (p_table) FROM TABLE <table>.
ELSE.
EXIT.
ENDIF.
IF sy-subrc EQ 0.
FORMAT COLOR COL_POSITIVE.
IF p_save = 'X'.
WRITE: /3 'Modify table OK'.
ELSE.
WRITE: /3 'Delete table OK'.
ENDIF.
FORMAT RESET.
IF p_test IS INITIAL.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: '- test only, no update'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: /3 'Error while modifying table'.
FORMAT RESET.
ENDIF.
ENDFORM.
FORM f_list_records *
FORM f_list_records.
DATA: l_tleng TYPE i,
l_lasti TYPE i,
l_offst TYPE i.
Output width
l_tleng = 1.
LOOP AT it_dd03p INTO is_dd03p.
l_tleng = l_tleng + is_dd03p-outputlen.
IF l_tleng LT sy-linsz.
l_lasti = sy-tabix.
l_tleng = l_tleng + 1.
ELSE.
l_tleng = l_tleng - is_dd03p-outputlen.
EXIT.
ENDIF.
ENDLOOP.
Output header
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Contents'.
FORMAT RESET.
ULINE AT /3(l_tleng).
Output records
LOOP AT <table> ASSIGNING <data>.
LOOP AT it_dd03p INTO is_dd03p FROM 1 TO l_lasti.
IF is_dd03p-position = 1.
WRITE: /3 sy-vline.
l_offst = 3.
ENDIF.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data> TO <fs>.
l_offst = l_offst + 1.
IF is_dd03p-decimals LE 2.
WRITE: AT l_offst <fs>.
ELSE.
WRITE: AT l_offst <fs> DECIMALS 3.
ENDIF.
l_offst = l_offst + is_dd03p-outputlen.
WRITE: AT l_offst sy-vline.
ENDLOOP.
ENDLOOP.
Ouptut end
ULINE AT /3(l_tleng).
ENDFORM.
Regards,
Joy.
Similar Messages
-
Read data from E$ table and insert into staging table
Hi all,
I am a new to ODI. I want your help in understanding how to read data from an "E$" table and insert into a staging table.
Scenario:
Two columns in a flat file, employee id and employee name, needs to be loaded into a datastore EMP+. A check constraint is added to allow data with employee names in upper case only to be loaded into the datastore. Check control is set to flow and static. Right click on the datastore, select control and then check. The rows that have violated the check constraint are kept in E$_EMP+ table.
Problem:
Issue is that I want to read the data from the E$_EMP+ table and transform the employee name into uppercase and move the corrected data from E$_EMP+ into EMP+. Please advise me on how to automatically handle "soft" exceptions in ODI.
Thank youHi Himanshu,
I have tried the approach you suggested already. That works. However, the scenario I described was very basic. Based on the error logged into the E$_EMP table, I will have to design the interface to apply more business logic before the data is actually merged into the target table.
Before the business logic is applied, I need to read each row from the E$EMP table first and I do not know how to read from E$EMP table. -
Fetch data from one table and insert into two tables in desired format
I have similar to the following data in a table and it is not normalized. The groupID is being used to group two records of similar nature.
DECLARE @OldDoc TABLE (oldDocID INT, groupID INT, deptID INT)
INSERT INTO @OldDoc (oldDocID, groupID) VALUES (1, NULL, 111),(2,NULL,111),(3,1,111),(4,NULL,333),(5,1,222),(6,NULL,333),(7,2,222),(8,2,333),(9,NULL,111),(10,3,222),(11,NULL,333),(12,3,444)
I need to process the data from the above table (@OldDoc) and write into two new tables (@NewDoc and @NewDocGroup) as follows.
oldDocID should be stored as newDocID when inserting to @NewDoc table. Only records with groupID NULL and one record (first one) per group should be considered (For example, oldDocID 5 is not considered as 3 and 5 belong to the same groupID 1) for insertion.
DECLARE @NewDoc TABLE (newDocID INT)
INSERT INTO @NewDoc (newDocID) VALUES (1),(2),(3),(4),(6),(7),(9),(10),(11)
All records from @OldDoc should be considered for insertion into @NewDocGroup table. OldDocID is inserted as NewDocID and deptID is as-is. Instead of groupID, the ID of the first record in the
group should be considered as parentNewDocID (For example, 3 is considered as parentNewDocID for newDocID 5 as 3 and 5 belong to the same groupID in @OldDoc table) for the newDocID.
DECLARE @NewDocGroup (newDocID INT, parentNewDocID INT, deptID INT)
INSERT INTO @NewDocGroup (newDocID, parentNewDocID, deptID) VALUES (1,1,111),(2,2,111),(3,3,111),(4,4,333),(5,3,222),(6,6,333),(7,7,222),(8,7,333),(9,9,111),(10,10,222),(11,11,333),(12,10,444)
How do I accomplish the above using SQL ? Thanks for the help.>> I have similar to the following data in a table and it is not normalized. The group_id is being used to group two records [sic] of similar nature. <<
Rows are not records. Tables have to have a key by definition. You do not do math with identifiers, so they should not be numeric. Let's ignore that error for now. In short, you are posting garbage. If you had followed Forum Netiquette, would you have posted
this?
CREATE TABLE Old_Documents
(old_doc_id INTEGER NOT NULL PRIMARY KEY,
group_id INTEGER,
dept_nbr INTEGER NOT NULL
REFERENCES Departments (dept_nbr));
INSERT INTO Old_Documents(old_doc_id, group_id, dept_nbr)
VALUES (1, NULL, 111),
(2, NULL, 111),
(3, 1, 111),
(4, NULL, 333),
(5, 1, 222),
(6, NULL, 333),
(7, 2, 222),
(8, 2, 333),
(9, NULL, 111),
(10, 3, 222),
(11, NULL, 333),
(12, 3, 444);
>> I need to process the data from the above table (Old_Documents) and write into two new tables (New_Documents and New_Documents_Groups) as follows. <<
Just like punch cards and mag tape data processing! Being old and being new are a status, not another kind of entity. But that is how mag tapes work. And you even use the verb "fetch" from tape files. This design flaw is called attribute splitting.
Do you have a Male_Personnel and Female_Personnel table? NO! It is just Personnel!
>> old_doc_id should be stored as new_doc_id when inserting to New_Documents table. Only records [sic] with group_id NULL and one record [sic] (first [sic; no ordering in a table] one) per group should be considered (For example, old_doc_id 5 is not considered
as 3 and 5 belong to the same group_id =1) for insertion. <<
Think about your punch card mindset. Why did you physically materialize that redundant New_Documents table? Let me answer that: this is how you work with punch cards! In SQL we use a VIEW:
CREATE VIEW New_Documents (new_doc_id)
AS
SELECT old_doc_id
FROM Old_Documents;
>> All records [sic] from Old_Documents should be considered for insertion into New_Documents_Groups table. The old_doc_id is inserted as new_doc_id and dept_nbr is as-is. Instead of group_id, the ID [sic: which identifier??] of the first [sic: tables
have no ordering like a deck of punch cards] record [sic] in the group should be considered as parent_new_doc_id (For example, 3 is considered as parent_new_doc_id for new_doc_id 5 as 3 and 5 belong to the same group_id in Old_Documents table) for the new_doc_id.
<<
Why not use 5 as the parent? My guess is that you are trying to form equivalence classes. See:
https://www.simple-talk.com/content/print.aspx?article=2020
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to read LONG RAW data from one table and insert into another table
Hello EVERYBODY
I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
and then sound will be played from the temp table.
declare
tmp sound.music%type;
temp1 sound.music%type;
item_id ITEM;
cursor c1
is select music
from sound
where lang=:LIST10;
begin
open c1;
loop
fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
temp1:=temp1||tmp;
exit when c1%notfound;
end loop;
CLOSE C1;
insert into temp values(temp1);
item_id:=Find_Item('Music');
go_item('music');
play_sound(item_id);
end;
but when i'm clicking the button it generates the following error.
WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
ORA-06502: PL/SQL: numeric or value error
SQL> desc sound;
Name Null? Type
SL_NO NUMBER(2)
MUSIC LONG RAW
LANG CHAR(10)
IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
THANKS IN ADVANCE.
D. PrasadYou can achieve this in many different ways, one is
1. Create another VO based on the EO which is based on the dest table.
2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
3. commiting the transaction will push the data into the dest table on which the dest VO is based.
I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
Tapash -
Fetch data from two tables and insert into one table
I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director.
Data exists only for subset of plants and a Plant may have one or both roles.
DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
The above data needs to be inserted into one table (@PlantNew) as follows:
PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
How do I achieve the above using SQL ? Thanks.like this
INSERT @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
@PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
You're missing a FROM
insert into @PlantNew
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
from @PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID -
Build a sql query fro different table and insert into a table
Hi I have a requirement ,
i have some table 1 table which holds rules which rules i have to apply on the sql query
2 table will hold table name and column name and transformation
with these help of 2 tables i want to build a sql quey and the sql query need to be insert into another table.Hi Karthick,
I am not going to build Dynamic Data Model.
i already have table 1 contains rules let's say COUNT,
and another table contain source table name , column name , Target table name, Source Table name like that
so with the help of these 2 tables i want to build Sql query and going to insert into 3rd table. -
Import parametes and insert into database table suggestions
experts need suggestions
created a table with 3 fields.
zstable.
field dataelement type length
kunnr kunnr char 10 key field
name dname char 30 key field
aedat aedat dats 8
aenam aenam char 12
now i am creating a function modlue with two input parameters
1)kunnr
2)name
i want to update this two fields into table zstable.
1. so suggest me the best way to do this.
Delcarations in import options which one of the below is best and why?
name type char30
kunnr type kunnr
or
name like zstable-name
kunnr like zstable-kunnr
or
kunnr type zstable-kunnr
name type zstable-name.
2. inserting into table
the data that we recieve from the import parameters need to be inserted into the zstable.
please suggest me the appropriate statement waht i need to code for this.
insert kunnr name into zstable.
can i ignore the third field as it is not the key field?
3. before inserting do i need to check whether kunnr and uname is initial ie import parametrs?
4. suppose if i delcared two input parameters in function module zfuntion say vbeln and posnr.
and source code
insert vbeln and posnr into zstable.
now i am calling from the program
zreport.
call function 'ZFUNCTION'.
EXPORT
NAME =
KUNNR =
Will the above statement updates the blank records into the table zstable?.Hi,
1) I think the best is either refer directly to data element or to table field. This is beacuse once any change is made to this data element it will automatically reflect in your parameters. For table fields it is a bit less safier but still correct. Golden rule - always try to refer to DDIC components like data elements.
name type dname
kunnr type kunnr
2) You need to provide all key fields. I recommend to use MODIFY as it would hanlde both INSERT (if yet no such record exists ) and UPDATE (if already exists).
data: wa_zstable type zstable. "declare work area
wa_zstable-kunnr = kunnr. "pass parameters here
wa_zstable-name = name.
modify zstable from wa_zstable.
3) good practise, for this use
if kunnr is initial and
name is initial.
"modify ...
endif.
"or if parameters are set as OPTIONAL, then use
if kunnr is supplied and
name is supplied.
endif.
4) No, the statment you want to use
insert vbeln and posnr into zstable.
is only used for FIELD GROUPS, not DB table. Please refer [INSERT|http://help.sap.com/abapdocu/en/ABAPINSERT_DBTAB_SHORTREF.htm] for correct syntax.
You can alternatively use somthing like
UPDATE zstable SET vbeln = ...
posnr = ...
WHERE ...
This will update fields VBELN and PONR for all records fullfilling WHERE condition. These however musn't be key fields, only non-key fields can be udpated.
Regards
Marcin -
How to get the data from one table and insert into another table
Hi,
We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
For the above requirement what the best way to implement in OAF.
I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
ThanksYou can achieve this in many different ways, one is
1. Create another VO based on the EO which is based on the dest table.
2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
3. commiting the transaction will push the data into the dest table on which the dest VO is based.
I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
Tapash -
How to Query from table and insert into another table.
Hi
I am using the following query in VO and all the columns are attached to EO ( table name emp_temp)
select a.npw_number, a.person_id,b.assignment_id,a.title,a.last_name,a.first_name,a.date_of_birth,a.sex,
b.organization_name,b.organization_id,b.job_id,b.job_name,b.position_id,b.position_name,b.supervisor_id,
b.supervisor_name,b.location_id,b.effective_start_date,b.effective_end_date
from per_all_people_f a,per_assignments_v b
where a.person_id=b.person_id
and a.npw_number=:1
I can query the data in screen. I need into insert the data into the emp_temp.
I don't know how to do this . Please help me.
Thanks
SubraYou can create a VO based on EO on emp_temp table.....
And u have attached a Different VO on the page... Right...
Now what u can do is....once u click on apply....
u can set the each attributes of EO based VO explicitly via code, from the values of second VO.... and then commit.....
Perhaps this might help... -
How to extract data from xml and insert into Oracle table
Hi,
I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
I need to extract the values of these columns and insert into the table
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>Re: Insert from XML to relational table
http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta= -
How to read ecel sheet and insert into oracle table
hi all,
am working on forms builder 6i. and i want , from a trigger to read from a a sheet excel file the data and insert into a table that i had aleady created.
i whrite a code that can till now open the excel file but i cant read the data to insert it into the table.
am using TEXT_IO.IS_OPEN to open the file
TEXT_IO.GET_LINE to take each line
and subst(x as variable) to read the first line , but the subsrt return nohing
any solution??There's already a topic made on this: how to copy data from excel to oracle forms
-
Pool data from text file and insert into database
Can anyone tell me how to pool data from a text file and insert into database?
let's say my text file is in this format
123456 Peter 22
234567 Nicholas 24
345678 Jane 20
Then I need to insert the all the value for this three column into a table which has the three column name ID, Name, Age
Anyone knows? I need to do this urgently...Thank in advanced1. Use BufferedReader and read the file line by line.
2. Loop thru the file and do the following steps with in this loop.
3. Use StringTokenizer to seperate each line into three values (columns).
4. Now create a insert statement with these values and add the statement to the batch (using addBatch() method of PreparedStatement or Statement).
5. Finally (after exiting the loop), execute these batch of statements (using ps.executeBatch()).
Sudha -
Hi Guy's,
Please help me, trying to insert the records into database table. when i debug the program work area contain data records but not insert into databse table. Here pasted my code pls suggest me where i did mistake.
FUNCTION ZEXM_PHOTOCOPYDTLS_EP.
""Local Interface:
*" IMPORTING
*" VALUE(EXMCODE) TYPE ZEXMCODE OPTIONAL
*" VALUE(EXMMONTH) TYPE ZEXMMONTH OPTIONAL
*" VALUE(SEATNO) TYPE ZSEATNO OPTIONAL
*" VALUE(STDFIRSTNAME) TYPE ZSTDFIRSTNAME OPTIONAL
*" VALUE(STDMIDDLENAME) TYPE ZSTDMIDDLENAME OPTIONAL
*" VALUE(STDLASTNAME) TYPE ZSTDLASTNAME OPTIONAL
*" VALUE(ADDLINE1) TYPE ZADDLINE1 OPTIONAL
*" VALUE(CITY) TYPE ZCITY OPTIONAL
*" VALUE(COUNTRY) TYPE ZCOUNTRY OPTIONAL
*" VALUE(PIN) TYPE ZPIN OPTIONAL
*" VALUE(TELEPHONENO) TYPE ZTELEPHONENO OPTIONAL
*" VALUE(MOBNO) TYPE ZMOBNO OPTIONAL
*" VALUE(EMAIL) TYPE ZEMAIL OPTIONAL
*" VALUE(DDNO) TYPE ZDDNO OPTIONAL
*" VALUE(DDAMT) TYPE ZDDAMOUNT OPTIONAL
*" VALUE(DDDATE) TYPE ZDDDATE OPTIONAL
*" VALUE(BANKNAME) TYPE ZBANKNAME OPTIONAL
*" VALUE(COLNAME) TYPE ZCOLNAME OPTIONAL
*" VALUE(COLADDRESS) TYPE ZCOLADDRESS OPTIONAL
*" VALUE(COURSECODE) TYPE ZCOURSECODE OPTIONAL
*" VALUE(EXMYEAR) TYPE ZEXMYEAR OPTIONAL
*" VALUE(PAPERCODE) TYPE ZPAPERCODE OPTIONAL
*" VALUE(PAPERNO) TYPE ZPAPERNO OPTIONAL
*" VALUE(MARKSOBT) TYPE ZMARKSOBT OPTIONAL
*" VALUE(EXMDATE) TYPE ZEXMDATE OPTIONAL
*" VALUE(EXMTIME) TYPE ZEXMTIME OPTIONAL
*" VALUE(SUBCODE) TYPE ZSUBCODE OPTIONAL
*" EXCEPTIONS
*" SELECTION_ERROR
DATA : WA_OUTPUT TYPE ZEXM_PHOTOCOPYDT,
WA_COLL TYPE ZEXM_COLLEGEMST,
WA_COURSE TYPE ZEXM_COURSEMST,
WA_EXMCODE TYPE ZEXM_EXMCODEMST,
WA_PAPER TYPE ZEXM_PHOPAPERMAP,
WA_SUBJECT TYPE ZEXM_SUBJECTMST.
STUDENT DETAILS
MOVE : EXMCODE TO WA_OUTPUT-ZEXMCODE,
EXMMONTH TO WA_OUTPUT-ZEXMMONTH,
SEATNO TO WA_OUTPUT-ZSEATNO,
STDFIRSTNAME TO WA_OUTPUT-ZSTDFIRSTNAME,
STDMIDDLENAME TO WA_OUTPUT-ZSTDMIDDLENAME,
STDLASTNAME TO WA_OUTPUT-ZSTDLASTNAME,
ADDLINE1 TO WA_OUTPUT-ZADDLINE1,
CITY TO WA_OUTPUT-ZCITY,
COUNTRY TO WA_OUTPUT-ZCOUNTRY,
PIN TO WA_OUTPUT-ZPIN,
TELEPHONENO TO WA_OUTPUT-ZTELEPHONENO,
MOBNO TO WA_OUTPUT-ZMOBNO,
EMAIL TO WA_OUTPUT-ZEMAIL,
DDNO TO WA_OUTPUT-ZDDNO,
DDAMT TO WA_OUTPUT-ZDDAMT,
DDDATE TO WA_OUTPUT-ZDDDATE,
BANKNAME TO WA_OUTPUT-ZBANKNAME.
insert into ZEXM_PHOTOCOPYDT values wa_output.
if sy-subrc = 0.
commit work.
endif.
Thanks and Regards,
Sai.
Edited by: sai shanhu on Jun 4, 2008 11:13 AMHai,
move wa_output into ZEXM_PHOTOCOPYDT.
insert ZEXM_PHOTOCOPYDT.
Thanks,
Durai.V -
Best Practice to fetch SQL Server data and Insert into Oracle Tables
Hello,
I want to read sqlserver data everry half an hour and write into oracle tables ( in two different databases). What is the best practice for doing this?
We do not have any database dblinks from oracle to sqlserver and vice versa.
Any help is highly appreciable?
ThanksWell, that's easy:
use a TimerTask to do the following every half an hour:
- open a connection to sql server
- open two connections to the oracle databases
- for each row you read from the sql server, do the inserts into the oracle databases
- commit
- close all connections -
Create and insert into temporary table
Dear all,
I want to create an temporary table and insert data from select statement and order data by field in that table, at the end i want to drop temporary table.
CURSOR rob_twin
IS
SELECT t.tarj, s.b24, date, status, fii, acnt, mbr, pviv, type
FROM
p6.tarj t
p6.stb24 s
p6.cuet c
WHERE .......
--now I want to create table and insert above data (from cursor rob_twin)
--after that I need to order data by t.tary from new table
--finally I want to drop this table
Thank you for your help.
Regards,
RobertThe point is in Oracle you do not create the temporary table at run-time, use it, and drop it again.
But you can create a GTT (Global Temporary Table) once and then it stays in the data dictionary, just like a normal table. The "temporary" part is simply that the data is temporary, can only be seen in this one session, and will go away either on commit or when the session ends.
So first you create a global temporary table with the columns you wish. Using either ON COMMIT DELETE ROWS or ON COMMIT PRESERVE ROWS you decide whether data in this GTT should survive across transactions or not.
Your logic could then be to populate this GTT with data from your remote database using INSERT INTO gtt_table SELECT ... FROM ...@dblink
Then work with that data in the GTT as you would with any normal local table
And finally either you simply commit your transaction and the data in the GTT goes away (if you did ON COMMIT DELETE ROWS), or you just DELETE gtt_table.
You do not continually create and drop a GTT. The table definition is permanent - it is only the data that is temporary.
Edit:
PS: As Karthick stated above - for almost any usual purposes it is likely to be possible to solve the problem without having to use GTT's. Usually even with db_links it can be done with suitable SQL and joins without having to use a GTT. But if that turns out to be one of those rare occasions where that is hard - then the above is the way to go ;-)
Edited by: Kim Berg Hansen on Sep 19, 2011 1:38 PM
Maybe you are looking for
-
Coded UI Text not adding correctly to textbox
This error results when I try to do record/playback in Coded UI Test to add a # to phone # textbox. Can anyone please explain what I should do to resolve? Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform 'Set
-
Kernel Panics and Frequent Re-Boots - Help!
Hi all, I'm new to this, and haven't posted before - I am getting possibly three times a day random reboots and kernel panics (the same thing?). No pattern to the problems. Sometimes I'll close the lid of my Macbook and then a minute later and I'll h
-
trying to take photos off my 3G since the upgrade,,, I am not seeing the popup to take photo's off and store them on my computer
-
NullPointerException & java file missing!
I have a JSP which gets the following error, the problem is that the WEBLOGIC GENERATED JAVA FILE IS NOT THERE! When I search my hard drive, the _somethingwrongerrorpage.java file is NOT FOUND!!!!! The jsp code is at the
-
HT1926 When Installing new version error is quicktime cannot uninstall old version
When trying to install new version of Quicktime, I get a error message that quicktime cannot uninstall old version. This also affects Itunes to work. Get Message Itunes has encountered a problem and needs to close. I think not having quicktime workin