Saturday 14 April 2012

Hiding fields in an Infotype

It is sometimes required to customize the screen fields in the HR Infotypes. This can be done using
the view V_T588M.

hide_fields0


1. If we see in PA30, the standard screen for 0023 (Other/Previous Employers) is:
hide_fields1
2. Let us hide the field “Work Contract” & “Job” from the standard Infotype screen.
hide_fields2
Go to SM30 & enter view name as “V_T588M”. Click on “Maintain”.
hide_fields3
3. Enter the module pool program & click Ok. In our case it is MP002300.
hide_fields4
4. Now click on ‘New Entries’ button.
hide_fields5
5. Now enter the “Module Pool” (mandatory) “Standard screen” (mandatory).Press “Enter”.
hide_fields6
6. After we press “Enter”, all the screen fields of the Infotype are shown along with their attributes.
7. Now, we can change the attributes according to our requirements by selecting the desired radio button. After that press Save.
hide_fields7
8. Then Go to PA30 and check the changes done to the standard Infotype (here Infotype 0023). The fields we chose to hide gets hidden.
hide_fields8

Thursday 12 April 2012

Get Employees List

HR ABAP - Get Employees List Working Under An Organization Unit.


report ztests.

parameters:p_objid type orgeh .

data: pernr_table type HRPERNR occurs 0 with header line .

CALL FUNCTION 'HRCM_ORGSTRC_EMPLOYEE_LIST_GET'
EXPORTING
  plvar = '01'
  root_otype = 'O'
  root_objid = p_objid
  begda = '18000101'
  endda = '99991231'
TABLES
  pernr_table = pernr_table
EXCEPTIONS
  NO_ORGSTRUC_FOUND = 1
  NO_EMPLOYEES_FOUND = 2
OTHERS = 3
.
IF sy-subrc <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

loop at pernr_table.
  write:/ pernr_table-PERNR.
endloop.

Tuesday 10 April 2012

OOPS-5

REPORT  ZO_CLASS5.

*----------------------------------------------------------------------*
*       CLASS CLASS1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CLASS1 DEFINITION.

  PUBLIC SECTION.
    DATA: INSTDATA(25) TYPE C VALUE 'Instance Variable'.
    METHODS: INSTMET.

    CLASS-DATA: STATDATA(25) TYPE C VALUE 'Static Variable'.
    CLASS-METHODS: STATMET.

ENDCLASS.                    "CLASS1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS CLASS1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CLASS1 IMPLEMENTATION.

  METHOD INSTMET.

    WRITE:/ STATDATA, INSTDATA.

  ENDMETHOD.                    "INSTMET

  METHOD STATMET.

    WRITE:/ STATDATA.

  ENDMETHOD.                    "STATMET

ENDCLASS.                    "CLASS1 IMPLEMENTATION

START-OF-SELECTION.

  DATA: OREF TYPE REF TO CLASS1.

  CREATE OBJECT OREF.

  CALL METHOD CLASS1=>STATMET.

  CALL METHOD OREF->INSTMET.

OOPS-4







METHOD GET_MATERIAL.

  DATA: G_MATNR TYPE MARA-MATNR.

  SELECT SINGLE MATNR FROM MARA
               INTO G_MATNR
               WHERE MATNR = P_MATNR.

  IF SY-SUBRC = 0.

    SELECT MATNR
           ERNAM
           MATKL FROM MARA
                 INTO TABLE IT_MARA
                WHERE MATNR = P_MATNR.
  ELSE.

    RAISE MATERIAL_NOTFOUND.

  ENDIF.

ENDMETHOD.

REPORT  ZO_CLASS4.

PARAMETERS: P_MATNR TYPE MARA-MATNR.

TYPES: BEGIN OF T_MARA,
        MATNR LIKE MARA-MATNR,
        ERNAM LIKE MARA-ERNAM,
        MATKL LIKE MARA-MATKL,
       END OF T_MARA.

DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA,
      WA_MARA LIKE LINE OF IT_MARA.

START-OF-SELECTION.

  DATA: OREF TYPE REF TO ZO_CLASS5.

  CREATE OBJECT OREF.

  CALL METHOD OREF->GET_MATERIAL
    EXPORTING
      P_MATNR           = P_MATNR
    IMPORTING
      IT_MARA           = IT_MARA
    EXCEPTIONS
      MATERIAL_NOTFOUND = 1
      OTHERS            = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID 'ZACLASS' TYPE 'I' NUMBER '000'
               WITH P_MATNR.

  ELSE.

    LOOP AT IT_MARA INTO WA_MARA.

      WRITE:/ WA_MARA-MATNR, WA_MARA-ERNAM, WA_MARA-MATKL.

    ENDLOOP.


  ENDIF.

