Friday, 28 February 2014

Calling A Webdynpro Application from another Webdynpro Application

Scenario: In this case two web dynpro components/applications are there. One web dynpro application calls another web dynrpo application based on user interaction (Button Click).


Step1.  Create a web dynpro component in SE80.
















Step2. Provide description and continue.


















Step3. In the VIEW  just design your UI. In this case for the demo purpose we have taken a text .



















Step4. Create a application by navigating along the highlighted path.

























Step5. Provide an application Name and click on continue button. This application name is useful later from the web dynpro component who is calling it.










Step6. Click on Save and then click on test button.



















Step7. The Application appears.


















Step8. Create another application who is going to call the previous created application.










Step9. Provide short text and continue.















Step10. In the View create a text element.














Step11. Place a button on the View and provide the button text. As per our demo, while this user click on this button this would call another web dynpro application. In the events section, click on the CREATE button for the OnAction option.


















Step12. Provide an Action name and description and at last click on Continue button.
















Step13. In the attribute section, double click on the Interface which provides some api methods used later.






















Step14. Click on the Actions Tab and double click on the Event Handler method name for the above created button event.


















Step15. Provide the below code in the method.





















________________________________________________________________________________

METHOD onactioncall_ant_appl .

  DATA : o_comp TYPE REF TO if_wd_component.
  " CALL API METHOD TO GET THE REFERENCE OF THE COMPONNET CONTROLLER
  CALL METHOD wd_comp_controller->wd_get_api
    RECEIVING
      result = o_comp.

  DATA : wdw_mgr TYPE REF TO  if_wd_window_manager.
  " CALL BELOW METHOD TO GET THE REFERENCE OF WINDOW MANAGER
  CALL METHOD o_comp->get_window_manager
    RECEIVING
      window_manager = wdw_mgr.   " Reference to Window Manager

  DATA : appl_url TYPE string.
  " CALL THIS METHOS TO GET THE URL OF THE WEB DYNPRO APPLICATION TO BE CALLED
  CALL METHOD cl_wd_utilities=>construct_wd_url
    EXPORTING
      application_name = 'ZWD_COMP_CALLED_APPL'    " Application
    IMPORTING
      out_absolute_url = appl_url.   " Absolute URL (Incl. Log, Host, Port)

  DATA : wdw TYPE REF TO if_wd_window.
  " CALL THE BELOW METHOD TO CRETAE A WINDOW BY PASSING THE URL
  CALL METHOD wdw_mgr->create_external_window
    EXPORTING
      url    = appl_url
    RECEIVING
      window = wdw.
" CALL BELOW METHOD TO OPEN THE WINDOW
  CALL METHOD wdw->open.

ENDMETHOD.


_________________________________________________________________________________

Step16. Create an application.






















Step17. Save the application name and test it.



















Step18. The window is appeared. now click on the Button.















 Step19. The button click calls another web dynpro application window.















________________________________________________________________________________

Saturday, 22 February 2014

Dynamic Internal Table with Cl_ALV_TABLE_CREATE

Scenario: Creating a run time table design by using standard class : CL_ALV_TABLE_CREATE

Step1. Create a report in SE38.
_________________________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZDEMO4_DYNAMIC_TABLE_CREATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo4_dynamic_table_creation.

PARAMETERS : tab_name TYPE dd02l-tabname OBLIGATORY.
DATA : ls_tab TYPE dd02l,
              lo_type TYPE REF TO cl_abap_typedescr,
              lo_struc TYPE REF TO cl_abap_structdescr,
              lt_comp TYPE abap_compdescr_tab,
             ls_comp TYPE  abap_compdescr,
             lo_grid TYPE REF TO cl_gui_alv_grid,
             lt_fcat TYPE lvc_t_fcat,
             ls_fcat TYPE lvc_s_fcat.
DATA : dr_tab TYPE REF TO data.
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE.

