Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Display info from 4 tables

0 Kudos

Hi All, I'm still trying to learn ABAP by myself - I'm trying to create a program in which I could search for a value in a table it gives me the values after checks in other three tables as I do in SE16N.

Currently, I do the following steps in SE16N.

1º SE16N: Table AGR_1251 and fulfill as following: AGR_1251-OBJECT = S_TCODE; AGR_1251-FIELD = TCD; AGR_1251-LOW = transactions (more than 1) which I want to find users that have access to all of them. Here I want to get the "AGR_1251-AGR_NAME" results.

2º SE16N: Table AGR_1016 with the results of previously searched and fulfill as following: AGR_1016-AGR_NAME = (results of the first search). Here I want to get the information AGR_1016-PROFILE.

3º SE16N: Table UST04 with the results found in step 2 and I fulfill as following: UST04-PROFILE = (results of the second search). Here I want to get the information UST04-BNAME.

4º SE16N: Table USR02 with the results of step 3 and I fulfill as following: USR02-BNAME = (results of the third search) and USR02-CLASS = TEST.

The objective is to find generic tests users who have access to multiples transactions as in SUIM is possible to check one by one and sometimes I need these users which access to more than 5 or 6 transactions would take a lot of time.

I've started but with my knowledge, the far I can get I'll share below, I know it will demand a lot of time, but if someone could help would help me a lot.

REPORT ZUSERTEST.

TABLES: USR02, UST04, AGR_1016, AGR_1251.

DATA: T_USR02 TYPE TABLE OF USR02.
DATA: T_UST04 TYPE TABLE OF UST04.
DATA: T_AGR_1016 TYPE TABLE OF AGR_1016.
DATA: T_AGR_1251 TYPE TABLE OF AGR_1251.

DATA: W_AREA1251 TYPE AGR_1251.
DATA: W_AREA1016 TYPE AGR_1016.
DATA: W_AREAUST04 TYPE UST04.
DATA: W_AREAUSR02 TYPE USR02.

SELECT-OPTIONS: S_TCODE FOR AGR_1251-LOW.

START-OF-SELECTION.
SELECT *
INTO TABLE T_AGR_1251 FROM AGR_1251 WHERE LOW = S_TCODE.
IF sy-subrc EQ 0.
SORT T_AGR_1251 BY AGR_NAME.
DELETE ADJACENT DUPLICATES FROM T_AGR_1251 COMPARING AGR_NAME.
ENDIF.

SELECT *
INTO TABLE T_AGR_1016 FROM AGR_1016 FOR ALL ENTRIES IN T_AGR_1251 WHERE AGR_NAME EQ T_AGR_1251-AGR_NAME.
IF sy-subrc EQ 0.
SORT T_AGR_1016 BY PROFILE.
DELETE ADJACENT DUPLICATES FROM T_AGR_1016 COMPARING PROFILE.
ENDIF.

SELECT *
INTO TABLE T_UST04 FROM UST04 FOR ALL ENTRIES IN T_AGR_1016 WHERE PROFILE EQ T_AGR_1016-PROFILE.
IF sy-subrc EQ 0.
SORT T_UST04 BY BNAME.
delete ADJACENT DUPLICATES FROM T_UST04 COMPARING BNAME.
ENDIF.

SELECT *
INTO TABLE T_USR02 FROM USR02 FOR ALL ENTRIES IN T_UST04 WHERE BNAME EQ T_UST04-BNAME AND USR02-CLASS EQ TEST.
IF sy-subrc EQ 0.
SORT T_USR02 BY BNAME.
ENDIF.

5 REPLIES 5

jerryjanda
Community Manager
Community Manager
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment). While editing, you can also use the "insert code" button to make this portion of the question easier to read. You'll find that button in the question toolbar -- last selection on the right.

Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Kind regards,

--Jerry

Make sure to subscribe to What's New!

dev_parbutteea
Active Contributor

first of all, pretty weird choice of case study for learning ABAP. Next, you basically want us to review your whole code !!

tip: first select statement.. when you select from a table using data from a select option.. you need to use 'IN' instead of 'EQ'...

INTO TABLE T_AGR_1251 FROM AGR_1251 WHERE LOW IN S_TCODE.

then all I can say is that you need to debug and find issues in your own code.

michael_piesche
Active Contributor

Let me know if this works, and if not, what syntax error you get, what NW version you have (7.4x or 7.5x).

START-OF-SELECTION.

SELECT DISTINCT a.AGR_NAME, b.PROFILE, c.BNAME " add more columns if necessary
FROM AGR_1251 as a

INNER JOIN AGR_1016 as b
   on b.agr_name = a.agr_name

INNER JOIN UST04 as c
   on c.profile = b.profile

INNER JOIN USR02 as d
   on d.bname = c.bname
  and d.class = @'TEST'

WHERE a.LOW IN @S_TCODE
INTO TABLE @DATA(itable).

Once you have the information you need in one table, you could use OO SALV to display it. See report SALV_DEMO_TABLE_REAL_SIMPLE for a demonstration of it and use the following code:

data gr_table type REF TO cl_salv_table.

call method cl_salv_table=>factory
  IMPORTING
    r_salv_table = gr_table
  CHANGING
    t_table= itable.

gr_table->display( ).

former_member1716
Active Contributor
0 Kudos

jgomes28,

Recommend you to start with simple programs to learn ABAP, there are wide range of materials available for the same.

With respect to your program lines, apart from corrections given above kindly consider below points as well:

1) Try fetching only required fields in SELECT fields, do not use select * unless there is an absolute need for it.

2) Look out for options to Join the tables, always try to minimize the database fetch.

3) Before writing FOR ALL ENTRIES check if the Table is not initial. This is very important because in case if the internal table does not hold any value your select statement will fetch all the entries from the table.

Since you are getting started now, i would advise you to look out for using new syntax based on the system details.

Note: When you paste the code in SCN please use CODE option next time.

Regards!

michael_piesche
Active Contributor
0 Kudos

jgomes28, please follow up on your open question.

  • comment answers or your question if there are still open issues.
  • otherwise mark an answer as accepted if it helped you solve your problem
  • or post an answer of yourself and accept it if you found another useful solution yourself
  • or redirect your question to another question that is related and was useful to solve your problem
  • in the end, close your question