How to group by below query?
Hi All,
I have below query,
SELECT username,firstname,lastname,country
FROM emp e1
WHERE EXISTS (
SELECT 1
FROM emp
WHERE e1.lastname = firstname
AND e1.firstname) = lastname )
OR EXISTS (
SELECT 1
FROM emp
WHERE lastname = e1.lastname
AND firstname) = e1.firstname )
and the result of the query is
USERNAME, FIRSTNAME, LASTNAME, COUNTRY
1, b6, a6, CH
2, a6, b6, CH
3, a1, b1, CH
4, b1, a1, CH
5, a2, b2, CH
6, a2, b2, CH
7, b1, a1, CH
8, b1, a1, CH
9, b2, a2, CH
10, b2, a2, CH
now i have to group all the firstname and lastname which are haviing values
1) a1,b1 and b1,a1
2) a2,b2 and b2,a2
3) a6,b6 and b6,a6
Can you please help me in this?
Thanks in advance.
Edited by: user9258447 on Jul 27, 2010 6:16 AM
Welcome to the forum!
select least (first_name, last_name)
, greatest (first_name, last_name)
, ctry
from test
group by least (first_name, last_name)
, greatest (first_name, last_name)
, ctryas in
SQL> with test as
2 (
3 select 1 username, 'b6' first_name, 'a6' last_name, 'CH' ctry from dual union all
4 select 2 username, 'a6' first_name, 'b6' last_name, 'CH' ctry from dual union all
5 select 3 username, 'a1' first_name, 'b1' last_name, 'CH' ctry from dual union all
6 select 4 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
7 select 5 username, 'a2' first_name, 'b2' last_name, 'CH' ctry from dual union all
8 select 6 username, 'a2' first_name, 'b2' last_name, 'CH' ctry from dual union all
9 select 7 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
10 select 8 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
11 select 9 username, 'b2' first_name, 'a2' last_name, 'CH' ctry from dual union all
12 select 1 username0, 'b2' first_name, 'a2' last_name, 'CH' ctry from dual
13 )
14 select least (first_name, last_name)
15 , greatest (first_name, last_name)
16 , ctry
17 from test
18 group by least (first_name, last_name)
19 , greatest (first_name, last_name)
20 , ctry
21 /
LE GR CT
a1 b1 CH
a2 b2 CH
a6 b6 CH
Similar Messages
-
How to tune the below query?is taking 1min 15 sec to process 16,34,300 reco
SELECT
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt);Do you have multiprocessor CPU .
if the value is greater then 3 then you can try with parallel processing
select value from v$parameter where name ='cpu_count' ;Try this :-
ALTER SESSION ENABLE PARALLEL QUERY
SELECT /*+ parallel (a) */
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit),
min(start_time_utc) ,
max(end_time_utc),
min(srt.activedt),
min(srt.inactivedt)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid(+)
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt)Cheers
Nawneet
Edited by: Nawneet_Aswal on Aug 2, 2010 4:48 AM -
How to write the below query with parameter and is null
Hi, I need to retrive the data if the parameter is passed on the field, else retrive all records whose field is null
Example
CREATE TABLE DEPT
(DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13) );
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS');
insert into dept values (30, 'SALES', 'CHICAGO');
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');
alter table dept add(object_id number);
insert into dept values (50, 'OPERATIONS', 'BOSTON',1);
insert into dept values (60, 'OPERATIONS', 'BOSTON',1);
INSERT INTO DEPT VALUES (70, 'OPERATIONS', 'BOSTON',2);
select * from dept where object_id =:p_object_id
If i pass the object_id as 1 , it shloud retrive the values of dept with object_id 1, but if i dont pass the object_id, it should retrive all the records whose object_id is null
IF 1 is passed, as object id , it should retrive, 50, 60, if 1 is not passed as object_id it should retive 10,20,30,40
It works fine for me seperately as,
select * from dept where object_id =:p_object_id -- 1
select * from dept where object_id is null;
Is this possible to do in single query.
ThanksSELECT *
FROM dept
WHERE object_id = :p_object_id
OR (object_id is null and :p_object_id is null)
is one approach. It's a bit verbose but the meaning is clear. If you can identify a value that would never appear in the data (-1 for example)
WHERE nvl( object_id, -1 ) = nvl(p_object_id, -1 );
Justin -
How many ways we can create authorization for user groups in sap query reports
Hi Gurus, I am getting a problem when I am assigning users to user group in sap query report .The users other than created in user groups are also able to add &change the users .So please suggest me how to restrict users outside of the user group.
Please send me if u have any suggestions and useful threads.
Thank You,
Suneel Kumar.I don't think it can be done. According to the link below 'Users who have authorization for the authorization object S_QUERY with both the values Change and Maintain, can access all queries of all user groups without being explicitly entered in each user group.'
http://help.sap.com/saphelp_46c/helpdata/en/d2/cb3f89455611d189710000e8322d00/content.htm
Although I think you can add code to your infoset and maybe restrict according to authority group, i.e.:
Use AUTHORITY-CHECK to restrict access to the database based on user.
Press F1 on AUTHORITY-CHECK to find out how to use it in the code -
How the below query is working
Hi,
I am newly joined in the group.
the emp table has 5 rows as below
100 ram 10000.00 10
200 kumar 15000.00 10
300 william 20000.00 10
400 ravi 25000.00 10
500 victor 30000.00 10
i execute the below query
select ename,sal from emp_test where case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end < 20000
it gives the below output
ram 10000.00
kumar 15000.00
How the above query is working?
Please explain. thanks in advanceIf you want it to show the changed salary, it has to be in the select line not the where:
select ename,
(case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end) sal from emp_test
where case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end < 20000 -
How to frame a SQL for the below Query
i have a SQL query
select x,y from table1 where x=1
output
x y
1 a
1 b
where a means alpha and b means beta
select x,z from table2 where x=1
Output
x z
1 B
How do i build a query to achieve a following output
x z y1 y2
1 b alpha beta
Please noete : Instead of 'a' and 'b' i want it to be replaced by words and
i want two rows value to appear in one column together....Maybe this is what you want ... I'm under the impression of trying to catch a moving target here.
WITH tb_clr_doc_version_defs AS (SELECT 'A' datatype_cd,
13 doctype_id
FROM dual
UNION
SELECT 'A' datatype_cd,
14 doctype_id
FROM dual
tb_clr_doc_field_defs AS (SELECT 'AccountNb_ID' fieldname_nm,
13 doctype_id
FROM dual
UNION
SELECT 'TaxIDNb_NO' fieldname_nm,
13 doctype_id
FROM dual
SELECT datatype,
MAX(DECODE(fieldname_nm, 'AccountNb_ID', fieldname_nm, NULL)) fieldname_nm1,
MAX(DECODE(fieldname_nm, 'TaxIDNb_NO' , fieldname_nm, NULL)) fieldname_nm2
FROM (SELECT t1.doctype_id,
DECODE(t1.datatype_cd, 'A', 'afp', 'L', 'line', 'M', 'mixed', t1.datatype_cd) datatype,
t2.fieldname_nm
FROM tb_clr_doc_version_defs t1,
tb_clr_doc_field_defs t2
WHERE t1.doctype_id = t2.doctype_id(+)
GROUP BY doctype_id, datatype
; -
How can I replace the cursor in the below query?
I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
DECLARE db_cursor_ava CURSOR
FOR
SELECT t.[agent-id],
t.[start-date],
t.[end-date],
t.[monitor-days],
t.[monitor-start],
t.[monitor-end],
t.[timezone-offset]
FROM @tmpAgentPeriodTimeRange t
OPEN db_cursor_ava
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE
FROM @tmpMonitorPeriod
DELETE
FROM @tmpFinalResult
SET @runID = 1
IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
BEGIN
SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
END
INSERT INTO @tmpMonitorPeriod
EXEC core.usp_GetMonitoringPeriod
@startDate = @stDateTime_ava,
@endDate = @endDateTime_ava,
@monitoringDays = @monDays_ava,
@monitoringStart = @monSt_ava,
@monitoringEnd = @monEnd_ava
SELECT @maxID = MAX(tm.id)
FROM @tmpMonitorPeriod tm
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
END
CLOSE db_cursor_ava
DEALLOCATE db_cursor_ava
mayooran99You've been down this path before - and the response is exactly the same.
how to replace cursor logic
And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach. Who knows
- but it appears you may have prematurely assumed that the cursor is the problem. -
How to use outer join condition in my below query.
Hi All,
How to use outer join condition in my below query.
In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records
in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
including other conditions.
I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
[code]SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
gc.CUSTOMER_ID,
gc.OMEGA_CUSTOMER_NUMBER,
CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
AS COMPANY_NAME,
goh.ORDER_STATUS,
goh.TOTAL_SELLING_PRICE,
goh.TOTAL_MARGIN,
ga1.ADDRESS1
|| ','
|| ga1.ADDRESS2
|| ','
|| ga1.ADDRESS3
|| ','
|| ga1.POSTAL_CODE
|| ','
|| ga1.CITY
AS SHIPPING_ADDRESS,
ga2.ADDRESS1
|| ','
|| ga2.ADDRESS2
|| ','
|| ga2.ADDRESS3
|| ','
|| ga2.POSTAL_CODE
|| ','
|| ga2.CITY
AS BILLING_ADDRESS,
ga.ADDRESS_ID,
gol.DESCRIPTION,
APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
AS OFFER_DATE,
gc.LEVEL_8,
goh.NO_OF_BUILDS,
gob.SFDC_ID,
goh.PURCHASE_ORDER_NO AS PO,
gc1.CUSTOMER_NAME AS END_USAGE,
gol.LOB,
goh.TOTAL_MARGIN_PCT,
goh.TOTAL_DISCOUNT,
goh.TOTAL_DISCOUNT_PCT
FROM APPS_JP.GEDIS_OFFER_HEADER goh,
APPS_JP.GEDIS_ORDER_BUILDS gob,
APPS_JP.GEDIS_ORDER_LINES gol,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
APPS_JP.GEDIS_CUSTOMER gc,
APPS_JP.GEDIS_CUSTOMER gc1,
APPS_JP.GEDIS_CONTACT gct,
APPS_JP.GEDIS_ADDRESS ga,
APPS_JP.GEDIS_ADDRESS_NORM ga1,
APPS_JP.GEDIS_ADDRESS_NORM ga2,
(SELECT DISTINCT SALESPERSON_ID, USER_NAME
FROM APPS_JP.GEDIS_SALESPERSON
WHERE SALESPERSON_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
FROM TABLE (APPS_GLOBAL.SplitString ('337309'))))
gsp
WHERE goh.ORDER_NO <> 0
AND goh.OFFER_NO <> 0
AND goh.OFFER_NO=gol.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
AND goh.OFFER_NO=gob.OFFER_NO
AND gob.BUILD_NO = 1
AND goh.OFFER_NO = gorc.OFFER_NO
AND gct.CONTACT_ID = gorc.CONTACT_ID
AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
AND ga.PRIMARY = 'Y'
AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
AND goh.OFFER_NO = ship.OFFER_NO
AND ship.RELATION_TYPE = 'SHIP'
AND ga1.ADDRESS_ID = ship.ADDRESS_ID
AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
AND goh.OFFER_NO = bill.OFFER_NO
AND bill.RELATION_TYPE = 'BILL'
AND ga2.ADDRESS_ID = bill.ADDRESS_ID
AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
SYSDATE - 30
AND APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
AND gorc.RELATION_TYPE = 'BASE'
AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
AND gc.SALES_CHANNEL = 'SMB'
AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
ORDER BY goh.OFFER_NO;[/code]
Please help me how to use this outer join condition.
Thanks in advance.Hi,
If you want all the rows from goh, then you don't want any conditions like goh.OFFER_NO <> 0.
Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
FROM APPS_JP.GEDIS_OFFER_HEADER goh
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_BUILDS gob ON gob.OFFER_NO = goh.OFFER_NO
AND gob.BUILD_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_LINES gol ON gol.OFFER_NO = goh.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
gorc ...
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, do you really need all those tables to show what the problem is? Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ https://forums.oracle.com/message/9362002#9362002 -
how to add docentry with some num.?
can you solve below query
Declare @a as Numeric
SET @a=14900000;
SELECT (@a+($[@MAINTDCHEAD.DocEntry])as 'series no'Hi,
Yes possible.
Try this:
Declare @a as INT
SET @a=14900000;
SELECT (@a+($[ORDR.DocEntry]))
Thanks & Regards,
Nagarajan -
How to execute the output of the below query automatically
Hi All,
I want to execute the output of the below query automatically, instead of manually copying it and execute.
select 'alter database ['+name+'] set recovery simple' from master.sys.databases where database_id > 4 and state_desc = 'online'
Please provide me a script to do this.
ThanK
KateEXEC sp_MSforeachdb N'ALTER DATABASE [?] SET recovery simple';--- This will set the recovery model for all the system database.The query provided by Vikash16, meets my requirement. Thank you.
-
How i can add document nu in below query
i want to add one field in below query
field is bkpf-xblnr
i want document number after d_text.
here d_text = 'Payment for'
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'D_TEXT'.
tab_out-value = d_text.
MODIFY tab_out INDEX sy-tabix.
please help
thanks in advanced.hi help yar i m totaly new for this
i m pasting whole code here just see yar and where u changing please hight light that things
thanks yar
PROGRAM zfisp0001.
*& Subroutine pool ZFISP0001 *
*& Author: Rakesh Rao on 01.04.05 *
*& Modified by: Rakesh Rao on 15.07.2005 *
*& Description: This subroutine pool is called from Check and Payment *
*& Advice SAPScripts *
TABLES: itcsy.
TYPES: BEGIN OF t_itcsy.
INCLUDE STRUCTURE itcsy.
TYPES: END OF t_itcsy.
DATA: tab_in TYPE STANDARD TABLE OF t_itcsy WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 0.
DATA: tab_out TYPE STANDARD TABLE OF t_itcsy WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 0.
DATA: d_count(3) VALUE 0,
d_netamt_tot TYPE p DECIMALS 2,
d_tdsamt_tot TYPE p DECIMALS 2,
d_grossamt_tot TYPE p DECIMALS 2,
d_tdsamt TYPE p DECIMALS 2.
DATA flag.
DATA: bschl LIKE bseg-bschl.
DATA: shkzg LIKE bseg-shkzg.
clear: d_count,d_netamt_tot.
*& Form ZPAYMENT
text
--> p1 text
<-- p2 text
FORM zpayment TABLES tab_in STRUCTURE itcsy
tab_out STRUCTURE itcsy.
tables : bsak.
TYPES: imis_type_c20(20) TYPE c,
imis_type_c10(10) TYPE c.
DATA: l_intern TYPE imis_type_c20.
DATA: e_intern TYPE imis_type_c10.
DATA: i_extern TYPE imis_type_c10.
DATA: d_belnr(10),
D_VBLNR(10),
d_bukrs TYPE bseg-bukrs,
d_gjahr TYPE bseg-gjahr,
d_gjahr1 TYPE bseg-gjahr, " 15.07.2005 Rakesh
d_buzei TYPE bseg-buzei,
d_augbl TYPE bseg-augbl,
d_umskz TYPE bseg-umskz,
d_bschl TYPE bseg-bschl,
d_bktxt TYPE bkpf-bktxt,
d_budat(10),
d_rebzg TYPE bseg-rebzg,
D_SHKZG TYPE REGUP-SHKZG,
d_swnes TYPE regud-swnes,
d_netamt TYPE p DECIMALS 2,
d_tdsamt TYPE p DECIMALS 2,
d_discamt TYPE regud-wskto,
d_gross TYPE regud-wrbtr.
DATA: BEGIN OF t_bkpf,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
budat TYPE bkpf-budat,
bktxt TYPE bkpf-bktxt,
xblnr TYPE bkpf-xblnr,
END OF t_bkpf.
DATA: BEGIN OF t_bseg,
bukrs TYPE bseg-bukrs,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
umskz TYPE bseg-umskz,
bschl TYPE bseg-bschl,
qbshb TYPE bseg-qbshb,
augbl TYPE bseg-augbl,
rebzg TYPE bseg-rebzg,
rebzj TYPE bseg-rebzj,
sgtxt TYPE bseg-sgtxt,
xref1 TYPE bseg-xref1,
ebeln TYPE bseg-ebeln,
shkzg type bseg-shkzg,
END OF t_bseg.
DATA: num VALUE ' ',
d_result VALUE ' '.
DATA: d_symbol VALUE '/',
d_text(11) VALUE 'Payment for'.
DATA: d_belnr1 LIKE bseg-belnr.
DATA: wa_payrq TYPE payrq. " 15.07.2005 Rakesh
18.05.2006
data : wa_belnr like bseg-belnr,wa_augbl like bseg-augbl.
18.05.2006
06.09.2006
data : d_other type p decimals 2.
Read incoming data
*break-point.
*zpayment.
CLEAR: d_belnr,d_bukrs,d_gjahr,d_result.
clear d_tdsamt.
Company code
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BUKRS'.
d_bukrs = tab_in-value.
Document number
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BELNR'.
wa_belnr = d_belnr(10) = tab_in-value(10).
Posting Key
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BSCHL'.
d_bschl = tab_in-value.
Special G/L Indicator
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-UMSKZ'.
d_umskz = tab_in-value.
Fiscal year
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-GJAHR'.
d_gjahr = tab_in-value.
<-- 15.07.2005 Rakesh
Fiscal year1 - For Payment request case
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-GJAHR'.
d_gjahr1 = tab_in-value.
15.07.2005 Rakesh -->
Document item
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BUZEI'.
d_buzei = tab_in-value.
Discount amount, if any
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-WSKTO'.
REPLACE ALL OCCURRENCES OF ',' IN tab_in-value WITH ' '.
d_discamt = tab_in-value.
Gross Amount
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-WRBTR'.
REPLACE ALL OCCURRENCES OF ',' IN tab_in-value WITH ' '.
d_gross = tab_in-value.
Gross Amount
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-WNETT'.
REPLACE ALL OCCURRENCES OF ',' IN tab_in-value WITH ' '.
d_netamt = tab_in-value.
Clearing document 18.05.2006
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
wa_augbl = tab_in-value.
DEBIT/CREDIT INDICATOR
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-SHKZG'.
d_SHKZG = tab_in-value(1).
IF d_netamt < 0 AND D_SHKZG = 'S'.
D_NETAMT = D_NETAMT * '-1'.
ENDIF.
Check document no. is clearing document than reset wnett = 0.
18.05.2006
select single * from bsak where augbl = wa_augbl
and bukrs = d_bukrs and gjahr = d_gjahr1.
if sy-subrc = 0 and wa_belnr = wa_augbl.
d_netamt = 0.
endif.
18.05.2006
Check if Down payment request
IF d_bschl = '39'.
This line item is not considered
d_result = 'X'.
ELSE.
Check if Down payment
IF d_bschl = '29'
and wa_augbl = wa_belnr. "18.05.2006
IF d_umskz EQ 'A'
OR d_umskz EQ 'B'
OR d_umskz EQ 'I'
OR d_umskz EQ 'M'
OR d_umskz EQ 'D'.
Put Document Number of the Payment Document value to 'd_belnr'
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
ENDIF.
ENDIF.
<--15.07.2005 Rakesh
Check if Payment request exists in 'payrq'
CLEAR wa_payrq.
Convert 'd_belnr' to 10 digits,if required
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
d_belnr1 = d_belnr.
CLEAR d_belnr.
d_belnr = e_intern.
SELECT SINGLE keyno augbl FROM payrq
INTO CORRESPONDING FIELDS OF wa_payrq
WHERE keyno = d_belnr.
IF sy-subrc = 0. " Yes
Take clearing document which is the required accounting document
d_belnr = wa_payrq-augbl.
Convert 'd_belnr' to 10 digits,if required
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
CLEAR d_belnr.
d_belnr = e_intern.
Assign 'd_gjahr1' to 'd_gjahr' as this is relevant here.
d_gjahr = d_gjahr1. " 15.07.2005 Rakesh
Get BSEG data
SELECT SINGLE bukrs belnr gjahr buzei augbl rebzg rebzj
sgtxt qbshb umskz bschl xref1 ebeln
FROM bseg INTO CORRESPONDING FIELDS OF t_bseg
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr
AND buzei EQ d_buzei " not relevant
AND bschl EQ '25' " Posting key - Outgoing payment
AND koart EQ 'S' " G/L accounts
AND shkzg EQ 'S'. " Debit
ELSE. " No
For all other cases, we use this final logic, even though we have
taken d_belnr value from accounting doc no., in some earlier cases.
Put document number of the payment document(vblnr) value to 'd_belnr',
IF d_bschl = '29'
and wa_augbl <> wa_belnr. "18.05.2006
IF d_umskz EQ 'A'
OR d_umskz EQ 'B'
OR d_umskz EQ 'I'
OR d_umskz EQ 'M'
OR d_umskz EQ 'D'.
else.
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
endif.
else.
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
endif.
-->15.07.2005
Convert 'd_belnr' to 10 digits,if required
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
CLEAR d_belnr.
d_belnr = e_intern.
Get BSEG data
SELECT SINGLE bukrs belnr gjahr buzei augbl rebzg rebzj
sgtxt qbshb umskz bschl xref1 ebeln shkzg
FROM bseg INTO CORRESPONDING FIELDS OF t_bseg
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr1
"changed by Bharat 15.04.2006 - d_gjahr1 contains payment doc fiscal yea
"r and d_gjahr contains invoice fiscal year
AND buzei EQ d_buzei "amisha 10-10-2005
AND bschl EQ '25' " Posting key - Outgoing payment
AND shkzg EQ 'S' "added by Bharat 17.04.2006
AND ( koart EQ 'K' OR koart EQ 'D').
<--15.07.2005 Rakesh
18.05.2006
in clearing document payment advice not consider TDS amount of
payment document
if wa_belnr <> wa_augbl and d_shkzg = 'S'.
t_bseg-qbshb = t_bseg-qbshb * '-1'.
d_netamt = d_netamt + t_bseg-qbshb.
t_bseg-qbshb = 0.
endif.
18.05.2006
ENDIF.
-->15.07.2005
Get corresponding BKPF data
If Down payment
IF d_bschl = '29'.
IF d_umskz EQ 'A'
OR d_umskz EQ 'B'
OR d_umskz EQ 'I'
OR d_umskz EQ 'M'
OR d_umskz EQ 'D'.
SELECT SINGLE bukrs belnr gjahr budat bktxt xblnr
FROM bkpf INTO CORRESPONDING FIELDS OF t_bkpf
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr1.
"changed by Bharat 15.04.2006 - d_gjahr1 contains payment doc fiscal yea
"r and d_gjahr contains invoice fiscal year
ENDIF.
ELSE.
If Partial payment/On-account payment
IF t_bseg-augbl IS INITIAL.
On-Account case
IF t_bseg-augbl IS INITIAL.
IF t_bseg-rebzg IS INITIAL.
t_bseg-rebzg = t_bseg-belnr. " Payment Document Number
t_bseg-rebzj = t_bseg-gjahr. " Fiscal year
ENDIF.
ENDIF.
SELECT SINGLE bukrs belnr gjahr budat bktxt xblnr
FROM bkpf INTO CORRESPONDING FIELDS OF t_bkpf
WHERE bukrs EQ t_bseg-bukrs
AND belnr EQ t_bseg-rebzg
AND gjahr EQ t_bseg-rebzj.
ELSE.
FULL PAYMENT with Discount
clear d_tdsamt.
Following code added for GSPL by bharat06092006
if d_bukrs eq 'GSPL'.
DATA : V_TEXT(20) TYPE C.
V_TEXT = 'W%'.
SELECT SINGLE wrbtr FROM bseg
INTO d_tdsamt
WHERE bukrs EQ d_bukrs AND
belnr EQ d_belnr1 AND
gjahr EQ d_gjahr AND " Added by bharat on 10-04-2006 fiscal year
bschl EQ '50' AND
KTOSL EQ 'WIT' AND
QSSKZ NOT LIKE V_TEXT.
SELECT single wrbtr FROM bseg
INTO d_other
WHERE bukrs EQ d_bukrs AND
belnr EQ d_belnr1 AND
gjahr EQ d_gjahr AND " Added by bharat on 10-04-2006 fiscal year
bschl EQ '50' AND
KTOSL EQ 'WIT' AND
QSSKZ LIKE V_TEXT.
ELSE.
Added by bharat 06.09.2006
SELECT SINGLE wrbtr
FROM bseg INTO d_tdsamt
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr1
AND gjahr EQ d_gjahr
" Added by bharat on 10-04-2006 fiscal year
AND bschl EQ '50' AND KTOSL EQ 'WIT'.
ENDIF.
SELECT SINGLE bukrs belnr gjahr budat bktxt xblnr
FROM bkpf INTO CORRESPONDING FIELDS OF t_bkpf
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr1.
"changed by Bharat 15.04.2006 - d_gjahr1 contains payment doc fiscal yea
"r and d_gjahr contains invoice fiscal year
tab_in-value
*d_tdsamt_tot
ENDIF.
ENDIF.
IF sy-subrc = 0.
Sr. no. for Line items
d_count = d_count + 1.
ELSE.
Else, this line item is not considered
d_result = 'X'.
ENDIF.
ENDIF. " if d_bschl = '39'
Pass the output to the outgoing table 'tab_out', if 'd_result' is not
*set.
IF d_result = ' '.
Line count
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'COUNT'.
tab_out-value = d_count.
MODIFY tab_out INDEX sy-tabix.
Result flag
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'RESULT1'.
tab_out-value = d_result.
MODIFY tab_out INDEX sy-tabix.
Clearing document
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'AUGBL'.
tab_out-value = t_bseg-augbl.
MODIFY tab_out INDEX sy-tabix.
IF d_bschl <> '29'.
On-Account case
IF t_bseg-augbl IS INITIAL.
IF t_bseg-rebzg IS INITIAL.
t_bseg-rebzg = t_bseg-belnr. " Payment Document Number
ENDIF.
ENDIF.
ELSE.
Payment document request
IF NOT t_bseg-ebeln IS INITIAL. " First preference
t_bseg-rebzg = t_bseg-ebeln.
ELSE.
t_bseg-rebzg = d_belnr.
ENDIF.
ENDIF.
Number of the Invoice the Transaction Belongs to
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'REBZG'.
SHIFT t_bseg-rebzg LEFT DELETING LEADING num.
tab_out-value = t_bseg-rebzg.
MODIFY tab_out INDEX sy-tabix.
Document number - check use??
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'BELNR'.
tab_out-value = d_belnr. " check!!
MODIFY tab_out INDEX sy-tabix.
Net amount
d_netamt = d_gross - d_discamt - t_bseg-qbshb.
Gross amount
d_gross = d_netamt + d_tdsamt + t_bseg-qbshb.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'NETAMT'.
tab_out-value = d_netamt.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
TDS Amount
IF t_bseg-qbshb IS INITIAL.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'TDSAMT'.
tab_out-value = d_tdsamt.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
Added by bharat 06.09.2006
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'D_OTHER'.
tab_out-value = d_other.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
Added by bharat 06.09.2006
ELSE.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'TDSAMT'.
tab_out-value = t_bseg-qbshb.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
ENDIF.
*Calculate Total Net amount & TDS amount which is stored in Global
*memory and accessed later
from 'FORM Z_TOTAL_AMT'
d_netamt_tot = d_netamt_tot + d_netamt.
d_grossamt_tot = d_grossamt_tot + d_gross.
d_tdsamt_tot = d_tdsamt_tot + t_bseg-qbshb + d_tdsamt + d_other.
CLEAR: tab_OUT-value,tab_out-name.
READ TABLE tab_OUT WITH KEY 'NETAMT_TOT'.
tab_out-value = d_netamt_tot.
shift tab_out-value left deleting leading space.
MODIFY tab_out INDEX sy-tabix.
Document Header text
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'BKTXT'.
IF d_bschl = '29'.
tab_out-value = t_bseg-sgtxt. " for down payment request
ELSE.
tab_out-value = t_bkpf-bktxt.
ENDIF.
MODIFY tab_out INDEX sy-tabix.
Reference Document Number - Header
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'XBLNR'.
IF d_bschl = '29'.
tab_out-value = t_bseg-xref1. " for down payment request
ELSE.
tab_out-value = t_bkpf-xblnr.
ENDIF.
MODIFY tab_out INDEX sy-tabix.
Symbol '/'
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'D_SYMBOL'.
tab_out-value = d_symbol.
MODIFY tab_out INDEX sy-tabix.
Text 'Payment for'
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'D_TEXT'.
tab_out-value = d_text.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'D_TEXT'.
tab_out-value = d_text.
tab_out-xblnr = t_bkpf-xblnr.
MODIFY tab_out by bkpf-xblnr INDEX sy-tabix.
Posting date
CLEAR d_budat.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = t_bkpf-budat
IMPORTING
date_external = d_budat
EXCEPTIONS
date_internal_is_invalid = 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.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'BUDAT'.
tab_out-value = d_budat.
MODIFY tab_out INDEX sy-tabix.
ELSE.
Result flag
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'RESULT1'.
tab_out-value = d_result.
MODIFY tab_out INDEX sy-tabix.
ENDIF.
d_gross = d_netamt + d_tdsamt + t_bseg-qbshb.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'GROSSAMT'.
tab_out-value = d_gross.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
ENDFORM. " ZPAYMENT
*& Form zamtwords
text - If only 'Net Amount' is required
--> p1 text
<-- p2 text
FORM zamtwords TABLES tab_in STRUCTURE itcsy
tab_out STRUCTURE itcsy.
DATA: d_swnet TYPE regud-swnes, " take character format type
d_swnet1 TYPE bseg-dmbtr.
d_words(160),
d_words1(80),
d_words2(80).
<-- 21.05.2005
DATA: d_words(160),
d_words1(80) TYPE c,
d_words2(80) TYPE c.
DATA: len TYPE i.
<-- 21.05.2005
*zamtwords
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-SWNET'.
d_swnet = tab_in-value.
REPLACE ALL OCCURRENCES OF '*' IN d_swnes WITH ' '.
REPLACE ALL OCCURRENCES OF ',' IN d_swnet WITH ' '.
d_swnet1 = d_swnet.
CLEAR d_swnet.
PERFORM z_conv_amt USING d_swnet1 CHANGING d_swnet.
Return 'SWNET1' without commas
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'SWNET1'.
d_swnet = d_swnet1.
tab_out-value = d_swnet.
MODIFY tab_out INDEX sy-tabix.
Amount in Indian currency format
CALL FUNCTION 'Z_SPELL_AMOUNT_INR'
EXPORTING
amount = d_swnet1
IMPORTING
rupees_str = d_words.
Adjust 'd_words' left aligned
SHIFT d_words LEFT DELETING LEADING space.
<-- 21.05.2005
Split 'd_words' into 'd_words1' and 'd_words2'
since 'DEFINE' in SAPScript displays maximum 80 characters
d_words1 = d_words(80).
d_words2 = d_words+80(80).
*CALL FUNCTION 'C147_STRING_SPLIT_AT_POSITION'
EXPORTING
i_string = d_words
i_position = 80
IMPORTING
E_HEAD = d_words1
E_TAIL = d_words2.
len = STRLEN( d_words ).
Only 80 characters can be passed to one SAPScript symbol
Split 'd_words' into 'd_words1' and 'd_words2'
since 'DEFINE' in SAPScript displays maximum 80 characters
Check if string split is required
IF len > 80.
d_words1 = d_words(80). " First 80
d_words2 = d_words+80(80). " Next 80
Introduce an initial space in 'd_words2' if 80th character in
'd_words1' is space, as this space is not considered when 'd_words1'
value is passed to the SAPScript, since we need proper spacing
between 'd_words1' and 'd_words2' in the Cheque layout.
IF d_words1+79(1) = ' '.
SHIFT d_words2 RIGHT BY 1 PLACES.
ENDIF.
ELSE.
d_words1 = d_words.
d_words2 = space.
ENDIF.
21.05.2005 -->
Amount in words1
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'WORDS'.
tab_out-value = d_words1.
MODIFY tab_out INDEX sy-tabix.
Amount in words2
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'WORDS1'.
tab_out-value = d_words2.
MODIFY tab_out INDEX sy-tabix.
ENDFORM. " zamtwords
*& Form z_address
text
--> p1 text
<-- p2 text
FORM z_address TABLES tab_in STRUCTURE itcsy
tab_out STRUCTURE itcsy.
DATA d_bukrs TYPE bseg-bukrs.
DATA: t_t001 TYPE t001,
t_adrc TYPE adrc.
CLEAR: tab_in-value,t_t001,t_adrc.
READ TABLE tab_in WITH KEY 'REGUP-BUKRS'.
d_bukrs = tab_in-value.
CALL FUNCTION 'K_READ_T001'
EXPORTING
i_bukrs = d_bukrs
IMPORTING
e_t001 = t_t001
EXCEPTIONS
not_found = 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.
ELSE.
CALL FUNCTION 'RTP_US_DB_ADRC_READ'
EXPORTING
i_address_number = t_t001-adrnr
I_NATION = ' '
I_READ_DB =
IMPORTING
e_adrc = t_adrc
EXCEPTIONS
not_found = 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.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'ADRC-NAME1'.
tab_out-value = t_adrc-name1.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'ADRC-STREET'.
tab_out-value = t_adrc-street.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'ADRC-CITY1'.
tab_out-value = t_adrc-city1.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'ADRC-POST_CODE1'.
tab_out-value = t_adrc-post_code1.
MODIFY tab_out INDEX sy-tabix.
ENDIF.
ENDFORM. " z_address
*& Form z_total_amt
text
--> p1 text
<-- p2 text
FORM z_total_amt TABLES tab_in STRUCTURE itcsy
tab_out STRUCTURE itcsy.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'NETAMT_TOT'.
tab_out-value = d_netamt_tot.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'TDSAMT_TOT'.
tab_out-value = d_tdsamt_tot.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'GROSSAMT_TOT'.
tab_out-value = d_grossamt_tot.
SHIFT tab_out-value LEFT DELETING LEADING space.
MODIFY tab_out INDEX sy-tabix.
ENDFORM. " z_total_amt
*& Form Z_NET_AMT
text
-->TAB_IN text
-->TAB_OUT text
FORM z_net_amt TABLES tab_in STRUCTURE itcsy
tab_out STRUCTURE itcsy.
TYPES: imis_type_c20(20) TYPE c,
imis_type_c10(10) TYPE c.
DATA: l_intern TYPE imis_type_c20.
DATA: e_intern TYPE imis_type_c10.
DATA: i_extern TYPE imis_type_c10.
DATA: d_belnr(10),
d_bukrs TYPE bseg-bukrs,
d_gjahr TYPE bseg-gjahr,
d_umskz TYPE bseg-umskz,
d_bschl TYPE bseg-bschl,
d_dmbtr1 TYPE bseg-dmbtr,
d_dmbtr(17). "prb16052006
d_dmbtr1 like regud-swnes. "prb16052006
DATA d_amt TYPE char18.
DATA: BEGIN OF t_bseg OCCURS 10,
bukrs TYPE bseg-bukrs,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
dmbtr TYPE bseg-dmbtr,
wrbtr TYPE bseg-wrbtr,
umskz TYPE bseg-umskz,
bschl TYPE bseg-bschl,
qbshb TYPE bseg-qbshb,
NEbtR TYPE BSEG-nebtr, "prb13052006
END OF t_bseg.
<-- 21.05.2005
DATA: d_words(160),
d_words1(80) TYPE c,
d_words2(80) TYPE c.
DATA: len TYPE i.
<-- 21.05.2005
DATA wa_payrq TYPE payrq. " 15.07.2005 Rakesh
Read incoming data
CLEAR: d_belnr,d_bukrs,d_gjahr.
Company code
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BUKRS'.
d_bukrs = tab_in-value.
Document number
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BELNR'.
d_belnr(10) = tab_in-value(10).
Posting Key
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-BSCHL'.
d_bschl = tab_in-value.
Special G/L Indicator
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-UMSKZ'.
d_umskz = tab_in-value.
Fiscal Year
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-GJAHR'. " Note
CHECK sy-subrc = 0.
d_gjahr = tab_in-value.
Check if Down payment
IF d_bschl = '29'.
IF d_umskz EQ 'A'
OR d_umskz EQ 'B'
OR d_umskz EQ 'I'
OR d_umskz EQ 'M'
OR d_umskz EQ 'D'.
Put Document Number of the Payment Document value to 'd_belnr'
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
ENDIF.
ENDIF.
Check if Down payment request
IF d_bschl = '39'.
Put Document Number of the Payment Document value to 'd_belnr'
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
ENDIF.
<--15.07.2005 Rakesh
Check if Payment request exists in 'payrq'
CLEAR wa_payrq.
Convert 'd_belnr' to 10 digits,if required
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
CLEAR d_belnr.
d_belnr = e_intern.
SELECT SINGLE keyno augbl FROM payrq
INTO CORRESPONDING FIELDS OF wa_payrq
WHERE keyno = d_belnr.
IF sy-subrc = 0. " Yes
Take clearing document which is the required accounting document
d_belnr = wa_payrq-augbl.
Convert 'd_belnr' to 10 digits,if required
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
CLEAR d_belnr.
d_belnr = e_intern.
Get BSEG data
SELECT bukrs belnr gjahr buzei augbl rebzg rebzj sgtxt dmbtr wrbtr
qbshb nebtr
FROM bseg INTO CORRESPONDING FIELDS OF TABLE t_bseg
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr
AND buzei EQ d_buzei
AND bschl EQ '25'
AND koart EQ 'S' " G/L accounts
AND shkzg EQ 'S'. " Debit
ELSE. " No
For all other cases, we use this final logic, even though we have
taken d_belnr value from accounting doc no., in some earlier cases.
Put document number of the payment document(vblnr) value to 'd_belnr',
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUP-VBLNR'.
d_belnr = tab_in-value.
-->15.07.2005
Convert 'd_belnr' to 10 digits.
CLEAR: l_intern,e_intern.
CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD d_belnr
ID 'OUTPUT' FIELD l_intern.
e_intern = l_intern+10.
CLEAR d_belnr.
d_belnr = e_intern.
*BSEG - PARTIAL PAYMT/FULL PAYMT WT DISC - Get Total Amount without Bank
*charges
SELECT bukrs belnr gjahr buzei augbl rebzg rebzj sgtxt dmbtr wrbtr
qbshb bschl NEBTR
FROM bseg INTO CORRESPONDING FIELDS OF TABLE t_bseg
WHERE bukrs EQ d_bukrs
AND belnr EQ d_belnr
AND gjahr EQ d_gjahr
AND buzei EQ d_buzei
AND bschl EQ '25'
AND ( koart EQ 'K' OR koart EQ 'D' ).
<--15.07.2005 Rakesh
ENDIF.
-->20.10.2005 By Yogesh.
CLEAR d_dmbtr.
IF sy-subrc = 0.
LOOP AT t_bseg.
d_dmbtr = d_dmbtr + t_bseg-dmbtr - t_bseg-qbshb.
SELECT SINGLE shkzg INTO (shkzg) FROM tbsl
WHERE bschl = t_bseg-bschl.
*BREAK-POINT.
*******prb13052
IF shkzg = 'S'.
d_dmbtr = d_dmbtr + t_bseg-wrbtr - t_bseg-qbshb.
ELSEIF shkzg = 'H'.
d_dmbtr = d_dmbtr - t_bseg-wrbtr - t_bseg-qbshb.
ENDIF.
IF shkzg = 'S'.
d_dmbtr = d_dmbtr + t_bseg-nebtr." - t_bseg-qbshb.
ELSEIF shkzg = 'H'.
if t_bseg-nebtr <> ''.
d_dmbtr = d_dmbtr - t_bseg-nebtr." - t_bseg-qbshb.
else.
d_dmbtr = d_dmbtr - t_bseg-wrbtr." - t_bseg-qbshb.
endif.
ENDIF.
*tables: reguh, payr.
select single * from reguh where zbukr = d_bukrs
and vblnr = d_belnr
and LAUFD+6(4) = d_gjahr.
*select single * from payr where zbukr = d_bukrs
*and vblnr = d_belnr
*and hbkid = reguh-hbkid
*and hktid = reguh-hktid.
*d_dmbtr = payr-rwbtr.
*if d_dmbtr < 0.
*d_dmbtr = d_dmbtr * ( -1 ).
*endif.
CLEAR tab_in-value.
READ TABLE tab_in WITH KEY 'REGUD-SWNES'.
d_DMBTR = tab_in-value.
translate d_dmbtr using '* '.
translate d_dmbtr using ', '.
condense d_dmbtr no-gaps.
d_dmbtr1 = d_dmbtr.
*******prb13052
ENDLOOP.
PERFORM z_conv_amt USING d_dmbtr CHANGING d_amt.
*Pass the Net Amount output to the outgoing table tab_out-name =
*'NETAMT_TOT'.
CLEAR: tab_out-value,tab_out-name.
READ TABLE tab_out WITH KEY 'NETAMT_TOT'.
tab_out-value = d_amt.
" For inserting '*' ahead of value
SHIFT tab_out-value LEFT DELETING LEADING space. """"????IMP
MODIFY tab_out INDEX sy-tabix.
Get the Amount in words for Indian currency
Can also use the FM 'HR_IN_CHG_INR_WRDS'
CALL FUNCTION 'Z_SPELL_AMOUNT_INR'
EXPORTING
amount = d_dmbtr1
IMPORTING
rupees_str = d_words.
Shift left since above Function Module introduces an initial space
SHIFT d_words LEFT DELETING LEADING space.
<-- 21.05.2005
*CALL FUNCTION 'C147_STRING_SPLIT_AT_POSITION'
EXPORTING
i_string = d_words
i_position = 80
IMPORTING
E_HEAD = d_words1
E_TAIL = d_words2.
len = STRLEN( d_words ).
Only 80 characters can be passed to one SAPScript symbol
Split 'd_words' into 'd_words1' and 'd_words2'
since 'DEFINE' in SAPScript displays maximum 80 charact -
How I can change this query, so I can display the name and scores in one r
How I can change this query, so I can add the ID from the table SPRIDEN
as of now is giving me what I want:
1,543 A05 24 A01 24 BAC 24 BAE 24 A02 20 BAM 20in one line but I would like to add the id and name that are stored in the table SPRIDEN
SELECT sortest_pidm,
max(decode(rn,1,sortest_tesc_code)) tesc_code1,
max(decode(rn,1,score)) score1,
max(decode(rn,2,sortest_tesc_code)) tesc_code2,
max(decode(rn,2,score)) score2,
max(decode(rn,3,sortest_tesc_code)) tesc_code3,
max(decode(rn,3,score)) score3,
max(decode(rn,4,sortest_tesc_code)) tesc_code4,
max(decode(rn,4,score)) score4,
max(decode(rn,5,sortest_tesc_code)) tesc_code5,
max(decode(rn,5,score)) score5,
max(decode(rn,6,sortest_tesc_code)) tesc_code6,
max(decode(rn,6,score)) score6
FROM (select sortest_pidm,
sortest_tesc_code,
score,
row_number() over (partition by sortest_pidm order by score desc) rn
FROM (select sortest_pidm,
sortest_tesc_code,
max(sortest_test_score) score
from sortest,SPRIDEN
where
SPRIDEN_pidm =SORTEST_PIDM
AND sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
and sortest_pidm is not null
GROUP BY sortest_pidm, sortest_tesc_code))
GROUP BY sortest_pidm;
Hi,
That depends on whether spriden_pidm is unique, and on what you want for results.
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
Either way, explain how you get those results from that data.
Always say which version of Oracle you're using.
It looks like you're doing something similiar to the following.
Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
DEPTNO DNAME LOC JOB_1 SAL_1 JOB_2 SAL_2 JOB_3 SAL_3
20 RESEARCH DALLAS ANALYST 3000 MANAGER 2975 CLERK 1100
10 ACCOUNTING NEW YORK MANAGER 2450 CLERK 1300
30 SALES CHICAGO MANAGER 2850 CLERK 950On each row, the jobs are listed in order by the highest salary.
This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
SELECT deptno
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT deptno
, job
, max_sal
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY max_sal DESC
) AS rn
FROM (
SELECT e.deptno
, e.job
, MAX (e.sal) AS max_sal
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno
, e.job
GROUP BY deptno
;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
SELECT deptno, dname, loc -- Changed
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT deptno, dname, loc -- Changed
, job
, max_sal
, ROW_NUMBER () OVER ( PARTITION BY deptno -- , dname, loc -- Changed
ORDER BY max_sal DESC
) AS rn
FROM (
SELECT e.deptno, d.dname, d.loc -- Changed
, e.job
, MAX (e.sal) AS max_sal
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno, d.dname, d.loc -- Changed
, e.job
GROUP BY deptno, dname, loc -- Changed
;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
SELECT deptno, dname, loc
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT e.deptno, d.dname, d.loc
, e.job
, MAX (e.sal) AS max_sal
, ROW_NUMBER () OVER ( PARTITION BY e.deptno
ORDER BY MAX (sal) DESC
) AS rn
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno, d.dname, d.loc
, e.job
GROUP BY deptno, dname, loc
;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature. -
How to write a simple query.
I have a table where I have data shown below. Now, I want to write a simple query which lists me the project and the count of the distinct effective dates for which data is existant there.
Sample data:
Project Task Effective Date (xx_proj_task_data)
101 T1 01-Jan-2008
101 T1 01-Feb-2008
101 T1 01-Mar-2008
101 T2 01-Jan-2008
101 T2 01-Apr-2008
101 T3 01-Apr-2008
102 T1 01-Jan-2008
102 T1 01-Feb-2008
102 T2 01-Apr-2008
103 T1 01-Jan-2008
103 T1 01-Feb-2008
103 T1 01-Mar-2008
103 T1 01-Apr-2008
103 T2 01-May-2008
103 T3 01-Jun-2008
103 T1 01-Jan-2008
103 T1 01-Aug-2008
103 T2 01-Apr-2008
Output Reqd:
Project Count(Distinct Effective Dates)
101 4
102 3
103 7
I can write a query that says:
select project_id, count(1)
from (select distinct project_id, effective_date
from xx_proj_task_data) x
group by project_id;
But, is there a way I can achieve the same by avoiding the inner Query (x) and just by a simple query ?
Thanks!Try below query:
select project_id
, count(distinct effective_date)
from xx_proj_task_data
group by project_id;
--venkata -
How to Create a Functiona Query
Dear all,
Could any body detail me how to create a functional query. Please give me step by step procedure to create a query.
I would appreciate if you can give me a material with screen shots. Your help will be highly appreciated.
Thank you
Raghu RamHi Raghu,
Go through this document it may help you,
SAP Query
Step 1: Create User Group SQ03
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
a) In the User Group: Initial Screen -
Enter User Group Code (self named)
Click on Create
b) In the User Group (Code): Create or Change pop-up window -
Enter the User Group Description
Click on Save
c) In the Create Object Directory Entry pop-up window -
Ö Click on Local Object button
Ö The User Group Created is saved
Step 2: Create User Group SQ02
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Infosets
a) In the Infoset: Initial screen -
Ö Enter Infoset Code (self named)
Ö Click on Create button
b) In the Infoset: Title & Database Screen -
Ö Enter Description of Infoset in the Name field
Ö In the Data Source selection: Select appropriate Data Source by clicking
the radio button
· Source the data can either be multiple tables OR single table. There are 4
options for the user to select from
Ö Click on Continue (Enter)
Ö Selected Table gets displayed in the Infoset : Initial Screen
c) In the Infoset: Initial Screen -
Ö Click on Insert Table button
d) In the Add Table Screen -
Ö Enter the Table Name that is to be inserted
Ö Click Continue (Enter)
e) In the Infoset: Initial Screen -
Ö Click on Back button
f) In the Field Group Defaults pop-up Screen -
Ö Select Appropriate Field Group Option by clicking on the radio button
· there are 3 options to select from. User can select Empty Field Group
option and then select the data fields in the steps explained further.
Alternatively, User can select an option which clubs all the data fields
From all the tables selected
Ö Click Continue (Enter)
g) In the Change Infoset Screen -
· the left side lists the Tables that the user has selected in step b, c & d
· In the right side, system creates field groups, one for each table listed in the
left part. Initially, the Field Groups are empty
Ö In the Left Side, Click on the arror next to the table name and expand and
display all the data fields in the table
Ö Select a Data Field from the expanded Table view, which is to be added to
the Field Group on the right.
Ö Select a Field Group on the right side, in which Data Field selected above
has to be added
Ö Right click on the Data Field selected and click on Add Field to Field Group
Ö The selected Data Field gets added to the selected Field Group, which is
indicated by an arrow next to the Field Group.
Ö Carry out the steps above to add the required Data Fields to the respective
Field Groups
Ö After transferring Data Fields to Field Groups click on Generate button
h) In the Create Object Directory Entry Screen -
Ö Click on Logical Object button to generate the infoset
i) In the Change Infoset Screen -
Ö Click on the Back button
j) User is taken back to the Infoset: Initial Screen which displays the
created Infoset record.
Step 3: Assigning User Group to Infoset SQ03
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
a) In the User Groups: Initial screen -
Ö Enter the User Group for which Infoset is to be assigned
Ö Click on Assign Users & Infosets button
b) In the User Group: Assign Users Screen -
Ö Click on Assign Infosets button
c) In the next screen, select the Infoset, which needs to be attached to the
User Group selected
d) Click on the Back button
Step 4: Creating Query SQ00 & SQ01
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Queries
a) In the Query from User Group: Initial Screen -
Ö Click on Other User Groups button
Ö In the pop-up screen, User Groups, select the User Group for which the
Query has to created. The pop-up screen closes.
Ö Enter the Query Code in the Query field
Ö Click on Create button
b) A pop-up screen Restrict Value Range shows the list of Infosets assigned to
the User Group
Ö Select the Infoset for which Query has to be created
c) In the new screen Create Query: Title, Format -
Ö Enter the Description of the Query in the Title field
Ö Click on the Next Screen button
d) In the Select Field Group screen
Ö Select the Field Groups from which Data Fields have to be selected for the
Output
Ö Click on the Next Screen button
e) In the Select Field screen -
Ö Select the Data Fields, which should appear in the output
Ö Click on the Next Screen button
f) In the Screen Selection -
Ö Select the Data Fields for the selection criteria
Ö Enter the sequence in which the selected fields would appear in the input
screen of the query.
Ö Define if the selection criteria should be Single Value or Multiple Value Range
by clicking in the appropriate check boxes
Ö Click on the Basic List button
g) In the screen Query Layout Design -
Ö Select the Output Fields from the Data Fields section by clicking the
appropriate check box
Ö Change the sequence of Data Field columns if required
Ö Click on the Test button to test the query created
h) On the Test Query screen click Continue
i) In the Query screen -
Ö Enter the selection criteria
Ö Click on Execute button
j) Save the Query created
Step 5: Running the Query SQ00
a) In the Query From User Group: Initial screen
b) Click on Other User Groups button to select the User Group
c) In the pop-up screen User Groups select the User Group
d) System lists all the queries created for the User Group
e) Select the appropriate Query
f) Click on Execute button
g) User is taken to the Selection screen
h) Enter the selection criteria and click on Execute button
i) System runs the query and gives the output
Regards,
Murali. -
How to view the sql query?
hi,
how to view the sql query formed from the xml structure in the receiver jdbc?You can view SAP Note at
http://service.sap.com/notes
But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
Reason and Prerequisites
You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
When you want to use a parameter documented here, please be aware to which category it belongs!
Solution
The following list shows all available parameters of category 1 or 2. Please note:
Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
The default value of a parameter is always chosen that it does not change the standard functionality
JDBC Receiver Adapter Parameters
1. Parameter name: "logSQLStatement"
Parameter type: boolean
Parameter value: true for any string value, false only for empty string
Parameter value default: false (empty String)
Available with: SP9
Category: 2
Description:
When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
This should be used only during the test phase and not in productive scenarios.
Regards,
Prateek
Maybe you are looking for
-
Error accessing PDF files from Java
In CF7, I have a routine that opens submitted PDF files through Java to do some manipulation. Similar to CF8 PDF manipulation, but more complex. In almost all cases, it works fine, except two. For one, a submitted PDF was corrupted somehow -- I can't
-
What is apple mobile service and how do i fix it
everytime iplug it in to my computer this mgs appears "this ipod cannot be used because the apple mobile device service is not started"
-
How To Add New Key Figure in Manual Planning
Dear All Please Help I Already implement BPS for 2 year. Now user want to add new key figure in Cube. I already add new key figure to cube and activated it. But in Manual Planning, The new key figure not show in selection what I must do? Please Help.
-
Why does FCP set 30fps TC Rate for certain audio clips that lack TC stream?
Hello folks, I'm cutting a DVCPRO HD 720p50 feature at 25fps on FCS2 w fcp 6.0.3. (Used a PAL Panasonic HVX200) When I import certain of the audio files from the location sound recordist, FCP lists the file as having a TC Rate of 30fps -- and puts a
-
Smatforms error message: 610
Hi , Due to some i am not able to generate Purchase requistion smartform for some PR numbers. At the time of debugging we find error message : 610 from msg class ssfcomposer for only some PR number not for all PR number . But when we check in