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: 

Authority Check

emylah
Explorer
0 Kudos

Hi all,

I have some question regarding authority check. There are 2 select options which is sales organization (vkorg) and customer code (kunnr). I did the authority check for vkorg and it works fine but as for the kunnr, there are multiple record with different sales org eg. 1 kunnr code could have multiple record with different sales org including authorized and not authorized. Instead of displaying all the kunnr record, how to filter the output of kunnr and display authorized record only ?

this is my code:

TABLES: kna1, knvv, tvzbt, tvkot, tvtwt, tspat.
TYPE-POOLS: slis.
TYPES: BEGIN OF cust_data,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
name2 TYPE kna1-name2,
stras TYPE kna1-stras,
zterm TYPE knvv-zterm,
vkorg TYPE knvv-vkorg,
vtweg TYPE knvv-vtweg,
spart TYPE knvv-spart,
pttx TYPE tvzbt-vtext,
sotx TYPE tvkot-vtext,
dctx TYPE tvtwt-vtext,
dvtx TYPE tspat-vtext,
conzterm TYPE string,
convkorg TYPE string,
convtweg TYPE string,
conspart TYPE string,
END OF cust_data.
DATA: gt_cust TYPE TABLE OF cust_data WITH HEADER LINE,
wa_cust TYPE cust_data,
gt_list_top_of_page TYPE slis_t_listheader,
gt_list_btm_of_page TYPE slis_t_listheader,
gt_events TYPE slis_t_event,
gs_layout TYPE slis_layout_alv,
gt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr.
SELECT-OPTIONS: s_vkorg FOR knvv-vkorg.
SELECTION-SCREEN END OF BLOCK B1.


AT SELECTION-SCREEN.
IF s_vkorg IS NOT INITIAL.
SELECT * FROM knvv WHERE vkorg IN s_vkorg.
AUTHORITY-CHECK OBJECT 'ZSORG'
ID 'ZTEM' FIELD knvv-vkorg
ID 'ACTVT' FIELD '03'.

 IF sy-subrc NE 0 .
MESSAGE e014(zmsg) WITH 'NOT AUTHORIZED'.
ENDIF.
ENDSELECT.

 IF sy-subrc NE 0.
MESSAGE e000(zmsg).
ENDIF.
ENDIF.

START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.

 PERFORM build.
PERFORM eventtab_build CHANGING gt_events.
PERFORM comment_build CHANGING gt_list_top_of_page.
PERFORM call_alv.

FORM GET_DATA .
*SQL Statement
SELECT kna1~kunnr kna1~name1 kna1~name2 kna1~stras
knvv~zterm knvv~vkorg knvv~vtweg knvv~spart
tvzbt~vtext tvkot~vtext tvtwt~vtext tspat~vtext
INTO TABLE gt_cust FROM kna1
INNER JOIN knvv ON kna1~kunnr = knvv~kunnr
INNER JOIN tvzbt ON tvzbt~zterm = knvv~zterm
INNER JOIN tvkot ON tvkot~vkorg = knvv~vkorg
INNER JOIN tvtwt ON tvtwt~vtweg = knvv~vtweg
INNER JOIN tspat ON tspat~spart = knvv~spart
WHERE knvv~kunnr IN s_kunnr AND knvv~vkorg IN s_vkorg.

 LOOP AT gt_cust INTO wa_cust.
CONCATENATE wa_cust-name1 wa_cust-name2 INTO wa_cust-name1 SEPARATED BY space.
CONCATENATE wa_cust-zterm wa_cust-pttx INTO wa_cust-conzterm SEPARATED BY '-'.
CONCATENATE wa_cust-vkorg wa_cust-sotx INTO wa_cust-convkorg SEPARATED BY '-'.
CONCATENATE wa_cust-vtweg wa_cust-dctx INTO wa_cust-convtweg SEPARATED BY '-'.
CONCATENATE wa_cust-spart wa_cust-dvtx INTO wa_cust-conspart SEPARATED BY '-'.
MODIFY gt_cust FROM wa_cust.
ENDLOOP.
IF sy-subrc <> 0.
MESSAGE s000(zmsg) DISPLAY LIKE 'E'.
ENDIF.
ENDFORM.
4 REPLIES 4

AlexGourdet
Community Manager
Community Manager
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with Community Q&A, as the overview provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a Picture to your profile you encourage readers to respond.

Sandra_Rossi
Active Contributor
0 Kudos

Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

Sandra_Rossi
Active Contributor
0 Kudos

You are using a custom Authorization Object (ZSORG) to check authorization for Sales Organization (no idea why you created a custom one), so do you want to check authorization for Customer Code based on a custom Authorization Object too? If yes people can't help you because it's custom, impossible to know how you want to design that.

raymond_giuseppi
Active Contributor
0 Kudos

Create a range similar to the select-options on Sales Organizations, fill it with a select and remove not allowed values (raise an error if final tabl'e is empty)

pattern:

" ...
DATA r_vkorg LIKE RANGE of knvv-vkorg.
" ...
AT SELECTION-SCREEN ON s_vkorg.
  refresh r_vkorg.
  SELECT 'EQ' AS option, 'I' AS sign, vkorg as low
   FROM tvko WHERE vkorg IN s_vkorg
    INTO CORRESPONDING FIELDS OF TABLE r_vkorg.
  LOOP AT TABLE r_vkorg ASSIGNING <fs>.
    AUTHORITY-CHECK OBJECT 'ZSORG'
      ID 'ZTEM' FIELD <fs>-low
      ID 'ACTVT' FIELD '03'.
	IF sy-subrc NE 0.
	  DELETE r_vkorg.
	  MESSAGE 'Some not allowed Sales Organizations were removed'
            TYPE S DISPLAY LIKE 'W'.
	ENDIF.
  ENDLOOP.
  IF r_vkorg IS INITIAL.
    MESSAGE 'No allowed Sales Organization was selected' TYPE E.
  ENDIF.
"...	
WHERE knvv~kunnr IN s_kunnr AND knvv~vkorg IN r_vkorg.
'"...