Vous êtes sur la page 1sur 74

How to Transport ABAP Report Variant

To transport the ABAP report variant go to ABAP Editor (SE38).

Enter the name of the program, choose Variants radio button and press Display button.

In the ABAP Variants screen, go to menu Utilities > Transport request

When you click on menu Utilities > Transport request, it will call the SAP standard report RSTRANSP. You can also reach the above screen by just executing the report RSTRANSP in ABAP Editor (SE38). Enter the name of the program and variant name and execute (F8).

Select all the variants you want to transport and press continue.

Assign the variant to an already existing Transport request or create a new request.

2. Download File to SAP Presentation Server using ABAP


Use the following steps to download the ABAP internal table data to a file in SAP application server. 1. 2. 3. Declare a ABAP internal table. Fill the internal table with required data. Use function module GUI_DOWNLOAD or GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES class to download the data. Below program uses function module GUI_DOWNLOAD to download the file.

*----------------------------------------------------------------------* * Data Decalaration

*----------------------------------------------------------------------* DATA: gt_spfli TYPE TABLE OF spfli,

gwa_spfli TYPE spfli.

DATA: gv_filename TYPE string, gv_filetype TYPE char10. *----------------------------------------------------------------------* * START-OF-SELECTION

*----------------------------------------------------------------------* PERFORM get_data. IF NOT gt_spfli[] IS INITIAL. PERFORM save_file. ELSE. MESSAGE 'No data found' TYPE 'I'.

ENDIF. *&---------------------------------------------------------------------* *& Form get_data

*&---------------------------------------------------------------------* FORM get_data. *Get data from table SPFLI SELECT * FROM spfli INTO TABLE gt_spfli. ENDFORM. " get_data

*&---------------------------------------------------------------------* *& Form save_file

*&---------------------------------------------------------------------* FORM save_file. *Move complete file path to file name gv_filename = 'C:\test\data.txt'.

*Download the internal table data into a file in SAP presentation server CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename filetype = gv_filename = 'ASC'

write_field_separator TABLES data_tab

= 'X'

= gt_spfli.

ENDFORM.

" save_file

When you execute the above program, the file data.txt will be downloaded to C:\test.

We can also use GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES class to download the file. Instead of calling GUI_DOWNLOAD function module in the save_file subroutine of above program, call the GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES class.

CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename filetype = gv_filename = 'ASC'

write_field_separator = 'X' CHANGING data_tab = gt_spfli.

3. Download File to SAP Application Server using ABAP


Posted in Files on 13/11/2012

Use the following steps to download the ABAP internal table data to a file in SAP application server. 1. 2. 3. Declare a ABAP internal table and fill the internal table with required data. Use OPEN DATASET ABAP statement to open/create a file on the SAP application server. Loop through the internal table and use TRANSFER ABAP statement to move each internal table record to file on application server. 4. Close the file on the application server using CLOSE DATASET ABAP statement. Below program uses OPEN DATASET, TRANSFER and CLOSE DATASET statements to download the file.

*----------------------------------------------------------------------* * Data Decalaration

*----------------------------------------------------------------------* DATA: gt_spfli TYPE TABLE OF spfli,

gwa_spfli TYPE spfli. DATA: gv_file TYPE rlgrap-filename.

*----------------------------------------------------------------------* * START-OF-SELECTION

*----------------------------------------------------------------------* PERFORM get_data. IF NOT gt_spfli[] IS INITIAL. PERFORM save_file. ELSE. MESSAGE 'No data found' TYPE 'I'.

ENDIF. *&---------------------------------------------------------------------* *& Form get_data

*&---------------------------------------------------------------------* FORM get_data. *Get data from table SPFLI SELECT * FROM spfli INTO TABLE gt_spfli. ENDFORM. " get_data

*&---------------------------------------------------------------------* *& Form save_file

*&---------------------------------------------------------------------* FORM save_file. DATA: lv_data TYPE string.

*Move complete path to filename gv_file = 'spfli.txt'.

* Open the file in output mode OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0.

MESSAGE 'Unable to create file' TYPE 'I'. EXIT. ENDIF.

LOOP AT gt_spfli INTO gwa_spfli. CONCATENATE gwa_spfli-carrid gwa_spfli-connid gwa_spfli-countryfr gwa_spfli-cityfrom gwa_spfli-airpfrom gwa_spfli-countryto gwa_spfli-cityto gwa_spfli-airpto gwa_spfli-arrtime INTO lv_data SEPARATED BY ','. *TRANSFER moves the above fields from workarea to file *delimited format TRANSFER lv_data TO gv_file. CLEAR: gwa_spfli. ENDLOOP. with comma

* close the file CLOSE DATASET gv_file.

ENDFORM.

" save_file

When you execute the above program, the data in the internal table will be downloaded to a file on the application server. Use t-code AL11 to view the file on SAP application server.

Just double click on the file spfli.txt to view the contents.

4. Upload File from SAP Application Server using ABAP


Posted in Files on 13/11/2012

