Application Development and Automation 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: 
Read only

ABAP code for selective deletion

Former Member
0 Likes
1,295

Hi ABAP Gurus,

I have an urgent requirement and would request community's help. Points guaranteed.

We have two user categories U1 and U2 who are assigned two roles R1 and R2 respectively. U1, U2 and their role assignment R1 and R2 are maintained in table AGR_USER in BW under fields UNAME and AGR_NAME respectively. Usernames U1, U2 are flowing in from a Z table in R/3.

Now the requirement is to write a code in update rule that checks

(1) Whether the users U1, U2 are existing in AGR_USER or not. If they are not existing, record is deleted ELSE record is passed on for for second level of check (described below).

(2) Passed records from (1) are further checked for, if R1 is assigned to U1, data is released and loaded into infoprovider IP1. But if R2 is assigned to U1 ... record is deleted.

Can anyone send me an ABAP code for this ?

Thanks in advance.

Abhishek

12 REPLIES 12
Read only

Former Member
0 Likes
1,238

just a sample code based on my understanding. Donno if this is correct and helps you. I hope u get some idea..

DATA: BEGIN OF LT_UINFO OCCURS 0,

LV_UNAME TYPE AGR_USER-UNAME,

LV_AGRNAME TYPE AGR_USER-AGRNAME,

END OF LT_UINFO.

DATA: WA_UINFO LIKE LINE OF LT_UINFO.

SELECT UNAME AGR_NAME

INTO TABLE LT_UINFO

FROM AGR_USER

WHERE UNAME EQ U1

OR UNAME EQ U2.

IF SY-SUBRC EQ 0.

LOOP AT LT_UINFO INTO WA_UINFO

IF WA_UINFO-LV_AGRNAME EQ U1.

  • DATA IS RELEASED AND LOADED INTO INFOPROVIDER

ENDIF.

ENDIF.

Thanks,

Santosh

Read only

0 Likes
1,238

Hi Santosh,

Thanks for your quick reply.

I do not see any command for deleting the record in the logic section (sorry, I am not an ABAP person). Usernames U1, U2 are passed on from a Z table in R/3 under the 'TCTUSRNM' and can increase / decrease depending onn users are added/deleted.

Can we use some kind of lookup faciltiy for validation of user existence instead of EQ ? I do not want to do any hard coding ... rather the code should check any user name which is appearing under field TCTUSRNM ! If I am to describe the function in language ... I will write ...

" Pick username from TCTUSRNM and check whether this user exists in table AGR_USER, if 'NO' then delete the record 'ELSE' check whether role R1 is assigned to him or R2 ... if R1 then let the record pass for loading into infoprovider 'ELSE' delete the record."

Does my requirement sound clearer now ?

Abhishek

Read only

0 Likes
1,238

Ok here is my understanding...

1. TCTUSRNM contains set of usernames.

2. We need to fetch only these usernames from AGR_USER z table and store it in an internal table (hope u know what is internal table!) to do further checks.

3. For all such users, check the role R1 or R2. If R1, then do the process else delete the record from internal table.

Correct me if am wrong. Also, what is this TCTUSRNM? Is it a table?

Thanks,

Santosh

Read only

0 Likes
1,238

Yes ... you are right.

1) TCTUSERNM is a field (InfoObject - 0TCTUSERNM) in the infoprovider 0TCA_DS01 (part of standard business content). It is polpulated from a Z table in R/3.

2) For the values those get populated from Z table above need to be checked in AGR_USER (purpose - validation). (I understand the purpose of internal table - conceptually).

3) Your understanding is accurate for applying the logic.

Can you send me a modified code ?

Thanks,

Abhishek

Read only

0 Likes
1,238

I have slightly modified the code below. Hope this helps.

DATA: BEGIN OF LT_UINFO OCCURS 0,

LV_UNAME TYPE AGR_USER-UNAME,

LV_AGRNAME TYPE AGR_USER-AGRNAME,

END OF LT_UINFO.

DATA: WA_UINFO LIKE LINE OF LT_UINFO.

  • Select user and role from table AGR_USER where username is equal to TCTUSRNM

SELECT UNAME AGR_NAME

INTO TABLE LT_UINFO

FROM AGR_USER

WHERE UNAME EQ TCTUSRNM.