OOPS-3

OOPS in Function Module






OOPS-2

REPORT  ZO_CLASS2.

*----------------------------------------------------------------------*
*       CLASS CLASS1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS PARENT DEFINITION.

  PUBLIC SECTION.
    DATA: VAR1(30) TYPE C VALUE 'Parent Class Public'.
    METHODS: MET1.

  PROTECTED SECTION.
    DATA: VAR2(330) TYPE C VALUE 'Parent Class Protected'.

  PRIVATE SECTION.
    DATA: VAR3(30) TYPE C VALUE 'Parent Class Private'.

ENDCLASS.                    "CLASS1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS CHILD DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CHILD DEFINITION INHERITING FROM PARENT.

  PUBLIC SECTION.
    METHODS: MET2.

ENDCLASS.                    "CHILD DEFINITION

*----------------------------------------------------------------------*
*       CLASS CLASS1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS PARENT IMPLEMENTATION.

  METHOD MET1.

    WRITE:/ VAR1, VAR2, VAR3.
  ENDMETHOD.                                                "MET1

ENDCLASS.                    "CLASS1 IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS CHILD IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CHILD IMPLEMENTATION.

  METHOD MET2.

    WRITE:/ VAR1, VAR2.

  ENDMETHOD.                                                "MET2

ENDCLASS.                    "CHILD IMPLEMENTATION

START-OF-SELECTION.

  DATA: OREF TYPE REF TO PARENT,
        ORE1 TYPE REF TO CHILD.

  CREATE OBJECT: OREF, ORE1.

  CALL METHOD OREF->MET1.
  CALL METHOD ORE1->MET2.

  WRITE:/ OREF->VAR1.

OOPS-1

REPORT  ZO_CLASS1.

*----------------------------------------------------------------------*
*       CLASS CLASS1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CLASS1 DEFINITION.

  PUBLIC SECTION.
    DATA: VAR1(10) TYPE C VALUE 'Demo Class'.

  PROTECTED SECTION.
    DATA: VAR2(10) TYPE C.

  PRIVATE SECTION.
    DATA: VAR3(10) TYPE C.

ENDCLASS.                    "CLASS1 DEFINITION

START-OF-SELECTION.

  DATA: OREF TYPE REF TO CLASS1.

  CREATE OBJECT OREF.

  WRITE:/ OREF->VAR1.

Sunday 8 April 2012

Report Program On ALV Tree Display

This report program can be used to display sales order for the given customers Using ALV Tree display (3 Levels).

Function Module Used are :
'RS_TREE_CONSTRUCT'
'RS_TREE_LIST_DISPLAY'

SAMPLE PROGRAM

REPORT ztest_alv_tree.

TABLES : kna1.

TYPES : BEGIN OF ts_vbak,
vbeln TYPE vbak-vbeln, "Sales Order
audat TYPE vbak-audat, "Order Date
kunnr TYPE vbak-kunnr, "Customer No.
END OF ts_vbak,

BEGIN OF ts_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr, "Order Item
kwmeng TYPE vbap-kwmeng, "Net weight
netpr TYPE vbap-netpr, "Item Price
END OF ts_vbap,

BEGIN OF ts_kna1,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1, "Customer Name
END OF ts_kna1.

DATA : lt_node TYPE TABLE OF snodetext,
lt_vbak TYPE TABLE OF ts_vbak,
lt_vbap TYPE TABLE OF ts_vbap,
lt_kna1 TYPE TABLE OF ts_kna1.

* WORKAREA DECLARATION
DATA : ls_node TYPE snodetext,
ls_vbak TYPE ts_vbak,
ls_vbap TYPE ts_vbap,
ls_kna1 TYPE ts_kna1.

* VARIABLE DECLARATION
DATA : w_value(15) TYPE C,
w_qty TYPE kwmeng,
w_amt TYPE netpr.

* SELECTION SCREEN
SELECT-OPTIONS : s_kunnr FOR kna1-kunnr.

START-OF-SELECTION.

PERFORM get_kna1.
PERFORM get_vbak.
PERFORM get_vbap.
PERFORM build_tree.

END-OF-SELECTION.
PERFORM display_tree.

*&---------------------------------------------------------------------*
*& Form get_vbak
*&---------------------------------------------------------------------
FORM get_vbak .

SELECT vbeln
audat
kunnr
FROM vbak
INTO TABLE lt_vbak
FOR ALL ENTRIES IN lt_kna1
WHERE kunnr EQ lt_kna1-kunnr.