Use the following steps to upload data from a file in SAP application server to ABAP internal table. 1. 2. 3. Declare a ABAP internal table. Use OPEN DATASET ABAP statement to open file on appliction server. Use READ DATASET ABAP statement to read each line in the file to workarea. Append work area data to internal table. 4. 5. Use CLOSE DATASET ABAP statement to close the application server file. Process the data in the internal table. Below program uses OPEN DATASET, READ DATASET and CLOSE DATASET statements to upload the file.

*----------------------------------------------------------------------* * Data Decalaration

*----------------------------------------------------------------------* DATA: gt_spfli TYPE TABLE OF spfli,

gwa_spfli TYPE spfli. DATA: gv_file TYPE rlgrap-filename.

*----------------------------------------------------------------------* * START-OF-SELECTION

*----------------------------------------------------------------------* PERFORM read_file. PERFORM display_data.

*&---------------------------------------------------------------------*

*&

Form

read_file

*&---------------------------------------------------------------------* FORM read_file. DATA: lv_data TYPE string.

*Move complete path to filename gv_file = 'spfli.txt'.

*Open the file in application server to read the data OPEN DATASET gv_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. MESSAGE 'Unable to open file' TYPE 'I'. ENDIF. DO. * * Loop through the file, if a record is found move it to temporary structure else exit out of the loop. READ DATASET gv_file INTO lv_data. IF sy-subrc = 0. * * Split the fields in temporary structure to corresponding fields in workarea. SPLIT lv_data AT ',' INTO gwa_spfli-carrid

gwa_spfli-connid gwa_spfli-countryfr gwa_spfli-cityfrom gwa_spfli-airpfrom gwa_spfli-countryto gwa_spfli-cityto gwa_spfli-airpto gwa_spfli-arrtime. APPEND gwa_spfli TO gt_spfli. CLEAR gwa_spfli. ELSE. EXIT. ENDIF. ENDDO. *Close the file CLOSE DATASET gv_file.

ENDFORM.

" read_file

*&---------------------------------------------------------------------* *& Form DISPLAY_DATA

*&---------------------------------------------------------------------* FORM display_data . LOOP AT gt_spfli INTO gwa_spfli. WRITE:/ gwa_spfli-carrid, gwa_spfli-connid, gwa_spfli-countryfr, gwa_spfli-cityfrom, gwa_spfli-airpfrom, gwa_spfli-countryto, gwa_spfli-cityto, gwa_spfli-airpto, gwa_spfli-arrtime. CLEAR: gwa_spfli. ENDLOOP. ENDFORM. " DISPLAY_DATA

When you execute the above program reads the data from the file in application server and displays the following output.

5.
1. 2.

ABAP F4 Help for File on SAP Application Server

Posted in Files on 13/11/2012

Use the following steps to provide ABAP F4 help for SAP application server file on selection screen. Declare a input field(PARAMETER) for filename. Use function module /SAPDMC/LSM_F4_SERVER_FILE in AT SELECTION-SCREEN ON VALUE-REQUEST FOR FIELD event to provide F4 help for SAP application server file. 3. Upload data from/Download data to file. Below program uses function module/SAPDMC/LSM_F4_SERVER_FILE to provide ABAP F4 help for a file on application server.

*----------------------------------------------------------------------* * Data Decalaration

*----------------------------------------------------------------------* DATA: g_directory(30). *----------------------------------------------------------------------* * SELECTION-SCREEN

*----------------------------------------------------------------------* PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

*----------------------------------------------------------------------* * AT SELECTION-SCREEN ON VALUE-REQUEST

*----------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*Set default directory

g_directory = '.'.

*F4 help for file name on SAP application server CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE' EXPORTING directory IMPORTING serverfile EXCEPTIONS canceled_by_user = 1 OTHERS IF sy-subrc <> 0. MESSAGE 'Error Message' TYPE 'I'. ENDIF. = 2. = p_file = g_directory

*----------------------------------------------------------------------* * START-OF-SELECTION

*----------------------------------------------------------------------* START-OF-SELECTION. WRITE:/ 'Filepath : ', p_file.

When you execute the above program and press F4 help for file on selection screen, file dialog pop up will be displayed.

6. Deactivate Execute Button in an ABAP report


Posted in Reports on 19/01/2011

Sometimes we want to run reports only in background due to performance issues or some other reasons. Here we are trying to deactivate the EXECUTE option altogether so that the user has to use background option only. Function module RS_SET_SELSCREEN_STATUS can be used to exclude any function codes from customized or standard GUI status on selection screen. ONLI is the function code attached to the EXECUTE option. We can deactivate this option using the following code.

DATA: gv_ucomm TYPE sy-ucomm. DATA: gt_ucomm TYPE TABLE OF sy-ucomm.

PARAMETERS: p_name(10).

AT SELECTION-SCREEN OUTPUT.

gv_ucomm = 'ONLI'. APPEND gv_ucomm TO gt_ucomm. CLEAR gv_ucomm.

CALL FUNCTION 'RS_SET_SELSCREEN_STATUS' EXPORTING p_status * P_PROGRAM TABLES = sy-pfkey = ' '

p_exclude

= gt_ucomm.

START-OF-SELECTION. WRITE: 'Hello ', p_name.


Run the report to see the EXECUTE button removed from the application toolbar in the selection screen.

Also the menu path Program->Execute is disabled.

