SELECT 시 TABLE 이름을 DYNAMIC 하게 이용하기 (PRO*C)
제품 : PRECOMPILERS
작성날짜 : 1998-02-04
다음은 method 3 를 이용해 select 하는 table 명을 dynamic 하게 가져가는
program 이다.
#include <stdio.h>
#include <string.h>
#define USERNAME "scott"
#define PASSWORD "tiger"
#include <sqlca.h>
#include <oraca.h>
EXEC ORACLE OPTION (ORACA=YES);
char *username = USERNAME;
char *password = PASSWORD;
VARCHAR dynstmt[80];
varchar ename[10] ;
int deptno = 10;
char tab[10];
void sql_error();
main()
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error");
oraca.orastxtf = ORASTFERR;
EXEC SQL CONNECT :username IDENTIFIED BY :password;
puts("\nConnected to Oracle.\n");
/*exec sql declare s statement;*/
gets(tab);
strcpy((char *)dynstmt.arr,
"SELECT ename FROM ");
strcat((char*) dynstmt.arr,tab);
dynstmt.len = strlen((char *)dynstmt.arr);
puts((char *) dynstmt.arr);
printf(" table name is %s\n", tab );
printf("\nEmployee\n");
printf("--------\n");
/*sprintf (statement ,"select ename from :tab");*/
EXEC SQL PREPARE S FROM :dynstmt;
EXEC SQL DECLARE C CURSOR FOR S;
EXEC SQL OPEN C ;
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
EXEC SQL FETCH C INTO :ename;
ename.arr[ename.len] = '\0';
puts((char *) ename.arr);
printf("\nQuery returned %d row%s.\n\n", sqlca.sqlerrd[2],
(sqlca.sqlerrd[2] == 1) ? "" : "s");
EXEC SQL CLOSE C;
EXEC SQL COMMIT RELEASE;
exit(0);
void sql_error(char *msg)
printf("\n%s", msg);
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
oraca.orastxt.orastxtc[oraca.orastxt.orastxtl] = '\0';
oraca.orasfnm.orasfnmc[oraca.orasfnm.orasfnml] = '\0';
printf("\n%s\n", sqlca.sqlerrm.sqlerrmc);
printf("in \"%s...\"\n", oraca.orastxt.orastxtc);
printf("on line %d of %s.\n\n", oraca.oraslnr,
oraca.orasfnm.orasfnmc);
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE C;
EXEC SQL ROLLBACK RELEASE;!!!! exit(1);
이상입니다.
Can you post a brief code example with what works and doesn't?
Similar Messages
-
Is it possible to make a search help with dynamic selection table?
Hi Experts,
Is it possible to create search helps with dynamic seletion tables means
i dont know the selection table names at the time of creation of search help.
These tables will be determined at runtime.
if yes, Please give an idea how to create and pass the table names at runtime.
Thanks
Yogesh GuptaHi Yogesh,
Create and fill your itab and show it with FM F4IF_INT_TABLE_VALUE_REQUEST
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'field to return from itab'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'field on your screen to be filled'
stepl = sy-stepl
window_title = 'some text'
value_org = 'S'
TABLES
value_tab = itab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
Darley -
How to create the selection screen dynamically
Hi,
I have a requirement to create the selection screen Dynamically. All the fields that should appear on the selection screen will be available in a custom table. So, based on the entries available in the Z tables, the selection screen should be built. Eg. If there are 10 records available in the Z table, the selection screen should consist of 10 fields. If there are 100 entries, the Selection screen should contain 100 fields. and the logic to build this selection screen should be carried out dynamically in the program.
Could anyone of you please share the valuable inputs on this. If anyone has the sample code to do this, please share.
Thanks in advance.
Regards,
Paddu.Hi,
Kindly go through this sample program below:
DEMO_LIST_FORMAT_INPUT *and
check this function module:
FREE_SELECTIONS_DIALOG *.
Hope it helps
Regards
Mansi -
Creation of internal table dynamically based on the Date Range entered
Hi SAPgurus,
I have been facing one issue i.e creation of internal table dynamically based on the date range entered in the selection screen. For example the date range I am giving as 06/2006 to 08/2006, it should display the Fieldcatelog dynamically, this part i have completed but the only issue I am facing is to populate the sales data into that fields.
Right now my program is displaying the ALV like this.
Ex:
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00
Shiva new york 30.00
Shiva new york 40.00
but it should display like this
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00 30.00 40.00
80.00
Please help me in this scenario, how to acheive like this..
Thanks & Regards,
Sivaram KandulaHi Sivaram,
I also got the same requirement . i saw rich and your code whatever you have uploaded.i have created dynamic internal table but i am facing the issue to populating the data to my dynamic internal table.
Sivaram, can you please explain your code after this.
*<dyn_table>
*tab_item.
LOOP AT tab_item.
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
* <dyn_wa> = tab_item-bztxt.
* <dyn_wa> = tab_item-total.
* APPEND <dyn_wa> TO <dyn_table>.
** <dyn_wa> = tab_item-total.
** ASSIGN tab_item-bezei TO <dyn_wa>.
* APPEND <dyn_table>.
ENDLOOP.
how you are puting the loop at tab_item. but tab_item is already commented.
can you send me the code after that.
i am sending some part of my code.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fCAT1
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <dyn_table>.
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
select vbeln
fkart
vkorg
vtweg
fkdat
spart
fksto
from vbrk
client specified
into table gt_vbrk
where mandt = sy-mandt
and fkart in ('ZF5','ZFR')
and vkorg = '1100'
and vtweg = '20'
and fkdat in s_fkdat
and spart = '06'
and fksto = ' '.
if gt_vbrk[] is not initial.
select vbeln
fkimg
prsdt
netwr
matnr
arktx
werks
mwsbp
from vbrp
client specified
into table gt_vbrp
for all entries in gt_vbrk
where vbeln = gt_vbrk-vbeln
and werks in s_werks
and matnr in s_matnr.
endif.
select mnr ltx spras from t247
into table it_t247
where spras = 'E'.
data: lv_month1 type vbrp-prsdt,
name1(3) type c,
s_month type string,
s_month1 type string,
s_month2 type string.
* lv_netwr1 type vbrp-netwr,
* lv_mwsbp1 type vbrp-mwsbp.
loop at gt_vbrp into gs_vbrp.
gs_final2-matnr = gs_vbrp-matnr.
gs_final2-arktx = gs_vbrp-arktx.
gs_final2-fkimg = gs_vbrp-fkimg.
lv_month1 = gs_vbrp-prsdt.
read table it_t247 into wa_t247 with key mnr = lv_month1+4(2).
if sy-subrc eq 0.
name1 = wa_t247-ltx.
endif.
concatenate name1
lv_month1(4) into s_month SEPARATED BY '_' .
CONCATENATE S_MONTH 'QTY' INTO S_MONTH1 SEPARATED BY ''.
CONCATENATE S_MONTH 'VALUE' INTO S_MONTH2 SEPARATED BY ''.
gs_final2-month = s_month.
lv_netwr1 = gs_vbrp-netwr.
lv_mwsbp1 = gs_vbrp-mwsbp.
gs_final2-MONTH_QTY = S_MONTH1.
GS_FINAL2-MONTH_VAL = S_MONTH2.
gs_final2-value = lv_netwr1 + lv_mwsbp1.
append gs_final2 to gt_final2.
clear: gs_final2. "lv_name2.
endloop.
if gt_final2[] is not initial.
sort gt_final2 by matnr month ascending .
loop at gt_final2 into gs_final2.
gs_final2_01 = gs_final2.
collect gs_final2_01 into gt_final2_01.
endloop.
endif.
ENDIF..
Regards
Ankur -
Problem creating an internal table dynamically
Hi,
I'm trying to create an internal table dynamically as i would be able to determine the structure of the table based on the user input.
I've used the sample code from this forum ...
REPORT ZRICH_0003 .
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text.
parameters: p_table(30) type c.
selection-screen end of block b1.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
<b>* Select Data from table.
select * into table <dyn_table> from
(p_table).</b>
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
I'm able to get the structure of the table that i want, but when i'm trying to select data from the table into this internal table..as highlighted in the sample code above..i'm getting a short dump...saying that ' the database table is 600 bytes wide but the internal table is only 576 bytes wide.
The internal table is declared as
field-symbols: <dyn_table> type standard table..
Could anyone please tell me how to rectify this.
Thanks in advance,
Harsha.Hi Smitha,
I'm building the internal table by getting the structure using the method
cl_abap_typedescr=>describe_by_name( p_table ).
where p_table is the table name determined dynamically..
Now using this structure, i'm building an internal table by calling the method
call method cl_alv_table_create=>create_dynamic_table
I've checked all the fields after the internal table has been created .. and it contains all the fields of the table that i'm supplying initially..
But when i read data into that internal table, it gives me that dump..I've described it in this post earlier.
Any more suggestions would be very helpful.
Thanks,
Harsha -
Reg. Creation of table dynamically
Hi Experts,
While creating a table dynamically some of the fields in it_lvc_cat are Integer but the created table (new_table) contains all the fields as character. Is there any possibility of changing the datatype as interger for required fields.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
ep_table = new_table.
Regards,
Vijay.Hi,
Refer this code:
REPORT zmtable LINE-SIZE 255
LINE-COUNT 65.
Program written by Vijay Chaitanya Raju
Maintain Table dynamicly (Table name is entered on Selection Screen)
Very powerfull program. Please maintain authorisation access and
restrict maintenance to Z-tables
Version 6.20 and up
(can be used in 4.6C with some modifications to block try - endtry
and classes)
Enhanced functionality with dynamic selection screen
TABLES: sscrfields. "Fields on selection screens
TYPE-POOLS rsds.
DATA ds_clauses TYPE rsds_where.
DATA: BEGIN OF ifield OCCURS 0,
fieldname LIKE dd03l-fieldname,
position LIKE dd03l-position,
keyflag LIKE dd03l-keyflag,
datatype LIKE dd03l-datatype.
DATA: END OF ifield.
DATA: sl_step LIKE sy-tabix,
ss_step LIKE sy-subrc,
ss_act(1) TYPE c,
sl_lines LIKE sy-tfill,
sl_status LIKE sy-subrc,
sl_subrc LIKE sy-subrc,
sl_update(1) TYPE c,
sl_mandt(1) TYPE c,
len(6) TYPE n,
f_value(255) TYPE c,
sl_datum LIKE sy-datum,
sl_uzeit LIKE sy-uzeit,
price1(15) TYPE c,
price2(15) TYPE c,
mess(60) TYPE c,
d_stat LIKE sy-subrc,
m_stat LIKE sy-subrc,
slchar(6) TYPE c.
DATA: ref_ptr TYPE REF TO cx_root. "Root class more common
DATA: text TYPE string.
DATA: sl_index LIKE sy-tabix.
DATA: zauth LIKE dd02l-tabname.
DATA: num TYPE i,
max_len TYPE i,
check_len TYPE i,
sl_sel(1) TYPE c.
TYPE-POOLS: icon.
SELECTION-SCREEN.
SELECTION-SCREEN BEGIN OF LINE.
text-012 - 'Table Name'
SELECTION-SCREEN COMMENT 1(25) text-012.
PARAMETERS: tabname LIKE dd02l-tabname DEFAULT 'ZSCARE'.
text-003 - 'Selection'
SELECTION-SCREEN PUSHBUTTON 75(9) text-003 USER-COMMAND sta1.
SELECTION-SCREEN END OF LINE.
numrows(text) - 'Max Number of ROWS'
PARAMETERS: numrows LIKE sy-subrc DEFAULT '100'.
At Selection-Screen *
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'STA1'.
CLEAR sl_sel.
CALL FUNCTION 'ZSTAN_SELECTIONS'
EXPORTING
tabname = tabname
IMPORTING
ds_clauses = ds_clauses
EXCEPTIONS
table_not_valid = 1
other_error = 2
OTHERS = 3.
IF sy-subrc = 0.
sl_sel = 'X'.
ENDIF.
ENDCASE.
*At Selection-Screen Output *
AT SELECTION-SCREEN OUTPUT.
SELECT SINGLE tabname
INTO tabname
FROM dd02l
WHERE tabname = tabname
AND as4local = 'A'
AND ( tabclass = 'TRANSP' OR tabclass = 'POOL'
OR tabclass = 'CLUSTER' ).
IF sy-subrc <> 0.
MESSAGE 'Table is not valid' TYPE 'S'.
RETURN.
ENDIF.
START-OF-SELECTION.
START-OF-SELECTION.
DEFINE: acheck.
zauth = 'ZTABAUTH'.
select single statu
into sl_update
from (zauth)
where tabname = tabname
and bname = sy-uname.
if sy-subrc <> 0.
message 'You are not authorized to view this table' type 'S'.
return.
endif.
END-OF-DEFINITION.
SELECT SINGLE tabname
INTO tabname
FROM dd02l
WHERE tabname = tabname
AND as4local = 'A'
AND ( tabclass = 'TRANSP' OR tabclass = 'POOL'
OR tabclass = 'CLUSTER' ).
IF sy-subrc <> 0.
MESSAGE 'Table is not valid' TYPE 'S'.
RETURN.
ENDIF.
DATA: ptr_itab TYPE REF TO data.
FIELD-SYMBOLS: <fs_itab> TYPE STANDARD TABLE. "ANY TABLE.
CREATE DATA ptr_itab TYPE STANDARD TABLE OF (tabname).
ASSIGN ptr_itab->* TO <fs_itab>.
For DELETION
DATA: ptr_itd TYPE REF TO data.
FIELD-SYMBOLS: <fs_itd> TYPE STANDARD TABLE.
CREATE DATA ptr_itd TYPE STANDARD TABLE OF (tabname).
ASSIGN ptr_itd->* TO <fs_itd>.
For MODIFICATION
DATA: ptr_itm TYPE REF TO data.
FIELD-SYMBOLS: <fs_itm> TYPE STANDARD TABLE.
CREATE DATA ptr_itm TYPE STANDARD TABLE OF (tabname).
ASSIGN ptr_itm->* TO <fs_itm>.
DATA: ptr_wtab TYPE REF TO data.
FIELD-SYMBOLS: <fs_wtab> TYPE ANY.
CREATE DATA ptr_wtab TYPE (tabname).
ASSIGN ptr_wtab->* TO <fs_wtab>.
DATA: itabname(15) TYPE c.
itabname = '<fs_wtab>'.
Standard list status with 'SAVE' button
SET PF-STATUS 'STLI'.
CLEAR sl_update.
Maintain authorisation access in table ZTABAUTH
Key fields: tabname - Table name
bname = sy-uname - User name
statu = 'X' - maintain
' ' - view
Check authorisation access
acheck.
SELECT fieldname position keyflag datatype
INTO TABLE ifield
FROM dd03l
WHERE tabname = tabname
AND fieldname NOT LIKE '.INCLU%'
ORDER BY position.
FIELD-SYMBOLS: <f1> TYPE ANY.
DATA: tab_field(60) TYPE c,
sline LIKE sy-lisel.
DATA: field_attr LIKE dfies.
DATA: BEGIN OF tfield_attr OCCURS 0.
INCLUDE STRUCTURE field_attr.
DATA: END OF tfield_attr.
LOOP AT ifield.
CALL FUNCTION 'G_FIELD_READ'
EXPORTING
table = tabname
fieldname = ifield-fieldname
text_flag = 'X'
IMPORTING
field_attr = field_attr.
tfield_attr = field_attr.
APPEND tfield_attr.
ENDLOOP.
IF sl_sel = 'X'.
SELECT *
FROM (tabname)
INTO TABLE <fs_itab> UP TO numrows ROWS
WHERE (ds_clauses-where_tab).
ELSE.
SELECT *
FROM (tabname)
INTO TABLE <fs_itab> UP TO numrows ROWS.
ENDIF.
DESCRIBE TABLE <fs_itab> LINES sl_lines.
Show two extra lines to allow addition up to 2 new lines
IF sl_update = 'X'.
DO 2 TIMES.
APPEND INITIAL LINE TO <fs_itab>.
ENDDO.
ENDIF.
DATA: info(22) VALUE 'D - Delete, M - Modify'.
WRITE: / icon_information AS ICON QUICKINFO info.
WRITE ' '.
CLEAR check_len.
LOOP AT tfield_attr.
IF tfield_attr-datatype = 'CLNT'.
CONTINUE.
ENDIF.
len = tfield_attr-outputlen.
IF tfield_attr-keyflag = 'X'.
check_len = check_len + len + 1.
ENDIF.
IF tfield_attr-scrtext_m IS NOT INITIAL.
WRITE: AT (len) tfield_attr-scrtext_m COLOR 1.
ELSE.
WRITE: AT (len) tfield_attr-fieldtext COLOR 1.
ENDIF.
ENDLOOP.
CLEAR ss_step.
CLEAR ss_act.
LOOP AT <fs_itab> INTO <fs_wtab>.
IF sy-tabix LE sl_lines.
ss_step = 1.
ELSE.
CLEAR ss_step.
ENDIF.
In field SS_STEP put D - to delete record
M - to modify/add new record
IF sl_update = 'X'.
WRITE:/ icon_change AS ICON.
IF ss_step = 1.
WRITE: ss_act INPUT ON.
ELSE.
ss_act = 'M'.
WRITE: ss_act.
CLEAR ss_act.
ENDIF.
ELSE.
WRITE:/ icon_display AS ICON.
WRITE: ss_act COLOR 2.
ENDIF.
LOOP AT ifield.
Maintain client dependant tables in the same client
IF ifield-datatype = 'CLNT'.
sl_mandt = 'X'.
CONTINUE.
ENDIF.
CONCATENATE itabname '-' ifield-fieldname INTO tab_field.
ASSIGN (tab_field) TO <f1>.
IF sl_update = 'X'.
IF ifield-keyflag = 'X' AND ss_step IS NOT INITIAL.
WRITE: <f1> COLOR 4.
ELSE.
WRITE: <f1> INPUT ON.
ENDIF.
ELSE.
IF ifield-keyflag = 'X' AND ss_step IS NOT INITIAL.
WRITE: <f1> COLOR 4.
ELSE.
WRITE: <f1> COLOR 2.
ENDIF.
ENDIF.
UNASSIGN <f1>.
ENDLOOP.
ENDLOOP.
END-OF-SELECTION.
END-OF-SELECTION.
AT USER-COMMAND.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'SAVE'.
IF sl_update = 'X'.
CLEAR: sl_step,
sl_status,
sl_subrc,
<fs_wtab>,
d_stat,
m_stat,
max_len.
REFRESH <fs_itd>.
REFRESH <fs_itm>.
DO.
IF sl_status <> 0.
EXIT.
ENDIF.
ADD 1 TO sl_step.
IF sl_subrc <> 0.
EXIT.
ENDIF.
CLEAR ss_step.
CLEAR ss_act.
READ LINE sl_step
FIELD VALUE ss_act INTO f_value.
sl_subrc = sy-subrc.
IF f_value(1) EQ 'D' OR f_value(1) = 'd'.
ss_step = 1. "Delete
ELSEIF f_value(1) EQ 'M' OR f_value(1) = 'm'.
ss_step = 2. "Modify
ELSE.
CLEAR ss_step.
ENDIF.
CHECK sy-lisel(3) = '0Z '.
IF ss_step GT 0.
CLEAR sline.
sline = sy-lisel+5(250).
max_len = 250.
CHECK sline(check_len) <> ' '.
LOOP AT tfield_attr.
CONCATENATE itabname '-' tfield_attr-fieldname
INTO tab_field.
ASSIGN (tab_field) TO <f1>.
IF tfield_attr-fieldname = 'MANDT'.
<f1> = sy-mandt.
ELSE.
CLEAR f_value.
IF max_len LT tfield_attr-outputlen.
max_len = 255.
ADD 1 TO sl_step.
READ LINE sl_step.
sline = sy-lisel.
ENDIF.
f_value = sline(tfield_attr-outputlen).
max_len = max_len - tfield_attr-outputlen - 1.
IF tfield_attr-inttype = 'D'.
IF f_value CO ' 0./-'.
CLEAR sl_datum.
<f1> = sl_datum.
ELSE.
CALL FUNCTION 'CONVERT_DATE_INPUT'
EXPORTING
input = f_value
plausibility_check = 'X'
IMPORTING
output = sl_datum
EXCEPTIONS
plausibility_check_failed = 1
wrong_format_in_input = 2
OTHERS = 3.
IF sy-subrc = 0.
<f1> = sl_datum.
ELSE.
text = 'Invalid Date'.
sl_status = 1.
EXIT.
ENDIF.
ENDIF.
ELSEIF tfield_attr-inttype = 'T'.
IF f_value CO ' 0:'.
CLEAR sl_uzeit.
<f1> = sl_uzeit.
ELSE.
CALL FUNCTION 'CONVERT_TIME_INPUT'
EXPORTING
input = f_value
plausibility_check = 'X'
IMPORTING
output = sl_uzeit
EXCEPTIONS
plausibility_check_failed = 1
wrong_format_in_input = 2
OTHERS = 3.
IF sy-subrc = 0.
<f1> = sl_uzeit.
ELSE.
text = 'Invalid Time'.
sl_status = 1.
EXIT.
ENDIF.
ENDIF.
ELSEIF tfield_attr-inttype = 'C'.
TRANSLATE f_value TO UPPER CASE.
<f1> = f_value.
ELSE.
TRANSLATE f_value USING ', '.
CONDENSE f_value NO-GAPS.
TRY.
<f1> = f_value.
CATCH cx_root INTO ref_ptr.
text = ref_ptr->get_text( ).
sl_status = 1.
EXIT.
ENDTRY.
ENDIF.
SHIFT sline BY tfield_attr-outputlen PLACES.
SHIFT sline LEFT.
ENDIF.
UNASSIGN <f1>.
ENDLOOP.
IF sl_status = 0.
CASE ss_step.
WHEN 1. "Delete
ADD 1 TO d_stat.
APPEND <fs_wtab> TO <fs_itd>.
WHEN 2. "Modify
ADD 1 TO m_stat.
APPEND <fs_wtab> TO <fs_itm>.
ENDCASE.
ENDIF.
ENDIF.
ENDDO.
IF sl_status = 0.
IF d_stat IS NOT INITIAL.
slchar = d_stat.
CONCATENATE 'Deleted -' slchar 'record.' INTO text
SEPARATED BY space.
DELETE (tabname) FROM TABLE <fs_itd>.
ENDIF.
IF m_stat IS NOT INITIAL.
slchar = m_stat.
CONCATENATE text 'Modified -' slchar 'record.' INTO text
SEPARATED BY space.
MODIFY (tabname) FROM TABLE <fs_itm>.
ENDIF.
IF d_stat IS INITIAL AND m_stat IS INITIAL.
MESSAGE 'No changes were done' TYPE 'S'.
ELSE.
MESSAGE text TYPE 'S'.
ENDIF.
LEAVE.
ELSE.
MESSAGE text TYPE 'I'.
EXIT.
ENDIF.
ELSE.
LEAVE.
ENDIF.
ENDCASE.
*--END--
Below is Function for a Dynamic Selection Screen
FUNCTION zstan_selections.
""Local interface:
*" IMPORTING
*" VALUE(TABNAME) LIKE DD02L-TABNAME DEFAULT 'ZSCARE'
*" EXPORTING
*" VALUE(DS_CLAUSES) TYPE RSDS_WHERE
*" EXCEPTIONS
*" TABLE_NOT_VALID
*" OTHER_ERROR
DATA texpr TYPE rsds_texpr.
DATA twhere TYPE rsds_twhere.
DATA trange TYPE rsds_trange.
DATA BEGIN OF qcat. "Selections View for
INCLUDE STRUCTURE rsdsqcat. "Free Selectoptions
DATA END OF qcat.
DATA BEGIN OF tabs OCCURS 10.
INCLUDE STRUCTURE rsdstabs.
DATA END OF tabs.
DATA BEGIN OF fields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF fields.
DATA BEGIN OF efields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF efields.
DATA selid LIKE rsdynsel-selid.
DATA actnum LIKE sy-tfill.
DATA title LIKE sy-title VALUE 'Selection Screen'.
DATA: maxnum LIKE sy-subrc VALUE '69'.
CLEAR tabs.
tabs-prim_tab = tabname.
COLLECT tabs.
DATA: position LIKE dd03l-position.
DATA: keyflag LIKE dd03l-keyflag.
CLEAR fields.
fields-tablename = tabname.
fields-sign = 'I'.
DATA: step LIKE sy-subrc.
SELECT fieldname keyflag position
INTO (fields-fieldname, keyflag, position)
FROM dd03l
WHERE tabname = tabname
AND fieldname NOT LIKE '.INCLU%'
AND datatype NE 'CLNT'
ORDER BY position.
ADD 1 TO step.
CHECK step LE maxnum.
IF keyflag <> 'X'.
efields = fields.
APPEND efields.
ENDIF.
APPEND fields.
ENDSELECT.
IF sy-subrc <> 0.
RAISE table_not_valid.
ENDIF.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = texpr
kind = 'F'
IMPORTING
selection_id = selid
expressions = texpr
where_clauses = twhere
field_ranges = trange
number_of_active_fields = actnum
TABLES
tables_tab = tabs
fields_tab = fields
fields_not_selected = efields
EXCEPTIONS
fields_incomplete = 01
fields_no_join = 02
field_not_found = 03
no_tables = 04
table_not_found = 05
expression_not_supported = 06
incorrect_expression = 07
illegal_kind = 08
area_not_found = 09
inconsistent_area = 10
kind_f_no_fields_left = 11
kind_f_no_fields = 12
too_many_fields = 13.
IF sy-subrc = 0.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = selid
title = title
IMPORTING
where_clauses = twhere
expressions = texpr
field_ranges = trange
number_of_active_fields = actnum
TABLES
fields_tab = fields
EXCEPTIONS
internal_error = 01
no_action = 02
no_fields_selected = 03
no_tables_selected = 04
selid_not_found = 05.
IF sy-subrc = 0.
CLEAR ds_clauses.
MOVE tabname TO ds_clauses-tablename.
READ TABLE twhere WITH KEY ds_clauses-tablename INTO ds_clauses.
IF sy-subrc <> 0.
RAISE other_error.
ENDIF.
ELSE.
RAISE other_error.
ENDIF.
ELSE.
RAISE other_error.
ENDIF.
ENDFUNCTION.
Regards,
Shiva -
How to create internal table dynamically based on a table entry
hi Experts,
I have table yprod_cat. It has product categories.
In my ABAP program I need to create internal table dynamically based on the number of entries in the table.
For example:
If the table has 3 entries for product category
1. Board
2. Micro
3. Syst
Then create three (3) internal tables.
i_board
i_micro
i_syst
How can we do this? Any sample code will be very usefull
Thanks & Regards
Gopal
Moderator Message: No sample codes can be given. Please search for them or work it!
Edited by: kishan P on Jan 19, 2011 4:22 PMOur APEX version is 4.2We are using below SQL query to display radio groups dynamically..
SELECT APEX_ITEM.RADIOGROUP (1,deptno,'20',dname) dt
FROM dept
ORDER BY 1;
Created a form using SQL type and given abouve SQL query as source.. But when we run the page, there were no radio groups displayed in the page..
Below is the output of the query..
<input type="radio" name="f01" value="10" />ACCOUNTING
<input type="radio" name="f01" value="20" checked="checked" />RESEARCH
<input type="radio" name="f01" value="30" />SALES
<input type="radio" name="f01" value="40" />OPERATIONS
>
If Tabular Form:
Edit Region > Report Attributes > Edit Column > Change the Column type to "Standard Report Column"
If normal Page Item:
Edit Page Item > Security > Escape special characters=No.
Pl read the help on that page item to understand the security risk associated with =NO.
Cheers,
Edited by: Prabodh on Dec 3, 2012 5:59 PM -
How to pass the feild names of a select query dynamically?
Hi
How can we pass the feilds names in select query dynamically?
For example in my selection screen i wil be giving the table name, and feilds in that table.....
those feilds should be taken in my select query...
instead of
PARAMETERS : tab_name TYPE ddobjname .
SELECT *
FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.
parametrs : feild1 like-------
feild2----
i need select feild1 feild2 feild3 FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.by the way, contrary to popular belief there is no performance problem when using
SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
as long as the structure of itab contains only the required fields.
I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
Maybe something you want to factor in here.
Cheers
Thomas -
How to change the select options selection text dynamically in webdynpro abap ?
I am using standard interface WDR_SELECT_OPTIONS.... i want to change the Selection text dynamically in my select options.I.E. if the select option is for VBELN field than i want to change its description SALES ORDER Number through Code to some other text.
If anyone can please help me in this.Hi,
You can achieve your requirement as below
Get the range table of your selection field as below
data lt_range_table type ref to data.
wd_this->m_handler->GET_RANGE_TABLE_OF_SEL_FIELD(
exporting
i_id = 'VBELN'
receiving
rt_range_table = lt_range_table ).
Update the selection field with new description - 'Your New Text'
wd_this->m_handler->UPD_SELECTION_FIELD(
exporting
I_ID = 'VBELN'
I_DESCRIPTION = 'Your New text'
I_IS_AUTO_DESCRIPTION = abap_false
IT_RESULT = lt_range_table ).
You can also pass the other parameters as per your requirement
Hope this helps you.
Regards,
Rama -
Hello,
I have an internal table which needs to be queried with set of attributes which change dynamically. How can I do it?
Eg: Internal Table i_tab contains attributes a,b,c,d,e etc... Now I should extract a single line from the table based based on the values I supply for the attributes.
Say if I give a=23 b='' c='abc' d='' e=''. Then the query should be able to return be the line where all the initial field attributes (here in this case b,d, and e) should not be considered for the query.
It shoud be
read table i_tab with key a= 23 c='abc'.
The next time a query can be shooted with the foll values
a='' b='SAP' c='ERP' d='' e=''.
Then the query shd be
read table i_tab with key b= 'SAP' c='ERP'.
In short can I get the functionality of the "select statement dynamic search string"?
select * from tab where ( search string ) .
and search string would be generated dynamically based on the inputs?
I would be really thankful if you can provide me an immediate answer.
Thanks and Regards,
SandhyaI think one of the simplest way is to define ranges for the variables a, b, c, d and e.
ranges : r_a for a, r_b for b...r_e for e.
refresh : r_a, r_b, r_c, r_d, r_e.
clear : r_a, r_b, r_c, r_d, r_e.
if a is not initial.
r_a-sign = 'I'.
r_a-option = 'EQ'.
r_a-low = value.
append r_a.
endif.
....similarly build for b, c, d and e.
Loop at itab.
check itab-a in r_a.
check itab-b in r_b.
check itab-e in r_e.
move-corresponding itab to <b>urval</b>.
exit.
endloop. -
How to make columns in the select list dynamic
Hi
I need to make columns in the select query dynamic.I have three tables.Table 1 contains master information lets say name of group(A group consists of members of various skill sets) and its period(A group is of specific period lets say for 18 months).Table 2 contains different skill sets corresponding to a group i.e there is one to many relationship between table 1 and table 2.Table 3 contains months information of skill sets.For example if skill set 1 is required for 5 months then there will be 5 rows(for each month) in table 3 corresponding to a skill set i.e there is again one to many relationship between table 2 and table 3.Tabale 3 will also contain man month value for perticular month.I need to show all the periods of a group and its sum of man month value for all skill sets.
If group1 is of 6 months (starts nov2006 and ends Apr2007) and has 5 skill sets then there will be one entry in table 1 and 5 entry in table 2(For skill set).For each entry in table 2 there will be 6 entry in table 3(for each month).I need to write a query which would display
Group name nov2006 dec2006 jan2007 feb2007 mar2007 apr2007
Gr1 10 15 21 17 18 22--These are sum of man month of all skill set for a particular groupIf Gr 2 is of 9 months then it would disply all the information in respective months.i.e for group 2 nine months information and group 1 six months information
Pls help
Thanks in advance
SasHi,
From your requirement, we understand that you want to make Rows in table 3 as Columns.
Please search pivot in this Forum.
Regards
K.Rajkumar -
How to create a table dynamically
Hello All,
I want to create a table dynamically in DDIC. I know that there is function module exist DB_CREATE_TABLE but i am getting some errors while using it.
Could any please post some code for it.
Regards,
LisaHere is the code i have writen my self.
PARAMETERS: tabname TYPE dd02l-tabname,
fldname TYPE dd03p-fieldname,
rollname TYPE dd03p-rollname.
DATA: gt_cl_bc_dyn TYPE REF TO zcl_bc_dyn,
status TYPE sy-subrc.
data: lct_table type ZTT_ZTSITAB.
INITIALIZATION.
tabname = 'ZTEST1'.
CREATE OBJECT gt_cl_bc_dyn.
START-OF-SELECTION.
CALL METHOD gt_cl_bc_dyn->create_table
EXPORTING
tabname = tabname
fieldname = fldname
rollname = rollname
itab = lct_table
IMPORTING
status = status .
IF status = 0.
WRITE: 'Table creation is successful'.
ELSE.
WRITE: 'Table creation is unsuccessful'.
ENDIF.
Code in the method
METHOD create_table.
DATA: ls_dd02v_wa TYPE dd02v,
ls_dd09l_wa TYPE dd09l,
ls_dd03p TYPE dd03p,
lt_dd03p TYPE TABLE OF dd03p,
rc TYPE sy-subrc.
ls_dd02v_wa-tabname = tabname.
ls_dd02v_wa-tabclass = 'TRANSP'.
ls_dd02v_wa-contflag = 'A'.
ls_dd09l_wa-tabname = tabname.
ls_dd09l_wa-tabkat = '0'.
ls_dd09l_wa-tabart = 'APPL0'.
ls_dd03p-tabname = tabname.
ls_dd03p-fieldname = fieldname.
ls_dd03p-position = '0001'.
ls_dd03p-keyflag = 'X'.
ls_dd03p-rollname = rollname.
APPEND ls_dd03p TO lt_dd03p.
CALL FUNCTION 'DDIF_TABL_PUT'
EXPORTING
name = tabname
dd02v_wa = ls_dd02v_wa
dd09l_wa = ls_dd09l_wa
TABLES
dd03p_tab = lt_dd03p
EXCEPTIONS
tabl_not_found = 1
name_inconsistent = 2
tabl_inconsistent = 3
put_failure = 4
put_refused = 5
OTHERS = 6
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'DDIF_TABL_ACTIVATE'
EXPORTING
name = tabname
IMPORTING
rc = rc
EXCEPTIONS
not_found = 1
put_failure = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
status = rc.
ENDMETHOD. -
Can we create internal table dynamically ? how?
hi to all experts,
can we create internal table dynamically ? how?plz explain me with an example.Anybody with good example will be rewarded.it was asked in an interview what the answer for itHI
Yes you can create
see this
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
JUST USE THIS CODE AND DO THE ESSENTIAL CHANGES ACCORDING TO YOU
STEP: 1 - get backend field catalog (currently displayed alv)
CLEAR: tl_fieldcatalog. REFRESH: tl_fieldcatalog.
CALL METHOD w_grid->get_backend_fieldcatalog
IMPORTING
et_fieldcatalog = tl_fieldcatalog.
STEP: 2 - create a new fieldcatalog for dynamic internal table
CLEAR: sl_fieldcatalog.
CLEAR: t_outtab_fieldname. REFRESH: t_outtab_fieldname.
CLEAR: tl_fieldcatalog_new. REFRESH: tl_fieldcatalog_new.
CLEAR: t_download_fieldname. REFRESH: t_download_fieldname.
CLEAR: t_download_fieldheading. REFRESH: t_download_fieldheading.
LOOP AT tl_fieldcatalog INTO sl_fieldcatalog.
STEP: 2.1 - populate data in T_OUTTAB_FIELDNAME
APPEND sl_fieldcatalog-fieldname TO t_outtab_fieldname.
STEP: 2.2 - populate TL_FIELDCATALOG_NEW & T_DOWNLOAD_FIELDNAME
IF sl_fieldcatalog-no_out EQ ''.
IF sl_fieldcatalog-fieldname NE 'STATUS'
OR sl_fieldcatalog-fieldname NE 'MESG_STATUS'
OR sl_fieldcatalog-fieldname NE 'ZLOCK'
OR sl_fieldcatalog-fieldname NE 'T_PLANT'
OR sl_fieldcatalog-fieldname NE 'T_CSR'.
If field is COMM_PLANT, change its length
IF sl_fieldcatalog-fieldname EQ 'COMM_PLANT'.
sl_fieldcatalog-outputlen = 1800.
sl_fieldcatalog-intlen = 1800.
sl_fieldcatalog-dd_outlen = 1800.
ENDIF. "comm_plant
sl_fieldcatalog_new = sl_fieldcatalog.
APPEND sl_fieldcatalog_new TO tl_fieldcatalog_new.
APPEND sl_fieldcatalog-fieldname TO t_download_fieldname.
APPEND sl_fieldcatalog-scrtext_l TO t_download_fieldheading.
CLEAR: sl_fieldcatalog, sl_fieldcatalog_new.
ENDIF.
ENDIF.
ENDLOOP.
STEP: 3 - create dynamic internal table
FREE: ref_download.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
I_STYLE_TABLE =
it_fieldcatalog = tl_fieldcatalog_new
IMPORTING
ep_table = ref_download
E_STYLE_FNAME =
EXCEPTIONS
generate_subpool_dir_full = 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.
ASSIGN ref_download->* TO <ft_download>.
CREATE DATA ref_wa LIKE LINE OF <ft_download>.
ASSIGN ref_wa->* TO <fs_download>.
STEP: 4 - populate data in dynamic internal table
LOOP AT t_outtab INTO wa_outtab.
LOOP AT t_download_fieldname.
ASSIGN COMPONENT t_download_fieldname OF STRUCTURE
<fs_download> TO <fs_download_field>.
IF t_download_fieldname-field EQ 'COMM_PLANT'.
STEP: 4.1 - get long text from database table
CLEAR: wal_table.
SELECT SINGLE * FROM zshaven_plnt_txt
INTO wal_table
WHERE vbeln = wa_outtab-vbeln
AND posnr = wa_outtab-posnr
AND del_no = wa_outtab-del_no
AND del_itm = wa_outtab-del_itm.
IF sy-subrc EQ 0.
STEP: 4.2 - break long-text into separate lines
CLEAR: tl_text. REFRESH: tl_text.
SPLIT wal_table-plant_comm
AT '~'
INTO TABLE tl_text.
STEP: 4.3 - Combine these separate lines with space in
between two lines
CLEAR: wal_text, final_text.
LOOP AT tl_text INTO wal_text.
IF final_text IS INITIAL.
final_text = wal_text.
ELSE.
CONCATENATE final_text '-' wal_text
INTO final_text.
REPLACE '-' WITH ' ' INTO final_text.
ENDIF.
ENDLOOP.
STEP: 4.4 - move long text to work-area
<fs_download_field> = final_text.
ENDIF. "subrc
ELSE. "t_download_fieldname
READ TABLE t_outtab_fieldname
WITH KEY field = t_download_fieldname-field.
ASSIGN COMPONENT t_outtab_fieldname-field OF STRUCTURE
wa_outtab TO <fs_outtab_field>.
<fs_download_field> = <fs_outtab_field>.
ENDIF.
ENDLOOP.
STEP: 4.5 - Move data from work-area to dynamic internal table
APPEND <fs_download> TO <ft_download>.
CLEAR: <fs_download>.
ENDLOOP.
STEP: 5 - download
CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = 'C:\zshaven.xls'
filetype = 'DAT'
filetype_no_show = 'X'
filetype_no_change = 'X'
TABLES
data_tab = <ft_download>
fieldnames = t_download_fieldheading
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. -
How to create a transparent table(z table) dynamically
Hi,
Can anyone explain me how to create a transparent table(z table) dynamically in the program.
Any function module or suggestions welcome.Hi Mithun
we will not create transparent table in the program . you could do it by using native SQL in the ABAP Program . the sample is show in below .
This is a sample that show how to connect to Database directly and can use the native SQL to select , create or delete table.
PARAMETERS dbs TYPE dbcon-con_name default 'SDB'.
DATA carrid_wa TYPE scarr-carrid.
DATA lv_int TYPE i.
*Types
data: begin of ty_equi,
equipment(25) type c,
SERIALENERGY(25) type c,
end of ty_equi.
*Internal Tables
data it_equi like table of ty_equi.
data wa_equi like line of it_equi.
DATA dbtype TYPE dbcon_dbms.
SELECT SINGLE dbms
FROM dbcon
INTO dbtype
WHERE con_name = dbs.
IF dbtype = 'ORA'.
TRY.
EXEC SQL.
CONNECT TO :dbs
ENDEXEC.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_sy_native_sql_error.
ENDIF.
EXEC SQL.
OPEN dbcur FOR
SELECT
EQUIPMENT,
SERIALENERGY
FROM emd.meter
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :wa_EQUI
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ELSE.
WRITE: /
wa_equi-equipment,
wa_equi-SERIALENERGY.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE dbcur
ENDEXEC.
EXEC SQL.
DISCONNECT :dbs
ENDEXEC.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in Native SQL.` TYPE 'I'.
ENDTRY.
ENDIF.
Regards
Wiboon -
Passing internal tables dynamically to a subroutine
Hi All,
How to pass internal tables dynamically to a subroutine?
In subroutine logic i'm fetching data from MARA table for all entries in the internal table passed to the subroutine. Based on some condition the internal table varies. I'm placing the code below
Both GT_AUFM & GT_AUFM1 are of 2 different structures having MATNR.
IF WA_AUFM1-BWART EQ '261'.
PERFORM GET_IF_SEMIFINISHED USING GT_AUFM1.
ELSE IF WA_AUFM1-BWART EQ '262'.
PERFORM GET_IF_SEMIFINISHED TABLES GT_AUFM.
ENDIF.
FORM GET_IF_SEMIFINISHED USING P_TABLE TYPE ANY TABLE.
REFRESH GT_MARA.
SELECT MATNR FROM MARA INTO TABLE GT_MARA
FOR ALL ENTRIES IN P_TABLE
WHERE MATNR EQ P_TABLE-MATNR
AND MTART IN R_MTART.
ENDFORM.
With this logic i'm getting an error that the specified type has no structure and therefore no component called MATNR.
Thanks,
Anil.refer this link
dynamic internal table
Maybe you are looking for
-
My Macbook Pro has been taking forever to start up, and open windows, plus I get a lot of the spinning wheel of slow death when I'm working in my design programs. I HATE messing with my systems, because something always seems to go wrong. Also, I hav
-
How to add link with mp3 to iTunes library?
I purchased a song which is actually a link ending in mp3. I want to save it to my itunes library, but when I highlight and right-click on it, it only gives me the option to "save as itunes spoken word." Also how do I make itunes as my default audio
-
Issue on Creating RFx in Business Package
Hi We are in to SRM 7.0 with the same version of Business Package. I am trying to create a RFx from Portal which in turn calls the webdynpro application (Strategic Purchasing->Strategic Sourcing->Create Documents->RFx) sap/bc/webdynpro/sapsrm/wda_l_f
-
Hi Experts, I have created documentation by going to se38 as below in english. goto->documentation->change mode I need to translate it into different languages, Please let me know the steps to do it. Many Thanks! Regards, Kiran
-
Hi guys I recently installed the MSI Z77 MPower after replacing it with the Asrock extreme 4 mobo which i had before, am currently having problems with the RAM it wont boot if i place them in the correct slots for dual channel configurations but if i