How to create authorization checking with Tcode - authorization

How to create authorization checking with tcode? I have tried many ways like creating transaction ZSDI_DRIVER_INFO and ZSDR_DRIVER_INFO during in tcode se80 and assigned the authorization object (F_BKPF_BUK) to the respective tcode.
But nothing change, even when testing I try to insert data not in authorization, It still allows the user to save. I am new in SAP ABAP. Hopefully can get some advice on this...
I create Transaction code here:
and add f_bkpf_buk at tcode su24
I think is putting here but not sure how...try many ways ady:
MODULE USER_COMMAND_0100 INPUT.
CASE ok_code.
WHEN 'CONFIRM' .
CALL TRANSACTION 'ZSDI_DRIVER_INFO'.
IF gv_bukrs IS INITIAL
OR gv_icno IS INITIAL
OR gv_status IS INITIAL.
MESSAGE 'Please fill in field required.' type 'E'.
CALL SCREEN '0100'.
ENDIF.
PERFORM check_data.
WHEN 'QUERY'.
CALL SCREEN '0200'.
WHEN 'UPDATE'.
IF gv_bukrs IS INITIAL
OR gv_icno IS INITIAL
OR gv_status IS INITIAL.
MESSAGE 'Please fill in field required.' type 'E'.
CALL SCREEN '0100'.
ENDIF.
PERFORM check_data2.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
The requirement as stated below:
Most of the tutorial online teach how to create normal authorization object that without tcode, hopefully can get some help about how to create this authorization checking.

Related

SubmitForm then Patch results in "The data returned by the service was invalid"

I'm building a PowerApps app on Azure SQL
The requirement
I have a form which has "Save" and "Confirm" buttons.
Both buttons should save the form data. The Commit button should also set database column "Confirm" to 1
I've read at length about how I can programatically override the update value of a hidden control for this. But I'm not satisfied with the level of complexity (maintenance) required to get this working, i.e.
Populate a variable with the current db value
In the button code set the variable value
In the form field, set the update property to the variable
What I'm Trying
So I'm trying a different approach: SubmitForm then Patch. Even though this requires an extra database call, I'd like to understand if this will work. This is the code for OnSelect in the commit button:
// Save the record
SubmitForm(frmEdit);
// Update confirmed to 1
Patch('[dbo].[Comments]',cRecord,{Confirmed:1});
Some Complexities
Note that my record is a variable, cRecord. In short I want this app to be able to upsert based on URL parameters.
This is my App.OnStart which captures URL values, inserts a record if required. Regardless, the result of this event is that cRecord is set to the record to be edited.
// Cache employees and store lookups (as they are in a different db)
Concurrent(Collect(cEmployees, Filter('[dbo].[SalesPerson]', Status = "A")),Collect(cStores, '[dbo].[Store]'));
// Check for parameters in the URL. If found, set to Edit/Add mode
Set(bURLRecord,If((!IsBlank(Param("PersonId")) && !IsBlank(Param("Date"))),true,false));
// If URL Parameters were passed, create the record if it doesn't exist
If(bURLRecord,
Set(pPersonId,Value(Param("PersonId")));
Set(pDate,DateValue(Param("Date")));
// Try and find the record
Set(cRecord,LookUp('[dbo].[Comments]',SalesPersonId=pPersonId && TransactionDate = pDate));
If(IsBlank(cRecord),
// If the record doesn't exist, create it with Patch and capture the resulting record
Set(cRecord,Patch('[dbo].[Comments]',Defaults('[dbo].[Comments]'),{SalesPersonId:pPersonId,TransactionDate:pDate}))
);
// Navigate to the data entry screen. This screen uses cRecord as its item
Navigate(scrEdit);
)
frmEdit.Item is set to cRecord. As an aside I also have a gallery that sets this variable value when clicked so we can also navigate here from a gallery.
The navigating using new and existing URL parameters works. Navigating from the gallery works.
The problem
When I press the Commit button against a record which has Confirmed=0 I get this popup error:
The data returned by the service is invalid
When I run this code against a record which already has Confirmed=1 I don't get an error
If I run the PowerApps monitor it doesn't show any errors but it does show some counts being run after the update. I can paste it here if required.
I also tried wrapping the Path in a Set in case it's result was confusing the button event but it didn't make a difference.
What I want
So can anyone offer me any of the following info:
How can I get more info about "The data returned by the service is invalid"?
How can I get this to run without erroring?
Is there a simpler way to do the initial upsert? I was hoping a function called Patch could upsert in one call but it seems it can't
With regards to the setting field beforehand approach, I'm happy to try this again but I had some issues implementing it - understanding which control where to edit.
Any assistance appreciated.
Edit
As per recommendations in the answer, I moved the patch code into OnSuccess
If(Confirmed=1,Patch('[dbo].[CoachingComments]',cRecord,{Confirmed:1}));
But now I get the same error there. Worse I cleared out OnSucces and just put SubmitForm(frmEdit); into the OnSelect event and it is saving data but still saying
The data returned by the service was invalid
First things first,
Refactoring has multiple steps,
I can t type all out at once...
The submitform and patch issue:
Never use the submitforn with extra conplexity
Submitform is only the trigger to send the form out,
The form handler will work with your data...
If you hsven t filled out the form correctly, u don t want to trigger your patch action...
So:
On your form, you have an OnSucces property,
Place your patch code there...
Change your cRecord in your patch statement:
YourForm.LastSubmit