7. Performance in SAP SD Customer Developments.


Posted in Performance on 10/01/2013

Sometimes

we

experience VBAK VBAP

bad

performance Sales

while

accessing

the

following

SAP Item Header Item

SD

tables: Data Data Data data Data Data

Document: Document: Delivery Delivery:

Header

Sales SD SD Document: document: Billing:

LIKP LIPS VBRK VBRP

Header Item

Billing:

VBFA Sales Document Flow

The R/3 System contains no secondary indexes to the most important SD transaction data tables in the delivery. Instead, the R/3 System has proprietary index tables (sales document indexes, for example the tables VAKPA and VAPMA, matchcode tables for example M_VMVAB, M_VMVAC or matchcode views for example M_VMVAA, M_VMVAE), which allow an efficient access. Consider the following NOTES mentioned in SAP Note 185530 while accessing SAP SD tables in order to improve the performance: 1. Search for deliveries with sales order number (preceding document, field LIPS-VGBEL): Incorrect:

SELECT FROM lips WHERE vgbel = ...


Correct:

SELECT FROM vbfa WHERE VBELV = ... AND VBTYP_N = 'J'

SELECT FROM lips WHERE vbeln = vbfa-vbeln AND posnr = vbfa-posnn


2. Search for invoices with delivery number (preceding document, field VBRP-VGBEL): Incorrect:

SELECT FROM vbrp WHERE vgbel = ...


Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'M' AND vbelv = ...

SELECT FROM vbrp WHERE vbeln = vbfa-vbeln AND posnr = vbfa-posnn


3. Search for invoices with order number (preceding document, field VBRP-AUBEL): Incorrect:

SELECT FROM vbrp WHERE aubel = ...


Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'M' AND vbelv = ...

SELECT FROM vbrp WHERE vbeln = vbfa-vbeln AND posnr = vbfa-posnn


4. Incorrect: Document flow:

SELECT vbelv FROM vbfa WHERE vbeln ...


In table VBFA only the preceding document is used to search for the subsequent document (for example, delivery for order). Searching the other way makes no sense with this table since the preceding documents (for example, order for delivery) are stored directly in the document tables. Thus reading in table VBFA is a one-way street. Correct:

SELECT vgbel FROM lips WHERE vbeln = ...; or

SELECT vgbel FROM vbrp WHERE vbeln = ...; or SELECT aubel FROM vbrp WHERE vbeln = ...
Search Incorrect: for shipping unit item with delivery

SELECT FROM vepo WHERE vbtyp = 'J' AND vbeln = i_lips-vbeln


Correct:

SELECT FROM vbfa WHERE vbtyp_n = 'X' AND vbelv = i_lips-vbeln

SELECT FROM vepo WHERE venum = vbfa-vbeln


Refer to SAP Note 185530 for more information.

8. Performance in SAP MM Customer Developments.


Posted in Performance on 10/01/2013

Sometimes

we

experience MSEG EBAN

bad

performance

while

accessing

the

following Segment:

SAP

MM

tables: Material

Document

Purchase

Requisition

RSEG Document Item: Incoming Invoice

Consider the following NOTES mentioned in SAP Note 191492 while accessing SAP MM tables in order to improve the 1. Access to material documents via the purchase order number Incorrect: performance:

SELECT FROM MSEG WHERE EBELN = ... AND EBELP = ...


Correct:

SELECT FROM EKBE WHERE EBELN = .. AND EBELP = ... AND VGABE IN (1,6,7,8,9).

SELECT FROM MSEG WHERE MBLNR = EKBE-BELNR AND MJAHR = EKBE-GJAHR AND ZEILE = EKBE-BUZEI.
Remark: The fiscal year must be specified so that the system has effective access possibilities via the primary index.If the fiscal year is missing, the database can no longer effectively use the item number for the search (this is a problem, especially for material documents with many items).If the operation type VGABE is specified, the values can be additionally restricted to the corresponding goods movements that are relevant. 2. Access to material documents Via the vendor number Incorrect:

SELECT FROM MSEG WHERE LIFNR = ...


Correct:

SELECT EKKO WHERE LIFNR = ....

SELECT EKBE WHERE EBELN = EKKO-EBELN AND VGABE = '1'.

SELECT MSEG WHERE MBLNR = EKBE-BELNR AND MJAHR = EKBE-GJAHR AND ZEILE = EKBE-BUZEI.
Remark: Accesses to EKKO and EKBE return several datasets under certain circumstances. This must be taken into account in the program logic.With the operation type VGABE = 1, only goods movements for purchase orders are selected. As an alternative you can use matchcode object M_MEKKL in place of table EKKO (for example SELECT FROM M_EKKL WHERE LIFNR = ).Access can be improved by specifying additional restrictions.Thefields purchasing organization EKORG, purchasing group EKGRP, document date BEDAT, purchasing document category BSTYP, order type BSART can make the access more selective. 3. Accesses to purchase requisitions via the reservation number Incorrect:

SELECT FROM EBAN WHERE EBELN = .... AND EBELP = ....


Correct:

SELECT FROM EKET WHERE EBELN = .... AND EBELP = ....

