‎2009 Feb 11 4:11 AM
Hi ,
How to create a ztable using programs for SQL database?
Can anyone plz explain it with a program!
Thanks in advance.
‎2009 Feb 11 10:34 AM
Hi,
It is because you might have executed the same code again.
exec sql.
drop table stu_det
endexec.
Execute it first in another program and then execute the earlier which I had given.It will create a table.
‎2009 Feb 11 4:18 AM
Hi,
Try this for creating and inserting data using native SQL.
REPORT zzz_jaytest.
Creating a table. No need of giving semicolon or colon for each statement.
exec sql.
create table stu_det ( regno char(10) primary key,
name char(20) not null,
total number(3) )
endexec.
Inserting first record
exec sql.
insert into stu_det values ('R1000', 'Ganesh', 500)
endexec.
Inserting Second record
exec sql.
insert into stu_det values ('R1001', 'Murugan', 480)
endexec.
‎2009 Feb 11 6:35 AM
Hi Jayanthi ,
I m getting a short dump if i use those queries..
Short Dump :
The error occurred in the current database connection "DEFAULT".
Plz suggest.
‎2009 Feb 11 4:33 AM
Hi,
Use this FM to create a Ztable, call this FM module in ur program and pass necessary fields to this FM.
It'll create Ztable.
RS_DD_TABL_ADD
and for creating Domain , Data element etc check in Se37 --> put RS_DD* and press F4.U'll get FM for each and every action u do in SE11.
‎2009 Feb 11 4:54 AM
hi,
Your purpose can be achieved through BDC programming too..
data:
t_bdcdata type table of bdcdata with header line.
start-of-selection.
perform bdc_dynpro using 'SAPMSRD0' '0102'.
perform bdc_field using 'BDC_OKCODE'
'=ADD'.
perform bdc_field using 'RSRD1-TBMA'
'X'.
perform bdc_field using 'RSRD1-TBMA_VAL'
'ztable_demo'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'=CHANGE_MAINTFLAG'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_field using 'DD02D-CONTFLAG'
'A'.
perform bdc_field using 'DD02D-MAINFLAG'
'X'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'=DEF'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_field using 'DD02D-CONTFLAG'
'A'.
perform bdc_field using 'DD02D-MAINFLAG'
'X'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_field using 'DD03D-ROLLNAME(01)'
'mandt'.
perform bdc_field using 'DD03D-FIELDNAME(01)'
'mandt'.
perform bdc_field using 'DD03P-KEYFLAG(01)'
'X'.
perform bdc_field using 'DD03P-NOTNULL(01)'
'X'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_field using 'DD03D-ROLLNAME(02)'
'S_CARR_ID'.
perform bdc_field using 'DD03D-FIELDNAME(02)'
'carrid'.
perform bdc_field using 'DD03P-KEYFLAG(02)'
'X'.
perform bdc_field using 'DD03P-NOTNULL(02)'
'X'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_field using 'DD03D-ROLLNAME(03)'
'S_CONN_ID'.
perform bdc_field using 'DD03D-FIELDNAME(03)'
'connid'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'=SE13'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_dynpro using 'SAPLSTRD' '0100'.
perform bdc_field using 'BDC_CURSOR'
'KO007-L_DEVCLASS'.
perform bdc_field using 'BDC_OKCODE'
'=TEMP'.
perform bdc_field using 'KO007-L_AUTHOR'
'SAPDEV02'.
perform bdc_dynpro using 'SAPMSEDS' '0050'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'DD09V-TABART'
'APPL0'.
perform bdc_field using 'DD09V-TABKAT'
'0'.
perform bdc_field using 'ALLOWSTATE-NOT_ALLOWED'
'X'.
perform bdc_dynpro using 'SAPMSEDS' '0050'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'DD09V-TABART'
'APPL0'.
perform bdc_field using 'DD09V-TABKAT'
'0'.
perform bdc_field using 'ALLOWSTATE-NOT_ALLOWED'
'X'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'=WB_ACTIVATE'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_dynpro using 'SAPLSEWORKINGAREA' '0205'.
perform bdc_field using 'BDC_OKCODE'
'=WEIT'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=NO'.
perform bdc_dynpro using 'SAPLSD41' '2200'.
perform bdc_field using 'BDC_OKCODE'
'=WB_BACK'.
perform bdc_field using 'DD02D-DDTEXT'
'Ztable'.
perform bdc_dynpro using 'SAPMSRD0' '0102'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'RSRD1-TBMA'
'X'.
perform bdc_field using 'RSRD1-TBMA_VAL'
'ZTABLE_DEMO'.
call transaction 'SE11' using t_bdcdata..
form BDC_DYNPRO using value(p_program)
value(p_num).
clear t_bdcdata.
t_bdcdata-program = p_program.
t_bdcdata-dynpro = p_num.
append t_bdcdata.
endform. " BDC_DYNPRO
form BDC_FIELD using value(p_fnam)
value(p_fval).
clear t_bdcdata.
t_bdcdata-fnam = p_fnam.
t_bdcdata-fval = p_fval.
append t_bdcdata.
endform. " BDC_FIELDThanks
Sharath
‎2009 Feb 11 10:34 AM
Hi,
It is because you might have executed the same code again.
exec sql.
drop table stu_det
endexec.
Execute it first in another program and then execute the earlier which I had given.It will create a table.
‎2009 Feb 11 11:27 AM
Hi Jayanthi ,
I think the table is created . But when i go to se11 and try to display the table, it says
<<Table name does not exist>>.
Where will the table be stored? How to check if its created?
‎2009 Feb 11 12:02 PM
You cannot see the table in the DDIC because you have not create the table there.
EXEC SQL CREATE TABLE creates only a table directly on the database and not in the DDIC.
And pls. be careful, EXEC SQL is heavily platform dependent, programs using EXEC SQL are very often not running w/o problems on all supported DB platforms.
Regards,
Axel
‎2009 Feb 12 2:40 AM
Hi,
You can check the entries in the table by using select statement.
Code Sample for performing form addition in EXEC SQL
REPORT zzz_jaytest.
data : v_name(20) type c,
v_total type i.
PARAMETERS : p_regno(10) TYPE c DEFAULT 'R1000'.
This directly selects the details of the record for the entered regno
and writes the information directly using performing
addition.
If the result of a SELECT command is a table, the system reads the
result set line by line in a loop. For each line, the system calls the
subroutine form .We can terminate the loop using the EXIT FROM SQL
statement in the subroutine form. If the result of the selection is a
single record, form is only called once.We can only use this addition
in a SELECT command.
EXEC SQL PERFORMING write_details.
SELECT name, total INTO :v_name, :v_total FROM stu_det
WHERE regno = :p_regno
ENDEXEC.
&----
*& Form WRITE_details
&----
text
----
FORM write_details.
WRITE: / 'Student Details:', p_regno, v_name, v_total.
ENDFORM. "WRITE_details
From documentation:
In a Native SQL statement, data is passed between the ABAP program and the database using host variables. A host variable is an ABAP variable that is identified as such in the Native SQL statement by a preceding colon (.
‎2009 Feb 11 12:11 PM
Hi,
Using BDC it is possible...
just record the creation of table by going to transaction SHDB...there give a name and transaction..do the steps..once u done with the recording just save it and call them into u r program...
Regards
Kiran
‎2009 Feb 11 12:15 PM
Hi,
to call those recording statements, after saving it will automatically comes to SHDB main window..there select u r recorded name-->click on PROGRAM button>give a program name of u wish->selct the transfer from recording radio button->the code will be automatically pasted into u r program.....
do some mall modification in u r program...
Regards
Kiran
‎2009 Feb 11 12:26 PM
‎2009 Feb 12 10:33 AM
Hi,
Please check following instructions to create Ztable using program.
Create a table maintainance program for a z table
In transaction SE11, in the attribute tab of your z table check table maintenance check box. Go to SM30 transaction, enter the ztable name and click on maintain button. Here you can enter new entries into the ztable .
Or
You can create a PARAMETER TRANSACTION for the transaction for SM30 .
Follow these steps :
1. go to transaction SE93 , give your own transaction code say ztran_tab, for maintaining your ztable.
2. Click on create button and check the radio button Transaction with parameters (PARAMETER TRANSACTION) and click on the tick button.
3. In the next screen enter default values:
transaction : SM30
check the check box skip initial screen
4. Scroll down you will find a table control for default values
-
Name of the screen field | value
-
VIEWNAME | your ztable name
SHOW | X
Save your work.
Now as you have created a custom transaction for maintaining your ztable this transaction can be called from any program with CALL transaction 'XXX'.
Hope this works for you.
Thanks...........
Edited by: Mandar kale on Feb 12, 2009 11:33 AM