Catch Post Goods Issue event while outbound delivery processing

I am using the user exit USEREXIT_SAVE_DOCUMENT_PREPARE to check some positions in a delivery for some specific criteria.
I just want to do this whenever PGI is triggered. For this I use this condition in the user-exit:
IF ( sy-tcode EQ 'VL01N' OR
sy-tcode EQ 'VL02N' ) AND
sy-ucomm EQ 'WABU_T'.
But now I am afraid that this is not enough for cases like:
booking the exit directly from vl02n (without checking the positions)
book the exit via "Edit --> Post Good Issue"
editing the positions and book
Are there some further options which can be checked to make sure that there is a booking?
How can I make completely sure that a post of goods was triggered in fact?
You can try to utilize Workflow to cover all possible cases.
Create Workflow event which will be triggered upon delivery creation/change and check for Post Goods Issue there. Delivery BO is LIKP so go to tcode SWU_EWCD and enter data like this
Workflow events are based on change documents so every times smth is written to the table it will be fired. Check that your event is properly created in SWEC transaction.
You can also create events based on NACE conditions. After that use your event to generate your own workflow.
Also BAdI LE_SHP_DELIVERY_PROC may be of interest for you, it has method
SAVE_AND_PUBLISH_BEFORE_OUTPUT which is executed before saving of delivery.
You have to check value in T180-TRTYP. If value is 'H' then it is create booking otherwise it is change booking.It is better to remove transaction code and sy-ucomm condition and condition for T180-TRTYP.
regards,
Umar Abdullah

RSA Archer user cannot specify a date in the future / past

Has anyone any good patterns for RSA Archer validation which prevents a user from saving the record when a given date specified is in the future (or past)?
Currently I am catching this using calculated fields after the data has been saved, in a data exceptions report. But ideally I would like to catch this early prior to the user saving the record.
I would suggest that you use custom object in this case.
So remove the basic onclick attribute of the SAVE and APPLY button.
In your custom object, check if the entered date matches the system date (or the time-zone you need). Set a flag. Based on the flag value, you can call the actual function call of the SAVE or APPLY button.
Hope that helps!
Alex,Tanveer is correct. You have to use a Custom Object with embedded JavaScript code to implement described functionality.
You will need to create a function that will validate the value entered by the end user and either accept it or make user correct himself.
Now, you have two options how to do it:
1. You can attach your validation function to the Save and Apply buttons as Tanveer described. I have shared a similar code in the following question before. You can review it here: LINK
2. You can attach your validation function to the element you plan to validate directly. So when user is done with given input element and input element loses focus your function will be called. Here is a sample code with jQuery:
$('#elementid').blur(function() {
// validate entered value here
// if required show a pop-up message
WarningAlert(msg, title);
});
Good luck!

how to add condition to not execute code for given user

I want to pass some abap code without executing according to sap user.
Here an example:
if userName is John Then
pass this code block without executing...
endif
Is it possible?
Is it possible to debug it so that when we add break <user_name>, the debug runs only for that user?
Yes you could if it is absolutely necessary . The system stores the user alias executing the program under the variable sy-uname and you can use this to do your condition check . But I wouldn't recommend this approach as it is not immediately visible why a certain block of code is being executed for some users and is bypassed for others. This would/should never pass a stringent quality check during code analysis .
Just for completeness, the technical solution would be:
IF sy-uname NE 'JOHN'.
* Code that is not executed for SAP user 'JOHN'
ENDIF.

Suppress first screen of transaction

I want to call Z-transaction via "CALL TRANSACTION" statement and skip the first screen, but AND SKIP FIRST SCREEN statement doesn't work.
I've read that it has sense only when 'ENTER' function code is used for moving between screens of transaction. Is it true?
Therefore I decided to use batch input table (BDC) via CALL TRANSACTION...USING bdc_table statement in order to process first screen in background.
However that way processing is returned to the initial transaction which I don't want to do!
The statement LEAVE TO TRANSACTION doesn't work with BDC table. Is there any other solution?
Addition to tomdemuyt:
Now I'm using batch table but if I used SKIP, I would rather write like this:
AUTHORITY-CHECK OBJECT 'S_TCODE'
ID 'TCD' FIELD lv_tcode.
IF sy-subrc <> 0.
MESSAGE 'No authorization for this operation!' TYPE 'E'.
ELSE.
* CALL TRANSACTION lv_tcode USING bdc_tab
* MODE 'E'
* UPDATE 'A'.
SET PARAMETER ID 'EBELN' FIELD p_ebeln.
LEAVE TO TRANSACTION lv_tcode AND SKIP FIRST SCREEN.
ENDIF.
On the first screen (the selection screen) p_ebeln parameter has to be selected and passed to the second screen without showing first.
I'm not sure what you're trying to do. Are you trying to skip the first screen and go to the second screen? If the transactions you're trying to call are executable programs, you have a few more options with submitting the program directly:
SUBMIT zprogram
WITH param1 = 'VALUE'
WITH selopt BETWEEN 'a' AND 'b'.
Alternatively you change the batch table to a selection table of type RSPARAMS. There are many other options including submitting with a specific variant, or calling a specific screen etc.