START-OF-SELECTION.

  SELECT SINGLE * FROM dd02l INTO ls_tab WHERE tabname = tab_name.
  IF sy-subrc <> 0.
    MESSAGE 'Table does not Exist.' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  CALL METHOD cl_abap_typedescr=>describe_by_name
    EXPORTING
      p_name      = tab_name
    RECEIVING
      p_descr_ref = lo_type.

  lo_struc ?= lo_type.
  lt_comp = lo_struc->components[].
  LOOP AT lt_comp INTO ls_comp .
    ls_fcat-fieldname = ls_comp-name.
    CASE ls_comp-type_kind .
      WHEN 'C'.
        ls_fcat-datatype = 'CHAR'.
      WHEN 'N'.
        ls_fcat-datatype = 'NUMC'.
      WHEN 'D'.
        ls_fcat-datatype = 'DATE'.
      WHEN 'P'.
        ls_fcat-datatype = 'PACK'.
      WHEN 'T'.
        ls_fcat-datatype = 'TIME'.
      WHEN OTHERS.
        ls_fcat-datatype = ls_comp-type_kind.
    ENDCASE.
    ls_fcat-inttype = ls_comp-type_kind.
    ls_fcat-intlen = ls_comp-length.
    ls_fcat-decimals = ls_comp-decimals.

    APPEND ls_fcat TO lt_fcat.
    CLEAR ls_fcat.
  ENDLOOP.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = lt_fcat
      I_LENGTH_IN_BYTE          = 'X'
  IMPORTING
   ep_table                  = dr_tab.

  ASSIGN dr_tab->* TO <fs_tab>.

  SELECT * FROM (tab_name) INTO TABLE <fs_tab>.

END-OF-SELECTION.

  CREATE OBJECT lo_grid
    EXPORTING
      i_parent          = cl_gui_container=>default_screen.

  CALL METHOD lo_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = tab_name
    CHANGING
      it_outtab        = <fs_tab>.

  CALL SCREEN 9999.
_________________________________________________________________________________

Step2. Run the program.












































_________________________________________________________________________________

Creating Dynamic Internal table with RTTS

Scenario: This post shows how to create an internal table using RTTS concepts.

Step1. Create a program in SE38.
_________________________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZDEMO3_DYNAMIC_TABLE_CREATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo3_dynamic_table_creation.

PARAMETERS : tab_name TYPE dd02l-tabname OBLIGATORY.

DATA : ls_tab TYPE dd02l,
             lo_type TYPE REF TO cl_abap_typedescr,
             lo_struc TYPE REF TO cl_abap_structdescr,
             lo_struct TYPE REF TO cl_abap_structdescr,
            lt_comp TYPE abap_component_tab,
            lo_table TYPE REF TO cl_abap_tabledescr,
            lo_grid TYPE REF TO cl_gui_alv_grid,
            dr_tab TYPE REF TO data.
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE.


START-OF-SELECTION.
  SELECT SINGLE * FROM dd02l INTO ls_tab WHERE tabname = tab_name.
  IF sy-subrc <> 0.
    MESSAGE 'Table does not Exist.' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  CALL METHOD cl_abap_typedescr=>describe_by_name
    EXPORTING
      p_name      = tab_name
    RECEIVING
      p_descr_ref = lo_type.

  lo_struc ?= lo_type.
  CALL METHOD lo_struc->get_components
    RECEIVING
      p_result = lt_comp.

  CALL METHOD cl_abap_structdescr=>create
    EXPORTING
      p_components = lt_comp
    RECEIVING
      p_result     = lo_struct.

  CALL METHOD cl_abap_tabledescr=>create
    EXPORTING
      p_line_type = lo_struct
    RECEIVING
      p_result    = lo_table.

  CREATE DATA dr_tab TYPE HANDLE lo_table.

  ASSIGN dr_tab->* TO <fs_tab>.

  SELECT * FROM (tab_name) INTO TABLE <fs_tab>.

END-OF-SELECTION.

  CREATE OBJECT lo_grid
    EXPORTING
      i_parent          = cl_gui_container=>default_screen.

  CALL METHOD lo_grid->set_table_for_first_display

    EXPORTING
      i_structure_name = tab_name
    CHANGING
      it_outtab        = <fs_tab>.

  CALL SCREEN 9999.

_________________________________________________________________________________

Step2.


































________________________________________________________________________________

Creating Dynamic Internal Table with Data Reference and Field Symbol

Scenario: This post shows how to create a table structure at run time based on the user input table name and displaying the table contents either on the list or on the ALV grid.


View1. Output view in list.

Step1: Create a program in SE38 and activate it.
_________________________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZDEMO1_DYNAMIC_TABLE_CREATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo1_dynamic_table_creation.

PARAMETERS : tab_name TYPE dd02l-tabname OBLIGATORY.
DATA : ls_tab TYPE dd02l.
DATA: dr_tab TYPE REF TO data.
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE,
                                 <fs_wa>,
                                 <fs_fld>.

START-OF-SELECTION.

  SELECT SINGLE * FROM dd02l INTO ls_tab WHERE tabname = tab_name.
  IF sy-subrc <> 0.
    MESSAGE 'Table does not Exist.' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  CREATE DATA dr_tab TYPE TABLE OF (tab_name).
  ASSIGN dr_tab->* TO <fs_tab>.

  SELECT * FROM (tab_name) INTO TABLE <fs_tab>.