DATA:v_line TYPE i.
v_line = LINES( lt_vbak ).

IF LINES( lt_vbak ) EQ 0.
MESSAGE 'No Orders found'(001) TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

ENDFORM. " get_vbak

*&---------------------------------------------------------------------*
*& Form build_tree
*&---------------------------------------------------------------------
FORM build_tree .

CLEAR : lt_node, ls_node.
SORT : lt_vbak BY kunnr vbeln,
lt_vbap BY vbeln posnr,
lt_kna1 BY kunnr.

ls_node-type = 'T'.
ls_node-name = 'Orders of Customers'(002).
ls_node-tlevel = '01'.
ls_node-nlength = '20'.
ls_node-color = '5'.
ls_node-text = 'Orders'(003).
ls_node-tlength = '10'.
ls_node-tcolor = '3'.
APPEND ls_node TO lt_node.
CLEAR ls_node.

ls_node-type = 'P'.
ls_node-tlevel = '2'.
ls_node-text = 'Customer No'(004).
ls_node-tlength = '15'.
ls_node-tcolor = '7'.
ls_node-text1 = 'Customer Name'(005).
ls_node-tlength1 = '30'.
ls_node-tcolor1 = '7'.
APPEND ls_node TO lt_node.
CLEAR ls_node.

LOOP AT lt_kna1 INTO ls_kna1.

DATA : w_flg TYPE c,
w_flg1 TYPE c.

ls_node-type = 'P'.
ls_node-tlevel = '2'.
ls_node-text = ls_kna1-kunnr.
ls_node-tlength = '15'.
ls_node-tcolor = '1'.
ls_node-text1 = ls_kna1-name1.
ls_node-tlength1 = '30'.
ls_node-tcolor1 = '1'.
APPEND ls_node TO lt_node.
CLEAR ls_node.

LOOP AT lt_vbak INTO ls_vbak WHERE kunnr EQ ls_kna1-kunnr.

IF w_flg1 IS INITIAL.
w_flg1 = 'X'.
ls_node-type = 'P'.
ls_node-tlevel = '3'.
ls_node-text = 'Sales Order'(006).
ls_node-tlength = '15'.
ls_node-tcolor = '7'.
ls_node-text1 = 'Order Date'(007).
ls_node-tlength1 = '15'.
ls_node-tcolor1 = '7'.
APPEND ls_node TO lt_node.
CLEAR ls_node.
ENDIF.

ls_node-type = 'P'.
ls_node-tlevel = '3'.
ls_node-text = ls_vbak-vbeln.
ls_node-tlength = 15.
ls_node-tcolor = 5.
CLEAR w_value.

WRITE ls_vbak-audat TO w_value.
ls_node-text1 = w_value.
ls_node-tlength1 = 15.
ls_node-tcolor1 = 5.
APPEND ls_node TO lt_node.

CLEAR : w_qty, w_amt.

LOOP AT lt_vbap INTO ls_vbap WHERE vbeln EQ ls_vbak-vbeln.

IF w_flg IS INITIAL.
w_flg = 'X'.
ls_node-type = 'P'.
ls_node-tlevel = '4'.
ls_node-text = 'Item'(008).
ls_node-tlength = '11'.
ls_node-tcolor = '7'.
ls_node-text1 = 'Net Weight'(009).
ls_node-tlength1 = '15'.
ls_node-tcolor1 = '7'.
ls_node-text2 = 'Net Price'(010).
ls_node-tlength2 = '15'.
ls_node-tcolor2 = '7'.
APPEND ls_node TO lt_node.
CLEAR ls_node.
ENDIF.

ls_node-type = 'P'.
ls_node-tlevel = '4'.
ls_node-text = ls_vbap-posnr.
ls_node-tlength = '11'.
ls_node-tcolor = '2'.

CLEAR w_value.
w_value = ls_vbap-kwmeng.
ls_node-text1 = w_value.
ls_node-tlength1 = '15'.
ls_node-tcolor1 = '2'.

CLEAR w_value.
w_value = ls_vbap-netpr.
ls_node-text2 = w_value.
ls_node-tlength2 = '15'.
ls_node-tcolor2 = '2'.
APPEND ls_node TO lt_node.
CLEAR ls_node.

ADD ls_vbap-kwmeng TO w_qty.
ADD ls_vbap-netpr TO w_amt.

ENDLOOP.

IF w_qty IS NOT INITIAL.

