Problem in SELECT SINGLE Query
Hi,
I am writing a small quesry in PS, Though the entry exist in database table PRPS, The sy-subrc is 4 for this query.Can u help me.
data : wa_src_prps like prps-posid.
start-of-selection.
wa_src_prps = '3-3310-02-01-01-10-20'.
DATA: lv_pbukr LIKE prps-pbukr.
CLEAR: lv_pbukr.
SELECT SINGLE pbukr INTO lv_pbukr
FROM prps
WHERE posid EQ wa_src_prps.
if sy-subrc = 0.
write:/5 wa_src_prps, lv_pbukr.
endif.
hi,
DATA : wa_src_prps LIKE prps-posid.
START-OF-SELECTION.
wa_src_prps = '0-1000-0'.
" Conversion Routine for domain PS_POSID
CALL FUNCTION 'CONVERSION_EXIT_ABPSN_INPUT'
EXPORTING
input = wa_src_prps
IMPORTING
output = wa_src_prps.
DATA: lv_pbukr LIKE prps-pbukr.
CLEAR: lv_pbukr.
SELECT SINGLE pbukr INTO lv_pbukr
FROM prps
WHERE posid EQ wa_src_prps.
IF sy-subrc = 0.
WRITE:/5 wa_src_prps, lv_pbukr.
ENDIF.
Similar Messages
-
Select single query working unexpectedly
Hi all,
I have used below select single * query as shown :
I have data in my table S022 as shown below, it has 2 records for material and aufnr combination :
WERKS ARBPL kapar MATNR AUFNR
w1 ar1 004 mat1 000300156789
w1 ar2 mat1 000300156789
The code used :
select single *
from s022
where werks = itab-ltap-werks "w1
and matnr = w_matnr "mat1
and aufnr = w_aufnr. " 000300156789
runtime select query is picking second record i.e of ar2.
I hope it should have picked ar1 record but its doesnt .
Also sometimes it picks 1st record for different data and for this data it picks the second record.
Kindly help me to explain why its not picking the first record.
Regards.ujjwal_d15 wrote:
It is as per the data in the table . The records are one below the another in database table.
> So i feel it should have picked the first record.
Hello Ujjwal,
The records shown in the databrowser is a snapshot of the entries in the DB & not how the recs are actually stored!
In RDBMS the sequence of entries is not defined at the DB layer. In SELECT SINGLE the 1st rec to be hit is returned to the result set. In your case this is the 2nd rec.
BR,
Suhas -
MIN in select SINGLE query.
I need to find a single record with lowest DDUP.
If there are 2 records exist, then i need a single record with lowest DDUP.
loop at it_mara.
SELECT SINGLE EKORG MATNR MFRPN ZEINR KUNNRS MIN( DDUP ) DCURR
FROM ZNVT_PRICE
INTO CORRESPONDING FIELDS OF LW_ZNVT_PRICE
WHERE EKORG EQ P_EKORG AND
MATNR EQ IT_MARA-MATNR AND
MFRPN EQ IT_MARA-MFRPN AND
ZEINR EQ IT_MARA-ZEINR AND
KUNNRS EQ IT_MARA-KUNNR AND
DATAB LE SY-DATLO AND
DATBI GE SY-DATLO
GROUP BY EKORG MATNR MFRPN ZEINR KUNNRS DCURR.
endloop.
there is only one record in the table ZNVT_PRICE. (1234.00)
Some times i am getting 1234.
Some times 0.00.
I need to find a single record with lowest DDUP.
If there are 2 records exist, then i need a single record with lowest DDUP.
if I do not use GROUP BY i am getting error.
I have to use SELECT SINGLE.
Guys...please help me to write reliable query.Hi,
Instead of SELECT SINGLE use
SELECT.. UP TO 1 ROWS
ENDSELECT.
It will also be very fast and suit your requirement.
Regards,
Atish -
hi
can you find any error in this
select single * from makt where matnr = p_matnr and spras = 'sv'.Hi,
Use like this.
data: BEGIN OF it_makt OCCURS 0,
matnr LIKE maKT-matnr,
maktx LIKE makt-maktx,
END OF it_makt.
data: process_tab_struct_tmp like IT_MAKT.
field-symbols: <fs1>.
after downloading file(excel) to excel_tab....code follows
LOOP AT EXCEL_TAB.
assign component excel_tab-col of structure
process_tab_struct_tmp to <fs1>.
<fs1> = excel_tab-value.
at end of row.
move-corresponding: process_tab_struct_tmp to IT_MAKT.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = <b>it_makt-matnr</b>
IMPORTING
OUTPUT = <b>it_makt-matnr</b>.
append IT_MAKT.
endat.
ENDLOOP.
Do reward points to useful answers.
Regards,
Atish -
Problem in select single statement : its urgent
Dear ,
i written one select single stmt i.e
tables : ser03 .
SELECT SINGLE * FROM ser03
WHERE obknr = objk-obknr
AND bwart = '101'
AND shkzg = 'S'.
based on this select stmt their are 5 records in database table satisfying the select stmt where clause and this select stmt is picking the fourth record . why this record is picking forth record only even this 4th record is not most recently created record and nor old record this record is middle one if any one plz tell me . points must be given . to access most recently recreated record how to write select stmt. plz tell me .Hi,
hope this code will help you.
just added the mandt in the where condition.
SELECT SINGLE * FROM ser03
WHERE mandt = sy-mandt
AND obknr = objk-obknr
AND bwart = '101'
AND shkzg = 'S'.
reward if helpful,
teja. -
Performance Problem While Selecting a Query....
Hi Users
I have problem with performance with appliction
where are using D2K frent end and backend oracle 9i
we have a validaion buttion that is taking lot of time to check the date like 500 records
i want some links about performance issue process pls help.
Here some of the query taking more than 1sec to more
1)
SELECT
/*+(INDEX(KBS_CHKSHTCARDTB(IND1_CHKSHTCARD))*/
COUNT(DISTINCT A.KBCK_CHKSHEET_NO)
FROM
KBS_CHKSHTCARDTB A ,KBS_CHKSHTHDRTB B WHERE A.KBCK_CHKSHEET_NO=B.KBCH_CHKSHEET_NO
AND KBCK_E_DATE =TRUNC(SYSDATE)
AND KBCH_PRINT_STATUS='P'
OutPut: 206
Time : 1sec
2)
UPDATE KBS_CARDMASTERTB
SET KBCM_LOCK_FROM = KBCM_LOCK_FROM_CONTROL,
KBCM_LOCK_STATUS= NULL
WHERE KBCM_LOCK_FROM_CONTROL is not null
and KBCM_LOCK_FROM IS NULL
and KBCM_LOCK_FROM_CONTROL <=trunc(sysdate)
AND KBCM_LOCK_STATUS = 'Y'
and KBCM_UNIQUE_IDNO IN(SELECT DISTINCT KBSA_UNIQUE_IDNO
FROM KBS_SCANTB WHERE TRUNC(KBSA_E_DATE) = TRUNC(:KANBAN_CTRL_BLK.DAT)
AND KBSA_TRUCK_SQ_NO = :Kanban_ctrl_blk.cycl
AND KBSA_ERROR_CODE IS NULL)
AND (KBCM_VENDOR_NO,KBCM_PLANT_CODE)in (SELECT DISTINCT kbsa_vendor_no,KBSA_PLANT_CODE
FROM KBS_SCANTB WHERE TRUNC(KBSA_E_DATE) = TRUNC(:KANBAN_CTRL_BLK.DAT) AND KBSA_TRUCK_SQ_NO = :Kanban_ctrl_blk.cycl AND KBSA_ERROR_CODE IS NULL)
AND KBCM_PROCESS_CODE IN (SELECT DISTINCT KBSA_PROCESS_CODE
FROM KBS_SCANTB WHERE TRUNC(KBSA_E_DATE) = TRUNC(:KANBAN_CTRL_BLK.DAT) AND KBSA_TRUCK_SQ_NO = :Kanban_ctrl_blk.cycl
AND KBSA_ERROR_CODE IS NULL);
OutPut: Totatl Number of Table:29288
Time : more than 5sec
3)
CURSOR GET_TEMP_CARDS_SWIPED_CUR IS
SELECT KBCM_VENDOR_NO
,KBCM_PLANT_CODE
,KBCM_FAMILY --ADDED BY SUJITH.C TO SUPPORT PSMS2
,KBCM_BACK_NO
,KBCM_UNIQUE_IDNO
,KBCM_KANBAN_TYPE
FROM KBS_CARDMASTERTB
WHERE KBCM_KANBAN_TYPE IN ('T','B')
AND KBCM_UNIQUE_IDNO IN
(SELECT KBSA_UNIQUE_IDNO
FROM KBS_SCANTB
WHERE KBSA_E_DATE = :DAT
AND KBSA_TRUCK_SQ_NO = :CYCL
AND KBSA_ERROR_CODE IS NULL
AND KBSA_TYPE IS NULL);
Thanks Advance ........[When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
[How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0] -
Problem with SELECT INTO Query
Why am I always getting 0 for returnvalue in the following query?
create or replace
PACKAGE BODY MyPKG AS
PROCEDURE SelectCount
returnvalue OUT INTEGER
AS
BEGIN
select COUNT(*) from MyTable into returnvalue;
IF( SQL%ROWCOUNT >= 1 )
THEN
returnvalue := 1;
ELSE
returnvalue := 0;
END IF;
dbms_output.put_line('returnvalue: ' || returnvalue);
END SelectCount;
END MyPKG ;Hi,
When you use an aggregate function, such as COUNT, without a GROUP BY clause, then the query is guaranteed to return exactly 1 row, regadless of whether there are any rows in the table or not.
Perhaps you meant:
create or replace
PACKAGE BODY MyPKG AS
PROCEDURE SelectCount
returnvalue OUT INTEGER
AS
BEGIN
select COUNT(*) from MyTable into returnvalue;
dbms_output.put_line('returnvalue: ' || returnvalue);
END SelectCount;
END MyPKG ;
that is, simply lose the IF block. -
Hello,
i used Vikas'example Re: cascading lov for tabular form
i have a problem with Select list (query based LOV)
when run tabular form i have the following error:
report error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
the number of rows of the Lov are 900
the display variable is 70 char
is there any limit?
Thank in advance
CostantiLeo,
Thanks for the response, but I don't think you quite understand my problem. If I go to the Column Attributes screen for the group_id field, I have the "Display As" drop down set to "Select List (query based LOV)", not "Select List (named LOV)". This requires that the sql query be written in the "List of values definition" text area below. Within that text area I have the following query:
SELECT DISPLAY_NAME, GROUP_ID
FROM APPLICATION_GROUPS
WHERE APP_ID = ?????
ORDER BY 1
The APP_ID that I need to reference is for the current row of data that is being processed. Therefore, I can't use a :PNNN_APP_ID variable, because that field does not exist on the page.
Hopefully this explains it a little better.
Thanks,
Kris -
Problem while using select single
Hii,
I am using a select single command, My code is
Select single * from zbe_gpfd_comment into wa_gpfd_comment where program_name = program
and box_type = box_type
and box_name = box_name.
even though the required data is in the database still nothing is retrived in wa_gpfd_comment.No problem with datatype, I have checked them all..but still I am not able to get where the problem is?
PS : program_name,box_type,box_name are primary key of the table zbe_gpfd_comment.Hi Priya,
Did u checked what values are u passing in where condition for program , box_type , box_name .
are there any values in the above the fields ,
or just try to check once by hardcoding the values of the above 3 like
Select single * from zbe_gpfd_comment into wa_gpfd_comment where program_name = 'ZABC'
and box_type = 'CUBE'
and box_name = 'NOKIA'.
give the 3 values which are existing in your zbe_gpfd_comment table .
if it works then nothing wrong with select query ,
and check the values in debugging whether the values are coming in : program , box_type , box_name .
I guess in ur query all the values are null or space , so it is not retriving values.
check subrc also for the query.
Regards,
Aby -
All selected 'n' consecutive rows in retrieved in a single query
hello,
I have table T with 50,000 rows
create table T
(student_id number,
class_id number,
quiz_id number,
marks number)
some sample rows like
INSERT INTO T VALUES (1,1, 1, 50);
INSERT INTO T VALUES (2,2, 2, 40);
INSERT INTO T VALUES (3,1, 3, 34);
INSERT INTO T VALUES (1,1, 4, 10);
INSERT INTO T VALUES (1,1, 5, 30);
INSERT INTO T VALUES (1,1, 6, 29);
INSERT INTO T VALUES (3,2, 7, 34);
INSERT INTO T VALUES (3,2, 8, 33);
INSERT INTO T VALUES (3,2, 9, 56);
INSERT INTO T VALUES (1,1, 7, 90);
INSERT INTO T VALUES (2,2, 8, 0,);
INSERT INTO T VALUES (1,1, 8, 80);
INSERT INTO T VALUES (2,2, 8, 65);
INSERT INTO T VALUES (1,1, 9, 34);
INSERT INTO T VALUES (2,2, 9, 11);each student belongs to one class_id. each student participates in many quizes. each quiz has its unique id. each student can appear once in a quiz_id
I am doing the below analysis and query:
1. with below query I am finding which student_id had most marks in any 3 successive quizes (see the 3-1 part below) in the query..
SELECT QUIZ_ID,
STUDENT_ID,
SUM (MARKS) OVER (PARTITION BY STUDENT_ID ORDER BY QUIZ_ID1
RANGE BETWEEN CURRENT ROW AND (3-1) FOLLOWING) consecMARKS , MARKS FROM
(SELECT QUIZ_ID,
STUDENT_ID,
MARKS,
ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
FROM T
WHERE MARKS IS NOT NULL
ORDER BY 1
ORDER BY 3 DESC
SQL> /
QUIZ_ID STUDENT_ID CONSECMARKS
7 1 170
6 1 166
8 1 129
5 1 106
8 3 89
8 2 76
3 3 68
7 3 67
8 2 65
1 1 60
9 3 56
QUIZ_ID STUDENT_ID CONSECMARKS
9 1 49
2 2 40
4 1 40
9 2 11
15 rows selected.With above query, I can play around and find for any 'n' number of consecutive quizes, like marks in 2 consecutives quizes, 3, 4 and so on but for each 'n' value I've to run a seperate query mentioning (2-1) or (3-1) or (4-1) and so on..
since my table is big and there are about 400 quizes so what I want to find out is for each 'n' consecutive quiz (from 1 to 400) which student had most marks for each consecutie 'n' quiz. Like in 1 (consecutive) quiz which student had the highest marks and then 2 conseuctive quiz who had most marks and then in 3 consecutive quiz who had most marks and so on till 400 consecutive quiz who had most marks... rather than running query for each 'n' value seperately i want a single query that can give me a summary of most marks in each n consecutive quizes...
my sample output is:
Nth consecutive quiz student_id sum(marks)
1 1 90
2 1 170
3 1 246
4
100
200
300
400 ? ? Is this possible to get the above output from one single query? If there are two or more students with equal most marks for any 'n' conseutive quizes then both should come in the summary.
Hope I have been able to put up my question clearly.
regards
RamisSomething like:
SELECT N,
QUIZ_ID,
STUDENT_ID,
SUM(MARKS) OVER (PARTITION BY N,STUDENT_ID ORDER BY QUIZ_ID1 RANGE BETWEEN CURRENT ROW AND (N-1) FOLLOWING) consecMARKS,
MARKS
FROM (SELECT QUIZ_ID,
STUDENT_ID,
MARKS,
ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
FROM T
WHERE MARKS IS NOT NULL
SELECT LEVEL N
FROM DUAL
CONNECT BY LEVEL <= (
SELECT COUNT(DISTINCT QUIZ_ID)
FROM T
ORDER BY N,
consecMARKS DESC
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
1 7 1 90 90
1 8 1 80 80
1 8 2 65 65
1 9 3 56 56
1 1 1 50 50
1 2 2 40 40
1 9 1 34 34
1 7 3 34 34
1 3 3 34 34
1 8 3 33 33
1 5 1 30 30
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
1 6 1 29 29
1 9 2 11 11
1 4 1 10 10
1 8 2 0 0
2 7 1 170 90
2 6 1 119 29
2 8 1 114 80
2 8 3 89 33
2 8 2 76 65
2 3 3 68 34
2 7 3 67 34
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
2 8 2 65 0
2 1 1 60 50
2 5 1 59 30
2 9 3 56 56
2 2 2 40 40
2 4 1 40 10
2 9 1 34 34
2 9 2 11 11
3 7 1 204 90
3 6 1 199 29
3 5 1 149 30
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
3 7 3 123 34
3 8 1 114 80
3 2 2 105 40
3 3 3 101 34
3 1 1 90 50
3 8 3 89 33
3 8 2 76 65
3 8 2 76 0
3 4 1 69 10
3 9 3 56 56
3 9 1 34 34
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
3 9 2 11 11
4 6 1 233 29
4 5 1 229 30
4 7 1 204 90
4 4 1 159 10
4 3 3 157 34
4 7 3 123 34
4 1 1 119 50
4 2 2 116 40
4 8 1 114 80
4 8 3 89 33
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
4 8 2 76 0
4 8 2 76 65
4 9 3 56 56
4 9 1 34 34
4 9 2 11 11
5 5 1 263 30
5 4 1 239 10
5 6 1 233 29
5 1 1 209 50
5 7 1 204 90
5 3 3 157 34
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
5 7 3 123 34
5 2 2 116 40
5 8 1 114 80
5 8 3 89 33
5 8 2 76 0
5 8 2 76 65
5 9 3 56 56
5 9 1 34 34
5 9 2 11 11
6 1 1 289 50
6 4 1 273 10
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
6 5 1 263 30
6 6 1 233 29
6 7 1 204 90
6 3 3 157 34
6 7 3 123 34
6 2 2 116 40
6 8 1 114 80
6 8 3 89 33
6 8 2 76 0
6 8 2 76 65
6 9 3 56 56
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
6 9 1 34 34
6 9 2 11 11
7 1 1 323 50
7 4 1 273 10
7 5 1 263 30
7 6 1 233 29
7 7 1 204 90
7 3 3 157 34
7 7 3 123 34
7 2 2 116 40
7 8 1 114 80
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
7 8 3 89 33
7 8 2 76 0
7 8 2 76 65
7 9 3 56 56
7 9 1 34 34
7 9 2 11 11
8 1 1 323 50
8 4 1 273 10
8 5 1 263 30
8 6 1 233 29
8 7 1 204 90
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
8 3 3 157 34
8 7 3 123 34
8 2 2 116 40
8 8 1 114 80
8 8 3 89 33
8 8 2 76 0
8 8 2 76 65
8 9 3 56 56
8 9 1 34 34
8 9 2 11 11
9 1 1 323 50
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
9 4 1 273 10
9 5 1 263 30
9 6 1 233 29
9 7 1 204 90
9 3 3 157 34
9 7 3 123 34
9 2 2 116 40
9 8 1 114 80
9 8 3 89 33
9 8 2 76 0
9 8 2 76 65
N QUIZ_ID STUDENT_ID CONSECMARKS MARKS
9 9 3 56 56
9 9 1 34 34
9 9 2 11 11
135 rows selected.
SQL> SY. -
Selecting data from single table with different condition in single query
Hi everybody...
I have one table with col1, col2, col3, col4, col5... as columns.
I want to select col1, col2, col3 with condition (x=y and a=b and c=d)
I want to select col4, col5 with condition (x=y and a=b and m=n )
in single query...
Thanx for ur helpGiven this data set...
SQL> select * from oddity
2 /
COL1 COL2 COL3 COL4 COL5 A X C M
1 2 3 4 5 B Y M
1 2 3 4 5 A Y C N
1 2 3 4 5 A Y D M
1 2 3 4 5 A Y D N
1 2 3 4 5 B Y D N
1 2 3 4 5 B Y D U
6 rows selected.
SQL>The following query meets the requirements. Of course, the requirements as stated are incomplete. I ahave assumed that we select all five columns if C=D andM=N.
SQL> SELECT decode(c, 'D', col1, '0') AS col1
2 , decode(c, 'D', col2, '0') AS col2
3 , decode(c, 'D', col3, '0') AS col3
4 , decode(m, 'N', col4, '-8') AS col4
5 , decode(m, 'N', col5, '-8') AS col5
6 FROM oddity
7 WHERE a = 'B'
8 AND x = 'Y'
9 /
COL1 COL2 COL3 COL4 COL5
0 0 0 -8 -8
1 2 3 4 5
1 2 3 -8 -8
SQL> Cheers, APC -
What is the problem in this code (problem in select query)
Just need your help in solving one issue. In the below code one query which is highlighted
Select statement not working means cursor directly goes to the endselect .means these two statements not executed.
CLASS cl_abap_container_utilities DEFINITION LOAD.
CALL METHOD cl_abap_container_utilities=>read_container_c
I am attaching that code with this mail. Please do the needful help.
*& Report ZEOU_RG1 *
REPORT zeou_rg1 LINE-SIZE 400.
Purpose : RG1 Report driver
Remarks :
constants
INCLUDE j_2icons.
type declerations
INCLUDE j_2isdef.
table definitions and internal tables
INCLUDE j_2iddef.
INCLUDE <icon>.
DATA: $plant TYPE bp_addr_typ,
$lincnt LIKE sy-linct,
m_date LIKE j_1ipart2-budat,
m_chapid LIKE j_1iexcdtl-chapid,
m_matform LIKE j_1irg1-matform,
m_bedrate LIKE j_1irg1-bedrate,
tot_op_bal LIKE j_1irg1-menge,
tot_qty_mnfr LIKE j_1irg1-menge,
tot_total_qty_mnfr LIKE j_1irg1-menge,
tot_remv_home LIKE j_1irg1-menge,
tot_remv_hval LIKE j_1irg1-exbas,
tot_remv_expr LIKE j_1irg1-menge,
tot_remv_eval LIKE j_1irg1-exbas,
tot_remv_expb LIKE j_1irg1-menge,
tot_remv_othr LIKE j_1irg1-menge,
tot_remv_opur LIKE j_1irg1-menge,
tot_duty_amt LIKE j_1irg1-exbed,
tot_cb_fr LIKE j_1irg1-exbed,
tot_cb_br LIKE j_1irg1-exbed.
DATA: t_rg1_cons TYPE rg1_typ OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <x_extrctdata> TYPE c,
<x_rg1> TYPE rg1_typ,
<x_part1typ> TYPE part1_typ.
DATA : it_j_1iexchdr TYPE j_1iexchdr OCCURS 0 WITH HEADER LINE,
wa_j_1iexchdr TYPE j_1iexchdr,
it_j_1iexcdtl TYPE j_1iexcdtl OCCURS 0 WITH HEADER LINE,
wa_j_1iexcdtl TYPE j_1iexcdtl.
selection screen
PARAMETERS: p_exgrp LIKE j_1iexchdr-exgrp OBLIGATORY MEMORY ID j2i,
p_stdate LIKE sy-datum OBLIGATORY,
p_endate LIKE sy-datum OBLIGATORY.
*SELECTION-SCREEN SKIP 1.
*SELECTION-SCREEN BEGIN OF BLOCK 4 WITH FRAME TITLE TEXT-001.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN POSITION 01.
*PARAMETERS: P_INDI RADIOBUTTON GROUP 57F4 DEFAULT 'X'.
*SELECTION-SCREEN COMMENT (25) TEXT-002.
*SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN POSITION 01.
*PARAMETERS: P_CONS RADIOBUTTON GROUP 57F4.
*SELECTION-SCREEN COMMENT (25) TEXT-003.
*SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN END OF BLOCK 4.
INITIALIZATION.
AT SELECTION-SCREEN.
SELECT SINGLE *
FROM j_1iexgrps
WHERE j_1iexcgrp = p_exgrp.
IF sy-subrc NE 0.
MESSAGE e399(8i) WITH p_exgrp.
ENDIF.
*check company code
SELECT SINGLE *
FROM t001k
WHERE bwkey = j_1iexgrps-j_1iwerks.
IF sy-subrc NE 0.
MESSAGE e518(8i) WITH 'the' 'plant' j_1iexgrps-j_1iwerks.
ENDIF.
<b>START-OF-SELECTION.
CLEAR: j_1irg1, j_2icomp.
retrieve layout name and details
SELECT SINGLE *
FROM J_2ILAYCTR
WHERE BUKRS = T001K-BUKRS
AND REGISTER = C_RG1
AND LAYOUTNR = 1.
IF SY-SUBRC NE 0.
MESSAGE E635(8I) WITH T001K-BUKRS C_RG1.
ENDIF.
SET COUNTRY 'IN'.
REFRESH t_reciepts.
report driver logic
SELECT *
FROM j_2iextrct
WHERE exgrp = p_exgrp
AND budat >= p_stdate
AND budat <= p_endate
AND register = c_rg1
ORDER BY budat keyid.
assign J_2IEXTRCT-EXTRCTDATA to <x_extrctdata> casting.
assign T_RG1 to <x_rg1> casting.
<x_rg1> = <x_extrctdata>.
CLASS cl_abap_container_utilities DEFINITION LOAD.
CALL METHOD cl_abap_container_utilities=>read_container_c
EXPORTING
im_container = j_2iextrct-extrctdata
IMPORTING
ex_value = t_rg1
EXCEPTIONS
illegal_parameter_type = 1
OTHERS = 2.
MOVE J_2IEXTRCT-EXTRCTDATA TO T_RG1.
APPEND t_rg1.
ENDSELECT.
DESCRIBE TABLE t_rg1 LINES $lincnt.
IF $lincnt = 0.
MESSAGE e548(8i) WITH p_stdate p_endate.
ENDIF.</b>
PERFORM PLANT_AND_EXCISE_DTLS USING P_WERKS.
PERFORM plant_and_excise_dtls USING j_1iexgrps-j_1iwerks.
MOVE : 'ZJ_2I_RG1' TO j_2ilayctr-layoutname.
SORT t_rg1 BY chapid matnr cpudt .
open form
PERFORM open_form USING j_2ilayctr-layoutname j_2ilayctr-noofcopies "J_2ILAYCTR-LAYOUTNAME
j_2ilayctr-outdevice true.
process extract data and write
IF P_INDI = 'X'.
PERFORM get_data_and_write.
ELSEIF P_CONS = 'X'.
PERFORM RG1_PRINT_CONS.
PERFORM GET_DATA_AND_WRITE_CONS.
ENDIF.
close form
PERFORM close_form.
F O R M S
INCLUDE j_2ilayo.
*& Form GET_DATA_AND_WRITE
Purpose : Logic to print RG1 report
FORM get_data_and_write.
DATA: save_matnr LIKE mara-matnr.
CLEAR: j_1irg1, j_2icomp, save_matnr.
SELECT * FROM j_1iexchdr INTO TABLE it_j_1iexchdr
WHERE exgrp = p_exgrp
AND budat >= p_stdate
AND budat <= p_endate.
SORT it_j_1iexchdr BY cpudt docno.
LOOP AT it_j_1iexchdr.
SELECT * FROM j_1iexcdtl INTO wa_j_1iexcdtl
WHERE docno = it_j_1iexchdr-docno.
APPEND wa_j_1iexcdtl TO it_j_1iexcdtl.
ENDSELECT.
ENDLOOP.
clear wa_j_1iexcdtl.
SORT it_j_1iexcdtl BY chapid matnr cpudt docno.
LOOP AT t_rg1.
CLEAR: j_1irg1, j_2icomp.
assign header fields
j_2icomp-stdate = p_stdate.
j_2icomp-endate = p_endate.
IF save_matnr NE t_rg1-matnr.
fill header line with matnr, description, chapterid and unit
j_1irg1-chapid = t_rg1-chapid.
mara-matnr = t_rg1-matnr.
marav-maktx = t_rg1-maktx.
mara-meins = t_rg1-meins.
save_matnr = t_rg1-matnr.
IF sy-tabix NE 1.
j_2icomp-new_page = true.
ELSE.
j_2icomp-new_page = false.
ENDIF.
ELSE.
j_2icomp-new_page = false.
ENDIF.
PERFORM write_form USING element-spac function-set
typ-body window-main .
determine line to display viz. manufacture entry/removal entry
IF t_rg1-matform = c_packed.
j_2icomp-rg1_p_l = c_packed.
ELSEIF t_rg1-matform = c_loose.
j_2icomp-rg1_p_l = c_loose.
ENDIF.
j_1irg1-cpudt = t_rg1-cpudt.
j_2icomp-op_qty = t_rg1-op_bal.
j_2icomp-mf_qty = t_rg1-qty_mfr.
j_2icomp-to_qty = t_rg1-total.
j_2icomp-cl_fin = t_rg1-cl_bal_fn.
j_2icomp-cl_bon = t_rg1-cl_bal_bn.
j_2icomp-remarks = t_rg1-remarks.
j_2icomp-h_menge = t_rg1-h_menge.
j_2icomp-h_value = t_rg1-h_value.
j_2icomp-e_menge = t_rg1-e_menge.
j_2icomp-e_value = t_rg1-e_value.
j_2icomp-e_menge_bn = t_rg1-e_menge_bond.
j_2icomp-o_menge = t_rg1-o_menge.
j_2icomp-o_purpose = t_rg1-o_purpose.
j_2icomp-o_pur_meng = t_rg1-o_pur_menge.
j_1irg1-bedrate = t_rg1-bedrate.
j_1irg1-exbed = t_rg1-bedamt.
j_2icomp-cl_fin = t_rg1-cl_bal_fn.
j_2icomp-cl_bon = t_rg1-cl_bal_bn.
j_2icomp-remarks = t_rg1-remarks.
READ TABLE it_j_1iexcdtl WITH KEY cpudt = t_rg1-cpudt
chapid = t_rg1-chapid
matnr = t_rg1-matnr.
IF sy-subrc = 0.
get duties for issues only.
IF t_rg1-rcptissrsn = 'IPD'
OR t_rg1-rcptissrsn = 'IWD'
OR t_rg1-rcptissrsn = 'IDH'
OR t_rg1-rcptissrsn = 'IDE'
OR t_rg1-rcptissrsn = 'IWE'
OR t_rg1-rcptissrsn = 'IWT'
OR t_rg1-rcptissrsn = 'IWO'.
READ TABLE it_j_1iexchdr WITH KEY exnum = t_rg1-rdoc1
trntyp = 'DLFC'
cpudt = t_rg1-cpudt.
READ TABLE it_j_1iexcdtl WITH KEY docno = it_j_1iexchdr-docno
cpudt = it_j_1iexchdr-cpudt
trntyp = 'DLFC'
matnr = t_rg1-matnr.
docyr = it_j_1iexchdr-docyr
IF IT_j_1iexchdr-expind <> 'B'
and it_j_1iexchdr-expind <> 'U'
and it_j_1iexchdr-expind <> 'D'
and it_j_1iexchdr-expind <> 'N'
AND T_RG1-h_menge > 0.
and it_j_1iexchdr-expind IS INITIAL.
IF it_j_1iexchdr-censtat = 'P'.
wa_j_1iexcdtl-ecs = it_j_1iexcdtl-ecs.
ENDIF.
IF it_j_1iexchdr-censtat = 'C'.
wa_j_1iexchdr-exbed = it_j_1iexchdr-exbed.
wa_j_1iexchdr-ecs = it_j_1iexchdr-ecs.
wa_j_1iexchdr-censtat = it_j_1iexchdr-censtat.
wa_j_1iexchdr-cpudt = it_j_1iexchdr-cpudt.
wa_j_1iexcdtl-rgplaser = it_j_1iexcdtl-rgplaser.
wa_j_1iexcdtl-rg23aser = it_j_1iexcdtl-rg23aser.
ENDIF.
ENDIF.
endif.
ENDIF.
PERFORM write_form USING element-d function-append
typ-body window-main .
CLEAR : wa_j_1iexchdr, wa_j_1iexcdtl.
ENDLOOP.
ENDFORM. " GET_DATA_AND_WRITE
*& Form GET_DATA_AND_WRITE_CONS
text *
--> p1 text
<-- p2 text
FORM get_data_and_write_cons.
DATA: save_chapid LIKE j_1iexcdtl-chapid.
CLEAR: j_1irg1, j_2icomp, save_chapid.
LOOP AT t_rg1_cons.
CLEAR: j_1irg1, j_2icomp.
assign header fields
j_2icomp-stdate = p_stdate.
j_2icomp-endate = p_endate.
IF save_chapid NE t_rg1_cons-chapid.
fill header line with chapterid
j_1irg1-chapid = t_rg1_cons-chapid.
save_chapid = t_rg1_cons-chapid.
IF sy-tabix NE 1.
j_2icomp-new_page = true.
ELSE.
j_2icomp-new_page = false.
ENDIF.
ELSE.
j_2icomp-new_page = false.
ENDIF.
PERFORM write_form USING element-spac function-set
typ-body window-main .
determine line to display viz. manufacture entry/removal entry
IF t_rg1_cons-matform = c_packed.
j_2icomp-rg1_p_l = c_packed.
ELSEIF t_rg1_cons-matform = c_loose.
j_2icomp-rg1_p_l = c_loose.
ENDIF.
j_1irg1-cpudt = t_rg1_cons-cpudt.
j_2icomp-op_qty = t_rg1_cons-op_bal.
j_2icomp-mf_qty = t_rg1_cons-qty_mfr.
j_2icomp-to_qty = t_rg1_cons-total.
j_2icomp-cl_fin = t_rg1_cons-cl_bal_fn.
j_2icomp-cl_bon = t_rg1_cons-cl_bal_bn.
j_2icomp-remarks = t_rg1_cons-remarks.
j_2icomp-h_menge = t_rg1_cons-h_menge.
j_2icomp-h_value = t_rg1_cons-h_value.
j_2icomp-e_menge = t_rg1_cons-e_menge.
j_2icomp-e_value = t_rg1_cons-e_value.
j_2icomp-e_menge_bn = t_rg1_cons-e_menge_bond.
j_2icomp-o_menge = t_rg1_cons-o_menge.
j_2icomp-o_purpose = t_rg1_cons-o_purpose.
j_2icomp-o_pur_meng = t_rg1_cons-o_pur_menge.
j_1irg1-bedrate = t_rg1_cons-bedrate.
j_1irg1-exbed = t_rg1_cons-bedamt.
j_2icomp-cl_fin = t_rg1_cons-cl_bal_fn.
j_2icomp-cl_bon = t_rg1_cons-cl_bal_bn.
j_2icomp-remarks = t_rg1_cons-remarks.
PERFORM write_form USING element-d function-append
typ-body window-main .
*for grand totals
tot_remv_hval = tot_remv_hval + t_rg1_cons-h_value.
tot_remv_eval = tot_remv_eval + t_rg1_cons-e_value.
tot_duty_amt = tot_duty_amt + t_rg1_cons-bedamt.
ENDLOOP.
*for grand totals
j_2icomp-amount1 = tot_remv_hval.
j_2icomp-amount2 = tot_remv_eval.
j_2icomp-amount3 = tot_duty_amt.
PERFORM write_form USING element-t function-append
typ-body window-footer.
ENDFORM. " GET_DATA_AND_WRITE_CONS
*& Form RG1_PRINT_CONS
text *
--> p1 text
<-- p2 text
FORM rg1_print_cons.
DATA : first_time VALUE on.
SORT t_rg1 BY chapid cpudt.
LOOP AT t_rg1.
IF first_time = on.
m_chapid = t_rg1-chapid.
m_date = t_rg1-cpudt.
m_matform = t_rg1-matform.
m_bedrate = t_rg1-bedrate.
first_time = off.
ENDIF.
IF m_chapid <> t_rg1-chapid.
PERFORM chapid_break.
ELSEIF m_date <> t_rg1-cpudt.
PERFORM date_break.
ENDIF.
Accumulate totals
tot_op_bal = tot_op_bal + t_rg1-op_bal.
tot_qty_mnfr = tot_qty_mnfr + t_rg1-qty_mfr.
tot_total_qty_mnfr = tot_total_qty_mnfr + t_rg1-total.
tot_remv_home = tot_remv_home + t_rg1-h_menge.
tot_remv_hval = tot_remv_hval + t_rg1-h_value.
tot_remv_expr = tot_remv_expr + t_rg1-e_menge.
tot_remv_eval = tot_remv_eval + t_rg1-e_value.
tot_remv_expb = tot_remv_expb + t_rg1-e_menge_bond.
tot_remv_othr = tot_remv_othr + t_rg1-o_menge.
tot_remv_opur = tot_remv_opur + t_rg1-o_pur_menge.
tot_duty_amt = tot_duty_amt + t_rg1-bedamt.
tot_cb_fr = tot_cb_fr + t_rg1-cl_bal_fn.
tot_cb_br = tot_cb_br + t_rg1-cl_bal_bn.
ENDLOOP.
PERFORM chapid_break.
ENDFORM. " RG1_PRINT_CONS
*& Form DATE_BREAK
text *
--> p1 text
<-- p2 text
FORM date_break.
CLEAR t_rg1_cons.
t_rg1_cons-chapid = m_chapid.
t_rg1_cons-cpudt = m_date.
t_rg1_cons-op_bal = tot_op_bal.
t_rg1_cons-qty_mfr = tot_qty_mnfr.
t_rg1_cons-total = tot_total_qty_mnfr.
t_rg1_cons-h_menge = tot_remv_home.
t_rg1_cons-h_value = tot_remv_hval.
t_rg1_cons-e_menge = tot_remv_expr.
t_rg1_cons-e_value = tot_remv_eval.
t_rg1_cons-e_menge_bond = tot_remv_expb.
t_rg1_cons-o_menge = tot_remv_othr.
t_rg1_cons-o_pur_menge = tot_remv_opur.
t_rg1_cons-bedamt = tot_duty_amt.
t_rg1_cons-cl_bal_fn = tot_cb_fr.
t_rg1_cons-cl_bal_bn = tot_cb_br.
t_rg1_cons-matform = m_matform.
t_rg1_cons-bedrate = m_bedrate.
APPEND t_rg1_cons.
tot_op_bal = 0.
tot_qty_mnfr = 0.
tot_total_qty_mnfr = 0.
tot_remv_home = 0.
tot_remv_hval = 0.
tot_remv_expr = 0.
tot_remv_eval = 0.
tot_remv_expb = 0.
tot_remv_othr = 0.
tot_remv_opur = 0.
tot_duty_amt = 0.
tot_cb_fr = 0.
tot_cb_br = 0.
m_date = t_rg1-cpudt.
m_matform = t_rg1-matform.
m_bedrate = t_rg1-bedrate.
ENDFORM. " DATE_BREAK
*& Form CHAPID_BREAK
text
--> p1 text
<-- p2 text
FORM chapid_break.
PERFORM date_break.
m_chapid = t_rg1-chapid.
ENDFORM. " CHAPID_BREAKhi rakesh,
in your first select single * statement you have given WHERE BUKRS = T001K-BUKRS..but at the point of execution, what will be the value stored in t001k-bukrs...i doubt it will be initial....so, store bukrs in a variable or hardcode it.....
in the second select, you hve not given any target work area for the into class...that's y your subrc is 4...specify a target area, where you want the data to be stored... -
Different selection in a single query according to an ID
Hi
I'm looking for a way to perform different selections in a single query according to a specific value:
Here is the first selection:
select g.*,gf.*,gs.*
FROM graphs g
LEFT JOIN graph_frames gf on g.graph_id = gf.graph_id
LEFT JOIN graph_sets gs on gf.frame_id = gs.frame_id
WHERE g.graph_id = :IDHere is the second selection:
SELECT gg.graph_id, gg.graph_name
FROM generic_graphs gg
INNER JOIN generic_graph_frames ggf on gg.graph_id = ggf.graph_id
INNER JOIN generic_graph_sets ggs on ggf.frame_id = ggs.frame_id
WHERE gg.graph_id = :IDNow, the ID cannot be in both the tables and I want to perform that in a single query, UNION cannot be applied since the tables are different.
Any ideas?
Edited by: BluShadow on 14-Sep-2011 09:09
added {noformat}{noformat} tags. Please read {message:id=9360002} and learn to do this yourself.Example of consolidating the columns...
SQL> ed
Wrote file afiedt.buf
1 with t as (select &id as id from dual)
2 select e.empno, e.ename, e.job, e.mgr, d.deptno, d.dname, d.loc
3 from (select * from emp cross join t where empno = t.id) e
4 full outer join
5 (select * from dept cross join t where deptno = t.id) d
6* on (1=1)
SQL> /
Enter value for id: 7521
old 1: with t as (select &id as id from dual)
new 1: with t as (select 7521 as id from dual)
EMPNO ENAME JOB MGR DEPTNO DNAME LOC
7521 WARD SALESMAN 7698
SQL> /
Enter value for id: 10
old 1: with t as (select &id as id from dual)
new 1: with t as (select 10 as id from dual)
EMPNO ENAME JOB MGR DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
SQL>Though, this would be considered poor design because you are trying to query two disperate things, so they should be treated differently. i.e. in my example, I should already know if I'm querying an employee or a department beforehand. -
Select top row in Single Query?
Hi
Can somebody help me to write a query to get the first row after order by clause using single query alone.
Example:
I can write following query to select first row
select * from (selec * from t order by col1) where rownum = 1;
But here I should not use inline view to get the result. Because my original requirement needs to use this query in select list and it needs to use a column (of a table from the FROM clause) in the where clause of inline query. Because there is restriction that we can not use the column (of a table from the FROM clause) more than one level of inline query.
Please help me.Raghav.786 wrote:
Hi
Can somebody help me to write a query to get the first row after order by clause using single query alone.
Example:
I can write following query to select first row
select * from (selec * from t order by col1) where rownum = 1;
But here I should not use inline view to get the result. Because my original requirement needs to use this query in select list and it needs to use a column (of a table from the FROM clause) in the where clause of inline query. Because there is restriction that we can not use the column (of a table from the FROM clause) more than one level of inline query.
Please help me.
What Oracle version are you?
If you have 12c you can use
select col1,...
from t
order by col1
fetch first 1 row only;
If less than 12c, you have can't do it without a subquery.
What are you actually trying to do? Read Re: 2. How do I ask a question on the forums?
and follow the advice there by giving example create table and insert sample data statements and
explaining clearly what you are trying to do. Then we can help more. -
Select single problem...
hi all,
i have to take first value of table BSIS according to condition. i m using select single statement in table BSIS, but problem is that i m getting the value only in header by which i m not able to apply loop at itab. can anyone please help me?
code.
SELECT single bukrs hkont gjahr monat shkzg prctr FROM bsis INTO itab
WHERE hkont IN hkont
AND bukrs IN bukrs
AND prctr IN prctr
AND gjahr IN gjahr
AND monat IN monat.
here sy-subrc is 0. but value is only in header.
regards saurabh.Hi Saurabh,
i don't know what your program does but if you process the data you retrieve from table bsis more than once, it may be useful to create your internal table identical to table bsis;
data: itab like bsis occurs 0 with header line.
then get all the data from table bsis to your internal table at once.
select * from bsis
into table itab.
then process itab with your selection criteria as you wish.
avoid using the statement ...into corresponding fields of table (i assume you already are not using this)
well i don't know what else you can do..
regards;
Murat Kaya
Maybe you are looking for
-
Macbook pro sporadically freezes when iTunes is open
When I open iTunes, even if I'm not playing or using it in any other way, my Macbook programs will freeze for 10 or so seconds every couple of minutes. It doesn't happen at regular intervals. I can move the mouse, but when it's hovering over programs
-
Payment terms---date and installments
hello SAP gurus, the issue is that we select payment terms when we create sales and order , and we want it to be printed under , 1st installment date and amount , 2nd installement date and amout , 3rd installemnt date and amount. we have defined the
-
My iphone4 stopped playing my downloaded music, how do i get it to play
My Iphone 4 has quit playing downloaded music, how do I get it to play again?
-
Can you please tell us which operating system you are running on and details of the camera producing the raw images (Make & Model). Each different camera model has it's own unique format of the raw file and so the camera raw has to be updated occasio
-
Hi, I'm using FCP 5.1.4 and I'm having a problem with the aspect ratio of the clips that were given to me. And pardon me in advance if some of what I write sounds silly, but I'm a beginner at FCP. I assumed that the clips were shot using the "Anamorp