END-OF-SELECTION.

  LOOP AT <fs_tab> ASSIGNING <fs_wa> .
   new-line.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <fs_fld>.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      WRITE  <fs_fld>.
    ENDDO.
  ENDLOOP.

_________________________________________________________________________________

Step2. Run and See the Output.

















________________________________________________________________________________
Run-2.






































_________________________________________________________________________________

View2. Output view in ALV grid.

Step1.

_________________________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZDEMO1_DYNAMIC_TABLE_CREATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo1_dynamic_table_creation.

PARAMETERS : tab_name TYPE dd02l-tabname OBLIGATORY.
DATA : ls_tab TYPE dd02l.
DATA: dr_tab TYPE REF TO data.
DATA : o_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE,
                <fs_wa>,
                <fs_fld>.

START-OF-SELECTION.
  SELECT SINGLE * FROM dd02l INTO ls_tab WHERE tabname = tab_name.
  IF sy-subrc <> 0.
    MESSAGE 'Table does not Exist.' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF.
  CREATE DATA dr_tab TYPE TABLE OF (tab_name).
  ASSIGN dr_tab->* TO <fs_tab>.

  SELECT * FROM (tab_name) INTO TABLE <fs_tab>.

END-OF-SELECTION.

  CREATE OBJECT o_grid
    EXPORTING
      i_parent          =  cl_gui_container=>default_screen.
*     i_parent          =  cl_gui_container=>screen0.     

  CALL METHOD o_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = tab_name
    CHANGING
      it_outtab        = <fs_tab>.

  CALL SCREEN 9999. " Provide a screen number and double click on it, provide a text and activate.
________________________________________________________________________________


________________________________________________________________________________

Step2. Run the program, provide the table name and observe the out put on alv grid.








































________________________________________________________________________________
Run-2



































_________________________________________________________________________________

Tuesday, 18 February 2014

SAP Code Inspector

Scenario: Code Inspector is used to analyse the Syntax and the performance of the development objects. The below post describes how to create code Inspectors for particular set of developed objects and saving the same so that the result can be analysed later.


Step1. Suppose we have a report, for which code Inspector needs to be checked.

















Step2. Right click on the Report Name and navigate along the highlighted Path.

















Step3.  The Result of Code Inspector displays, the below details. What if we want to store the result of the Code Inspector so that at a later point of time we can just check the result of the core inspector.














Step4. To Store the Result of the code inspector, Go to Tcode- SCI.







Case-1

Step5.  IN the inspector Section, click on the Create Button .



















Step6. Choose the radio button  SINGLE - provide the REPORT name and click on the Execute button.
























Step7. The Code Inspector Result for the REPORT is displayed as below.















CASE-2

Step8. If we want to store the code inspector result, In the OBJECT Set Option : Provide a Name and Click on the Create Button.





















Step9. In the program Section: Provide the Report Name and SAVE the Object Set and Go Back



























Step10. In the Inspector Section: Provide a NAME  and click on Create Button.




















Step11. In the object Set Option: Provide the Above created Object Set Name. In the Variant Section, from the F4 help provide as 'DEFAULT'.  This Default variant is provided by the standard. At last SAVE it. The traffic Light is RED at this point. Now Click on the Execute Button.

















Step12. The traffic light turns into Green. To display the result click on the Display Log button.

















Step13. It shows the code Inspector result details. This result is stored in the Data Base Table . Later point of time the User can come and provide the Inspector name and can see the result. No need to run the Code Inspector again.














CASE-3

Step14. In above Code Inspector We have used a Standard variant 'DEFAULT'. Let's create our own variant and use it in the code Inspector. Provide A Variant  name and click on the Create button.


















Step15. Select some of the point needs to be checked by the code inspector run and Save the Variant.






























Step16. Let's use the same Object Key. click on the Change button.






















Step17. The report name is provided before.
























Step18. Every time the code Inspector is changed a new version is generated without deleting the previous version result. Click on the Change button.




















Step19.  Click on the  Create New Version Button.

















Step20. In the Variant Section from the F4 option, choose the above created Variant Name.













Step21. Save it. Execute the same.

















Step22. The light turns green. Click on the Show Result button.


















Step23. The details of the code inspector for the object set with the new variant is displayed below.















Step24. If U want to see the result of the Code Inspector of Version-001. Mention the same and click on the Show result button.


















Step25. The result of the code inspector - version-001 is displayed.












Step26. If U want the result of Version-2. provide the same & click on the show result button.




















Step27. The result is displayed below.














_________________________________________________________________________________

Comments system

Disqus Shortname