ls_node-type = 'P'.
ls_node-tlevel = '4'.
ls_node-text = 'Total'(011).
ls_node-tlength = '11'.
ls_node-tcolor = '3'.
CLEAR w_value.
w_value = w_qty.
ls_node-text1 = w_value.
ls_node-tlength1 = '15'.
ls_node-tcolor1 = '3'.
CLEAR w_value.
w_value = w_amt.
ls_node-text2 = w_value.
ls_node-tlength2 = '15'.
ls_node-tcolor2 = '3'.
APPEND ls_node TO lt_node.
CLEAR ls_node.

ENDIF.

CLEAR w_flg.

ENDLOOP.
ENDLOOP.

ENDFORM. " build_tree

*&---------------------------------------------------------------------*
*& Form display_tree
*&---------------------------------------------------------------------
FORM display_tree .

CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
nodetab = lt_node
EXCEPTIONS
tree_failure = 1
id_not_found = 2
wrong_relationship = 3
OTHERS = 4.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
callback_program = sy-repid.

ENDFORM. " display_tree


*&---------------------------------------------------------------------*
*& Form get_vbap
*&---------------------------------------------------------------------
FORM get_vbap .

SELECT vbeln
posnr
kwmeng
netpr
FROM vbap
INTO TABLE lt_vbap
FOR ALL ENTRIES IN lt_vbak
WHERE vbeln EQ lt_vbak-vbeln.

ENDFORM. " get_vbap


*&---------------------------------------------------------------------*
*& Form get_kna1
*&---------------------------------------------------------------------
FORM get_kna1 .

SELECT kunnr
name1
FROM kna1
INTO TABLE lt_kna1
WHERE kunnr IN s_kunnr.

IF sy-subrc NE 0.

MESSAGE 'No customers exists'(012) TYPE 'I'.
LEAVE LIST-PROCESSING.

ENDIF.
ENDFORM. " get_kna1


OUTPUT SCREEN:


Program On Buttons In A Screen

SAP ABAP - Sample Program On How To Program On Buttons In A Screen.
This is a sample program on screen painter showing how to program on buttons in a screen.

REPORT ztest_screen_paint_program.
TABLES: mara.

DATA: matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
display TYPE c,
save TYPE c,
delete TYPE c,
clear TYPE c,
exit TYPE c,
ok_code TYPE sy-ucomm.

CALL SCREEN 9000.

*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.

SET PF-STATUS 'STATUS_9000'.
SET TITLEBAR 'TITLE_9000'.

ok_code = sy-ucomm.

CASE ok_code.
WHEN 'BACK'.
LEAVE PROGRAM.

WHEN 'EXIT'.
LEAVE PROGRAM.

WHEN 'CANCEL'.
LEAVE TO SCREEN 0.

WHEN 'CLEAR'.
CLEAR mara.

WHEN 'DISPLAY'.
SELECT SINGLE ersda ernam mtart matkl FROM mara
INTO (mara-ersda, mara-ernam, mara-mtart, mara-matkl)
WHERE matnr = mara-matnr.
ENDCASE.

ENDMODULE. " STATUS_9000 OUTPUT


On clicking a button a user command is thrown. In this case on clicking DISPLAY Button, the user command thrown is DISPLAY.
Hence it will fetch the respective details from mara table and displays it in the respective fields.

Say, the Output screen (9000) looks as below,


















On entering the material, or selecting an appropriate one from the F4 help, and on clicking the DISPLAY button, the remaining fields get automatically filled up.

















On clicking DISPLAY Button




Tabstrips & Subscreens In Selection Screen

SAP ABAP - Sample Program To Demonstrate Tabstrips & Subscreens In Selection Screen.

This sample report program explains the use of tabstrips and subscreen in main selection screen.

*& Use of TabStrip and SubScreen explained
*& ---- The report shows the material on one tab
*& and plant on one tab.Pressing the execute button will show
*& the description of the material or plant as the case is.
*& TEXT-002 = Material Number
*& TEXT-003 = Plant Number.


REPORT zjal_tabstrip_selscr NO STANDARD PAGE HEADING LINE-SIZE 80 LINE-COUNT 60.
TABLES : sscrfields.
DATA activetab(6) TYPE c .
DATA: mat_des TYPE makt-maktx,
pl_des TYPE t001w-name1 .

SELECTION-SCREEN BEGIN OF SCREEN 001 AS SUBSCREEN NO INTERVALS.

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-002 NO INTERVALS.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 14(18) text-002 FOR FIELD matnr.
PARAMETERS matnr TYPE mara-matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK block1.
SELECTION-SCREEN END OF SCREEN 001.