SELECT FROM EBAN WHERE BANFN = EKET-BANFN AND BANFPO = EKET-BANFPO.


4. Access to incoming invoices via the purchase order number Incorrect:

SELECT FROM RSEG WHERE EBELN = ... AND EBELP = ...


Correct:

SELECT FROM EKBE WHERE EBELN = ... AND EBELP = ... AND VGABE IN (2,3,P).

SELECT FROM RSEG WHERE BELNR = EKBE-BELNR AND GJAHR = EKBE-GJAHR AND BUZEI = EKBE-BUZEI.
Remark: By specifying transaction type VGABE, the values are restricted to the relevant goods movements. With GJAHR and BUZEI, the primary index is completely utilized by RSEG. Refer to SAP Note 191492 for more information.

9. How to Change Logo in SAP Easy Access?


Posted in ABAP General on 27/01/2012

The properties for the logo in SAP Easy Access is maintained in the table "SSM_CUST". First upload the logo to SAP system. Then go to SM30 to maintain the table SSM_CUST.

Enter the name of the table as SSM_CUST and press maintain.

The table SSM_CUST consists name value pairs for different properties. The property START_IMAGE contains the name of the logo to be displayed in SAP Easy Access. Please maintain the proper name of the logo i.e uploaded using SMW0 and save the entries. Now open a new session and observe the new logo in SAP Easy Access.

Other properties in the table also controls the display of the logo in SAP Easy Access. For example, if we set HIDE_START_IMAGE to YES it will not display the logo. Similarly if we set RESIZE_IMAGE to NO it will display the image with original size.

12. Upload Logo to SAP System


Posted in Reports on 18/01/2012

Use the tcode SMW0 to upload the company logo to SAP system. Go to tcode SMW0.

Select Binary data for WebRFC applications radio button and press find(F8) button.

Enter the proper package and press execute(F8).

Enter object name and description and press import.

Select the proper logo(GIF image) from the desktop.

Save it to proper package.

The logo is uploaded to SAP and is ready to use in SAP ABAP programs.

13. Custom F4 Help on Selection Screen


Posted in Selection Screen on 30/11/2011

We can provide custom F4 help for any input fields on selection screen using the function module F4IF_INT_TABLE_VALUE_REQUEST in AT SELECTION-SCREEN ON VALUE-REQUEST FOR field event.

TYPES: BEGIN OF ty_matnr, matnr TYPE makt-matnr, maktx TYPE makt-maktx, END OF ty_matnr. *--------------------------------------------------------------* *Data Declaration *--------------------------------------------------------------* DATA: gwa_matnr gt_matnr DATA: gt_return TYPE ty_matnr, TYPE TABLE OF ty_matnr. TYPE TABLE OF ddshretval,

gwa_return TYPE ddshretval. *--------------------------------------------------------------* *Selection-Screen *--------------------------------------------------------------* PARAMETERS: p_matnr TYPE mara-matnr.

*--------------------------------------------------------------* *Selection-Screen on Value-Request *--------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_matnr.

REFRESH gt_matnr.

gwa_matnr-matnr = 'AAA'. gwa_matnr-maktx = 'Dummy Material 1'. APPEND gwa_matnr TO gt_matnr.

gwa_matnr-matnr = 'BBB'. gwa_matnr-maktx = 'Dummy Material 2'. APPEND gwa_matnr TO gt_matnr.

gwa_matnr-matnr = 'CCC'. gwa_matnr-maktx = 'Dummy Material 3'. APPEND gwa_matnr TO gt_matnr.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield value_org TABLES value_tab return_tab EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3. = gt_matnr = gt_return = 'MATNR' = 'S'

READ TABLE gt_return INTO gwa_return INDEX 1. IF sy-subrc = 0. p_matnr = gwa_return-fieldval. ENDIF.
Selection Screen Output

16. Custom F1 Help for ABAP Checkbox and Radiobutton


Posted in Selection Screen on 29/08/2012

Use the function module COPO_POPUP_TO_DISPLAY_TEXTLIST to create custom F1 help for checkbox and radio button in SAP ABAP.

DATA: gt_text

TYPE TABLE OF tline,

gwa_text TYPE tline. *&---------------------------------------------------------------------* *& Selection Screen

*&---------------------------------------------------------------------* PARAMETERS: p_chk AS CHECKBOX.

*&---------------------------------------------------------------------* *& At Selection Screen Event

*&---------------------------------------------------------------------* AT SELECTION-SCREEN ON HELP-REQUEST FOR p_chk.

gwa_text-tdformat = 'U1'. " To display text in blue color gwa_text-tdline = 'F1 Help'. APPEND gwa_text TO gt_text. CLEAR gwa_text.

gwa_text-tdline = 'ABAP Demo Checkbox'.

APPEND gwa_text TO gt_text. CLEAR gwa_text.

CALL FUNCTION 'COPO_POPUP_TO_DISPLAY_TEXTLIST' EXPORTING titel TABLES text_table = gt_text.


When you press F1 on checkbox on selection screen, the following popup will be displayed.

= 'F1 Help'

20. How to create dropdown list in selection screen?


Posted in Selection Screen on 20/04/2011