IF SY-SUBRC EQ 0.

  • Looping at rows, check if the role is R1

LOOP AT LT_UINFO INTO WA_UINFO.

IF WA_UINFO-LV_AGRNAME EQ R1.

  • Data is released and loaded into inforprovider

ENDIF.

ENDLOOP.

ENDIF.

Thanks,

Santosh

Read only

0 Likes
1,238

Thanks Santosh,

I have made some more changes but the logic seems to have some problem ... though it is not showing any syntax error but it is not producing the desired result. Please see below ...

TABLES: AGR_USERS.

DATA: BEGIN OF LT_UINFO OCCURS 0,

LV_UNAME TYPE AGR_USERS-UNAME,

LV_AGRNAME TYPE AGR_USERS-AGR_NAME,

END OF LT_UINFO.

DATA: WA_UINFO LIKE LINE OF LT_UINFO.

  • Select user and role from table AGR_USER where username is equal to TC

SELECT UNAME AGR_NAME

INTO TABLE LT_UINFO

FROM AGR_USERS

WHERE UNAME = DATA_PACKAGE-TCTUSERNM.

IF SY-SUBRC EQ 0.

  • Looping at rows, check if the role is R1

LOOP AT LT_UINFO INTO WA_UINFO.

IF WA_UINFO-LV_AGRNAME EQ 'ZSD_REP_USR'.

DELETE DATA_PACKAGE.

  • Data is released and loaded into inforprovider

ENDIF.

ENDLOOP.

ENDIF.

Would appreciate if you can help me with the error in logic.

Abhishek

Read only

0 Likes
1,238

Does the query fetch you any rows?

Is this condition IF WA_UINFO-LV_AGRNAME EQ 'ZSD_REP_USR' getting satisfied?

Thanks,

Santosh

Read only

0 Likes
1,238

Hi Santosh,

The code is not doing anything and all the data is passing as if there is NO start routine in place. Here is the final version of corrections which I made and to me it looks OK but it does not do anything !!!

TABLES: AGR_USERS.

DATA: BEGIN OF LT_UINFO OCCURS 0,

LV_UNAME TYPE AGR_USERS-UNAME,

LV_AGRNAME TYPE AGR_USERS-AGR_NAME,

END OF LT_UINFO.

DATA: WA_UINFO LIKE LINE OF LT_UINFO.

SELECT UNAME AGR_NAME

INTO TABLE LT_UINFO

FROM AGR_USERS

WHERE UNAME = DATA_PACKAGE-TCTUSERNM.

IF SY-SUBRC EQ 0.

LOOP AT LT_UINFO INTO WA_UINFO.

IF WA_UINFO-LV_AGRNAME = 'ZSD_REP_USR'.

DELETE DATA_PACKAGE.

ENDIF.

ENDLOOP.

ENDIF.

All I want is the routine should check whether the USER1 or USER2 is existing in table AGR_USERS, and if YES and ROLE assigned (value of field AGR_NAME in table AGR_USERS) to USER1 is 'ZSD_REP_USR' - the record should get deleted.

Else, record should be passed to infoprovider !

Can anybody help me by correcting the logic ?

Abhishek

Read only

Former Member
0 Likes
1,238

Hi Abhishek,

I created a form and loop at my output results like the following, checking the user's objects. In the following case, it is comparing company code from my output results to the company code in IT0001. If the user does not have permission to 'R' (read) this, then delete the entry from the table.

FORM authority_check.

LOOP AT out_dme.

AUTHORITY-CHECK OBJECT 'P_ORGIN'

ID 'INFTY' FIELD '0001' "check infotype 0001

ID 'SUBTY' DUMMY

ID 'AUTHC' FIELD 'R' "read priverlages

ID 'BUKRS' FIELD out_dme-zbukr . "company code

IF sy-subrc NE 0. "if not authorized

DELETE out_dme.

ENDIF.

ENDLOOP.

ENDFORM.

hope this answers you first question, although im not sure about the infoset

Warren

Read only

Former Member
0 Likes
1,238

Hi Abi,

The below statement in Clement's answer deletes the record from the internal table.

<b>DELETE out_dme. </b>

Regards,

Raj

Read only

0 Likes
1,238

Thanks Raj,

I noticed ...

Abhishek

Read only

Former Member
0 Likes
1,238

Able to fix the bug in my program.