SELECTION-SCREEN BEGIN OF SCREEN 002 AS SUBSCREEN NO INTERVALS.
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-003 NO INTERVALS.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 14(18) text-003 FOR FIELD matnr.
PARAMETERS werks TYPE t001w-werks.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK block2.
SELECTION-SCREEN END OF SCREEN 002.

SELECTION-SCREEN BEGIN OF TABBED BLOCK tabb1 FOR 5 LINES NO INTERVALS.

SELECTION-SCREEN TAB (15) tabs1 USER-COMMAND ucomm1
DEFAULT SCREEN 001.
SELECTION-SCREEN TAB (15) tabs2 USER-COMMAND ucomm2.

SELECTION-SCREEN END OF BLOCK tabb1.

INITIALIZATION.
tabs1 = text-002.
tabs2 = text-003.
activetab = 'TABS1'.

AT SELECTION-SCREEN .

CASE sscrfields-ucomm.

WHEN 'UCOMM1'.
tabb1-prog = sy-repid.
tabb1-dynnr = 001.
tabb1-activetab = 'TABS1'.
activetab = 'TABS1' .

WHEN 'UCOMM2'.
tabb1-prog = sy-repid.
tabb1-dynnr = 002.
tabb1-activetab = 'TABS2'.
activetab = 'TABS2'.

ENDCASE.

START-OF-SELECTION.

CASE activetab.

WHEN 'TABS1'.
SELECT SINGLE maktx
FROM makt
INTO mat_des
WHERE matnr = matnr.

WRITE: 'Material ' , matnr , mat_des .

WHEN 'TABS2'.
SELECT SINGLE name1
FROM t001w
INTO pl_des
WHERE werks = werks.

WRITE: 'Plant ' , werks ,pl_des.
ENDCASE.


OUTPUT SCREEN:




Upload Excel File Data Into Internal Table

SAP ABAP - Report Program To Upload Excel Sheet Data Into Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE.


This function module is used to transfer data from excel sheet to internal table. The only problem with this FM is it transfers all the excel data as char type and hence type conversion is needed to be done.

For Example, IDATE is of type DATS - Date field (YYYYMMDD) stored as char(8). In excel sheet the date format was : 01.01.2011. hence data conversion has to take place to save the date in internal table in the format YYYYMMDD.


Again PRICE is of type CURR of length 13 & decimals 2. Since the FM retrieves the data from excel in CHAR type, hence type conversion has to be done to convert CHAR type to CURR type. PRICE in excel sheet is saved as 23,864.00 .


SAMPLE PROGRAM:

REPORT z_zvgaq_update.

TYPES: BEGIN OF x_zvgaq,
mandt LIKE zvgaq-mandt,
werks LIKE zvgaq-werks,
matnr LIKE zvgaq-matnr,
idate LIKE zvgaq-idate,
drate LIKE zvgaq-drate,
price LIKE zvgaq-price,
udate LIKE zvgaq-udate,
END OF x_zvgaq.

DATA: it_zvgaq TYPE STANDARD TABLE OF x_zvgaq,
wa_zvgaq TYPE x_zvgaq.

DATA: it_zvgaq1 TYPE STANDARD TABLE OF x_zvgaq.

DATA:price_tmp(17) TYPE C,
idate_tmp(10) TYPE C,
udate_tmp(10) TYPE C.

DATA : dd(2) TYPE C,
mm(2) TYPE C,
yy(4) TYPE C,
dat(8) TYPE C.

DATA: it_intern LIKE STANDARD TABLE OF alsmex_tabline,
wa_intern LIKE alsmex_tabline.

SELECTION-SCREEN SKIP.
 
SELECTION SCREEN BEGIN OF BLOCK block1 WITH FRAME title text-001.
  SELECTION-SCREEN SKIP.

 PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

 SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK block1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file.

START-OF-SELECTION.
PERFORM upload.

*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM upload.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 10
i_end_row = 65536
TABLES
intern = it_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
others = 3.

IF SY-SUBRC <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CLEAR wa_zvgaq .
LOOP AT it_intern INTO wa_intern.

CASE wa_intern-col .
WHEN '1'.
wa_zvgaq-mandt = wa_intern-value.

WHEN '2'.
IF wa_intern-value CP 'E*'.
wa_zvgaq-werks = wa_intern-value+3(04).
ELSE.
wa_zvgaq-werks = wa_intern-value.
ENDIF.

WHEN '3'.
wa_zvgaq-matnr = wa_intern-value.