Dropdown list is a user interface element which displays a list of values from which a user can select one value. Follow the below steps to create a dropdown list in SAP ABAP selection screen.

First build the list in the INITIALIZATION event. Capture the value selected by the user from the list in the AT SELECTION-SCREEN event. Use the selected value for further processing.

TYPE-POOLS: vrm.

DATA: gt_list DATA: gwa_list DATA: gt_values gwa_values

TYPE vrm_values. TYPE vrm_value. TYPE TABLE OF dynpread, TYPE dynpread.

DATA: gv_selected_value(10) TYPE c. *--------------------------------------------------------------* *Selection-Screen *--------------------------------------------------------------* PARAMETERS: list TYPE c AS LISTBOX VISIBLE LENGTH 20. *--------------------------------------------------------------* *At Selection Screen *--------------------------------------------------------------* AT SELECTION-SCREEN ON list. CLEAR: gwa_values, gt_values. REFRESH gt_values. gwa_values-fieldname = 'LIST'. APPEND gwa_values TO gt_values. CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING dyname dynumb = sy-cprog = sy-dynnr

translate_to_upper = 'X' TABLES dynpfields = gt_values.

READ TABLE gt_values INDEX 1 INTO gwa_values. IF sy-subrc = 0 AND gwa_values-fieldvalue IS NOT INITIAL. READ TABLE gt_list INTO gwa_list WITH KEY key = gwa_values-fieldvalue. IF sy-subrc = 0. gv_selected_value = gwa_list-text. ENDIF. ENDIF. *--------------------------------------------------------------* *Initialization *--------------------------------------------------------------* INITIALIZATION. gwa_list-key = '1'. gwa_list-text = 'Product'. APPEND gwa_list TO gt_list. gwa_list-key = '2'. gwa_list-text = 'Collection'. APPEND gwa_list TO gt_list. gwa_list-key = '3'. gwa_list-text = 'Color'. APPEND gwa_list TO gt_list. gwa_list-key = '4'. gwa_list-text = 'Count'. APPEND gwa_list TO gt_list.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING id values EXCEPTIONS id_illegal_name = 1 OTHERS = 2. = 'LIST' = gt_list

*--------------------------------------------------------------* *Start of Selection *--------------------------------------------------------------* START-OF-SELECTION. WRITE:/ gv_selected_value.


Selection Screen Output

21. Pushbutton on ABAP Selection Screen


Posted in Selection Screen on 30/11/2011

We can create pushbuttons on ABAP selection screen using the statement SELECTION-SCREEN PUSHBUTTON. The event that gets triggered when the pushbutton is pressed is handled in the AT SELECTION-SCREEN event.

TABLES sscrfields. *--------------------------------------------------------------* *Selection-Screen *--------------------------------------------------------------* SELECTION-SCREEN: PUSHBUTTON /2(40) button1 USER-COMMAND but1, PUSHBUTTON /2(40) button2 USER-COMMAND but2. *--------------------------------------------------------------* *At Selection-Screen *--------------------------------------------------------------* AT SELECTION-SCREEN. CASE sscrfields. WHEN 'BUT1'. MESSAGE 'Button 1 was clicked' TYPE 'I'. WHEN 'BUT2'. MESSAGE 'Button 2 was clicked' TYPE 'I'. ENDCASE. *--------------------------------------------------------------* *Initialization *--------------------------------------------------------------* INITIALIZATION. button1 = 'Button 1'. button2 = 'Button 2'.
Selection Screen Output

If Button 1 is clicked then we get the following popup.

Even we can add icons to the pushbuttons on selection screen.

TYPE-POOLS: icon. TABLES sscrfields. *--------------------------------------------------------------* *Selection-Screen *--------------------------------------------------------------* SELECTION-SCREEN: PUSHBUTTON /2(40) button1 USER-COMMAND but1, PUSHBUTTON /2(40) button2 USER-COMMAND but2. *--------------------------------------------------------------* *At Selection-Screen *--------------------------------------------------------------* AT SELECTION-SCREEN. CASE sscrfields. WHEN 'BUT1'. MESSAGE 'Button 1 was clicked' TYPE 'I'. WHEN 'BUT2'. MESSAGE 'Button 2 was clicked' TYPE 'I'. ENDCASE. *--------------------------------------------------------------* *Initialization *--------------------------------------------------------------*

INITIALIZATION. button1 = 'Button 1'. button2 = 'Button 2'.

CALL FUNCTION 'ICON_CREATE' EXPORTING name text info IMPORTING RESULT = button1 EXCEPTIONS OTHERS = 0. = icon_okay = 'Continue' = 'Click to Continue'

CALL FUNCTION 'ICON_CREATE' EXPORTING name text info IMPORTING RESULT = button2 EXCEPTIONS OTHERS = 0.
Selection Screen Output

= icon_cancel = 'Exit' = 'Click to Exit'

25. How to find LSMW for a SAP T-Code?


Posted in LSMW on 30/06/2012

There is no standard way to find a LSMW for a SAP tcode. But we can achieve this by writing a small program.

First check if the tcode is used in any recording. Check if the recordings found are assigned to any objects Program

TYPE-POOLS: slis. *----------------------------------------------------------------------* * Constants

