How to check if a field is present in a particular view or table using ABAP - abap

I have list of 100 views for which I need to check if those views have fields A and B. If any of those 100 views uses those two fields, I need to display a message. Any existing function module will help.

Sujeet,
Function module ISB_TABLE_READ_FIELDS accepts a table or view name and returns a table of fields on the structure. If you don't have this function module, you can write your code to select entries from table DD03L, which is keyed on table name and contains all of the fields on all database table structures.
Once you have the list of fields, the code to implement the logic you want should be trivial.

I doubt there is an existing SAP Function Module to do this - I suspect you will have to write some ABAP or do some Excel manipulation.
I would expect that there is a table within SAP which defines views - I'm not sure which though.
If no-one suggests anything else I would use ST05 - "SQL Trace" to see which tables SAP reads when you call SE12 to look at the view you are interested in. You can look at the SELECT statements and see which tables it reads to get the view definition.
I just tried pressing F1 on a field in SE12 for a view to see if there was a mention of a table. The technical info made reference to a structure containing the string "DD27" - I had a look in SE16 for tables with similar names and DD27SV looks like it might help.
Have a look and see what you think - you'd need to query that table in some ABAP or extract to Excel and do equivalent manipulation there.

Related

Access 2010 Database Clenup

I have problems with my records within my database, so I have a template with about 260,000 records and for each record they have 3 identification columns to determine what time period the record is from and location: one for year, one for month, and one for region. Then the information for identifying the specific item is TagName, and Description. The Problem I am having is when someone entered data into this database they entered different description for the same device, I know this because the tag name is the same. Can I write code that will go through the data base find the items with the same tag name and use one of the descriptions to replace the ones that are different to have a more uniform database. Also some devices do not have tag names so we would want to avoid the "" Case.
Also moving forward into the future I have added more columns to the database to allow for more information to be retrieved, is there a way that I can back fill the data to older records once I know that they have the same tag name and Description once the database is cleaned up? Thanks in advance for the information it is much appreciated.
I assume that this will have to be done with VBA of some sort to modify records by looking for the first record with that description and using a variable to assign that description to all the other items with the same tag name? I just am not sure of the correct VBA syntax to go about this. I assume a similar method would be used for the backfilling process?
Your question is rather broad and multifaceted, so I'll answer key parts in steps:
The Problem I am having is when someone entered data into this
database they entered different description for the same device, I
know this because the tag name is the same.
While you could fix up those inconsistencies easily enough with a bit of SQL code, it would be better to avoid those inconsistencies being possible in the first place:
Create a new table, let's call it 'Tags', with TagName and TagDescription fields, and with TagName set as the primary key. Ensure both fields have their Required setting to True and Allow Zero Length to False.
Populate this new table with all possible tags - you can do this with a one-off 'append query' in Access jargon (INSERT INTO statement in SQL).
Delete the tag description column from the main table.
Go into the Relationships view and add a one-to-many relation between the two tables, linking the TagName field in the main table to the TagName field in the Tags table.
As required, create a query that aggregates data from the two tables.
Also some devices do not have tag names so we would want to avoid the
"" Case.
In Access, the concept of an empty string ("") is different from the concept of a true blank or 'null'. As such, it would be a good idea to replace all empty strings (if there are any) with nulls -
UPDATE MyTable SET TagName = Null WHERE TagName = '';
You can then set the TagName field's Allow Zero Length property to False in the table designer.
Also moving forward into the future I have added more columns to the
database to allow for more information to be retrieved
Think less in terms of more columns than more tables.
I assume that this will have to be done with VBA of some sort to modify records
Either VBA, SQL, or the Access query designers (which create SQL code behind the scenes). In terms of being able to crunch through data the quickest, SQL is best, though pure VBA (and in particular, using the DAO object library) can be easier to understand and follow.

In a SQL Server view, get the "AS" info for the columns in the view

So I have a view that has lots of "AS" stuff defined for different columns, e.g., some view columns simply map to one column in one physical table, some are defined by functions etc:
SELECT
dbo.LoanDataTable.F123 AS LoanOfficer,
dbo.udf_GetChannelTypeValueWithLoanOfficer(dbo.LoanDataTable.F123) AS ChannelType
In our application I want to be able to display on a web page the mapping of the view columns to their "AS" definitions, in a grid with two columns like so:
LoanOfficer dbo.LoanDataTable.F123
ChannelType dbo.udf_GetChannelTypeValueWithLoanOfficer(dbo.LoanDataTable.F123)
I have researched on stackoverflow:
Is there a way to retrieve the view definition from a SQL Server using plain ADO?
and
Suggestions on storing view meta in SQL Server 2008
All the first one does is retrieve the full text of the view definition, and no one ever answered the second one.
If I retrieve the full text of the view definition, such as seen at the top of this post, then I still need to somehow parse the text to extract the "AS" components. So my question is: is there a way to easily extract this information from SQL Server 2008 R2 and above, or if not, has someone already written some view-definition-parser code that will do this?
This will get you the actual DDL, if that's the first part of what you're looking for:
SELECT OBJECT_DEFINITION (OBJECT_ID('yourSchema.yourViewGoesHere')) AS ObjectDefinition;