WHEN '4'.
idate_tmp = wa_intern-value.
REPLACE '.' WITH '' INTO idate_tmp.
REPLACE '.' WITH '' INTO idate_tmp.
CONDENSE idate_tmp NO-GAPS.
dd = idate_tmp(2).
mm = idate_tmp+2(2).
yy = idate_tmp+4(4).
CONCATENATE yy mm dd INTO dat.
MOVE dat TO wa_zvgaq-idate.
CLEAR:idate_tmp,dd,mm,yy,dat.

WHEN '5'.
wa_zvgaq-drate = wa_intern-value.

WHEN '6'.
price_tmp = wa_intern-value.
REPLACE ',' WITH '' INTO price_tmp.
CONDENSE price_tmp NO-GAPS.
MOVE price_tmp TO wa_zvgaq-price.
CLEAR price_tmp.

WHEN '7'.
udate_tmp = wa_intern-value.
REPLACE '.' WITH '' INTO udate_tmp.
REPLACE '.' WITH '' INTO udate_tmp.
CONDENSE udate_tmp NO-GAPS.
dd = udate_tmp(2).
mm = udate_tmp+2(2).
yy = udate_tmp+4(4).
CONCATENATE yy mm dd INTO dat.
MOVE dat TO wa_zvgaq-udate.
CLEAR:udate_tmp,dd,mm,yy,dat.
ENDCASE.

AT END OF row.
APPEND wa_zvgaq TO it_zvgaq.
CLEAR wa_zvgaq .
ENDAT.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM it_zvgaq COMPARING ALL FIELDS.

ENDFORM. "upload


THE EXCEL SHEET FORMAT & THE INPUT SCREEN LOOKS LIKE




Using SELECT-OPTIONS Stmt With Syntax

The SELECT-OPTIONS statement creates selection criteria for a particular
database field.
SYNTAX:

SELECT-OPTIONS <sel> FOR <f>
                                  [DEFAULT <g> [TO <h>]  [OPTION <op>] SIGN <s>]
                                  [MEMORY ID <pid>]
                                  [LOWER CASE]
                                  [OBLIGATORY]
                                  [NO-DISPLAY]
                                  [MODIF ID <key>]
                                  [NO-EXTENSION]
                                  [NO INTERVALS]
                                  [NO DATABASE SELECTION]

<sel> is the selection name that can have a max of 8 characters.

The above syntax declares a selection table <sel> for the field <f> and also places input fields on the corresponding selection screen.

- DEFAULT <g> - This optional allows to set a single value <g> as a default value.

- DEFAULT <g> TO <h> - This optional allows to set a range selection.

- DEFAULT <g> [TO <h>]  [OPTION <op>] - The additional OPTION basically defines the relational operator.

For single field comparisons, OPTION <op> can be EQ, NE, GE, GT, LE, LT, CP, or NP.
The default value is EQ.

For range selections, OPTION <op> can be BT (Between) or NB (Not In Between).
The default value is BT.


- DEFAULT <g> [TO <h>]  [OPTION <op>] SIGN <s> - The optional SIGN indicates whether the entry is Inclusive(I) or Exclusive (E).

The value of <s> can be I or E.
The default value is I.


- MEMORY ID <pid> - On the selection screen, the SET/GET ID <pid> is assigned to the left range limit of the selection criterion. Remember to specify the memory ID without quotation marks. It can be up to 3 characters long.


- LOWER CASE - This optional accepts input in lowercase.


- OBLIGATORY - This optional is used to make the an entry mandatory. Using this optional makes the user mandatory to enter a value for this selection (in the LOW field).


- NO-EXTENSION - This option restricts user to make entry in one line. When the NO-EXTENSION option is used, the user will not be able to see the pushbutton containing arrows pointing to the right at the far sight.


- NO INTERVALS - This option removes the 'to' field. It  means the selection option is displayed on the selection screen without a 'to' field.. The pushbutton for calling the "Multiple Selection" screen appears immediately after the 'from' field.



EXAMPLES:


SELECT-OPTIONS: s_deldt FOR likp-erdat DEFAULT '20110101' TO '20110202'.
SELECT-OPTIONS: date FOR sy-datum DEFAULT sy-datum.





SELECT-OPTIONS: s_ernam FOR likp-ernam DEFAULT 'NAVEENT' SIGN E NO INTERVALS.




SELECT-OPTIONS: s_ernam FOR likp-ernam .




On pressing ENTER:




SELECT-OPTIONS: s_ernam FOR likp-ernam LOWER CASE.




SELECT-OPTIONS: s_deldt FOR likp-erdat OBLIGATORY.