*----------------------------------------------------------------------* CONSTANTS: con_user_comm TYPE slis_formname VALUE 'USER_COMMAND', con_ucomm TYPE sy-ucomm VALUE '&IC1'.

*----------------------------------------------------------------------* * Data Declaration

*----------------------------------------------------------------------* DATA: g_repid TYPE sy-repid.

DATA: gt_tcode

TYPE TABLE OF /sapdmc/lsgbdca.

DATA: gt_object TYPE TABLE OF /sapdmc/lsorec, wa_object TYPE /sapdmc/lsorec. DATA: g_title g_layout TYPE lvc_title, TYPE slis_layout_alv.

DATA: it_fieldcat wa_fieldcat

TYPE slis_t_fieldcat_alv, TYPE slis_fieldcat_alv.

*----------------------------------------------------------------------* * SELECTION SCREEN

*----------------------------------------------------------------------* PARAMETERS: p_tcode TYPE /sapdmc/lsgbdca-recordingtcode OBLIGATORY. *----------------------------------------------------------------------* * START-OF-SELECTION

*----------------------------------------------------------------------* START-OF-SELECTION.

g_repid = sy-repid. *Check if the tcode is used in any recording SELECT * FROM /sapdmc/lsgbdca INTO TABLE gt_tcode WHERE recordingtcode = p_tcode. IF sy-subrc = 0. *Check if the recordings found are assigned to any objects SELECT * FROM /sapdmc/lsorec

INTO TABLE gt_object FOR ALL ENTRIES IN gt_tcode WHERE recording = gt_tcode-recording. ENDIF.

IF NOT gt_object IS INITIAL. PERFORM display_data. ENDIF.

*&---------------------------------------------------------------------* *& Form display_data

*&---------------------------------------------------------------------* FORM display_data.

*Customize ALV Layout g_layout-colwidth_optimize = 'X'. g_layout-zebra = 'X'.

*Set Layout title g_title = 'LSMW Details'(000).

*Build Field Catalog PERFORM build_fld_catalog USING: 'PROJECT' 'SUBPROJ' 'OBJECT' 'GT_OBJECT' 'Project'(001), 'GT_OBJECT' 'Sub Project'(002), 'GT_OBJECT' 'Object'(003),

'RECORDING' 'GT_OBJECT' 'recording'(004).

*Display table values in ALV CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = g_repid

i_callback_user_command = con_user_comm i_grid_title is_layout it_fieldcat TABLES t_outtab EXCEPTIONS program_error OTHERS IF sy-subrc <> 0. = 1 = 2. = gt_object = g_title = g_layout = it_fieldcat

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.

ENDFORM.

" display_data

*&---------------------------------------------------------------------* *& Form build_fld_catalog

*&---------------------------------------------------------------------* FORM build_fld_catalog USING value(p_fieldname) value(p_tabname) value(p_description). CLEAR wa_fieldcat. wa_fieldcat-fieldname = p_fieldname. wa_fieldcat-tabname = p_tabname.

wa_fieldcat-seltext_m = p_description. APPEND wa_fieldcat TO it_fieldcat.

ENDFORM.

" build_fld_catalog

*&---------------------------------------------------------------------* * Form User Command

*&---------------------------------------------------------------------*

FORM user_command USING r_ucomm

TYPE sy-ucomm

rs_selfield TYPE slis_selfield. IF r_ucomm EQ con_ucomm. READ TABLE gt_object INTO wa_object INDEX rs_selfield-tabindex. IF sy-subrc = 0. * Start LSMW CALL FUNCTION '/SAPDMC/LSM_OBJ_STARTER' EXPORTING project subproj object EXCEPTIONS no_such_object = 1 OTHERS IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. = 2. = wa_object-project = wa_object-subproj = wa_object-object

ENDIF. ENDIF.

ENDFORM.
Output

"User_command

Enter the tcode for which you want to find the LSMW.

The output will display all the LSMW project details for the given tcode. Double click on any line will take you to the LSMW project overview screen.

See step 3(Fields from flat file) and 5(All fields updating in current LSMW) to check whether the existing LSMW satisfy your requirement.

26. How to copy a function group in SAP?


Posted in Modularization on 11/03/2011

Function modules can be copied in function builder(SE37). But if you want to copy an entire function group along with all the function modules follow the steps given below. First go to Object Navigator(SE80).

Select Function Group in the drop down box and enter the name of the Function Group that we want to copy and press enter.

Once the enter is pressed, the function group will be displayed in the bottom window. Now right click on the function group name and select copy.

Enter the name for the new function group and press copy.

This will create the new function group, now we can copy all the function modules one by one. Just press continue.

This will display all theFunction Modules that is there in the original function group. Here we copy all the function modules or we can deselect the function modules that we dont want. Press copy.

A popup will be displayed for the first function module, enter the name for the new function module and press copy. This will copy the first function module and again a popup will be displayed for the next function module. Follow the same procedure for all the remaining function modules.

28. Select All Checkbox option in the selection screen


Posted in Selection Screen on 02/02/2011

This code shows how to check all/uncheck all checkboxes in one go on the selection screen instead of checking the checkboxes individually.If the user checks the Select All checkbox then all other checkboxes will be checked, similarly if the user unchecks the Select All checkbox then all other checkboxes will be unchecked.

