Thursday 31 August 2023

Designing Custom Tree Screen Using Report Program

REPORT ysk_modulepool_tree.

INCLUDE ymodulepool_tree_top.  “data declaration
INCLUDE ymodulepool_tree_cl1.  “class declaration
INCLUDE ymodulepool_tree_o01.  “PBO Modules
INCLUDE ymodulepool_tree_i01.  “PAI Modules
INCLUDE ymodulepool_tree_f01.  “Form Routines

START-OF-SELECTION.

CREATE OBJECT g_application.
SET SCREEN 100.

1. Draw one screen name as 100 and create a custom control name as YCONTROL.

SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

2. In the same screen create one more custom control and name as ZPP_CONTOL.

SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_TOP
*&———————————————————————*

class lcl_application DEFINITION DEFERRED.

class cl_gui_cfw DEFINITION load.

DATA: g_application TYPE REF TO lcl_application,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_simple_tree_model,
g_ok_code TYPE sy-ucomm.

* Fields on Dynpro 500
DATA: g_event(30),
g_node_key(30) TYPE c.
*——————————————————–
******Data Declarations For Insert Image on Screen.***********
CONSTANTS: cntl_true  TYPE i VALUE 1,
cntl_false TYPE i VALUE 0.
DATA:
h_picture       TYPE REF TO cl_gui_picture,
h_pic_container TYPE REF TO cl_gui_custom_container.
DATA: graphic_size TYPE i.

DATA: BEGIN OF graphic_table OCCURS 0,
line(255) TYPE x,
END OF graphic_table.
DATA: graphic_url(255),
graphic_refresh(1),
g_result    LIKE cntl_true.


*&———————————————————————*
*& Include          YMODULEPOOL_TREE_CL1
*&———————————————————————*

CLASS lcl_application DEFINITION.

PUBLIC SECTION.
METHODS:
handle_node_double_click
FOR EVENT node_double_click
OF cl_simple_tree_model
IMPORTING node_key.
ENDCLASS.                    “lcl_application DEFINITION

CLASS lcl_application IMPLEMENTATION.

METHOD handle_node_double_click.
g_event = ‘NODE_DOUBLE_CLICK’.
g_node_key = node_key.

IF g_node_key EQ ‘Vendor Sampling'(001).
CALL TRANSACTION ‘ZQM_VNSMPL’.
ELSEIF g_node_key EQ ‘Trim Audit'(003).
CALL TRANSACTION ‘ZQM_TRIM’.
ELSEIF g_node_key EQ ‘Out Source'(004).
CALL TRANSACTION ‘ZQM_OUTSOURCE’.“
ELSEIF g_node_key EQ ‘Final Goods'(005).
CALL TRANSACTION ‘ZQM_FG_FINAL’..
ELSEIF g_node_key EQ ‘Inspection’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.“
ELSEIF g_node_key EQ ‘Fout Source’.
CALL TRANSACTION ‘ZFOUTSOURCE’.
ELSEIF g_node_key EQ ‘Finish goods’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.
ELSEIF g_node_key EQ ‘FVNSMPL’.
CALL TRANSACTION ‘ZFVNSMPL’.“‘
ELSEIF g_node_key EQ ‘VNSMPL’.
CALL TRANSACTION ‘ZVNSMPL’.
ELSEIF g_node_key EQ ‘TRIMAUDIT’.
CALL TRANSACTION ‘ZTRIMAUDIT’.
ELSEIF g_node_key EQ ‘FINAL INS’.
CALL TRANSACTION ‘ZQM_FINAL_INS’.
ELSEIF g_node_key EQ ‘ZQM_TRIM’.
CALL TRANSACTION   ‘ZQM_TRIM’.
ELSEIF g_node_key EQ ‘ZTRIMAUDIT’.
CALL TRANSACTION ‘ZTRIMAUDIT’.
ELSEIF g_node_key EQ ‘ZQM_OUTSOURCE’.
CALL TRANSACTION ‘ZQM_FINISHED’.
ELSEIF g_node_key EQ ‘ZQM_INSPECTION’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.
ELSEIF g_node_key EQ ‘ZFOUTSOURCE’.
CALL TRANSACTION ‘ZQM_FINAL_INS’.
ELSEIF g_node_key EQ ‘ZQM_FG_FINAL’.
CALL TRANSACTION ‘ZQM_FG_FINAL’.
ELSEIF g_node_key EQ ‘ZQM_FINISHGOODS’.
CALL TRANSACTION ‘ZQM_INSPECTION’.
ELSEIF g_node_key EQ ‘ZQM_FINAL_INS’.
CALL TRANSACTION ‘ZFOUTSOURCE’.
ELSEIF g_node_key EQ ‘ZQM_TRIMADOBE’.
CALL TRANSACTION ‘ZQM_TRIMADOBE’.
ENDIF.
ENDMETHOD.                    “handle_node_double_click
ENDCLASS.                    “lcl_application IMPLEMENTATION

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_O01
*&———————————————————————*
*&———————————————————————*
*& Module STATUS_0100 OUTPUT
*&———————————————————————*
*&
*&———————————————————————*
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘YTREE’.
SET TITLEBAR ‘YTREET’.
IF g_tree IS INITIAL.
PERFORM create_and_init_tree. “calling subroutine
ENDIF.