SELECT-OPTIONS: s_ernam FOR likp-ernam NO INTERVALS.





SELECT-OPTIONS: s_ernam FOR likp-ernam NO-EXTENSION.




SELECT-OPTIONS: s_ernam FOR likp-ernam NO-EXTENSION NO INTERVALS.





SELECTION TABLE:


- SELECT-OPTIONS on the report program initial screen are a convenient way to enter simple or
complex selection criteria. The SELECT-OPTIONS statement creates a selection table which is basically an internal table that holds the selection criteria for that field.

- Selection criteria for each item on a selection screen are stored in a selection table. Selection tables are system generated internal tables that have the following standard field format:

SIGN:

-  It is either I or E, I means to include the found results, E excludes them.

- This field indicates whether the current row of the table is INCLUSIVE (I) or EXCLUSIVE (E). Each row of the internal table represents a particular condition (e.g. BETWEEN 1 & 5).

- The overall condition specified by the selection table is the union of lines marked with sign I (Inclusive), less the union of lines marked with sign E (Exclusive).

OPTION:

- This field holds the relational operator for the current row of the selection table (e.g. "NE" <>).

LOW:

- This field holds the low value for range comparisons. If the comparison is against a single value, this field contains that value.

HIGH:

- This field holds the high value for range comparisons (Only for "BT" option).

EXAMPLE:

I       BT       3        10
I       EQ      2
E      GE      8

The result set of the mentioned selection table is: 2, 3, 4, 5, 6, 7.


Using PARAMETERS with syntax

PARAMETERS : s_plant LIKE lips-werks.





PARAMETERS : s_plant TYPE lips-werks.





PARAMETERS : s_plant TYPE n,
                          s_matnr(18) TYPE c.






PARAMETERS : s_plant(4) TYPE n DEFAULT '1501',
                          s_matnr(18) TYPE c DEFAULT 'Power Circuits'.






PARAMETERS : s_plant(4) TYPE n DEFAULT '1501',
                           s_matnr(18) TYPE c DEFAULT 'Power Circuits',
                           s_date LIKE sy-datum DEFAULT '20110216'.






* CHSPL is of type CHAR with length 1. Also it's domain XFELD has value range set as 'X' and blank.

PARAMETERS : s_CHSPL LIKE lips-CHSPL.




PARAMETERS : s_kostl LIKE lips-kostl MATCHCODE OBJECT qals.









PARAMETERS : s_matnr LIKE lips-matnr LOWER CASE.




PARAMETERS : s_matnr LIKE lips-matnr LOWER CASE OBLIGATORY.





PARAMETERS : s_matnr TYPE c AS CHECKBOX.




PARAMETERS : s_matnr TYPE c AS CHECKBOX DEFAULT 'X'.





PARAMETERS : s_matnr TYPE c RADIOBUTTON GROUP abc,
                          s_matnr1 TYPE c RADIOBUTTON GROUP abc ,
                          s_matnr2 TYPE c RADIOBUTTON GROUP abc .







PARAMETERS :s_matnr TYPE c RADIOBUTTON GROUP abc,
                          s_matnr1 TYPE c RADIOBUTTON GROUP abc DEFAULT 'X',
                          s_matnr2 TYPE c RADIOBUTTON GROUP abc .



ABAP Events Program- Excellent Output

REPORT ztest MESSAGE-ID zebg1.

TABLES: bsid, vbrk.

DATA: temp_vkorg TYPE vbrk-vkorg,
           temp_bukrs TYPE bsid-bukrs.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title.

   PARAMETER: s_bukrs LIKE bsid-bukrs. " Company Code
   PARAMETER: s_hkont LIKE bsid-hkont OBLIGATORY. " G/L Account
   PARAMETER: s_vkorg LIKE vbrk-vkorg. " Sales Organization
   PARAMETER: p_budat LIKE bsid-budat OBLIGATORY DEFAULT sy-datum. " As On Date

 SELECTION-SCREEN END OF BLOCK b1.


SELECTION-SCREEN SKIP.

INITIALIZATION.

 s_hkont = '0015515001'.
 title = 'Please enter the following details'.

AT SELECTION-SCREEN.

IF s_bukrs IS NOT INITIAL.

  SELECT SINGLE bukrs FROM bsid INTO temp_bukrs
  WHERE bukrs EQ s_bukrs.

  IF sy-subrc NE 0 .
    MESSAGE 'Please enter correct Company Code' TYPE 'E'.
  ENDIF.

ENDIF.

