Dynamice field in the Select statement ?
I want to query a table and get the SUM ( fieldx) without any where clause. However, the fieldx should be dynamic.
Select SUM ( Gross_Wt ) from table. I want the Gross_Wt field to be dynamic.
Any sugestions.
Welcome to SDN,
You can try like this
DATA : v_field(40) like c VALUE 'SUM(<FIELD NAME>)',
v_var TYPE p.
SELECT v_field FROM <TABLE> INTO v_var.
Just this blog you will get more idea
/people/alvaro.tejadagalindo/blog/2006/12/13/dynamic-inner-join-function-module
Regards
Kathirvel
Similar Messages
-
Fields sequence in the select statement
experts, help needed
itab has following fields,
vbeln posnr erdat erzet vkorg vtweg
kunnr posnr matnr bmeng status.
i have written like this
SELECT avbeln aerdat aerzet avkorg a~vtweg
akunnr bposnr b~matnr
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
endif.
but my internal table fields sequence are different. so i changed the posnr field in the select query to the second place.
SELECT avbeln bposnr aerdat aerzet avkorg avtweg
akunnr bmatnr
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
endif.
so in above two select statements which one is right , according to coding standards,?
in this case do i need to use the into corresponding fields addition because i am not selecting bmeng , status fields into the itab?Hi,
Of the two select statements,
SELECT a~vbeln b~posnr a~erdat a~erzet a~vkorg a~vtweg
a~kunnr b~matnr
FROM vbak AS a INNER JOIN vbap AS b
ON a~vbeln = b~vbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
is the better one. I,e specifyiig the field sequence exactly as you have in the internal table. Even according to standards, this is better.
If you are chaning the sequence of select fields, then you have to use the INTO CORRESPONDING FILEDS OF TABLE addition, so that the system itself finds the relevant order of fields and fill them automatically.
This is a additional work which has to be performed by the compiler.
Thus its better to use INTO CORRESPONDING FILEDS OF TABLE only when you are using select * , or when you are not sure of the field sequence inthe table.
Regards,
Vik -
If I want to order by dateAdded to I have to include it in the select statement like
If I do this:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101)
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>
If I want to order by dateAdded to I have to include it in
the select statement like so:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101),dateAdded
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>you should be able to order by dateAdded without it being in
the select clause. The only time the order by field has to be in
the select clause is when your query has an aggregate and group by
clause, like this:
select field1, field2, max(field3) as youralias
from sometables
where whatever
group by field1, field2
order by ???
You can only order field1, field2, max(field3) or youralias.
You can't order by field4. -
Case sensitive statement in the select-statement
Hi All,
i have a table in the abap-dictionary filled with names...when i try to select them with the select-statement with condition:
table-name_column like 'some_name'
I have encountered some problems...the inquiry is case-sensitive. What i want to do is to read the value from the abap-dictionary table uppercase or lowercase and compare it with the needed value also translated in uppercase or lowercase.
The only idea i have is to select all values of the dictionary table into an internal table and to translate the values there in uppercase or lowercase and then to loop trough it. But this approach would cost a lot of performance.
Do someone has an other proposal?check...
Select statement
It would be difficult , because it is based on how data is stored in the data base , now consider the scenario of the system i am using , we can material description as 'test' or 'TEST' , 'Test' .
If in your system there are only stored in either caps or small the you can perform the select twice .
But i myself dont find it to be such a good solution , but you can give it a try
There is one more solution specific to material description ,and that is in the table MAKT there is a field MAKTG , which stored the description in uppercase , so for this you can first convert the description to uppercase and then perform select on this field -
Problem in the select statement
I have to select the values of the fields BEZEI depending on tha sales order number vbeln. HOw can i write the select statement what will be the tables associated?
Hi,
tables: vbak.
types: begin of ty_vbak,
vbeln type vbeln,
kokrs type kokrs,
end of ty_vbak,
begin of ty_it_tka01,
kokrs type kokrs,
bezei type bezei,
end of ty_tka01.
data: it_vbak type table of ty_vbak,
wa_vbak type ty_vbak,
it_tka01 type table of ty_tka01,
wa_tka01 type ty_tka01.
Select-options: s_vbeln for vbak-vbeln.
Select VBELN KOKRS from VBAK into table it_VBAK where vbeln in s_vbeln.
if sy-subrc = 0.
select KOKRS BEZEI from TKA01 into it_tka01 for all entries in it_vbak where kokrs = it_vbak-kokrs.
endif.
Loop at it_vbak into wa_vbak.
read table it_tka01 into wa_tka01 with key kokrs = wa_vbak-kokrs.
if sy-subrc = 0.
* Move data to final internal table.
endif.
endloop.
Regards,
Satish -
How to find the select statement has written all selected values into text
Hi,
I am using form6i. i am selecting a set of values from database tables based upon some user parameters and writing into the text file using Text_io.put_line . In this case how we can make sure that the text fille contains all the data what we are selected from selected statement. somebody told that there might be chances of aborting of data while writing into the text file. is there any way to fild out the selected statements has written all the selected fields and corresponding output into the .txt file.
Please suggest me.somebody told that there might be chances of aborting of data while writing into the text fileWhat kind of "chance" does that somebody refer to?
If you want to verify if the number of records (lines) in the file matches the number of records from the cursor, you could re-open the written file in read-mode and count the number of lines by reading one by one, then compare the number of lines with the number of records from the cursor. -
Break the SELECT statement.
Hi,
My requirement is to break the Select statement and get the fields in where clause in one internal table.
For eg: Select VBELN
POSNR
MATNR from VBAP into wa_vbap where VBELN = '0000000001'
and POSNR = '000010'.
Here i need to put fields VBELN, POSNR, MATNR in one internal table, table name VBAP in second internal table and where clause fields VBELN, POSNR in third internal table.
Please let me know if anyone has any solution for this.
Thanks in advance.
Sunanda.Hi
*& Report YSELECT *
REPORT YSELECT .
*Select VBELN
*POSNR
*MATNR from VBAP into wa_vbap where VBELN = '0000000001'
*and POSNR = '000010'.
*Here i need to put fields VBELN, POSNR, MATNR in one internal table,
*table name VBAP in second internal table and where clause fields VBELN,
* POSNR in third internal table.
TABLES: VBAP.
TYPES: BEGIN OF STRUCT1,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
END OF STRUCT1.
TYPES: BEGIN OF STRUCT2,
TBLNAME(10),
END OF STRUCT2.
TYPES: BEGIN OF STRUCT3,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
END OF STRUCT3.
DATA: ITAB1 TYPE TABLE OF STRUCT1 WITH HEADER LINE,
ITAB2 TYPE TABLE OF STRUCT2 WITH HEADER LINE,
ITAB3 TYPE TABLE OF STRUCT3 WITH HEADER LINE,
V_TBLNAME(10).
ITAB3-VBELN = '0000000001'.
ITAB3-POSNR = '000010'.
APPEND ITAB3.
LOOP AT ITAB3.
SELECT VBELN POSNR MATNR FROM VBAP INTO TABLE ITAB1 WHERE VBELN EQ
ITAB3-VBELN AND POSNR EQ ITAB3-POSNR.
WRITE ITAB1-VBELN.
ENDLOOP.
WRITE: 'SUBRC=', SY-SUBRC.
I am unable to find out how to satisfy your second internal table requirement.
Hope this helps
Regards,
Jayanthi.K -
Can we write Field Symbols in SELECT statement?
Hi
Can we write teh Fiel Symbols in the SELECT Statement ?
Can you give how to write it, with Example ?
Regards,
N.L.NarayanaHi,
Do you ask for that ? :
field-symbols: <field1> type any ,
<field2> type any.
assign component 'TOTO' of structure 'TATA' to <field1>.
assign component 'TUTU' of structure 'TATA' to <field2>.
select single toto
into <field1>
from tata
where tutu = <field2>.
Rgd
Frédéric -
Need to fetch only the select statement
Hi ,
I am able to fetch all the select statements from my program if program name as my input.
I want only the select statement where we fetch the field entries like
select single from mara
select * from mara
select count(*)
select matnr from mara
like this i want to fetch i dont want to display the select-options or start-of-selection .Hello Shwetha
If the function module <b>RS_PROGRAM_TABLES</b> (function group <b>SEA1</b>) is available on your system you can run this fm with the following parameters:
- OBJECT_TYPE = 'TRAN' " transaction
- OBJECT_NAME = 'VA03' " example
- OBJECT_TYPE = 'PROG' " report
- OBJECT_NAME = 'SAPMV45A' " example: report executed by VA03
The fm returns you a list of tables that are accessed.
Regards,
Uwe -
Issue with Past Month data in the Select Statement
Hi,
I written the following query,
SELECT /*+NO_MERGE(A)*/
CASE
WHEN snap_shot_date > a.q3
AND snap_shot_date <= a.q4
THEN q4char
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN q3char
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN q2char
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN q1char
END snap_shot_date,
CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN 1
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN 2
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN 3
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN 4
END sort_by,
pillar3_exposure_class_code, pd_band_description,
ROUND (SUM (p3.ead_post_sec_post_crm)),
ROUND (SUM (notional_principle)),
DECODE (SUM (notional_principle),
0, 0,
ROUND ( SUM (DECODE (exposure_type,
'UNDRAW', ead_post_sec_post_crm,
0
/ SUM (notional_principle),
4
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND ( SUM (pd_value * p3.ead_post_sec_post_crm)
/ SUM (p3.ead_post_sec_post_crm),
2
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND (SUM (rwa) / SUM (p3.ead_post_sec_post_crm), 4)
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND ( SUM (lgd_rate * p3.ead_post_sec_post_crm)
/ SUM (p3.ead_post_sec_post_crm),
2
TO_CHAR (MAX (a.max_date), 'FMMonth DD, YYYY')
FROM summary.pillar3 p3,
(SELECT DISTINCT (month_end_date) max_date,
LAST_DAY (month_end_date) q4,
TO_CHAR (LAST_DAY (month_end_date),
'MON YYYY'
) q4char,
ADD_MONTHS (LAST_DAY (month_end_date), -3) q3,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -3),
'MON YYYY'
) q3char,
ADD_MONTHS (LAST_DAY (month_end_date), -6) q2,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -6),
'MON YYYY'
) q2char,
ADD_MONTHS (LAST_DAY (month_end_date), -9) q1,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -9),
'MON YYYY'
) q1char,
ADD_MONTHS (LAST_DAY (month_end_date), -12) q0
FROM rcdwstg.stg_bcar_detail) a
WHERE snap_shot_date BETWEEN ADD_MONTHS (a.max_date, -12) AND a.max_date
GROUP BY CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN q4char
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN q3char
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN q2char
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN q1char
END,
CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN 1
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN 2
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN 3
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN 4
END,
pillar3_exposure_class_code,
pd_band_description
ORDER BY 2 DESC;I have written the query to get the latest 12 months data from a table and split that into 4 quarter to show in the Cognos Report. But when the table having 13th or the past months data, the select statement is showing Empty values in the first two columns and fetching the 13 month data too.
Can anyone help me in this to avoid the problem.
Thanks
Radha KWHERE snap_shot_date BETWEEN ADD_MONTHS(TRUNC(a.max_date, 'MM'), -11) AND a.max_date
.... -
How can I call a Page Process from the Select statement for Report Page
I'm able to call a javascript using the below:
img src="#IMAGE_PREFIX#add2.gif" border="0" alt="Icon 4" onClick="javascript:add_connect1('||CPORT.ID||')"
But Now,
I'd like to accomplish (2) New things:
1. instead of using,....... onClick="javascript:add_connect1,
I'd like to call a Page Process, onClick=
2. I'd like to be able to call two different processes onClick.
a. onClick="javascript:passBack('||ID||')"
b. onClick= <Please see my question #1 above>
Can someone please help me with the syntax for this,
If indeed it can even be done?
Thanks- GaryGreg.
It seems that my situation is the one you describe in you second paragraph, where you mention:
you could then add the ID column value as a parameter to the javascript functionBut,
I do not know how to reference the variable in my javascript nor how to use it in my on-demand process.
If you can hellp me past this last little bump, then I think I will be able to use these skills in Sooo many different areas of my design.
Here's what I've got so far:
A. In the select statement I identify the javascript as:
onClick="javascript:connect_port('<font color=blue>''||ID||''</font>')";
B. In my javascript I have this:
<script language="JavaScript" type="text/javascript">
function connect_port(ID)
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=CONNECT_PORT',0);
gReturn = get.get();
get = null;
</script>
C. In my on demand function I have this:
BEGIN
INSERT INTO CCONNECTIONS_B
BLDG_ID,CLST_ID,PORT_ID,STRAND_ID
) VALUES
:P2004_BLDG_ID,:P2004_CLST_ID,:P2004_PORT_ID,:P2004_STRAND_ID1
END;
You can see that I dont know how to use the value for 'ID' in either the javascript or the On-Process function.
If you can help me out with this one, Then I can imitate it for the rest.
-Gary
Edited by: garyNboston on Apr 3, 2009 6:44 AM
Edited by: garyNboston on Apr 3, 2009 6:44 AM
Edited by: garyNboston on Apr 3, 2009 6:45 AM
Edited by: garyNboston on Apr 3, 2009 6:47 AM -
How to Add a new fields in the selection screen of LDB.
Hi All,
I want to add a new fields in the selection screen of LDB & then i need to select the data for that fields.
So could you please tell me for that where i need to add the code for selecting the data.
Thanks
RoliHi
welcome to SDN forum
If you are designing your own LDB with your own tables you can define tree structure and then the selection screen for the tables
if you wants to modify the std LDB of SAp means take the access key and to modify that code
if you add the extra field you have to modify the where conditions in the code also
see the doc
A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.
LDB offers an easy-to-use selection screens. You can modify the pre-generated selection screen to your needs. It offers check functions to check whether user input is complete, correct, and plausible. It offers reasonable data selections. It contains central authorization checks for data base accesses. Enhancements such as improved performance immediately apply to all report programs that use the logical database.
Less coding s required to retrieve data compared to normal internel tables.
Tables used LDB are in hierarchial structure.
Mainly we used LDBs in HR Abap Programming.
Where all tables are highly inter related so LDBs can optimize the performance there.
Check this Document. All abt LDB's
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2flibrary%2fabap%2fabap-code-samples%2fldb+browser.doc
GO THROUGH LINKS -
http://www.sap-basis-abap.com/saptab.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
/people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
Re: **LDB**
www.sapbrain.com/FAQs/TECHNICAL/SAP_ABAP_Logical_Database_FAQ.html
www.sap-img.com/abap/abap-interview-question.htm
www.sap-img.com/abap/quick-note-on-design-of-secondary-database-indexes-and-logical-databases.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9bb935c111d1829f0000e829fbfe/content.htm
Gothru the blog which provides info on LDB's:
/people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
Sample code
TABLES: SPFLI,
SFLIGHT,
SBOOK,
SCARR.
START-OF-SELECTION.
GET SPFLI.
WRITE:/ SPFLI: , SPFLI-CARRID, SPFLI-CONNID,
SPFLI-AIRPFROM, SPFLI-AIRPTO.
GET SFLIGHT.
WRITE:/ SFLIGHT: , SFLIGHT-CARRID, SFLIGHT-CONNID, SFLIGHT-FLDATE.
GET SBOOK.
WRITE:/ SBOOK: , SBOOK-CARRID, SBOOK-CONNID,
SBOOK-FLDATE, SBOOK-BOOKID.
GET SFLIGHT LATE.
WRITE:/ GET SFLIGHT LATE: , SFLIGHT-FLDATE.
Regards
anji -
Adding field in the selection-screen of a zprogram
hi gurus,
i have to add field in the selection-screen of oppurtunities. in database i have a field salesvalues, some of oppurtunity guids have this field value. first i need to add in selection-screen in this alv report. and fetch the data from ztable into required field . if the input fields of the salesvalues field id filled, then filter the global guids(from global table which had the guid values already) with this guids related to salesvalues. and if one single guid mathes to 2 values of salesvalues then concatenate 2 values with comma and display in single field. if select-options are blank then fetch all opportunity guids which have salesvalues. pls give solution.Hi Srini,
Thanks for your Reply
I have kept 01 against the field BSEG-AUGDT and selected the preselect check box also.
But still that field is not visible in the dynamic selection screen.
Thanks
Ajay.D -
Functional area(FKBER( field in the selection screen))
Hi,
I have a requirement to add functional area field in the selection screen for a report painter report. This report using library 1VK and table 'CCSS'. I added functional area field in the general data selection . After the execution of report with functional area field filled with value. report not giving any output. do i need to maintain any setting to achieve?
Regards,
PalaniHi,
How you have filled the values?
It is 16 CHAR long. -
Functional area(FKBER field in the selection screen of the report painter))
Hi,
I have a requirement to add functional area field in the selection screen for a report painter report. This report using library 1VK and table 'CCSS'. I added functional area field in the general data selection . After the execution of report with functional area field filled with value. report not giving any output. do i need to maintain any setting to achieve?
Regards,
Palani1. Call GR22 and click "Characteristics".
2. Check FKBER and assign a position number to it.
3. Save and close the library.
4. Call your report in GRR2 and you should now see FKBER as an available characteristic.
5. Use it in the General Data Selection or as a Lead Column, as per requirement.
Or,
1. Call GR21 and create a custom library. Provide a name and description and also provide a library you can copy from (scan for the best-fit library).
2. Now follow the steps 2 through 5 above to achieve your result.
Hope this helps.
Cheers.
Maybe you are looking for
-
Service billing for the material and service registers
Dear All, I have doubt, if i do a sale of material 'X' and for the same material if i have to do a service invoice for rendering some service at the customer end. eg:- service charges for transportaion of the material to the customer place, doing ins
-
I am heading to Italy in a week or so and am bringing my iPad. However there is no wifi in the hotel... only wired internet connection in the rooms. Is there a way to connect my iPad to the internet still. Should I buy a router? Or some sort of ho
-
Button stops working when load a mc inside.
Hi if I load a movieclip within a _mc it stops working as a button. I use mcLoader.loadClip (File, Sprite); and then: mc.play(); Anyone can help me?
-
Error 46: Can't find or load QuickTime ActiveX control
Have tried many times to download and use QuickTime on my HP Pavillion laptop running Windows 7. Disabled antivirus, firewall, SpySweeper, etc. but to no avail. Uninstalled, reinstalled, etc. Keep getting the same error when attempting to run program
-
Do I need to uninstall pages '08 before installing the newest version?
I bought a new MacPro in November 2013 and the technician transferred my iLife 'o8 package with Pages in it. Can I install the newest Pages and Numbers over the existing ones, or do I need to uninstall the old ones first? Can't seem to find a straig