* ———————————-THIS LOGIC FOR WALLPAPER IMAGE —————
DATA: l_graphic_xstr TYPE xstring,
l_graphic_conv TYPE i,
l_graphic_offs TYPE i.

CALL METHOD cl_ssf_xsf_utilities=>get_bds_graphic_as_bmp
EXPORTING
p_object  = ‘GRAPHICS’
p_name    = ‘MCFL’ “IMAGE NAME – Image name from SE78
p_id      = ‘BMAP’
p_btype   = ‘BCOL’  “(BMON = black&white, BCOL = colour)
RECEIVING
p_bmp     = l_graphic_xstr
EXCEPTIONS
not_found = 1
OTHERS    = 2.

graphic_size = XSTRLEN( l_graphic_xstr ).
CHECK graphic_size > 0.

l_graphic_conv = graphic_size.
l_graphic_offs = 0.

WHILE l_graphic_conv > 255.
graphic_table-line = l_graphic_xstr+l_graphic_offs(255).
APPEND graphic_table.
l_graphic_offs = l_graphic_offs + 255.
l_graphic_conv = l_graphic_conv – 255.
ENDWHILE.

graphic_table-line = l_graphic_xstr+l_graphic_offs(l_graphic_conv).
APPEND graphic_table.

CALL FUNCTION ‘DP_CREATE_URL’
EXPORTING
type                 = ‘image’                    “#EC NOTEXT
subtype              = cndp_sap_tab_unknown ” ‘X-UNKNOWN’
size                 = graphic_size

lifetime             = cndp_lifetime_transaction  “‘T’
TABLES
data                 = graphic_table
CHANGING
url                  = graphic_url
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_put_table   = 2
dp_error_general     = 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.
EXIT.
ENDIF.

CREATE OBJECT h_pic_container
EXPORTING container_name =  ‘ZPP_CONTROL’.
CREATE OBJECT h_picture EXPORTING parent = h_pic_container.

CALL METHOD h_picture->load_picture_from_url
EXPORTING
url    = graphic_url
IMPORTING
RESULT = g_result.

————————————-END CODE OF IMAGE —————————-
ENDMODULE.


*&———————————————————————*
*& Include          YMODULEPOOL_TREE_I01
*&———————————————————————*
*&———————————————————————*
*&      Module  USER_COMMAND_0100  INPUT
*&———————————————————————*
*       text
*———————————————————————-*
MODULE user_command_0100 INPUT.
DATA: return_code TYPE i.
* CL_GUI_CFW=>DISPATCH must be called if events are registered
* that trigger PAI
* this method calls the event handler method of an event
CALL METHOD cl_gui_cfw=>dispatch
IMPORTING return_code = return_code.
IF return_code <> cl_gui_cfw=>rc_noevent.
” a control event occured => exit PAI
*    CLEAR g_ok_code.
EXIT.
ENDIF.