SQL Split functions and imported data

Ok, I've got a database table where data gets dumped by this horrid little program that I despise, but can't change at the moment. It has merchant data in there, names, addresses, and a set of categories that are pipe-delimited. What I need is a clean way to split these out, so I have one row for each merchant/category pair. From there, I can easily get it into the new data structure. This will need to be a repeatable process for a short period of time. I realize the optimal solution is to rid myself of this structure, but I've wracked my brain trying to figure out how to do this cleanly in sql.
I already have a function in the database that will split a delimited string and return a table.
This is in sql server 2008, btw.
Edit (for clarity_
Basically, the following might be a merchant (with the categories attached - other fields redacted for simplicity. Using commas for field delimiters here).
Jimbo's Bait Shoppe, Bait|Sports Gear|Sandwiches
What I need is:
Jimbo's Bait Shoppe, Bait
Jimbo's Bait Shoppe, Sports Gear
Jimbo's Bait Shoppe, Sandwiches
If you have already written a function that splits the string and returns the table you can use a trigger.
Create a trigger on INSERT on the table where the "horrid" program spits the data. The trigger will then take the unformatted data and populate two clean tables (I think in your case you should have two tables: one is a merchant, and another one is products, that are linked using one-to-many relationship using MerchantID).
In this case you can use the table with unformatted data as a "dirty" table. You can cleanse straight after the "horrid" program imported a file.
Please comment if you need help with the triggers

Get column name & table name from value

Actually I have a new client & their Database has no standard naming conventions & the application is in classic asp.I have a form in which a form there are many values in the different textboxes, it it very difficult to trace the value come from which table.& also there is no erd.
I need a query from which I can get the table name with column name by giving Value.
Let's suppose I have a value having label name abc#= '6599912268'
& the new project has no ERD no standard of naming conventions... I need a fast way to know the abc# ='6599912268' is taking from which table & which column name.... like this the UI has many values which is time taken to trace manually
Is there any way to trace it?
The simple answer is no. There is no way to trace table/column it comes from by mere inspection of the value.
I suggest the following.
Find out what type of db your product is using. Where it is situatede, do you have access to it.
If you have access to the database, get to know the db structure. What each table is meant to store, the relationships etc. Speak to the db administrator or the business analayst to increase your knowledge on the product domain.
Once you have the db structure, try and compare the table to the page. Eg. The user details will most like be stored in a db table named 'Users' or 'Membership' Catch my drift?
Then have a look at the web sites source code. Look at the specific page you are at. Is the sql code embedded in the source code (asp page) or does it call a COM server or something similar? If you are "lucky" (and I say lucky for on the purpose of your problem that you are having) you fill find the sql code in the asp page.
If it calls a COM object or something similar, then you will have to dig up the source code for that, and that is most likely where you sql will reside.
There is no easy way to do this, you have to use a stored procedure to loop over all the tables in the database and search for the value, and it will probably take a while.
There's a stored procedure and examples here: Search all columns in all the tables in a database for a specific value. You'll see there are stored procedures for finding dates, strings, numbers.
Not possible, and If you search the column with the value, there is a possible chance that you get multiple columns with the same value, so how would you differentiate them and the same case is for the table.

How to create a custom extractor in SAP R/3 system?

I have to create a custom extractor in SAP R/3 system.
What are the ways to extract the data from required tables like COVP, COEP, EKKN etc.?
I suppose you are asking to extract to SAP BI, although it seems you are probably lacking a bit in experience you'll have to ask an ABAPer to help you with some of this.
First you need to build a view on the DB table you want: go to transaction SE11 and select View, and give it a name. Usually I like to do ZBW_tablename and a Description such as BW Extractor View for Table tablename
Select all the fields from tge database table and activate.
Then go to transaction RSO2 and in this case you are dealing with Transactional tables.
Create a transactional extrator by entering a name Z_tablename_TRANS. Click CREATE.
On the next screen, select the position for your extractor in the application component hierarchy. When you replicate into SAP BI you will see your extractor in this position in the hierarchy, so it's important you remember where you put it.
Add the descriptions, and the Viewname that you just created. Select save.
That's it.
in addition you can also create an extractor using a function module and an underlying structure. For that, select FM in RSO2 after you create your generic extractor and provide your structure and function module.
You can create the structure in SE11 and the function module in SE80. You need to know ABAP here but it's an extremely powerful approach to extracting data provided you don't need something simpler.
first you will create the view on using se11 given the name and create now given the condition to the condition field and given the what are the fields you want in view field now you go to rso2 and create what type of the data source you needed and given they application component name for the reason of where your data source shown now select the view and save the extract structure will be automatically created