Mass unlock/lock users

How to mass unlock or lock a list of users

You may use transaction code SU10, User maintenance: Mass Changes.
You may noticed that you are needed to manually key in the user id up to 18 rows only. But afraid not, you may paste a long list of users id with this method

  1. Go to SU10
  2. Click on Authorisation Data button
  3. Click Multi selection for user column 
  4. Key in list of users
     Image
  5. Execute 
  6. This will bring you to a report page 
  7. Select all users and click Transfers
     Image
  8. Now you will be back at User maintenance along with the list of users 
  9. Click on Lock users 
  10. Done. Check the log.

 

dynamic search help to auto populate screen

Here is an sample program I created where a parameter has a search help that will auto populate another parameter. The program is not perfect and I will continue to update and explain in my next post.

Here you can also see how to disabled or grey out a field by using screen attribute input = 0 during selection screen output.

The function to be call are F4IF_INT_TABLE_VALUE_REQUEST, DYNP_VALUES_UPDATE. The rest I will let the code do the talking 😉

In this screenshot, I chose AA

Capture

The name of AA will be auto populated

Capture2

*&———————————————————————*
*& Report  ZALEX_SEARCHHELP_F4_SFLIGHT
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZALEX_SEARCHHELP_F4_SFLIGHT.

TYPES:BEGIN OF T_SCARR,
CARRID       TYPE SCARR-CARRID,
END OF T_SCARR,
T_RETURN_TAB  TYPE DDSHRETVAL.

DATA:S_SCARR      TYPE T_SCARR,
W_RETURN_TAB TYPE T_RETURN_TAB.
DATA:I_SCARR      TYPE STANDARD TABLE OF T_SCARR,
I_RETURN_TAB TYPE STANDARD TABLE OF T_RETURN_TAB.
DATA:W_DYNPFIELDS TYPE DYNPREAD,
I_DYNPFIELDS LIKE STANDARD TABLE OF DYNPREAD,
lv_carrname type SCARR-carrname.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS :P_ID TYPE SCARR-CARRID.
PARAMETERS :P_NAME TYPE SCARR-CARRNAME.
SELECTION-SCREEN END OF BLOCK B1.

“Disable parameter
at selection-screen output.
loop at screen.
if screen-name = ‘P_NAME’.
screen-input = 0.
modify screen.
endif.
endloop.

“F4 Help for CARRID
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ID.
IF I_SCARR[] IS INITIAL.
SELECT CARRID
FROM SCARR
INTO TABLE I_SCARR.
ENDIF.

“Function module for F4 help
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
RETFIELD    = ‘CARRID’   “field name on f4 help window
DYNPPROG    = SY-REPID
DYNPNR      = SY-DYNNR
DYNPROFIELD = ‘P_CARRID’ “Screen field name
VALUE_ORG   = ‘S’
TABLES
VALUE_TAB   = I_SCARR
RETURN_TAB  = I_RETURN_TAB.

READ TABLE I_RETURN_TAB INTO W_RETURN_TAB INDEX 1.
P_ID = W_RETURN_TAB-FIELDVAL.
READ TABLE I_SCARR INTO S_SCARR WITH KEY CARRID = P_ID.

IF SY-SUBRC = 0.

select single CARRNAME
from SCARR
into lv_carrname
where CARRID = P_ID.

if sy-subrc EQ 0.
W_DYNPFIELDS-FIELDNAME    = ‘P_NAME’.
W_DYNPFIELDS-FIELDVALUE   = lv_carrname.

APPEND W_DYNPFIELDS TO I_DYNPFIELDS.
CLEAR W_DYNPFIELDS.

“DYNP_VALUES_UPDATE
CALL FUNCTION ‘DYNP_VALUES_UPDATE’
EXPORTING
DYNAME     = SY-REPID
DYNUMB     = SY-DYNNR
TABLES
DYNPFIELDS = I_DYNPFIELDS.
endif.
ENDIF.

