Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

How to convert a local class into a global class?

Hello everyone... Its been quite sometime that I have not added some posts here. I just arrive from a vacation and I dont have any access on the net so its only now again I will add some tutorials. Anyway, what I will discuss today is all about converting your local class into a global class. What I mean is, a class declared directly into your program (SE38) and convert it into a global class found in SE24. Any class declared in SE24 are considered global class. 

So this technique is simple to process just follow the steps below. By the way, I will not discussing here how to create a class. It will be discuss in another post.

Steps:
1. Make it sure that you have a local class defined (in SE38) just like this one below. If none, please create a simple one to proceed with this tutorial. So in my sample below, I created a class which I called "Computer". Then I added a method which I named it as "get_brand". This method, once our tutorial is finished, must appear on the global class.


2. Once you created your local class, go to tcode SE24. On its main screen, click on the main menu, Object Type-->Import-->Local classes in program.


3. This screen below appears. Enter the name of your class. It can be different to the name of your local class. No worries on it. Just follow the naming conventions that you have.


Afterwhich, click this Import button below the screen.


4. Lastly, open now your new global class. The method I mentioned above, "get_brand" is now copied into this new global class. This class is now visible then to other programs that you will do in the future.


Enjoy. Keep on visiting my blog. :)

How to display two ALV grid in one screen?

Hello everyone. Its another topic I want to discuss with you today. Pause for a moment and take a look with this simple ALV grid below. Do you see it? Its two ALV Grid in just one screen. Have you been asked to do to display such? If not yet, then its time for you to take this sample codes I provided below.


REPORT  YYZZYY_TWO_ALV.


DATA: ok_code LIKE sy-ucomm,
      gt_sflight TYPE TABLE OF sflight,
      grid1  TYPE REF TO cl_gui_alv_grid,
      grid2  TYPE REF TO cl_gui_alv_grid.

* splitter control
DATA splitter TYPE REF TO cl_gui_easy_splitter_container.
* container for the splitter control
DATA container TYPE REF TO cl_gui_custom_container.

* containers created by the splitter control
DATA container_1 TYPE REF TO cl_gui_container.
DATA container_2 TYPE REF TO cl_gui_container.
* load control framework definition
TYPE-POOLS cndp.
*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*

SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
 SET PF-STATUS 'MAIN100'.
  set TITLEBAR '100'.
  IF  container_1 IS INITIAL.

* create a container for the splitter control
    CREATE OBJECT container
                  EXPORTING container_name = 'CUSTOM'.
* create the splitter control
    CREATE OBJECT splitter
                  EXPORTING parent = container
                            orientation    = 1. "0-horizontal; 1-vertical
* get the containers of the splitter control
    container_1 = splitter->top_left_container.
    container_2 = splitter->bottom_right_container.
* create the picture controls inside the containers of the splitter

    CREATE OBJECT GRID1
           EXPORTING I_PARENT =  container_1.
    CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
         EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
         CHANGING  IT_OUTTAB        = GT_SFLIGHT.


    CREATE OBJECT GRID2
           EXPORTING I_PARENT =  container_2.
    CALL METHOD GRID2->SET_TABLE_FOR_FIRST_DISPLAY
         EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
         CHANGING  IT_OUTTAB        = GT_SFLIGHT.
endif.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CALL METHOD container->free.
  LEAVE PROGRAM.
ENDMODULE.                 " USER_COMMAND_0100  INPUT
 

How to implement a drop down list in ALV grid?

Drop down list is feasible to integrate into an ALV grid. It is different with a Search Help approach since we need to hit the F4 key first. But their functionality is just the same which displays a list of data where the user can select and no need for him to type.

In this tutorial, I will discuss to you how to implement a drop down list into your ALV grid. I am using the class approach and not the FM way in displaying the ALV grid.

STEPS:
1. In setting the fieldcatalog, set the column where the drop down list will appear. Set the parameter drdn_hndl which is included in the structure LVC_S_FCAT. So if your ALV grid will display four(4) columns and you want to display the drop down list on the second column, the value of the parameter would be drdn_hndl = 2.

2. Create a sub routine where it will fill the dropdown table. Call this subroutine before the method set_table_for_first_display.

3.Inside this subroutine, do the following steps. First, call the internal table which consists the records for display. Second, loop the internal table and pass the value of the text to another internal table, let say i_dropdown. Be sure to pass also the handle which is equivalent to the value you set in fieldcatalog. Lastly, pass the internal table to the method set_drop_down_table. (see sample codes below)

4. Once done, activate and run your program. Your output must look something like this. If you haven't produce the same, please leave a message and I will try to answer your questions.

Thanks a lot again for reading my tutorial. See you on my next post. ::) Keep on reading.

