Two Tables in alv - abap

I am having two tables BKPF and TOA01.
Report should have the following selection screen fields.
Company code(BUKRS), Document Number(BELNR), Fiscal Year(GJAHR)
For ALV report following field should be available in the layout.
BKPF-BUKRS
BKPF-BELNR
BKPF-GJAHR
BKPF-USNAM
TOA01-ARCHIV_ID
TOA01-ARC_DOC_ID
**Link between BKPF and TOA01:
TOA01-SAP_OBJECT = 'BKPF'
AND
TOA01-OBJECT_ID = concatenate -> BKPF-BUKRS + BKPF-BELNR + BKPF-GJAHR.
I want the logic to display (the alv) using two given tables using the link between them (given above).
Please help me with the answer.

If you familiar with ABAP-CDS, you can define two CDS-views. The first one
contains the data from table BKPF:
define view zbooking_doc as select from bkpf {
key bukrs,
key belnr,
key gjahr,
usnam,
concat(bukrs, belnr, gjahr) as archiv_object_id
}
The second CDS-View joins BKPF with table TOA01 (according to your condition TOA01-SAP_OBJECT = 'BKPF' AND TOA01-OBJECT_ID = concatenate -> BKPF-BUKRS + BKPF-BELNR + BKPF-GJAHR.):
define view zbooking_doc_and_archiv as select from zbooking_doc
left outer join toa01 on toa01.object_id = zbooking_doc.archiv_object_id {
key bukrs,
key belnr,
key gjahr,
usnam,
archiv_id,
arc_doc_id
} where toa01.sap_object = 'BKPF'
The tables shown in the ALV can be filled with a select-statement on view zbooking_doc_and_archiv.

Related

Is there a method in Microsoft Access to populate a field based on another table?

I currently have a table called ClinicT that contains: ClinicID (primary key), ClinicSite, ClinicDiscipline and ClinicArea. I have other tables in my database that have the ClinicSite, ClinicDiscipline and ClinicArea as well. However, I would like to replace those three fields for a field called ClinicID that would capture all those information. I have tried two methods:
Lookup Wizard: it does show the corresponding Clinic ID with its discipline, site and area but I would need to manually enter the Clinic ID for each record and I have over 100,000 records.
Use a join and union: although the Clinic ID appears when only site and discipline are included in the query, it shows up blank when I introduce clinic area in the query.
SELECT
ClinicT.ClinicID, DNAT.UR, DNAT.ApptDate, DNAT.DNA, DNAT.ApptDuration, DNAT.ClinicSite, DNAT.ClinicDiscipline
FROM DNAT
LEFT JOIN ClinicT
ON (ClinicT.ClinicDiscipline = DNAT.ClinicDiscipline) AND (ClinicT.ClinicSite = DNAT.ClinicSite) AND (ClinicT.ClinicArea = DNAT.ClinicArea);
UNION
SELECT
ClinicT.ClinicID, DNAT.UR, DNAT.ApptDate, DNAT.DNA, DNAT.ApptDuration, DNAT.ClinicSite, DNAT.ClinicDiscipline
FROM ClinicT
RIGHT JOIN DNAT
ON (ClinicT.ClinicDiscipline = DNAT.ClinicDiscipline) AND (ClinicT.ClinicSite = DNAT.ClinicSite) AND (ClinicT.ClinicArea = DNAT.ClinicArea);
For the ClinicArea field, some records are empty (no data entered) because they don't have a specific area they work in (e.g. cardiac rehabilitation).
Thanks,
QuestionsEverywhere

Cannot add row to SQL Server View