Excel remove leading zero, Excel missing leading zero

Are you experiencing missing leading zero in excel ? Here is a short summary about excel and leading zero

When you export a file as excel file in SAP using function module GUI_DOWNLOAD, actually it is downloading as a tab delimited format which you can open with Excel or a notepad. If you export as a plain text file, the leading zero will be maintained but if you open with Excel, the leading zero is not maintained because Excel has it own formatting.  By default, Excel set a cell  as ‘General’ and this formatting will remove any leading zero of a value.

There are three methods how to maintain the leading zero in excel.

Method 1 – use DBF file type
Method 2 – set value into excel’s formula
Method 3 – use function module XXL_FULL_API

Method 1 
Use function module gui_download with the filetype set to ‘DBF’

call method cl_gui_frontend_services=>gui_download
  exporting
    filename                = ‘H:/PD Video/test.xls’
    filetype                = ‘DBF’
    write_field_separator   = ‘X’
  changing
    data_tab                = iexcel.

According do the function module documentation

‘DBF’ :

Data is downloaded in dBase format. Since in this format the data types
of the individual columns are stored as well, you can often avoid import
problems, for example, into Microsoft Excel, especially when
interpreting numeric values.

Method 2

A simple workaround for this is to set the value in the cell’s formula.

I believe you may use any excel formula. In my example I used CONCATENATE.