*-------------------------------------------------------------

* Constants

*-------------------------------------------------------------

CONSTANTS: c_title(10) VALUE 'Options'.

*-------------------------------------------------------------

* Selection Screen

*-------------------------------------------------------------

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE v_name.

SELECTION-SCREEN: SKIP.

PARAMETERS: cb_all AS CHECKBOX USER-COMMAND uc.

SELECTION-SCREEN: SKIP.

PARAMETERS: cb_a AS CHECKBOX,

cb_b AS CHECKBOX,

cb_c AS CHECKBOX,

cb_d AS CHECKBOX,

cb_e AS CHECKBOX.

SELECTION-SCREEN: END OF BLOCK b1.

*-------------------------------------------------------------

* At Selection Screen Event

*-------------------------------------------------------------

AT SELECTION-SCREEN.

IF sy-ucomm = 'UC'.

IF cb_all = 'X'.

cb_a = cb_b = cb_c = cb_d = cb_e = 'X'.

ELSE.

Clear: cb_a, cb_b, cb_c, cb_d, cb_e.

ENDIF.

ENDIF.

*-------------------------------------------------------------

* Initialization

*-------------------------------------------------------------

INITIALIZATION.

v_name = c_title.
Selection Screen

Try check/uncheck the Select All checkbox observing the status of other checkboxes. Maintain Selection Texts to get the proper descriptions for the checkboxes on the selection screen.

29. How to create dropdown list in selection screen?


Posted in Selection Screen on 20/04/2011

Dropdown list is a user interface element which displays a list of values from which a user can select one value. Follow the below steps to create a dropdown list in SAP ABAP selection screen.

First build the list in the INITIALIZATION event. Capture the value selected by the user from the list in the AT SELECTION-SCREEN event. Use the selected value for further processing.

TYPE-POOLS: vrm.

DATA: gt_list DATA: gwa_list DATA: gt_values gwa_values

TYPE vrm_values. TYPE vrm_value. TYPE TABLE OF dynpread, TYPE dynpread.

DATA: gv_selected_value(10) TYPE c. *--------------------------------------------------------------* *Selection-Screen *--------------------------------------------------------------* PARAMETERS: list TYPE c AS LISTBOX VISIBLE LENGTH 20. *--------------------------------------------------------------* *At Selection Screen *--------------------------------------------------------------* AT SELECTION-SCREEN ON list. CLEAR: gwa_values, gt_values. REFRESH gt_values. gwa_values-fieldname = 'LIST'. APPEND gwa_values TO gt_values. CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING dyname dynumb = sy-cprog = sy-dynnr

translate_to_upper = 'X' TABLES dynpfields = gt_values.

READ TABLE gt_values INDEX 1 INTO gwa_values. IF sy-subrc = 0 AND gwa_values-fieldvalue IS NOT INITIAL. READ TABLE gt_list INTO gwa_list WITH KEY key = gwa_values-fieldvalue. IF sy-subrc = 0. gv_selected_value = gwa_list-text. ENDIF. ENDIF. *--------------------------------------------------------------* *Initialization *--------------------------------------------------------------* INITIALIZATION. gwa_list-key = '1'. gwa_list-text = 'Product'. APPEND gwa_list TO gt_list. gwa_list-key = '2'. gwa_list-text = 'Collection'. APPEND gwa_list TO gt_list. gwa_list-key = '3'. gwa_list-text = 'Color'. APPEND gwa_list TO gt_list. gwa_list-key = '4'. gwa_list-text = 'Count'. APPEND gwa_list TO gt_list.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING id values EXCEPTIONS id_illegal_name = 1 OTHERS = 2. = 'LIST' = gt_list

*--------------------------------------------------------------* *Start of Selection *--------------------------------------------------------------* START-OF-SELECTION. WRITE:/ gv_selected_value.


Selection Screen Output

30. Create password field in ABAP selection screen


Posted in Selection Screen on 11/04/2011

There is no password field type in ABAP. But it is very easy to create a password like field in ABAP selection screen using the invisible field of the screen table. Refer to the below code to create a password like field on selection screen

*----------------------------------------------------------------------* *Selection-Screen *----------------------------------------------------------------------* PARAMETERS: p_name TYPE char10. PARAMETERS: p_pass TYPE char10.

*----------------------------------------------------------------------* *At Selection Screen Output *----------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. IF screen-name = 'P_PASS'. screen-invisible = 1. MODIFY SCREEN. ENDIF. ENDLOOP.

*----------------------------------------------------------------------* *Start of Selection *----------------------------------------------------------------------* START-OF-SELECTION. WRITE:/ 'Name', ' : ', p_name. WRITE:/ 'Pass', ' : ', p_pass.
Selection Screen

31.

Logo on ABAP Selection Screen


Posted in Selection Screen on 25/01/2012

First upload the logo into SAP system to display it on the SAP ABAP selection screen. Split the selection screen using docking container and use the HTML Viewer to display the logo.

TYPE-POOLS cndp. *&---------------------------------------------------------------------* *& Data Declaration. *&---------------------------------------------------------------------* DATA: docking TYPE REF TO cl_gui_docking_container,

