How to add field via Enhancement in SM20 (SAPMSM20) - abap

I have a requirement to display the tcode description along with tcode field(column) in the output ALV grid of the report SM20.
The report already contain the tcode field (column) , so just want to add an additional column in the output to show the description of tcode along with the tcode.
TSTCT is the table and TTEXT is the field for tcode description.
How can i achieve this using enhancement .
I have searched and found that in the include rsau_class_auditlist_impl
there is a method i.e METHOD write_list_about_auditlog. In that method the itab is filled by
go_sal_rf->get_result_tab( EXPORTING id_reset = abap_false
CHANGING et_out_ext = mt_outtab_l ).
So as for me I have to implement the enhancement in this method.
Please, guide me how will I do the enhancement, so that it will display one column in the output.

If you need to concatenate the additional data into the table mt_outtab, you can do this via implicit enhancement in rsau_class_auditlist_impl.
My recommendation would be:
Add an additional Column to ts_out_ext in CL_SAL_READ_FILES line 145, this type definition can be enhanced, but you need to check where it's used.
Alternatively, you could replace program id with tcode description when the tcode description isn't empty, and re-purpose the programID field.
You would do this at the end of method WRITE_LIST_ABOUT_AUDITLOG line 167 has an ehnacement spot.

Related

Trying to fill empty fields by using IS INITAL

I am trying to update a certain part of the code, where the code is shown below.
READ TABLE lt_cc_data ASSIGNING <ls_cc_data>
WITH KEY qmnum = ls_refferal-qmnum.
IF <ls_cc_data>-pruef is INITAL. *>>>>>Statement that I added
IF sy-subrc IS INITIAL.
<ls_cc_data>-pruef = <ls_ccicons>-icon_id.
ENDIF.
ENDIF.
Before entering the statement that I have shown in the code, the program would enter in each qnum = ls_refferal-qmnum and fill the pruef field, however it did not take into account the cases when the qnum had the same values throughout the table. What I try to did is filling the pruef field only in those cases when the field is empty.
Being that I cannot test it due to lack of data in the development system, is the logic behind my solution correct and if not can someone give me an similar solution?
Thank you all in advance!
EDIT
The code would look like this now:
READ TABLE lt_cc_data ASSIGNING <ls_cc_data>
WITH KEY qmnum = ls_refferal-qmnum.
IF <ls_cc_data>-pruef is INITAL. *>>>>>Statement that I added
<ls_cc_data>-pruef = <ls_ccicons>-icon_id.
ENDIF.

BAPI/FM to search prod orders confirmations by workcenter and date?

I'm trying to figure out which BAPI/FM I could use to search amounts confirmed based on search criteria of date (+time if possible) and workcenter confirmed where was confirmed...
I would be using BAPI_PRODORDCONF_GETDETAIL which contains these informations, but according to BAPI guide I can only load in the data of confirmation number+confirmation counter.
Therefore the option would be to run BAPI_PRODORDCONF_GETLIST (but I can only input the production order range or confirmation number range), then filter what includes the workcenter and date I need and from those pick up confirmation number+counter and run it through BAPI_PRODORDCONF_GETDETAIL.
but this procedure of getting list of everything without data being filtered on serverside is extemly timeconsuming and out of SAP Gui I have timeout error... therefore I need any BAPI/FM which I could input the workcenter where was confirmed and date, and have the data filtered already...
Any ideas how to do that?
As far as I know there is no such standard FM, so your only choice is custom development.
I would suggest you MCPK transaction were this info is exposed in a handy form, but as I see that your requirement is to receive this info externally this is not appropriate for you.
The confirmations reside in AFRU table and workcenters are in CRHD, so to find confirmed quantities by workcenter you should join these tables, or use a view u_15673 where this info is linked:
TYPES: BEGIN OF prod_orders,
rueck TYPE afru-rueck, "confirmation number
rmzhl TYPE afru-rmzhl," confirmation counter
gmnga TYPE afru-gmnga, " quantity
arbid TYPE crhd-arbpl, " workcenter
END OF prod_orders.
DATA: orders TYPE TABLE OF prod_orders.
SELECT *
FROM u_15673
INTO CORRESPONDING FIELDS OF TABLE orders
WHERE isdd >= '20180101' AND isdz <= '163000'.
To pull this externally, you must create RFC-enabled FM or use RFC_READ_TABLE and fetch this view with parameters, here is the sample.
Another approach is to use RFC_ABAP_INSTALL_AND_RUN. You must create an ABAP program that uses WRITE for output the results as a standard list to screen.
Send the lines of this program to RFC_ABAP_INSTALL_AND_RUN to PROGRAM parameter and the code will be executed on the remote system and this FM will return screen results as the lines of table WRITES.
Possible sample based on MCPK tcode to send to RFC_ABAP_INSTALL_AND_RUN:
CLEAR lwa_selection.
lwa_selection-selname = 'SL_SPTAG'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'BT'.
lwa_selection-low = '20180101'.
lwa_selection-high = '20201231'.
APPEND lwa_selection TO li_selection.
CLEAR lwa_selection.
lwa_selection-selname = 'SL_ARBPL'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'EQ'.
lwa_selection-low = '10400001'.
APPEND lwa_selection TO li_selection.
SUBMIT rmcf0200 WITH SELECTION-TABLE li_selection
with par_stat = abap_true
EXPORTING LIST TO MEMORY
AND RETURN.
DATA: xlist TYPE TABLE OF abaplist.
DATA: xtext TYPE TABLE OF char200.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = xlist.
CALL FUNCTION 'LIST_TO_TXT'
EXPORTING
list_index = -1
TABLES
listtxt = xtext
listobject = xlist.
IF sy-subrc = 0.
LOOP AT xtext ASSIGNING FIELD-SYMBOL(<text>).
WRITE <xtext>.
ENDLOOP.
ENDIF.
However, this approach is not flexible because MCPK standard layout is a bit different than you want, and is not easy to adjust programmatically.
Because of that I recommend to stick to the RFC_READ_TABLE approach.