I have a View which is comprised of two tables, TABLE_ONE and TABLE_TWO.
These two tables are linked by their primary key: PKT_UID (see pic).
I have added two rows to the two tables and given them the same PKT_UID but the View is not displaying any rows with this PKT_UID when I search the view for that UID.
I don't know much about SQL views, but my understanding was that as long as the two rows from both tables are linked by the same primary key, it should display in the view. What am I missing?
VIEW CODE:
SELECT dbo.TABLE_ONE.PKT_UID, dbo.TABLE_ONE.IT_UID, dbo.TABLE_ONE.SKT_UID, dbo.TABLE_ONE.RMS_XSP,
dbo.TABLE_ONE.S_MT, dbo.TABLE_ONE.E_MT, dbo.TABLE_ONE.KILP, dbo.TABLE_ONE.KILT,
dbo.TABLE_ONE.IIC, dbo.TABLE_ONE.L_D, dbo.TABLE_ONE.S_D, dbo.TABLE_ONE.S_DAM,
dbo.TABLE_ONE.E_DF, dbo.TABLE_ONE.E_DFD, dbo.TABLE_ONE.H_U, dbo.TABLE_ONE.JK,
dbo.TABLE_ONE.JKT, dbo.TABLE_ONE.TRCE, dbo.TABLE_ONE.MOD, dbo.TABLE_ONE.TAK, dbo.TABLE_ONE.DG_AR,
dbo.TABLE_ONE.DG_LENGTH, dbo.TABLE_ONE.XSP_OFF, dbo.TABLE_ONE.JIK_UID, dbo.TABLE_ONE.FA_UID,
dbo.TABLE_ONE.JOB, dbo.TABLE_TWO.PKT_UID AS GULL_UID, dbo.TABLE_TWO.GULL_T_UID, dbo.TABLE_TWO.GULL_FRC_UID,
dbo.TABLE_TWO.GULLOPP_UID, dbo.TABLE_ONE.RMMS_XSP, dbo.TABLE_ONE.GANG, dbo.TABLE_ONE.TRM_BSD_DATE,
dbo.TABLE_ONE.DOLM, dbo.TABLE_ONE.DONM, dbo.TABLE_TWO.GULLM_UID, dbo.TABLE_TWO.AR_UID,
dbo.TABLE_TWO.PAR_UID, dbo.TABLE_TWO.RCT_UID, dbo.TABLE_TWO.PG_C, dbo.TABLE_TWO.RCT_YN_UID,
dbo.TABLE_TWO.SCHD_TM_UID, dbo.TABLE_ONE.NRS, dbo.TABLE_TWO.BS_M, dbo.TABLE_TWO.EMB_UID,
dbo.TABLE_TWO.MNG_REQ_UID, dbo.TABLE_TWO.FORM_R, dbo.TABLE_TWO.FORM_R_NAME, dbo.TABLE_TWO.SCHED_UID,
dbo.TABLE_ONE.SH_G, dbo.TABLE_ONE.SH_GT, dbo.TABLE_TWO.PKT_UID AS IT_N, CAST(dbo.TABLE_TWO.PKT_UID AS char(15))
AS GULL_NAME, dbo.TABLE_TWO.PACK
FROM dbo.TABLE_TWO INNER JOIN
dbo.TABLE_ONE ON dbo.TABLE_TWO.PKT_UID = dbo.TABLE_ONE.PKT_UID
WHERE (dbo.TABLE_ONE.IT_UID = 1160) AND (dbo.TABLE_ONE.E_DFD = 0)```
SELECT
rm_c.ITEM_UID
,rm_g.ITEM_UID
FROM
RM_COMMON_ATTRIBUTES rm_c
LEFT JOIN RM_GULLY_2010_A rm_g
ON rm_g.ITEM_UID = rm_c.ITEM_UID
If this shows both UIDs as matching then it's not the table
If you're using report builder (have you tried refreshing all fields)
Solved thanks to #BarneyL. There was a WHERE RM_COMMON_ATTRIBUTES.ITEM_TYPE_UID = 1160 condition in the view code that was not being fulfilled.

displaying data in dropdownlist using sql with querystring

I have three tables:
tbprd -- prdcod int PK, prdtit v(100), prddefuom int FK to prduomcod (tbprduom)
tbuom -- uomcod int PK, uomnam v(100)
tbprduom -- prduomcod int PK, prduomprdcod int FK prdcod(tbprd), prduomuomcod int FK uomcod(tbuom)
What I need is to display uomnam in dropdownlist display field and uomcod in data value field from prdcod which I have passed through query string but if the chosen prdcod is 4 then the dropdownlist should display all the uomnam matching w.r.t all matching prdtit
Query I am using:
select uomcod, uomnam
from tbuom, tbprd, tbprduom
where prdcod = 4
and prduomuomcod = uomcod
and prddefprduomcod = prduomcod
Look at the images for more clearer idea about what I want and table data
https://drive.google.com/drive/folders/17p3d1WXMppndIq1bXf6EwShLWBrh-IsC?usp=sharing
Based on what I understand, you want to get all products that have the same title as the product with the given prdcod. If that's correct, then here's one way to do it:
Write a query to get the prdtit value for prdcod = 4 (return one column from one row):
SELECT prdtit
FROM ...
Use this value to filter the rest of the rows in the tbprd table:
SELECT *
FROM tbrpd
WHERE prdtit = (<Query in Step 1>)
Add two joins to the tbprduom and tbuom tables to Step #2 to get the remaining info:
SELECT tbuom.uomcod, tbuom.uomnam
FROM tbrpd
WHERE prdtit = (<Query in Step 1>)
LEFT JOIN tbprduom ON ... <PK/FK fields) -- Get uomcod for products
LEFT JOIN tbuom ON ... <PK/FK fields) -- Get "uom" fields to return
Give it a try and see how far you get. If you get stuck on a step, just let me know.

Access 2013 ComboBox value based on other ComboBox with Junction Table

Good day. This is a follow-up to a previous question. I have a form with 2 comboboxes where the 2nd one depends on the value in the 1st one. I have the code to show the drop down list in the 2nd combobox but I am unable to select anything but the first entry.
Table 1: name - Supply_Sources, fields - Source_ID(pk), SupplySourceName
Table 2: name - Warehouse_Locations, fields - WLocation_ID(pk), Location_Name
Table 3 (junction): name - SupplySource_WarehouseLocation, fields - Supply_Source_ID(pk), Location_In_ID(pk)
On my form 'frmInventoryReceivedInput' I have cboSupplySource and cboWLocation. I populate cboSupplySource with
SELECT [Supply_Sources].[Source_ID], [Supply_Sources].[SupplySourceName]
FROM Supply_Sources;
The SQL for cboWLocation is:
SELECT SupplySource_WarehouseLocation.Supply_Source_ID,
Warehouse_Locations.Location_Name FROM Warehouse_Locations
INNER JOIN (Supply_Sources INNER JOIN SupplySource_WarehouseLocation
ON Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID)
ON Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE ((( SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
There are 3 options for me in the cboWLocation drop down list (based on cboSupplySource). However, it doesn't matter which one I choose, it defaults to the first one. What do I need to do to be able to choose the other options?
I recreated it and it works OK, the only thing I did differently was create a query with the SQL:
SELECT
SupplySource_WarehouseLocation.Supply_Source_ID, Warehouse_Locations.Location_Name
FROM
Warehouse_Locations INNER JOIN
(Supply_Sources INNER JOIN
SupplySource_WarehouseLocation ON
Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE
(((SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
so I could check that part separately from the UI.
For cboWLocation, I have column widths 0";1", rowSource qry_cbo2, and bound column 2. Try changing your bound column from 1 to 2 and see if that helps.
-Beth

Creating filter with SQL queries

I am trying to create a filter with SQL queries but am having trouble with numeric values linking to other tables.
Every time I try to link to another table, it takes the same record and repeats it for every element in the other table.
For example, here is query:
SELECT ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID AND
ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0
The last line is the actual filtering criteria.
Here is an example result:
There should only be ONE result (Item has an RID of 0). But it's repeating a copy of the one record for every result inside the substitution groups table (there's 4).
Here is my database schema for reference. The lines indicate relationships between tables and the circles indicate the values I want:
You're forgot to join between ELEMENTS and SUBSTITUTION_GROUPS in your query.
SELECT
ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM
ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE
ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID
AND ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = SUBSTITUTION_GROUPS.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0