How to implement a "Context Menu" in ALV Tree?

Context menu is triggered when the user pressed the right mouse key or SHIFT F10 (see screenshot below). It allows user to select list of functions dynamically defined. It may contain any functions, and is not restricted to function keys. Context menu can be assigned to the following screen elements namely: Input/output fields, Text fields, Table controls, Group boxes, subscreens pushbuttons, checkboxes, or radio buttons. 

In this tutorial, I will show to you how to add a context menu in ALV Tree.By the way, I am using here OOP approach. So if you dont have any background in OOP, I hope you have time to read some OOP materials so that you have an in-depth background for this implementation. Otherwise, you will not appreciate such tutorial.

STEPS:
1. Define a local class with a method handle_node_cm_req and handle_node_cm_sel.

2. In the method, handle_node_cm_req, define here the function list you want to appear as context menu. Use the method add_function to add the different context menus.

Also you can use the method add_separator to show a horizontal grayed bar between menus. Position this in between context menus.

3. In the method, handle_node_cm_sel, this will handle the PAI of the object. So once the user click on the menu, this method will be triggered and catches the sy-ucomm. For demonstration purposes, I haven't added any logic. Its up to you what to logic to add depending on your requirement.

4. Once the methods of the class is set-up, go to the PBO of your main screen where the ALV tree will be displayed. In OOP, ALV tree or ALV grid is displayed using the method set_table_for_first_display. So after this method is called, you need to register the events for the ALV. For context menu, you need to pass the attribute EVENTID_NODE_CONTEXT_MENU_REQ from the class cl_gui_column_tree. 

Then pass the internal table to the method set_registered_events.

5. Finally, register the context menu event on the backend for event handling using SET HANDLER commands. 

6. Once done, activate your program and try to run. Your ALV tree must look something like this.

I hope you enjoy reading my tutorial again and wishing to hear from you. By the way, there are other approach on how to implement a context menu using the PF-STATUS. On my succeeding post, I will discuss this subject matter for everyone.

Enjoy :)

SAP REPORT LIST: How to add a "Link Click" on ALV Report in SAP ABAP?

A Link Click is similar with a hotspot that when you hover your mouse, the cursor changes into a hand like this on the left. Then upon clicking on it, it will execute an action such as calling a new screen.

In this tutorial, I will discuss to you how to implement this functionality in ALV Report Tree using SAP ABAP OOP. I assumed however, that you have background knowledge now on how to manipulate ALV trees using Object Oriented concept. Otherwise, please stop and have some refresher first in OOP so that you have further understanding on how to control the ALV tree.


As can be seen into this screenshot above, the column Airline has a link click functionality. As I said, upon hovering your mouse, the cursor changes into a hand style. Actually, we can manipulate each node, if it has a link click functionality or none. So in this case, both LH and SQ have link click functionality under the Airline column.


STEPS:
1. Create a local class and define a method named "handle_link_click".

2. On the implementation of the method "handle_link_click" write any ABAP codes you want. In my example, I try to call a new screen, 201 which is in pop up mode using the keyword AT x-position y-position.

3. In the PBO of your main screen, let say screen 100, do the following additional steps. Normally, when creating the hierarchy tree, this is done after calling the method "set_table_for_first_display". This is the time you are adding the node to your ALV tree. During the node creation using the method "add_node", add the exporting parameter "it_item_layout".

4. In this next step you need to fill up the internal table "li_item_layout". First declare it accordingly. Then pass the name of the column where the link click will appear. In my example, I passed the field CARRID which represents the airline column. Finally, pass the value of the attribute "item_class_link" (which is 5 initially) from the class cl_gui_column_tree .

As I said above, we can manipulate each node of the ALV tree. If you want to show a link click of that particular node, pass the attribute item_class_link but if you want just to display the text without any link click of that node, pass the attribute item_class_text.

In my sample below, I just pass the attribute item_class_link to every node. Thus all nodes will have a link click effect. Please refer below for sample codes.

5. After doing so, register the event. This is needed so that the ALV tree will recognize the link click event, once triggered.

6. Once the event is registered, set handler to it. Please take note that the name of my local class in this tutorial is lcl_toolbar_event_receiver. So this might change depending on you.

7. Lastly, Save and Activate . Run your program and you will see the link click functionality in your ALV tree.
OUTPUT:










I Hope you enjoy this tutorial in implementing the link click functionality of ALV report in SAP ABAP using OOP method. For any clarifications and suggestions, please leave your comments below. I love to hear you guys.

How to download the data structure of tables in SE11?

Good morning people around the world. Its me again doing some blogs. Sharing to you some tips and tricks in the SAP world. Well, before I s...