AUTHORITY-CHECK for complex selection field (like SELECT-OPTIONS)

I have a custom report with the following selection screen. It allows the user to input value ranges when executing the report.
I want to carryout an authorization check to the inputs that the user has entered.
For this I use AUTHORITY-CHECK OBJECT with the user and the selection field;
AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
FOR USER sy-uname
ID 'BUKRS' FIELD pnpbukrs-low
.
Where pnpbukrs is the selection field that the user has entered.
How do I do this check properly for all possible combinations that the user might give?
When I provide the direct pnpbukrs field, the Options in the selection field is considered in the auth. check giving errors.
When I user pnpbukrs-low, only a single value is used in the auth. check making a check bypass.
In case the selection table contains generic entries, intervals, excluded entries or excluded intervals, you should first get the list of companies corresponding to the selection table (with WHERE ... IN selectiontable ; IN will deal with all these kinds of filters), then do an authority-check on each of the real companies.
For instance, I assume that the companies are to be taken from the table T001 :
SELECT bukrs FROM t001 WHERE bukrs IN pnpbukrs INTO TABLE #DATA(companies).
LOOP AT companies ASSIGNING FIELD-SYMBOL(<company>).
AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
ID 'BUKRS' FIELD <company>.
IF sy-subrc <> 0.
" this company is not authorized, do something
ENDIF.
ENDLOOP.
PS #1: If the goal is only to select the authorized data from a given table, you may use the class CL_AUTH_OBJECTS_TO_SQL (>= 7.50)
PS #2: for AUTHORITY-CHECK, it's useless to mention FOR USER sy-uname as it's the default setting.
For range with any data
Go for #Sandra Rossi answer
For range filled with LOW component only:
Try looping over the select-options field and make an authority check for each iteration:
LOOP AT pnpbukrs ASSIGNING FIELD-SYMBOL(<line>).
AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
FOR USER sy-uname
ID 'BUKRS'
FIELD <line>-low.
ENDLOOP.

ALV report fill gap between documents

I was trying to challenge myself to make an ALV report that displays all the data by company code. but some document number has a gap.
I want to fill the gap between missing number
For example:
last index value: 20012
then next value is: 20014
How do I able to insert 20013 in the grid if the report is using all the data that exist in internal tables?
Thanks.
This is just blind text typing, but I hope you are able to understand it ... should be quite simple. Dont expect complete code, unless your are not even providing ANY code.
DATA: lv_current type i,
lv_next type i.
SORT lt_internalTable by BUKRS ascending.
LOOP AT lt_internalTable into ls_internalTable.
MOVE sy-tabix to lv_current.
READ TABLE lt_internalTable into ls_tempinternalTable INDEX sy-tabix + 1.
MOVE sy-tabix to lv_next.
IF (lv_next - lv_current) > 1.
... do your stuff
ENDIF.
CLEAR: ls_internalTable, lv_current, lv_next.
ENDLOOP.

How to retrieve a specific field from a list output?

I don't have any developer rights in my SAP-System but I found a way to write some ABAP-Code in a tiny "User-Exit" box (I don't know if that's what you call it) inside a report.
I'm trying to submit a HR-Report and plug it's outcoming PERNR into that same report again.
There's a syntax-error that is telling me that t_list doesn't have a component with the Name PERNR.
What do I have to do in order to get this to work?
DATA: t_list TYPE TABLE OF abaplist WITH HEADER LINE,
seltab TYPE TABLE OF rsparams,
selline LIKE LINE OF seltab.
*I found out that the name of the selection field in the Report-GUI is "PNPPERNR" and tested it
selline-selname = 'PNPPERNR'.
selline-sign = 'I'.
selline-option = 'EQ'.
SUBMIT Y5000112
USING SELECTION-SET 'V1_TEST'
EXPORTING LIST TO MEMORY
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE 'Unable to get list from memory'.
ELSE.
LOOP AT t_list.
*The Problem is here: how do I get the pnppernr out of t_list, it's the first column of the report output
selline-low = t_list-pernr.
append selline to seltab.
ENDLOOP.
SUBMIT Y5000112
WITH SELECTION-TABLE seltab
USING SELECTION-SET 'V2_TEST'
AND RETURN.
ENDIF.
Use the function module LIST_TO_ASCI to decode the contents of t_list into something readable. This answer contains some sample code including the data types required. At this point, the data you're looking for will probably occur at the same column range in the output. Use the standard substring access methods - e. g. line+42(21) to obtain the part of the line you need.
The vwegert's answer is more than useful! In my previous answer I forgot to mention LIST_TO_ASCI FM :)
The only thing I can add is that parsing of result lines has no universal solution and greatly depends on its structure. Usually it is done like:
LOOP AT t_list.
SPLIT t_list AT '|' INTO <required_structure>.
selline-low = <required_structure>-pernr.
APPEND selline TO seltab.
ENDLOOP.
where <`required_structure> is your Y5000112 output structure. But this may be not so simple and may require additional manipulations.