Problem accessing TABLE fields in SELECT statement
Hi,
We are currently using Oracle Database 10.2.0.2.0.
In the following code, using a function to access TABLE fields works, but not when accessing the table fields directly (in the latter case, I get a no data found exception).
Why is that?
Thanks for your help.
Olivier
PS: I do have a lengthy explanation of why we would want to do that as well as the full packages, etc... But I didn't want to bore you to no end.
I'll post it if required.
CREATE OR REPLACE PACKAGE PA_TEST_DEVTBL AS
TYPE TBL_ROLCODE IS TABLE OF LANROLE.ROLCODE%TYPE INDEX BY BINARY_INTEGER;
TYPE TBL_ROLLABEL IS TABLE OF LANROLE.ROLLABEL%TYPE INDEX BY BINARY_INTEGER;
end PA_TEST_DEVTBL;
CREATE OR REPLACE PACKAGE BODY PA_TEST AS
-- Array containing the selected data
TblRolCode PA_TEST_DEVTBL.TBL_ROLCODE;
TblRolLabel PA_TEST_DEVTBL.TBL_ROLLABEL;
-- Functions created to retrieve each array data
FUNCTION F_GET_ROLCODE( nIndex NUMBER ) RETURN LANROLE.ROLCODE%TYPE IS
BEGIN
RETURN TblRolCode( nIndex );
END F_GET_ROLCODE;
FUNCTION F_GET_ROLLABEL( nIndex NUMBER ) RETURN LANROLE.ROLLABEL%TYPE IS
BEGIN
RETURN TblRolLABEL( nIndex );
END F_GET_ROLLABEL;
PROCEDURE S_TEST (
-- THIS DOESN'T WORK (ORA-01403: no data found)
OPEN cReturn FOR
SELECT TblRolCode( ROWNUM ),
TblRolLabel( ROWNUM )
FROM TABLE( CAST( tblRows AS T_TBL_NUMBER ) );
-- BUT THIS WORKS !!!
OPEN cReturn FOR
SELECT F_GET_ROLCODE( ROWNUM ) AS ROLCODE,
F_GET_ROLLABEL( ROWNUM ) AS ROLLABEL
FROM TABLE( CAST( tblRows AS T_TBL_NUMBER ) );
..
well it could be managed by simple HTML tags or simple javascript properties and events itself...
All you have to do is encode URL and pass it as the request parameters to the next page.
Checkout a simple example down below.
MainTable.jsp:
============
<table>
<thead>
<tr>
</tr>
</thead>
<tbody>
<c:forEach var="DTOBean" items="${request.dbList}">
<tr>
<td><c:out value="${DTOBean.rowId}"/></td>
<td onClick="window.location.href='/testpage.jsp?col2='+escape('<c:out value="${DTOBean.col2}"/>')+'&col3='+escape('<c:out value="${DTOBean.col3}"/>'); " ><c:out value="${DTOBean.col1"/></td>
<!-- or try with to work with simple hyperlink
<td><a href="# " onclick="window.location.href='/testpage.jsp?col2='+escape('<c:out value="${DTOBean.col2}"/>')+'&col3='+escape('<c:out value="${DTOBean.col3}"/>');"><c:out value="${DTOBean.col1"/></a></td>
-->
<td><c:out value="${DTOBean.col2"/></td>
<td><c:out value="${DTOBean.col3"/></td>
</tr>
</c:forEach>
</tbody>
</table>
--------------------------------------------------testpage.jsp:
==========
Column2 : <c:out value="${param.col2}"/>
Column3 : <c:out value="${param.col3}"/>
--------------------------------------------------Hope that might help.
REGARDS,
RaHuL
Similar Messages
-
Restrict number of characters in table field for select statement.
SELECT * FROM table
WHERE column1 = z-column.
The field column1 is of type char and size 20
The field z-column is of type char size 10.
how do we perform this select?
Anyone can guide me?
Edited by: Hadesfx on Sep 11, 2009 3:56 PM
Edited by: Hadesfx on Sep 11, 2009 3:59 PMHello,
In your OP did you mention this? Please be specific when you post the next time.
Can you please post your code?
I think you have to try a work around:
DATA:
RS_STOCKID TYPE SELOPT,
RT_STOCKID TYPE STANDARD TABLE OF SELOPT.
LOOP AT GT_ZB1PUT_STOCKTMP.
RS_STOCKID-SIGN = 'I'.
RS_STOCKID-OPTION = 'EQ'.
RS_STOCKID-LOW = GT_ZB1PUT_STOCKTMP-STOCKID.
APPEND RS_STOCKID TO RT_STOCKID.
CLEAR RS_STOCKID.
ENDLOOP.
You can use this RANGE table to SELECT data from the table.
SELECT * FROM zb1xxt_param
FOR ALL ENTRIES IN gt_zb1put_stocktmp[]
WHERE zzcode = 'DEV036'
AND zzdomain = 'SD'
AND zzdata = 'INBOUND'
AND zzinput1 = 'STOCKID'
AND zzinput2 IN RT_STOCKID. "Use RT_STOCKID for SELECT'ing data
BR,
Suhas -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
Is it Possible to join 4 or more tables in a Select Statement?
Hello guys,
Can I do Inner Join 4 or 5 tables in a select statement?U HAVE TO SERCH FOR KEY FIELD FOR THAT . MEANS HOW TABELS ARE RELATED EACH OTHE FOR THIS U ALSO USE SQ02
FOR EXAMPLE
SELECT bkpf~belnr
bkpf~gjahr
bkpf~bukrs
bkpf~blart
bkpf~bldat
bkpf~budat
bkpf~usnam
bkpf~tcode
bkpf~xblnr
bsik~lifnr
bsik~bupla
bsik~secco
INTO CORRESPONDING FIELDS OF TABLE itab_pur
FROM bkpf INNER JOIN bsik
ON bkpfbelnr = bsikbelnr
and bkpfbukrs = bsikbukrs
WHERE bkpf~bukrs IN co_code
AND bkpf~budat IN pos_dt
AND bkpf~tcode IN t_code
AND bsik~secco IN se_code.
U CAN ALSO ADD MORE TABLE BASED ON CONDITION -
How to use bind variable value for table name in select statement.
Hi everyone,
I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
:p37_table_name or v('p37_table_name) but none worked.
Following is the sql for interactive report:
select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
I am setting value of p37_table_name in previous page which is atm_state_day_insp.
Following is error msg:
"Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
Any help would be higly appreciated.
RajInterestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)
-
ACCESSING MULTIPLE TABLES THRU ONE SELECT STATEMENTS
How to access multiple tables through one single select statement and also using where condition in it for multiple fields which are from different tables. please give me any example from any tables ....thanks in advance
See the below example code :
REPORT ZMM_COST no standard page heading
line-size 255
message-id zwave .
type-pools
type-pools : slis.
Tables
tables : mara,
makt,
mbew,
konp,
pgmi,
marc,
RMCP3,
sscrfields,
mvke.
Internal Table for MARC and MARA
data : begin of i_join occurs 0,
matnr like mara-matnr, " Material #
meins like mara-meins, " Unit of Measure
werks like marc-werks, " Plant
zzdept like marc-zzdept," Department
end of i_join.
Internal table for PGMI
data : begin of i_pgmi occurs 0,
werks like pgmi-werks, " Plant,
nrmit like pgmi-nrmit, " Material #
wemit like pgmi-wemit, " Plant
end of i_pgmi.
Internal Table for MBEW
data i_mbew like mbew occurs 0 with header line.
Internal Table for Output
data : begin of i_output occurs 0 ,
matnr like mara-matnr, " Material #
maktx like makt-maktx, " Material Desc
VPRSV like mbew-VPRSV, " Price Control Indicator
VERPR like mbew-VERPR, " Moving Avg Price
meins like mara-meins, " Base Unit of Measure
STPRS like mbew-STPRS, " Standard Price
LPLPR like mbew-LPLPR, " Current Planned Price
ZPLPR like mbew-ZPLPR, " Future Planned Price
VPLPR like mbew-VPLPR, " Previous Planned Price
kbetr like konp-kbetr, " Sales Price
KMEIN like konp-KMEIN, " Sales Unit
margin(5) type p decimals 2,
vmsta like mvke-vmsta, " Material Status.
end of i_output.
Internal Table for A004
data : i_a004 like a004 occurs 0 with header line.
Variables
data : wa_lines type i,
wa_maktx type makt-maktx,
v_flag type c.
ALV Function Module Variables
DATA: g_repid like sy-repid,
gs_layout type slis_layout_alv,
g_exit_caused_by_caller,
gs_exit_caused_by_user type slis_exit_by_user.
DATA: gt_fieldcat type slis_t_fieldcat_alv,
gs_print type slis_print_alv,
gt_events type slis_t_event,
gt_list_top_of_page type slis_t_listheader,
g_status_set type slis_formname value 'PF_STATUS_SET',
g_user_command type slis_formname value 'USER_COMMAND',
g_top_of_page type slis_formname value 'TOP_OF_PAGE',
g_top_of_list type slis_formname value 'TOP_OF_LIST',
g_end_of_list type slis_formname value 'END_OF_LIST',
g_variant LIKE disvariant,
g_save(1) TYPE c,
g_tabname_header TYPE slis_tabname,
g_tabname_item TYPE slis_tabname,
g_exit(1) TYPE c,
gx_variant LIKE disvariant.
data : gr_layout_bck type slis_layout_alv.
Selection-screen
selection-screen : begin of block blk with frame title text-001.
parameters : p_werks like marc-werks default '1000' obligatory.
select-options : s_dept for marc-zzdept obligatory,
s_matnr for mara-matnr,
s_mtart for mara-mtart,
s_vprsv for mbew-VPRSV,
s_PRGRP for RMCP3-PRGRP MATCHCODE OBJECT MAT2 ,
s_vmsta for mvke-vmsta.
selection-screen: end of block blk.
*SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
*PARAMETERS: p_vari LIKE disvariant-variant.
*SELECTION-SCREEN END OF BLOCK b3.
At slection screen events *
*-- Process on value request
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
PERFORM f4_for_variant.
Initialization *
Initialization.
g_repid = sy-repid.
sscrfields-functxt_01 = 'Clear Selection'.
selection-screen function key 1.
AT SELECTION-SCREEN.
case sscrfields-ucomm.
when 'Clear Selection' or 'FC01'.
clear: s_matnr,
p_werks.
refresh: s_matnr,
s_dept,
s_mtart,
s_vprsv,
s_PRGRP,
s_vmsta.
endcase.
Start-of-selection.
start-of-selection.
Clear the all data.
perform clear_data.
Get the data from PGMI Table
perform get_pgmi.
Get the data from MARC and MARA Table
perform get_mara_marc.
Get the data from MBEW Table
perform get_mbew.
Move the data into OUTPUT Table
perform move_output_internal.
*end-of-selection.
end-of-selection.
if not i_output[] is initial.
ALV Function Module
perform print_alv.
endif.
*& Form get_pgmi
Select the data from PGMI Table
FORM get_pgmi.
clear v_flag.
If Product group has a value at Selection-screen.
if not s_prgrp is initial.
select werks nrmit wemit from pgmi into table i_pgmi
where prgrp in s_prgrp
and werks = p_werks
and wemit = p_werks.
v_flag = 'X'.
endif.
ENDFORM. " get_pgmi
*& Form get_mara_marc
Select the data from MARA and MARC
FORM get_mara_marc.
if v_flag = 'X'.
select amatnr ameins bwerks bzzdept into table i_join
from mara as a inner join marc as b on amatnr = bmatnr
for all entries in i_pgmi
where a~matnr in s_matnr
and b~werks = p_werks
and b~zzdept in s_dept
and a~mtart in s_mtart
and a~matnr = i_pgmi-nrmit
and b~werks = i_pgmi-werks.
else.
Get the data from MARA and MARC Table
select amatnr ameins bwerks bzzdept into table i_join
from mara as a inner join marc as b on amatnr = bmatnr
where a~matnr in s_matnr
and b~werks = p_werks
and b~zzdept in s_dept
and a~mtart in s_mtart.
endif.
clear wa_lines.
describe table i_join lines wa_lines.
if wa_lines is initial.
message i000(zwave) with 'List contains no data'.
stop.
endif.
sort i_join by matnr werks zzdept.
ENDFORM. " get_mara_marc
*& Form get_mbew
Select the data from MBEW Table
FORM get_mbew.
Get the data from MBEW.
select * from mbew into table i_mbew
for all entries in i_join
where matnr = i_join-matnr.
clear wa_lines.
describe table i_mbew lines wa_lines.
if wa_lines is initial.
message i000(zwave) with 'List contains no data'.
stop.
endif.
sort i_mbew by matnr bwkey.
ENDFORM. " get_mbew
*& Form move_output_internal
Final Results
FORM move_output_internal.
loop at i_join.
clear wa_maktx.
Compare the data with MVKE Table
select single vmsta from mvke into mvke-vmsta
where matnr = i_join-matnr
and vkorg = '0001'
and vtweg = '01'
and vmsta in s_vmsta.
if sy-subrc ne 0.
continue.
else.
i_output-vmsta = mvke-vmsta.
endif.
read table i_mbew with key matnr = i_join-matnr
bwkey = i_join-werks
binary search.
if sy-subrc eq 0.
Price Control Indicator
i_output-VPRSV = i_mbew-VPRSV.
Moving Average Price
i_output-VERPR = i_mbew-VERPR / i_mbew-peinh.
Standard Price
i_output-STPRS = i_mbew-STPRS / i_mbew-peinh.
Current Planned Price
i_output-LPLPR = i_mbew-LPLPR / i_mbew-peinh.
Future Planned Price
i_output-ZPLPR = i_mbew-ZPLPR / i_mbew-peinh.
Previous Planned Price
i_output-VPLPR = i_mbew-VPLPR / i_mbew-peinh.
Base Unit of Measure - Added by Seshu 01/09/2007
i_output-meins = i_join-meins.
else.
continue.
endif.
Get the sales Price.
perform get_sales_data.
if i_mbew-VPRSV = 'V'.
Get the Percentage of Margin
if i_output-kbetr ne '0.00'.
i_output-margin = ( ( i_output-kbetr - i_mbew-VERPR )
/ i_output-kbetr ) * 100 .
endif.
else.
Get the Percentage of Margin
if i_output-kbetr ne '0.00'.
i_output-margin = ( ( i_output-kbetr - i_output-stprs )
/ i_output-kbetr ) * 100 .
endif.
endif.
Get the material Description from MAKT Table
select single maktx from makt into wa_maktx
where matnr = i_join-matnr
and spras = 'E'.
if sy-subrc eq 0.
i_output-matnr = i_join-matnr.
i_output-maktx = wa_maktx.
endif.
append i_output.
clear : i_output,
i_join,
i_mbew.
endloop.
ENDFORM. " move_output_internal
*& Form get_sales_data
Get the Sales Price for each material
FORM get_sales_data.
Get the data from A004 table to get KNUMH
Added new field Sales Unit - Seshu 01/09/2006
refresh : i_a004.
clear : i_a004.
data : lv_kbetr like konp-kbetr," Condition value
lv_KPEIN like konp-kpein , "per
lv_KMEIN like konp-KMEIN. " Sales Unit
select * from a004 into table i_a004
where matnr = i_join-matnr
and vkorg = '0001'
and vtweg = '01'.
if sy-subrc eq 0.
sort i_a004 by DATAB descending.
Get the Latetest Date
read table i_a004 with key matnr = i_join-matnr
vkorg = '0001'
vtweg = '01'
binary search.
Get the Sales Value
select single kbetr KPEIN KMEIN from konp
into (lv_kbetr,lv_KPEIN, lv_KMEIN)
where knumh = i_a004-knumh
and kappl = i_a004-kappl
and kschl = i_a004-kschl.
if sy-subrc eq 0.
i_output-kbetr = lv_kbetr / lv_KPEIN.
i_output-KMEIN = lv_KMEIN.
endif.
endif.
clear : lv_kbetr,
lv_kpein,
lv_KMEIN.
ENDFORM. " get_sales_data
*& Form print_alv
ALV Function Module
FORM print_alv.
Fill the Fiedlcat
PERFORM fieldcat_init using gt_fieldcat[].
gr_layout_bck-edit_mode = 'D'.
gr_layout_bck-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = g_repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = g_user_command
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT = gr_layout_bck
IT_FIELDCAT = gt_fieldcat[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = g_save
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_ADD_FIELDCAT =
IT_HYPERLINK =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IT_EXCEPT_QINFO =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = i_output
EXCEPTIONS
PROGRAM_ERROR = 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.
ENDFORM. " print_alv
*& Form fieldcat_init
Fieldcat
FORM fieldcat_init USING e01_lt_fieldcat type slis_t_fieldcat_alv.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
Material #
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MATNR'.
LS_FIELDCAT-ref_fieldname = 'MATNR'.
LS_FIELDCAT-ref_tabname = 'MARA'.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Material'.
ls_fieldcat-seltext_M = 'Material'.
ls_fieldcat-seltext_S = 'Material'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Material Description
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MAKTX'.
LS_FIELDCAT-OUTPUTLEN = 35.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Description'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Price Indicator
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'VPRSV'.
LS_FIELDCAT-OUTPUTLEN = 7.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Price Control Indicator'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Moving Avg Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'VERPR'.
LS_FIELDCAT-OUTPUTLEN = 11.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Moving Avg Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Base Unit of Measure
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MEINS'.
LS_FIELDCAT-OUTPUTLEN = 7.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Base Unit'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Standard Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'STPRS'.
LS_FIELDCAT-OUTPUTLEN = 11.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Standard Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Current Planned Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'LPLPR'.
LS_FIELDCAT-OUTPUTLEN = 11.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Current Planned Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Future Planned Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'ZPLPR'.
LS_FIELDCAT-OUTPUTLEN = 11.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Future Planned Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Previous Planned Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'VPLPR'.
LS_FIELDCAT-OUTPUTLEN = 11.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Previous Planned Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Sales Price
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'KBETR'.
LS_FIELDCAT-OUTPUTLEN = 13.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Sales Price'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Sales Unit
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'KMEIN'.
LS_FIELDCAT-OUTPUTLEN = 7.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Sales Unit'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
% of Gross Margin
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MARGIN'.
LS_FIELDCAT-OUTPUTLEN = 13.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = '% of Gross Margin'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
Material Status
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'VMSTA'.
LS_FIELDCAT-OUTPUTLEN = 13.
LS_FIELDCAT-TABNAME = 'I_OUTPUT'.
ls_fieldcat-seltext_L = 'Material Status'.
APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.
ENDFORM. " fieldcat_init
**& Form f4_for_variant
text
*FORM f4_for_variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = g_variant
i_save = g_save
i_tabname_header = g_tabname_header
i_tabname_item = g_tabname_item
it_default_fieldcat =
IMPORTING
e_exit = g_exit
es_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 2.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF g_exit = space.
p_vari = gx_variant-variant.
ENDIF.
ENDIF.
*ENDFORM. " f4_for_variant
*& Form clear_data
Clear the Internal table
FORM clear_data.
clear : i_output,
i_join,
i_mbew,
i_a004,
i_pgmi.
refresh : i_output,
i_join,
i_mbew,
i_a004,
i_pgmi.
ENDFORM. " clear_data
FORM USER_COMMAND *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield. "#EC CALLED
CASE R_UCOMM.
WHEN '&IC1'.
read table i_output index rs_selfield-tabindex.
SET PARAMETER ID 'MAT' FIELD i_output-matnr.
SET PARAMETER ID 'WRK' FIELD p_werks.
if not i_output-matnr is initial.
call transaction 'MD04' and skip first screen.
endif.
ENDCASE.
ENDFORM.
Reward Points if it is helpful
Thanks
Seshu -
Dynamic fields in select statement
Hi all,
In selection screen we are having period as select option.The values for period are 01 to 16. Based on
the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.
For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03
from FAGLFLEXT.
Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.
Regards,
Swethahi Swetha,
the third select statemnet will work for you..
try this..
_Dynamic where clause in select query.._
* With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = ' '''' i_tab-zgsber ''''
append where_clause to where_tab.
* Select
select * from zcostfreq
where (where_tab).
endselect.
_Using a dynamic table name_
parameters:
p_tab type tabname.
start-of-selection.
select count(*) from (p_tab) into l_count.
_Dynamic retrieval and writing of data_
FIELD-SYMBOLS:
<row> TYPE ANY,
<component> TYPE ANY.
PARAMETERS:
p_tab TYPE tabname.
CREATE DATA dataref TYPE (p_tab).
* The variable dataref cannot be accessed directly, so a field symbol is
* used
ASSIGN dataref->* TO <row>.
SELECT *
FROM (p_tab) UP TO 10 ROWS
INTO <row>.
NEW-LINE.
DO.
* Write all the fields in the record
ASSIGN COMPONENT sy-index
OF STRUCTURE <row>
TO <component>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE <component>.
ENDDO.
ENDSELECT.
Regards,
Prabhduas -
Adding one more table to the select statement joining 4 tables gives dump
Hi All,
There is a select statement using which four tables namely VBAK,VBAP,LIPS and LIKPUK(view) are joined(inner join).Here, date and time fields are selected from LIPS and used.
My requirement is to consider the Date (LIKP - WADAT_IST) instead of LIPS-ERDAT and time(LIKP-SPE_WAUHR_IST) is to be used instead of LIPS-erzet.
Neither LIPS nor LIKPUK contains time(SPE_WAUHR_IST) field. And, I cannot remove LIPS table or LIKPUK view as each contains a unique field which is used in the report.
When I tried to join LIPS in the select query, it is going to dump.
Can someone suggest a good approach ?
Thanks,
PavanThank you for the detailed explanation of the dump.
The dump details together with your code lead to the answer: 42.
Regards,
Clemens -
Determine Length of Field in Select Statement
Hi Experts!
My officemate has this little problem regarding selection of data based on a certain condition...
Here is the situation:
For Example...
In table KNA1....
KUNNR NAME1 Length of Data in Name1
000001 AA 2
000002 AB 2
000003 ABCD 4
000004 ABCDE 5
She only wants to get the records that has the length of 2 in KNA1-NAME1,
i.e., 'AA' and 'AB' without having to put it in the internal table then make a loop and update the table using the strlen() condition....
Experts, is this possible? Knowing the length of the data in the select statement? She wants this alternative because it is faster rather than having to loop in internal tables and check if this data has the length of 2 or 3 or 4 and so on....
Can you please help me out with this one? Thanks in advance!
<b></b>Hi
If the lenghtn is 6 characters and if you want to fetch only first 2 characters.
you can use offset
fetch data from internal table and take variable
v_var1 = itab-name1+0(2).
you get only first 2 characters....
if you want last 2 characters itab-name1+4(2).
Thanks -
Select table fields on selection screen
I have a requirement, where I need to select the table fields dynamically from the selection screen and further I should give option to user to save selected fields as variant and display the final report with the selected fields as catalog.
For EX: In the selection screen user have two options, one is to check the select fields option where all fields from KNA1 will display from that user will select few and he can save as variant. After execution the report output should display?
Could you please guide me how to go ahead?
Thanks,
A Raghu.Hi Raghu,
For your requirements, you have to define the all the select-options inyour code but at first display onlya few selected ones. Then you can give a button to the user to select the fields and depending on the selection you can hide/unhide the select-options.
For e.g. you define the select-options on your screeen for all the fields of KNA1. But at first go, display only the customer. Now give a button to the user on the toolbar. When user clicks on the button, give a popup to the user displaying all the fields except customer and allow him to select them. Based on the selection of the user, you can hide/unhide the select-options for the remaining fields.
Also, in this case your select query will be dynamic. The field list and the where clause have to be maintained in a string and then passed to the select statement.
Try the functions: FREE_SELECTION_INIT, FREE_SELECTION_DIALOG and MASS_SEL_FIELDS_ENTERPRISE.
Hope this helps,
Regards,
Himanshu -
Where condition with optional fields in select statement
Hi,
In a function module I have to fetch data based on 7 fields out of which 6 are optional.
If we won't enter values for optional fields it will take default values as zeroes .
So this is not fetching data. But for some fields some values has zero values.
How to solve this condition?
Regards,
maha.Hi,
For those import parameters for which its mentioned as optional, use like condition in the where clause of select statement in the function module.
try like this,
concatenate pfield2 '%' into pfield2.
concatenate pfield3 '%' into pfield3.
concatenate pfield4 '%' into pfield4.
concatenate pfield5 '%' into pfield5.
concatenate pfield6 '%' into pfield6.
concatenate pfield7 '%' into pfield7.
select *
from db table
into itab
where field1 = pfield1 and
field2 like pfield2 and
field3 like pfield3 and
field7 like pfield7.
Now even if the optional fields are blank, data will be selected
Regards,
Vik -
Validation of a field in select statement
In selection screen, skunag(vbrk-kunag) and swerks(vbrp-werks) fields are there.these two fileds are obligatory.
If skunag field values start with 'P'.I have to remove the initial 'P' in that values,because I have to validate that field with ztable-kunag.
i have written folllowing way.but no result.
AT SELECTION-SCREEN ON SKUNAG.
PERFORM check_skunag.
form check_skunag.
data: p_kunag(10) type c.
if not skunag is initial.
p_kunag = skunag+4(4).
move p_kunag to skunag.
endif.
endform.
one more thing this skunag filed is also using in another form for database selection.In this form i want to use the above skunag field, after validation....
form gatherdata.
SELECT vbeln kunag zuonr vkorg waerk fkart FROM vbrk INTO CORRESPONDING FIELDS OF TABLE itab
WHERE vbeln IN svbeln
AND kunag IN <b>skunag</b>.
endform.
how can i write the above scenario...
thanks in advance,
fractalLooks like skunag is a select-option. In that case, it will be very difficult to validate it because if the user enters a range like P00001 to P99999, how are you going to validate this against the Z table.
First you will have to restrict the user from using ranges. That you can do by defining your skunag with no-intervals. Then you will be able to validate that easily as user can only enter single values, no ranges.
You need to have your validation in AT SELECTION-SCREEN ON <b>skunag-low</b>.
In your FORM check_skunag, you need to change the code as follows
data: p_kunag(10) type c.
LOOP AT skunag.
*-- only if the first character is P
CHECK skunag-low+0(1) = 'P'.
p_kunag = skunag-low+1(remove the first P)
*-- check against the Z table with p_kunag
SELECT KUNAG FROM ztable WHERE kunag = p_kunag.
IF sy-subrc <> 0.
*-- invalid KUNAG
DELETE skunag.
ELSE.
*-- If you want to move the value without P back into
* your skunag then do the following
MOVE p_kunag to skunag-low.
MODIFY skunag.
ENDIF.
ENDLOOP. -
How user variable table names in select statement
Dear all,
I have three table gp1,gp2,g3. i want user variable table in sql query
for example at oracle forms have a list table showing table names gp1,gp2,gp3
at form i want user this query
select gpno from :table where gpno=120;
how i can specify table name Dynamicly in select query
ThanksForms_DDL is a one-way street: You can only pass DDL commands TO the database; you cannot get data back using Forms_DDL.
Exec_SQL is the Forms package that enables dynamic sql within a form. But to retrieve data, you have to make a Exec_SQL call for every column in every row. So it is not a good thing to use, either.
The ref cursor method should work. You could also retrieve the data into a record group using populate_group_with_query -- it also enables dynamic data retrieval.
But if you already know you have three distinct tables and you know their names, I would keep it simple and just write three sql select statements. -
How can I select columns from a table EMP, using Select statement?.
Hi Friends,
How can I select columns from a table EMP?.
I want to select columns of EMP table, using select statement.
Please reply me urgently.
ShahzadSomething like this:
scott@DBA> select empno,ename,job from emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.Check the documentation:
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
Message was edited by:
Delfino Nunez -
Dynamically assigning table name in select statement
how can i assign the table name dynamically in Select statement?
i tried following code
create or replace procedure proc1
as
x varchar2(100);
y varchar2(10);
begin
x='UNIT_MASTER';
execute immediate 'select unit_code into y from x where
rownum=1';
dbms_output.put_line(y);
end;
the procedure is created but when i execute the procedure the
error is shown in the execute immediate statementDo the following :
Create or replace procedure pro1 as
x varchar2(100);
y varchar2(10);
begin
x := 'UNIT_MASTER';
EXECUTE IMMEDIATE 'select unit_code from '||x||' where rownum
= 1' INTO y;
dbms_output.put_line(y);
Maybe you are looking for
-
How to overcome "dropped frame" issues on my project
Hey reader, I have a MacBook Pro 2.4GHz with 250GB hd (85GB free just now) running 10.4.11, FCE HD 3.5 (and QT 7.5.5) and using a Sony Handycam DCR-HC96 (which is works BEAUTIFULLY with iMovie 08 and 6 and is always used with Sony tapes) and I am not
-
I have problem with the sound entry. The imac does not recognize next sound internal microphone and external microphone). I have checked the configurations. Everything looks like OK but it does not bring in sound. Can they help me? I have Snow leopar
-
Hi all, can anybody advise on the following problem with above BB curve. As i am partially deaf, i use an ICOM Bluetooth device with my BB Curve, which is, basically, a wifi connection between my BB and my hearing aids. This device works perfectly wh
-
Help Me Please! - What is the problem?
Hi, Ive had my macbook for about 2 weeks and everything has been perfect! Untill yesterday afternoon..... I was on ebay yesterday morning before work to check some things i was selling all fine, then went to check my e-mail on hotmail - all fine. Got
-
Intel or not intel? Advice wanted.
I need some advice here... I've decided to buy a dual g5 imac, but now I can't decide to go with the intel or not...I'll be primarily using the maching for dvd authoring, editing and motion graphics...so I already have final cut studio, combustion, a