CONCATENATE ‘=CONCATENATE(“‘xt001-bukrs'”)’ into wa_t001-field_a
wa_t001-field_b = xt001-bukrs.
wa_t001-field_c = xt001-description.

Image

Method 3 
Use FM XXL_FULL_API, where you can define the cell formatting to ‘Text’ instead of ‘General’.
With ‘Text’ formatting , the leading zero of a value will be maintained.

Table maintenance event

How to create event at table maintenance.

Scenario

My scenario was user wants to default a date to today’s date in the table maintenance.

Prerequisites 

1. Table created and activated
2. Table maintenance created and saved

Image

1. First enter se11 to your table in change mode.

Image

2. Secondly enter environment->modification->events

bitcoin4

3. Click on ‘New Entries’

Image

4. Select one of the event provided. For this example, i choose 05, creating a new entry. A common scenario is to default the date as today’s date when inserting a data into the table.

This will create an include and inside that include you may perform your logic inside a function call.
Take note that your function routine has to be the same name as specify in the screen below.

Image

An example would be like this.

*———————————————————————-*
***INCLUDE LZALEX_DUMMYF01 .
*———————————————————————-*

form create_entry.
ZALEX_DUMMY-DATE1 = sy-datum.
endform.

5. Save all objects. That’s it your done. So whenever you add a new entry, a default value which is today’s date will be auto inserted into the entry.

Dynamic date for selection screen

There are two methods to have a dynamic date at the selection screen.

  1. ABAP
  2. Variant

Method one

In ABAP, use the value option default with value of ‘sy-datum’.

PARAMETERS: s_date TYPE sy-datum DEFAULT sy-datum.

This method is more flexible as you may code the logic at ‘AT SELECTION-SCREEN OUTPUT.’

Method two

Method two does not require ABAP and it would be useful if you could not edit a program or program is standard.

Save the selection screen variant with the following attributes

  • selection variable = ‘D’
  • Name of variable = Current date.

Image

Following are the list of option for variable.

Image

Function module to retrieve Fiscal year and duration

* retrieve fiscal year
SELECT SINGLE periv INTO l_periv FROM t001
WHERE bukrs = wa_cust_temp-bukrs.
IF sy-subrc EQ 0.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date         = berdatum
i_periv        = l_periv
IMPORTING
e_gjahr        = v_year
EXCEPTIONS
input_false    = 1
t009_notfound  = 2
t009b_notfound = 3
OTHERS         = 4.
  IF sy-subrc EQ 0.

  CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
    EXPORTING
      i_gjahr        = v_year
      i_periv        = l_periv
    IMPORTING
      e_first_day    = l_firstday
      e_last_day     = l_lastday
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.

    ENDIF.

ENDIF.

spro_fiscal

WRITE – int_format_options

Syntax

… [LEFT-JUSTIFIED|CENTERED|RIGHT-JUSTIFIED]
[NO-GAP]
[UNDER other_dobj]
{ { [EXPONENT exp]
[NO-GROUPING]
[NO-SIGN]
[NO-ZERO]
[CURRENCY cur]
{ { [DECIMALS dec]
[ROUND scale] }
| [UNIT unit] } }
| { [ENVIRONMENT TIME FORMAT]
[TIME ZONE tz] } }
[USING { {NO EDIT MASK}|{EDIT MASK mask} }]
[ DD/MM/YY | MM/DD/YY
| DD/MM/YYYY | MM/DD/YYYY
| DDMMYY | MMDDYY
| YYMMDD ] … .

Translate condense

Today I would like to introduce the syntax TRANSLATE and CONDENSE which I found it pretty handy but less commonly used. Translate can be used to convert text to upper or lower case or convert according to a mask specified. Condense is like a combination of shift right deleting trailing+ shift left deleting trailing. Add in a ‘no-gaps’ and it will be like middle shift deleting trailing. I came across it when I was trying to remove a comma from a number. I will post an example below on what I did exactly. I felt it was clean, elegant and easily readable too.

Translate

Syntax

TRANSLATE text {TO {UPPER|LOWER} CASE}
| {USING mask}.

http://help.sap.com/abapdocu_702/en/abaptranslate.htm

Condense

Syntax

CONDENSE text [NO-GAPS].

http://help.sap.com/abapdocu_702/en/abapcondense.htm

Example

        TRANSLATE gs_excel-value USING ', '.
        CONDENSE gs_excel-value NO-GAPS.

gs_excel-value = 10,000.00

the syntax TRANSLATE will replace the comma as empty character. The output will be

gs_excel-value = 10 000.00

After condense with no gaps, the output would be

gs_excel-value = 10000.

Move/Copy file to directory at AL11

Move file to directory at AL11
Copy file to directory at AL11

To copy or move a file from directory at  AL11, I have used this function ARCHIVFILE_SERVER_TO_SERVER.
Take note that if the system is in unix, the path is case sensitive!

for example

/path1/path2/path3/file.xml

is different from

/path1/path2/path3/File.xml

CALL FUNCTION ‘ARCHIVFILE_SERVER_TO_SERVER’
EXPORTING
SOURCEPATH       =
*     TARGETPATH       = ‘ ‘
*   IMPORTING
*     LENGTH           =
*   EXCEPTIONS
*     ERROR_FILE       = 1
*     OTHERS           = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 

After you have copy a file, you may use DELETE DATASET to delete a file.

To add, I also have use this function module to list all the files in a directory

CALL FUNCTION ‘EPS_GET_DIRECTORY_LISTING’
EXPORTING
DIR_NAME                     =
*     FILE_MASK                    = ‘ ‘
*   IMPORTING
*     DIR_NAME                     =
*     FILE_COUNTER                 =
*     ERROR_COUNTER                =
TABLES
DIR_LIST                     =
*   EXCEPTIONS
*     INVALID_EPS_SUBDIR           = 1
*     SAPGPARAM_FAILED             = 2
*     BUILD_DIRECTORY_FAILED       = 3
*     NO_AUTHORIZATION             = 4
*     READ_DIRECTORY_FAILED        = 5
*     TOO_MANY_READ_ERRORS         = 6
*     EMPTY_DIRECTORY_LIST         = 7
*     OTHERS                       = 8

 

If you face error, it’s might be these following possibility which I faced.
1. Authorisation ( you may use this function module to check , AUTHORITY_CHECK_DATASET )
2. Mode of the directory ( go to AL11, double click a directory, click Attributes, check Mode. It should have write privileges.