IF s_vkorg IS NOT INITIAL.

   SELECT SINGLE vkorg FROM vbrk INTO temp_vkorg
   WHERE vkorg EQ s_vkorg.

  IF sy-subrc NE 0 .
    MESSAGE 'Please enter correct Sales Organisation' TYPE 'E'.
  ENDIF.

ENDIF.

IF p_budat CP '2011*'.
  MESSAGE 'The report will be generated For year 2011' TYPE 'I'.
ENDIF.


START-OF-SELECTION.


  WRITE: 'This is a test program.'


OUTPUT:












Enter Company Code: 2522. Execute the report or press enter.
















Enter Sales Organization: 5436. Execute the report or press enter.












When the user enters valid company code and sales organization and executes the report or press enter button on the screen. 













On executing the report:


SET CURSOR FIELD

Sometimes there is a requirement to place the cursor on the field having a wrong value in the selection screen.

OUTPUT:


On pressing “ENTER” button or executing (F8) the program, it can be seen that the entry was wrong for customer number field but the cursor gets placed in company code field.

 









If such are the cases then modify the program as:


MODIFIED PROGRAM:

REPORT ztest.

TABLES:bsid.

DATA: temp_hkont TYPE bsid-hkont,
temp_kunnr TYPE bsid-kunnr,
temp_bukrs TYPE bsid-bukrs.

SELECT-OPTIONS: s_bukrs FOR bsid-bukrs.
PARAMETERS: s_hkont LIKE bsid-hkont.
PARAMETERS: s_kunnr LIKE bsid-kunnr.

AT SELECTION-SCREEN.
CLEAR: temp_hkont.
IF s_hkont IS NOT INITIAL.
SELECT SINGLE hkont FROM bsid INTO temp_hkont
WHERE hkont = s_hkont.

IF sy-subrc <> 0.
SET CURSOR FIELD 'S_HKONT' DISPLAY OFFSET 0.
MESSAGE 'Enter a valid G/L Account' TYPE 'E'.
ENDIF.
ENDIF.

CLEAR: temp_kunnr.
IF s_hkont IS NOT INITIAL.
SELECT SINGLE kunnr FROM bsid INTO temp_kunnr
WHERE kunnr = s_kunnr.

IF sy-subrc <> 0.
SET CURSOR FIELD 'S_KUNNR' DISPLAY OFFSET 0.
MESSAGE 'Enter a valid G/L Account' TYPE 'E'.
ENDIF.
ENDIF.


CLEAR: temp_bukrs.
IF s_bukrs IS NOT INITIAL.
SELECT SINGLE bukrs FROM bsid INTO temp_bukrs
WHERE bukrs = s_bukrs-low.

IF sy-subrc = 0.
   SELECT SINGLE bukrs FROM bsid INTO temp_bukrs
                   WHERE bukrs = s_bukrs-high.

   IF sy-subrc <> 0.
       SET CURSOR FIELD 'S_BUKRS' DISPLAY OFFSET 0.
       MESSAGE 'Enter a Valid Company Code' TYPE 'E'.
   ENDIF.

ELSE.
       SET CURSOR FIELD 'S_BUKRS' DISPLAY OFFSET 0.
       MESSAGE 'Enter a Valid Company Code' TYPE 'E'.

ENDIF.
ENDIF.

OUTPUT:

In this case, the user enters correct company code and G/L account values, but the user gives a wrong value in customer Number field.

On pressing “ENTER” button or executing (F8) the program, it can be seen that the cursor gets placed in G/L account field correctly.




AT SELECTION-SCREEN OUTPUT

This event can be used to change the properties of the selection screen fields dynamically. Hence this event allows us to modify the selection screen and its fields directly before it is displayed.


REPORT ztest.

PARAMETERS: field_1(10) TYPE c MODIF ID sc1,
                          field_2(10) TYPE c MODIF ID sc2,
                          field_3(10) TYPE c MODIF ID sc1,
                          field_4(10) TYPE c MODIF ID sc2,
                          field_5(10) TYPE c OBLIGATORY.

INITIALIZATION.

field_5 = '5000'.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

 IF screen-group1 = 'SC1'.
   screen-intensified = '1'. “ Intensify the Field.
   MODIFY SCREEN.
   CONTINUE.
ENDIF.

IF screen-group1 = 'SC2'.
  screen-intensified = '0'.
  MODIFY SCREEN.
ENDIF.

ENDLOOP.

AT SELECTION-SCREEN.

field_1 = '10'.


OUTPUT:

Here the order of execution of events is:
  • Initialization.
  • At Selection-Screen Output.
  • At selection-Screen.
The two fields belonging to modification id ‘SC1’ are intensified.