htmlviewer TYPE REF TO cl_gui_html_viewer, picture TYPE REF TO cl_gui_picture.

DATA url

TYPE cndp_url.

*&---------------------------------------------------------------------* *& SELECTION SCREEN. *&---------------------------------------------------------------------* PARAMETERS: s_matnr TYPE mara-matnr.

*&---------------------------------------------------------------------* *& AT SELECTION-SCREEN OUTPUT. *&---------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT.

PERFORM build_htmlviewer.

CALL METHOD picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center.

CALL FUNCTION 'DP_PUBLISH_WWW_URL' EXPORTING objid = 'ZLOGO'

lifetime = cndp_lifetime_transaction IMPORTING url = url

EXCEPTIONS OTHERS = 1.

* Load the picture. IF sy-subrc = 0. CALL METHOD picture->load_picture_from_url_async EXPORTING url = url. ENDIF. *&---------------------------------------------------------------------* *& Form build_htmlviewer

*&---------------------------------------------------------------------* FORM build_htmlviewer . DATA: repid LIKE sy-repid. repid = sy-repid.

IF docking IS INITIAL.

CREATE OBJECT docking EXPORTING REPID DYNNR SIDE EXTENSION EXCEPTIONS CNTL_ERROR CNTL_SYSTEM_ERROR CREATE_ERROR LIFETIME_ERROR = 1 = 2 = 3 = 4 = repid = sy-dynnr = cl_gui_docking_container=>dock_at_top = 150

LIFETIME_DYNPRO_DYNPRO_LINK = 5 others = 6.

IF htmlviewer IS INITIAL .

CREATE OBJECT picture EXPORTING parent ENDIF . ENDIF . ENDFORM.


Output

= docking .

We can also split the selection screen vertically and display the logo on right side of the selection screen using the side parameter of the docking container.

CREATE OBJECT docking EXPORTING REPID DYNNR SIDE EXTENSION = repid = sy-dynnr = cl_gui_docking_container=>dock_at_right = 500

EXCEPTIONS CNTL_ERROR CNTL_SYSTEM_ERROR CREATE_ERROR LIFETIME_ERROR = 1 = 2 = 3 = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5 others = 6.

Output

32. F4 Help for Month in ABAP Selection Screen

Posted in Selection Screen on 27/08/2012

We have a database field to hold year and month together in the format YYYYMM (example 201201). We are creating a report using this field on the selection screen, so we need to provide F4 help for this month field. The following code will provide the F4 help for month.

*&---------------------------------------------------------------------* *& Selection Screen

*&---------------------------------------------------------------------* PARAMETERS: p_month TYPE isellist-month.

*&---------------------------------------------------------------------* *& At Selection Screen Event

*&---------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_month.

CALL FUNCTION 'POPUP_TO_SELECT_MONTH' EXPORTING actual_month IMPORTING selected_month EXCEPTIONS factory_calendar_not_found = 1 holiday_calendar_not_found = 2 = p_month = sy-datum(6)

month_not_found OTHERS IF sy-subrc <> 0.

= 3 = 4.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
When we press F4 help for the month field, the following popup will be displayed.

33. How to create a report variant with dynamic date


Posted in Selection Screen on 06/03/2011

Sometimes we want to schedule a report to run daily to update some information in certain tables based on todays or yesterdays date or to mail the output of daily MIS reports. We a need a variant to schedule a report, so following are the steps to create a report variant with dynamic date. First display the selection screen.

Press save button to create a new variant.

Enter variant name and description, select the selection variable checkbox and click on Selection variables in the application toolbar.

Select the option D i.e Dynamic date calculation.

Once option D is selected, click on the small black triangle to get the F4 values.

From the list of F4 values select the appropriate value. Here we are creating a variant with yesterdays date, so we select the second option from the list.

To get yesterdays date enter the value -1. Save the variant.

35. Control List Save Option in a ABAP Report


Posted in Reports on 22/06/2012

When we try to download the list using the menu System->List-Save, function module "DOWNLOAD" will be called. DOWNLOAD Function module will perform a dynamic authorization check if the program and subroutine names are set.

The program and subroutine names can be set using the function module SET_DOWNLOAD_AUTHORITY which is present in the same function group (GRAP). Program ZZDEMO

CALL FUNCTION 'SET_DOWNLOAD_AUTHORITY' EXPORTING form = 'CHECK_AUTH' prog = 'ZZDEMO_AUTH'.

WRITE:/ 'Hello'.

In the above program we are setting the program(ZZDEMO_AUTH) and subroutine (CHECK_AUTH) to check the authorization for list download before generating the list output. In program ZZDEMO_AUTH we will implement a subroutine CHECK_AUTH and write the authorization logic inside the subroutine. Program ZZDEMO_AUTH

*---------------------------------------------------------------------* * FORM check_auth *

*---------------------------------------------------------------------* FORM check_auth USING result TYPE i. result = 1. ENDFORM.


If the subroutine returns any value other than zero (i.e. result = 1 in the above case ), then the following message will be displayed and the list will not be downloaded.

Vous aimerez peut-être aussi