CASE SY-UCOMM.   “g_ok_code.
WHEN ‘BACK’.                       ” Finish program
IF NOT g_custom_container IS INITIAL.

“Destroy tree container (destroys contained tree control, too)
CALL METHOD g_custom_container->free
EXCEPTIONS
cntl_system_error = 1
cntl_error        = 2.
IF sy-subrc <> 0.
**          MESSAGE a000.
ENDIF.
CLEAR g_custom_container.
CLEAR g_tree.
ENDIF.
LEAVE PROGRAM.
WHEN ‘EXIT’.
LEAVE TO SCREEN 0.
WHEN ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDCASE.
* CAUTION: Clear ok code!
CLEAR g_ok_code.
ENDMODULE.

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_F01
*&———————————————————————*
*&———————————————————————*
*& Form create_and_init_tree
*&———————————————————————*
*& text
*&———————————————————————*
*& –>  p1        text
*& <–  p2        text
*&———————————————————————*
FORM create_and_init_tree .” defined form logic
DATA: event  TYPE cntl_simple_event,
events TYPE cntl_simple_events.

* Create a simple tree model instance
CREATE OBJECT g_tree
EXPORTING
node_selection_mode         = cl_simple_tree_model=>node_sel_mode_single
EXCEPTIONS
illegal_node_selection_mode = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* Create a container for the tree control
CREATE OBJECT g_custom_container
EXPORTING      ” The container is linked to the custom control with the
” name ‘TREE_CONTAINER’ on the Dynpro
container_name              = ‘YCONTROL’ “custom container name

EXCEPTIONS
cntl_error                        = 1
cntl_system_error           = 2
create_error                   = 3
lifetime_error                 = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* create the view (control) of the tree model

CALL METHOD g_tree->create_tree_control
EXPORTING
parent                       = g_custom_container
EXCEPTIONS
lifetime_error               = 1
cntl_system_error            = 2
create_error                 = 3
failed                       = 4
tree_control_already_created = 5.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* define the events which will be passed to the backend
” node double click
event-eventid = cl_simple_tree_model=>eventid_node_double_click.
event-appl_event = ‘X’.              ” process PAI if event occurs
APPEND event TO events.

CALL METHOD g_tree->set_registered_events
EXPORTING
events                    = events
EXCEPTIONS
illegal_event_combination = 1
unknown_event             = 2.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* assign event handlers in the application class to each desired event
SET HANDLER g_application->handle_node_double_click FOR g_tree.

* add nodes to the tree model
PERFORM add_nodes.

* expand the root node
CALL METHOD g_tree->expand_node
EXPORTING
node_key       = ‘PP’                                 “#EC NOTEXT
EXCEPTIONS

node_not_found = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.
ENDFORM.
*&———————————————————————*
*& Form add_nodes
*&———————————————————————*
*& text
*&———————————————————————*
*& –>  p1        text
*& <–  p2        text
*&———————————————————————*
FORM add_nodes .
* Node with key ‘Root’
CALL METHOD g_tree->add_node
EXPORTING
node_key = ‘PP’                                       “#EC NOTEXT
isfolder = ‘X’
text     = ‘Quality Management’                       “#EC NOTEXT
EXCEPTIONS
OTHERS   = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*————————— Vendor Sampling ————————*
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘Vendor Sampling1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Vendor Sampling’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* Node with key Vendor Sampling
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘Vendor Sampling’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Vendor Sampling Inspection’

“#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘FVNSMPL’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’           “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘VNSMPL’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’           “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&———->Trim Audit Inspection
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIM1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Trim Audit Inspection’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.

ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIM’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Trim Audit Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZTRIMAUDIT’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIMADOBE’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&————->  Outsource Goods Inspection
CALL METHOD g_tree->add_node
EXPORTING

node_key          = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Outsource Goods Inspection’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_OUTSOURCE’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Outsource Goods Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_INSPECTION’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZFOUTSOURCE’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’

C NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&————->Finished Goods Inspection
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Finished Goods Inspection
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FG_FINAL’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Finished Goods Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FINISHGOODS’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FINAL_INS’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.
ENDFORM.

Output:


SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

No comments:

Post a Comment