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,
fractal
Looks 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.
Similar Messages
-
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 -
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 -
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 -
Dynamic field in Select Statement
I am able to create a dynamic statement to insert into the where clause of my sql, but I am unable to dynamically create a select statement. Oracle Reports produces the following error:
REP-0499: Column " selected by the query is incompatible with report definition.
Here is an example of my select:
Select
&dynamic_field
from
any_table
Any help is appreciated.I figured it out. Thanks
-
Using a varchar field to select statement
Hi all
I have a single row and single column table
T(command varchar2(4000))
and the row is
sno,name
And I have another table T1(sno number,name varchar)
Now can any body tell how can i use command column in table T to query T1 to get sno,name from T1
I am looking for a select statement like this
select (select command from T) from T1;
but it is printing out the data in T i mean sno, name
This is a copy of thread Selecting output of a select statement
but explained more clearly
Thanks,
ganesh.I don't know why your tables are designed like this but what I think you want to do is join T1 with the data in T.
select sno, name from T1
where sno in (select substr(command,0,instr(command,',')-1) from T)
and name in (select substr(command,instr(command,',')+1) from T);
substr returns a string up to a position
instr returns the position of a string
and the other post you refer to as about as confusing as your one. -
How to get around Ampersand in text field in Select statement
I have an SQL statement I am trying to run in SQL*Plus. In one of my subqueries, I have a select statment in which some of the fields I am trying to pull have an "&" within the text. So, when I try and run the query it returns "Enter value for 35:". I've even tried wildcard characters and it is still not working. If anyone could help me with this, I would appreciate it. Here is a sample of my statement (the subquery is at the bottom of the statement):
select real_case.file_dt, real_case.dscr, pty_cd, first_name, last_name, addr_line1, addr_line2, city, st_cd, zip_cd
from real_case, pty, idnt, ptyaddr s1, addr
where real_case.case_id = pty.case_id
AND pty.idnt_id = idnt.idnt_id
AND pty.case_id = s1.case_id
and pty.seq = s1.seq
and s1.addr_id = addr.addr_id
and (real_case.file_dt >= '01-NOV-06'
and real_case.file_dt <= current_date)
and (real_case.dscr like '79D01-%'
or real_case.dscr like '79C01-%'
or real_case.dscr like '79D02-%')
and (pty.pty_cd like 'DFNDT')
and (s1.ins_dttm in
(select max(s2.ins_dttm) from ptyaddr s2
where s2.case_id = s1.case_id
and s2.seq = s1.seq))
and (real_case.case_id in
(select case_id from ptychrg
where ptychrg.actn_cd IN ('35-41-5-1&35-48-4-1')));Thanks,
Shannonthis?
SQL> set define off
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 'a&b' col from dual
3 union all
4 select 'abc' from dual)
5 select * from t
6* where col like '%\&%'
7 /
COL
a&b
or this
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 'a&b' col from dual
3 union all
4 select 'abc' from dual)
5 select * from t
6* where col like '%'||chr(38)||'%'
SQL> /
COL
a&bjust '%'||chr(38)||'%' will not work.
You nedd either set scan off or set define off
correction
Message was edited by:
devmiral -
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 -
Group by function with CLOB fields in Select statement
I have the following sql trying to query our database. Removing the Clob field (a.description) I am successful. But I need the Clob field (a.description). Here is my current sql
select a.id_number, a.id_owner, MAX (n.next_action_required)
KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date)
from table1 a, table2 n
where a.id_number = n.id_number
group by a.id_number, a.id_ownerI tried the following which works sometimes but not always because the Clob field (a.description)'s length varies; anywhere from 10 characters up to 12,000 characters. I get some blanks with the following and some where text is cut off. I may not be writing the dbms_lob.substr function correct.
select a.id_number, a.id_owner, MAX (n.next_action_required)
KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) , DBMS_LOB.SUBSTR (a.description, 8001, 10000)
from table1 a, table2 n
where a.id_number = n.id_number
group by a.id_number, a.id_owner, DBMS_LOB.SUBSTR (a.description, 8001, 10000)Please help. Thank you,Maybe,
but throw it away if the combination a.id_number,a.id_owner,n.next_action_required(a.id_number = n.id_number),n.modified_date(a.id_number = n.id_number) is not unique
select nd.id_number,
nd.id_owner,
nd.next_action_required,
nd.modified_date,
a.description
from (select a.id_number,
a.id_owner,
MAX (n.next_action_required) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) next_action_required,
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) modified_date
from table1 a,
table2 n
where a.id_number = n.id_number
group by a.id_number,
a.id_owner
) nd,
table1 a
where nd.id_number = a.id_number
and nd.id_owner = a.id_owner
and nd.id_number = (select id_number
from table2
where next_action_required = nd.next_action_required
and modified_date = nd.modified_date
)Regards
Etbin -
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 -
Moderator message: Please use meaningful subject in future
Hi,
I've a requirement that I need to get a record from EREV table for a Purchase Requisition no. based on Latest Version No. (REVNO. ) at a single shot.
I hav used the following code but i dint get desired values.
Select EDOKN
FGNAM
FGDAT
REVNO
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Any body pl help me.
-Rajiv
Edited by: Vaddepati on Dec 3, 2008 11:01 AM
Edited by: Matt on Dec 3, 2008 10:03 AMHi veddapati,
Your sequence of using the fields in Select statement is wrong...thats why, you are not getting the required output..
You should select revno in the select statement before FGNAM as it is present in the table..
Please modify your select statement like this..... ::
Select EDOKN
REVNO
FGNAM
FGDAT
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Hope it will solve your problem
Regards,,
Nikita
Edited by: Nikita Jain on Dec 3, 2008 2:29 PM -
Nested select statements.
Hi, I am writing a piece of code in which i use nested select statements for 4 tables to retrieve one column's data (ie: POSNR). But when i execute it, it takes way too long to get the data. I'm quite new to ABAP so very in need of your help. Thanks
REPORT z_impos_test.
TABLES: coss, "CO Object: Cost Totals for Internal Postings
afvc, "Operation within an order
prps, "WBS (Work Breakdown Structure) Element Master Data
imzo. "Table: CO Object - Capital Investment Prog.Pos.
TYPES: BEGIN OF st_impos,
objnr TYPE coss-objnr,
gjahr TYPE coss-gjahr,
kstar type coss-kstar,
projn type afvc-projn,
pspnr type prps-pspnr,
posnr type imzo-posnr,
END OF st_impos.
data: year TYPE coss-gjahr value '2007'.
DATA: t_output TYPE STANDARD TABLE OF st_impos WITH HEADER LINE,
st_output TYPE st_impos,
t_output2 TYPE STANDARD TABLE OF st_impos WITH HEADER LINE,
st_output2 TYPE st_impos.
SELECT objnr gjahr kstar FROM coss
INTO CORRESPONDING FIELDS OF st_output
WHERE ( objnr LIKE 'NV%' OR
objnr LIKE 'PR%' ) AND
gjahr = year.
SELECT SINGLE projn from afvc into CORRESPONDING FIELDS OF st_output
WHERE objnr = st_output-objnr.
APPEND st_output to t_output.
ENDSELECT.
SORT t_output BY objnr.
DELETE ADJACENT DUPLICATES FROM t_output.
LOOP AT t_output into st_output.
SELECT objnr pspnr
INTO CORRESPONDING FIELDS OF st_output2
FROM prps
WHERE objnr = st_output-objnr
AND pspnr = st_output-pspnr.
SELECT SINGLE posnr from imzo into CORRESPONDING FIELDS OF st_output2
WHERE objnr = st_output2-objnr.
APPEND st_output2 to t_output2.
ENDSELECT.
ENDLOOP.
LOOP AT t_output2 to st_output2.
WRITE: st_output2-posnr.
ENDLOOP.
Edited by: Jacie Johns on Apr 23, 2009 11:26 PMHI John,
Try to avoid INTO CORRESPONDING FIELDS in SELECT statement.
As you are not using PSPNR and POSNR fields in the first SELECT statement. If you remove these fields, in structure, INTO CORRESPONDING FIELDS can be avoided. Create a separate structure with the fields that are required for T_OUTPUT table (i.e. create another structure with only first 4 fields, as T_OUTPUT1.
And as mentioned in your code,
WHERE objnr = st_output-objnr
AND pspnr = st_output-pspnr
in select statement, ST_OUTPUT-PSPNR value is not fetched in the previous select statements.
Create Another structure with fields OBJNR, PSPNR, POSNR for table T_OUTPUT2 to store the data from tables, PRPS and IMZO.
Use JOINS and FOR ALL ENTRIES to fetch the desired data.
The sample code is as follows:
===
TYPES: BEGIN OF ty_output1,
objnr TYPE coss-objnr,
gjahr TYPE coss-gjahr,
kstar type coss-kstar,
projn type afvc-projn,
END OF ty_output1,
BEGIN OF ty_output2,
objnr TYPE coss-objnr,
pspnr type prps-pspnr,
posnr type imzo-posnr,
END OF ty_output2,
BEGIN OF ty_output3,
objnr TYPE coss-objnr,
gjahr TYPE coss-gjahr,
kstar type coss-kstar,
projn type afvc-projn,
pspnr type prps-pspnr,
posnr type imzo-posnr,
END OF ty_output3.
data: year TYPE coss-gjahr value '2007'.
DATA:
wa_output1 TYPE ty_output1,
wa_output2 TYPE ty_output2,
wa_output3 TYPE ty_output3,
t_output1 TYPE STANDARD TABLE OF ty_output1 ,
t_output2 TYPE STANDARD TABLE OF ty_output2 ,
t_output3 TYPE STANDARD TABLE OF ty_output3..
SELECT cobjnr cgjahr ckstar aprojn FROM coss as c
INNER JOIN afvc as A on aobjnr = cobjnr
INTO table t_output1
WHERE ( c~objnr like 'NV%' or
c~objnr like 'PR%' ) and
c~gjahr = year.
SELECT pobjnr ppspnr i~posnr FROM prps as P
INNER JOIN imzo AS I on pobjnr = iobjnr
INTO TABLE t_output2
for all entries in table T_OUTPUT1
WHERE p~objnr = t_output1-objnr.
SORT : t_output1 BY objnr,
t_output2 BY objnr.
DELETE ADJACENT DUPLICATES FROM : t_output1 COMPARING objnr,
t_output2 COMPARING objnr.
LOOP AT t_output1 INTO wa_output1
READ TABLE t_output2 INTO wa_output2 WITH KEY objnr - wa_output1-objnr BINARY SEARCH.
if sy-subrc = 0.
MOVE <wa_output1 fiels> and <wa_output2 fields> to WA_OUTPUT3.
append wa_output3 to T_OUTPUT3.
endif.
ENDLOOP.
Hope this will solve your problem.
Regards,
Sai Prasad -
Hi Gurus,
How can i split this select statement..can you please tell me .its veru urgent.
SELECT MARA~MATNR
MAKT~MAKTX
MARA~MEINS
MCHA~WERKS
MCH1~CHARG
MCH1~LICHA
MCH1~VFDAT
MCH1~ERSDA
MCH1~LWEDT
MCH1~HSDAT
INTO TABLE TB_BATCH
FROM MCH1 INNER JOIN MCHA ON
MCHAMATNR = MCH1MATNR AND
MCHACHARG = MCH1CHARG
INNER JOIN MARA ON
MARAMATNR = MCH1MATNR
INNER JOIN MAKT ON
MAKTMATNR = MCH1MATNR
WHERE MCH1~MATNR IN S_MATNR AND
MCHA~WERKS = P_WERKS AND
MARA~MTART IN R_MTART AND
MAKT~SPRAS = SY-LANGU.take three different internal tables and one final internal table which will contains fields of the three fields.
write select statements to fetch the data from each internal tables using for entries statement for 2nd and 3rd table and move all the corresponding values to the final table.
loop at final table and display that. -
Adding field in a smart form select statement
hi,
i am modifying a report in which i have to add sortl from kna1 in the select statement .
when i try to modify the statement it gives error as i ahev defined the value in the global variable .
plzz help me out as help will be definately rewarded.Ric,
loop at ivbrk.
select name1 name2 name3 name4 stras pstlz ort01 land1 from
kna1 into (vname11, vname12, vname13, vname14, vstrask, vpstlzk,
vort01k, vland1) where kunnr = ivbrk-kunrg.
endselect.
endloop.
Seems you are modifying the select statement in the smartform which is selecting some data based on the internal table data that is there in the driver program.
If I am not wrong you want to select SORTL too in the above given select statement.
In the Global Definitions declare a variable like vsort type kna1-sortl and then in the select statement add this sortl field.
loop at ivbrk.
select name1 name2 name3 name4 stras pstlz ort01 sortl land1 from kna1 into (vname11, vname12, vname13, vname14, vstrask, vpstlzk,vort01k, vsortl, vland1)
where kunnr = ivbrk-kunrg.
endselect.
endloop.
Do check the select statement how you are writing.
K.Kiran. -
Field symbols as Table name and in where condition in a select statement
Hello All,
I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
Here is my code:
DATA: TAB LIKE SY-TNAME,
TAB_COMP1 LIKE X031L-FIELDNAME,
TAB_COMP2 LIKE X031L-FIELDNAME,
NO_OF_FLD TYPE N.
DATA: BEGIN OF BUFFER,
ALIGNMENT TYPE F,
C(8000) TYPE C,
END OF BUFFER.
FIELD-SYMBOLS: <WA> TYPE ANY,
<COMP1> TYPE ANY,
<COMP2> TYPE ANY.
GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
TAB = TAB_NAME.
CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
KEY FIELD
TAB_COMP1 = 'GL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OPSL'.
KEY FIELD
TAB_COMP1 = 'OPSL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'OTAX_GL_SYS_NO'.
TAB_COMP2 = 'OTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN 'OIUH_RV_GTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'GTAX_GL_SYS_NO'.
TAB_COMP2 = 'GTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN OTHERS.
EXIT.
ENDCASE.
SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
How to add where clause and remove the if condition in the select -- endselect
SELECT * FROM (TAB) INTO <WA>.
ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
IF NO_OF_FLD = 2.
ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
ENDIF.
IF <COMP1> = OLD_SYS_NO.
code for updating table would come here
WRITE: 'MATCH FOUND'.
EXIT.
ENDIF.
ENDSELECT.
Please advice. Thanks much.
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM1. Create single column table for holding field name depending on the table entered.
2. Take input from user: for e.g. table_name
3. Using case load single column table with required fields
for e.g.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
WHEN 'OIUH_RV_OPSL'.
Append 'OPSL_GL_SYS_NO'.
WHEN 'OIUH_RV_OTAX'.
Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN 'OIUH_RV_GTAX'.
Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN OTHERS.
EXIT.
ENDCASE.
Now depending on the table name you have required column ready
4. Create dynamic internal table using following sudo code
Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
loop at internal table with all the fields.
move it to field catalog.
append field catalog.
endloop.
5. Pass this field catalog table to static method create_dynamic_table method
DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = fieldcatalog_tab
importing
ep_table = table.
6. Now assign table reference to field symbol of type table.
ASSIGN table->* to <field-tab>.
7. Also create work area <field-wa> using refrence of table.
create data object wa LIKE LINE OF <field-tab>.
ASSIGN wa->* to <field-wa>.
8. Also define field symbol for field name.
for e.g. <field_name>
4. Dynamic internal table is ready
5. Now execute the select statement as follows:
SELECT (KEY_FIELD)
INTO <ITAB> --> created dynamically above
FROM (TABLE_NAME)
WHERE (WHERE). --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
In this case you need to append all your where condition line by line in to WHERE.
5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
loop at internal table containing list of fields into field_wa --> single column field table
ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
Move <your_new_value> to <field-name>. --> Assign new value
or
<field-name> = <your_new_value>.
Endloop.
6. After completing all the fields one row will be ready in <field_wa>.
APPEND <field_wa> to <field_tab>.
Hope this helps you.
Thanks,
Augustin.
Maybe you are looking for
-
Help Needed in Manual DB Creation
Hi, I'm creating database manuall using Oracle 10 on windows platform first I set Oracle_sid then, I started the services using oradim utility by proving instance name along with password the I connect to sqlplus as salplus /nolog SQL> connect sys/pa
-
HTTP to File Scenario using URL parameters.
Hi, I am working on a HTTP to file scenario where POST method is hirring the XI server with authentication parameters. CAD application is trying to hot our XI server using POST Method and the application does not have ability to send XML payload to X
-
Is it possible to run a java program without using the command prompt?
Hi, I was wondering whether it is possible to run a Java program (not an applet) without using a command line in the command prompt? Basically I want to run a program that will be continually running in the background and hence I don't want to have a
-
Mixing traditional and recursive queries
Hello, I'm trying to solve this problem on a single SQL statement but I haven't been able to do it. Let me explain. I've a plain table where I'm doing a single select without problems. There is another recursive table that is used to retrieve the hie
-
How do you execute return code 4 in transformations?
In previous BI versions, you can skip an update of a field by returning a return code 4. How is this done now using the OO programing in 2004s? Regards, Dae Jin