Wednesday, November 10, 2010

Making ALV to react to Change data automatically
Scenario:
To make ALV to react to data change automatically without any need for the user to click on ENTER or any other button/menu item.
Procedure:
In order to make the system react to an edit event, we need to first register the edit event.  
To register the edit event, call the method REGISTER_EDIT_EVENT
CALL METHOD cont_editalvgd -> register_edit_event
    Exporting
            {}I_event_id = cl_gui_alv_grid => mc_evt_modified.
When user press 'ENTER' the event MC_EVT_ENTER is triggered which automatically sets the variable M_cell_edit to 'X'.
But if the user bypasses the enter key then the variable M_CELL_EDIT has to be set explicitly which is done by passing mc_evt_modified to the exporting parameter I_EVENT_ID instead of mc_evt_enter.
In the PAI event, call the method CHECK_CHANGED_DATA. This method automatically triggers the data_changed event.
By default, SAP recognizes 'ENTER' event.  When only the CHECK_CHANGED_DATA is called in PAI event, then the 'ENTER' event is not recognized by the system.  In order to have both the events recognized by the system, we need to register the edit event.

Scenario 1: When there is no call to the method REGISTER_EVT_MODIFIED and just go with the calling of the method CHECK_CHANGED_DATA in the PAI event.
The whole scenario would work fine when you change the data and press the "OK" button on the application toolbar.
But, when you change the data and press the 'ENTER' key then the event data_changed is not triggered.
1.  Change the data in the editable ALV and press 'ENTER' key.


The changes are not reflected in the ALV as no data_changed event has been triggered.

Scenario 2: When you register the edit event and call the method CHECK_CHANGED_DATA in the PAI event.
1. Change the data in the editable ALV and press the 'OK' button on the application toolbar.

The changed data is recognized and is reflected on to the editable ALV

In the same case, when you change the data in the ALV and press 'ENTER' key, you can still see the changes reflected.

Click on ENTER.

The change event is triggered and the data has been changed accordingly.
Sample code:

REPORT  Z_ALV_EDIT_EVENT.


*"Table declarations...................................................
TABLES:
  spfli.                               " Flight Schedule Details

*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables                                                      *
*"--------------------------------------------------------------------*
DATA:
  w_grid TYPE REF TO cl_gui_alv_grid,  " Reference object for alv grid
  w_container TYPE REF TO cl_gui_custom_container.
                                       " Reference object for container

*"--------------------------------------------------------------------*
* Structure to hold Flight Schedule details                           *
*"--------------------------------------------------------------------*
data:
  fs_spfli type spfli.
*"--------------------------------------------------------------------*
* Structure to hold Field Catalog details                             *
*"--------------------------------------------------------------------*
data:
  wa_field_catalog TYPE lvc_s_fcat.

*"--------------------------------------------------------------------*
* Structure to hold Layout of the ALV Report                          *
*"--------------------------------------------------------------------*
data:

  wa_layout TYPE lvc_s_layo.


*"--------------------------------------------------------------------*
* Internal table to hold Flight Schedule details from table SPFLI     *
*"--------------------------------------------------------------------*
DATA:
  t_spfli like
 STANDARD TABLE
       OF fs_spfli.
*"--------------------------------------------------------------------*
* Internal table to hold Field Catalog Details                        *
*"--------------------------------------------------------------------*

data:
  t_field_catalog TYPE  lvc_t_fcat.

*"--------------------------------------------------------------------*
*                       START-OF-SELECTION EVENT                      *
*"--------------------------------------------------------------------*
START-OF-SELECTION.

* Data retrieval from the database table

SELECT * FROM spfli INTO TABLE t_spfli.

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  set_layout  OUTPUT
*&---------------------------------------------------------------------*
*   This module is used to set the layout for the alv grid display     *
*----------------------------------------------------------------------*
MODULE set_layout OUTPUT.
  wa_layout-grid_title = 'SPFLI TABLE DETAILS'.
  wa_layout-zebra = 'X'.
  wa_layout-edit = 'X'.

ENDMODULE.                             " set_layout  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  field_catalog  OUTPUT
*&---------------------------------------------------------------------*
*   This module is used to populate the field catalog                  *
*----------------------------------------------------------------------*
MODULE field_catalog OUTPUT.

  CLEAR wa_field_catalog.
  wa_field_catalog-fieldname = 'CARRID'.
  wa_field_catalog-ref_field = 'CARRIDS'.
  wa_field_catalog-ref_table = 'SPFLI'.
  wa_field_catalog-col_pos   = 1.
  APPEND wa_field_catalog TO t_field_catalog.

  CLEAR wa_field_catalog.
  wa_field_catalog-fieldname = 'CONNID'.
  wa_field_catalog-ref_field = 'CONNID'.
  wa_field_catalog-ref_table = 'SPFLI'.
  wa_field_catalog-col_pos   = 2.
  APPEND wa_field_catalog TO t_field_catalog.

  CLEAR wa_field_catalog.
  wa_field_catalog-fieldname = 'CITYFROM'.
  wa_field_catalog-ref_field = 'CITYFROM'.
  wa_field_catalog-ref_table = 'SPFLI'.
  wa_field_catalog-col_pos   = 3.
  APPEND wa_field_catalog TO t_field_catalog.

  CLEAR wa_field_catalog.
  wa_field_catalog-fieldname = 'CITYTO'.
  wa_field_catalog-ref_field = 'CITYTO'.
  wa_field_catalog-ref_table = 'SPFLI'.
  wa_field_catalog-col_pos   = 4.
  APPEND wa_field_catalog TO t_field_catalog.

ENDMODULE.                             " field_catalog  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*  This module is used to handle the PAI events
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'OK'.

* Calling the check_changed_data method to trigger the data_changed
* event
*
      CALL METHOD w_grid->check_changed_data
*  IMPORTING
*    E_VALID   =
*  CHANGING
*    C_REFRESH = 'X'
          .
      update spfli from table t_spfli.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE TO SCREEN 0.

  ENDCASE.                             " CASE SY-UCOMM
ENDMODULE.                             " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Module  manage_alv_grid  OUTPUT
*&---------------------------------------------------------------------*
*   This module is used to manage the Grid display
*----------------------------------------------------------------------*
MODULE manage_alv_grid OUTPUT.


  IF w_grid IS INITIAL.

    CREATE OBJECT w_container
      EXPORTING
        container_name              =   'CONTAINER1'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6
        .
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.                             " IF SY-SUBRC NE 0

    CREATE OBJECT w_grid
      EXPORTING
        i_parent          =  w_container
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.                             " IF SY-SUBRC NE 0


    CALL METHOD w_grid->set_table_for_first_display
      EXPORTING
        i_structure_name              = 'SPFLI'
        is_layout                     = wa_layout
      CHANGING
        it_outtab                     = t_spfli[]
        it_fieldcatalog               = t_field_catalog
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 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.                             " IF SY-SUBRC NE 0

  ENDIF.                               " IF W_GRID IS INITIAL

*  Registering the EDIT Event


CALL METHOD w_grid->register_edit_event
  EXPORTING
    i_event_id = cl_gui_alv_grid=>mc_evt_modified
  EXCEPTIONS
    ERROR      = 1
    others     = 2
        .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.                                 " IF SY-SUBRC NE 0

ENDMODULE.                             " manage_alv_grid  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*   This module is used to set the PF-Status and title bar             *
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'ALVS_GUI'.
  SET TITLEBAR 'ALV_TITLE'.
ENDMODULE.                             " STATUS_0100  OUTPUT
ref: http://wiki.sdn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically

Sunday, November 7, 2010

Display two or more ALVs on one screen using Splitter Control

Data: custom_container TYPE REF TO cl_gui_custom_container,
splitter TYPE REF TO cl_gui_splitter_container,
graphic_parent1 TYPE REF TO cl_gui_container,
graphic_parent2 TYPE REF TO cl_gui_container.

DATA ref_grid TYPE REF TO cl_gui_alv_grid.
DATA ref_grid1 TYPE REF TO cl_gui_alv_grid.

** create container in which to place splitter
** (place it in the custom control named CONTAINER
** defined using screenpainter in dynpro 100)

CREATE OBJECT custom_container
EXPORTING
container_name = 'CONTAINER'. "use uppercase letters!
*
** create splitter container in which to place graphics
CREATE OBJECT splitter
EXPORTING
parent = custom_container
rows = 2
columns = 1
align = 15. " (splitter fills the hole custom container)

** get part of splitter container for 1st table
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = graphic_parent1.
** get part of splitter container for 2nd table
CALL METHOD splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = graphic_parent2.

CREATE OBJECT ref_grid EXPORTING i_parent = graphic_parent1.
** Display first ALV
PERFORM set_display.

CREATE OBJECT ref_grid1 EXPORTING i_parent = graphic_parent2.
** Display second ALV
PERFORM set_display1.

*&--------------------------------------------------------------------*
*& Form set_display
*&--------------------------------------------------------------------*
* text Display first ALV
*---------------------------------------------------------------------*
FORM set_display.
CALL METHOD ref_grid->set_table_for_first_display
EXPORTING
is_variant = st_var
i_save = save
is_layout = loyo
CHANGING
it_outtab = itab_final[]
it_fieldcatalog = fcat.
ENDFORM. "set_display

*&--------------------------------------------------------------------*
*& Form set_display1
*&--------------------------------------------------------------------*
* text Display second ALV
*---------------------------------------------------------------------*
FORM set_display1.
CALL METHOD ref_grid1->set_table_for_first_display
EXPORTING
is_variant = st_var
i_save = save
is_layout = loyo1
CHANGING
it_outtab = itab_final1[]
it_fieldcatalog = fcat1.
ENDFORM. "set_display1

ref:http://wiki.sdn.sap.com/wiki/display/ABAP/Display+two+or+more+ALVs+on+one+screen+using+Splitter+Control

Friday, November 5, 2010

Calling a BDC in parallel using update task
by Kevin Wilson

URL: http://abaptips.erpgenie.com



The situation: We have an internal table LT_DATA that is used to loop and build up BDC related data. At the end of VBELN we have all the data in our BDC table to be called. We need the program to wait and display the result of the called BDC.

STEP 1: The LC_PER constant stores the percentage value of unused work processes to make available to our report.
constants: lc_per TYPE numc2 value '75'.

data: lv_free_threads TYPE i,
lv_thread TYPE numc2,
lv_thread_count TYPE i,
gv_active_threads TYPE i.

STEP 2: Get the number of free work processes
*** Get Number of Free Processes.
CALL FUNCTION 'SPBT_INITIALIZE'
IMPORTING
free_pbt_wps = lv_free_threads
EXCEPTIONS
invalid_group_name = 1
internal_error = 2
pbt_env_already_initialized = 3
currently_no_resources_avail = 4
no_pbt_resources_found = 5
cant_init_different_pbt_groups = 6
OTHERS = 7.

IF sy-subrc <> 0.
*** Issue error message
LEAVE LIST-PROCESSING.
ENDIF.

STEP 3: Calculate how many sessions we'd like to run in parallel
*** Determine no of Free threads to be used. Based on % of available
lv_thread_count = lv_free_threads * lc_per / 100 .
lv_thread = 0.
gv_active_threads = 0.

STEP 4: Loop through the data building your BDC data
*** Loop through data
LOOP at lt_data.

perform build_BDC tables it_bdctab.

STEP 5: At the end of VBELN and at the time to call the BDC insert our code
*** Do your process at end of Order Number
AT END OF VBELN.

STEP 6: Perform a DO loop. Since we don't know how many times we need to call it and since we need to control how many sessions we generate
DO.

STEP 7: Increment the number of threads we are currently using
ADD 1 TO gv_active_threads.

STEP 8: Check if the number of threads we are using is still within our limit.
IF gv_active_threads <= lv_thread_count.

STEP 9: Give the thread a unique number and call the tRFC. Notice we perform a subroutine at the end of the task. In this subroutine we'll decrement the number of active threads we are using
add 1 to lv_thread.

* Call remotely enable function in update task. In this function we call the normal BDC transaction.
CALL FUNCTION 'ZISD_CALL_TRANSACTION'
STARTING NEW TASK lv_thread
DESTINATION IN GROUP DEFAULT
PERFORMING update_order ON END OF TASK
EXPORTING
iv_transaction = 'VA01'
iv_mode = 'N'
iv_update = 'A'
TABLES
it_bdctab = it_bdctab
et_bdcmsg = it_bdcmsg
EXCEPTIONS
not_a_valid_tcode = 1
bdc_data_empty = 2
OTHERS = 3.

IF sy-subrc <> 0.


STEP 10: If the tRFC fails then try again but first decrement the number of used active threads. Beware not to entire an infite loop if an error is issued. Only do this if it's a technical error otherwise you should exit the DO loop in this case as well. I received SY-SUBRC = 3 on occasion so I implemented this code to retry the execution which resolved the issue.
SUBTRACT 1 FROM gv_active_threads. "Try again if it fails

ELSE.
EXIT.

ENDIF.

ELSE.
SUBTRACT 1 FROM gv_active_threads.

ENDIF.

ENDDO.

ENDAT.

ENDLOOP.

IF sy-subrc = 0.

STEP 11: Wait until all active threads are completed. This number is decremented in the subroutine below and incremented each time the RFC is called.
* Wait till all threads are completed.
WAIT UNTIL gv_active_threads = 0.

PERFORM display_results.

COMMIT WORK AND WAIT.

ENDIF.

STEP 12: On return of the call BDC we decrement the number of active threads counter. When it's zero the program will execute.

******* SUBROUTINES
FORM update_order USING name.

DATA: lv_order TYPE vbeln.

* Get Response from Threads.
RECEIVE RESULTS FROM FUNCTION 'ZISD_CALL_TRANSACTION'
IMPORTING
et_br = lv_order. "Now you have the order to display

SUBTRACT 1 FROM gv_active_threads.

ENDFORM. " UPDATE_ORDER

Know the difference between Class and Function Module

Difference between class and a function module?

Ans. Function modules are ABAP routines that are administered in a central function library. They apply across applications and are available throughout the system. You must assign function modules to a function pool that is called a function group. A function group is nothing but a container for the function modules.
Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.

What is wrapper class?

A data structure or software that contains ("wraps around") other data or software, so that the contained elements can exist in the newer system. The term is often used with component software, where a wrapper is placed around a legacy routine to make it behave like an object. This is also called "encapsulation" or "wrapper encapsulation," but is not the same as "object encapsulation," a fundamental concept of object technology.


What are events in classes?

Triggering Events

To trigger an event, a class must

- Declare the event in its declaration part

- Trigger the event in one of its methods

Declaring Events

You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:

EVENTS EXPORTING... VALUE() TYPE type [OPTIONAL]..

To declare static events, use the following statement:

CLASS-EVENTS ...

Both statements have the same syntax.

When you declare an event, you can use the EXPORTING addition to specify parameters that are passed to the event handler. The parameters are always passed by value. Instance events always contain the implicit parameter SENDER, which has the type of a reference to the class or the interface in which the event is declared.

Triggering Events

An instance event in a class can be triggered by any method in the class. Static events can be triggered by any static method. To trigger an event in a method, use the following statement:

RAISE EVENT EXPORTING... = ...

For each formal parameter that is not defined as optional, you must pass a corresponding actual parameter in the EXPORTING addition. The self-reference ME is automatically passed to the implicit parameter SENDER.

Handling Events

Events are handled using special methods. To handle an event, a method must

- be defined as an event handler method for that event

- be registered at runtime for the event.


Difference between global and local class?
Local and Global Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.

There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.


Difference between static method and instance method?

Instance Methods

You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.

Static Methods

You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

What is friend class?

In object-oriented programming to allow access to "private" or "protected" data of a class in another class, the latter class is declared as a friend class.

Purpose

A friend class has full access to the private data members of a class without being a member of that class.

Example

A friend class can be declared as shown:

class A

Unknown macro: { private}


What is static constructor and instance constructor?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class.

Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.

You may say, why not initialize static data members where we declare them in the code. Like this :

private static int id = 10;
private static string name = "jack";

Static data members can certainly be initialized at the time of their declaration but there are times when value of one static member may depend upon the value of another static member. In such cases we definitely need some mechanism to handle conditional initialization of static members.


What is abstract class?

A class without a instance is abstract classes. Consists of abstract methods whose implementation is to be provided by the user itself. Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.


What is overriding polymorphism?

Method overriding, in object oriented programming, is a language feature that allows a subclass to provide a specific implementation of a method that is already provided by one of its super-classes. The implementation in the subclass overrides (replaces) the implementation in the super-class.

A subclass can give its own definition of methods which also happen to have the same signature as the method in its super-class. This means that the subclass's method has the same name and parameter list as the super-class's overridden method. Constraints on the similarity of return type vary from language to language, as some languages support covariance on return types.

Method overriding is an important feature that facilitates polymorphism in the design of object-oriented programs.

Some languages allow the programmer to prevent a method from being overridden, or disallow method overriding in certain core classes. This may or may not involve an inability to subclass from a given class.

In many cases, abstract classes are designed — i.e. classes that exist only in order to have specialized subclasses derived from them. Such abstract classes have methods that do not perform any useful operations and are meant to be overridden by specific implementations in the subclasses. Thus, the abstract super-class defines a common interface which all the subclasses inherit.



It is normal when we hit password wrong and our login gets lock,
this small piece of code unlocks the user when he/she hits wrong password.

*&---------------------------------------------------------------------*
*& program unlock password flag
*&---------------------------------------------------------------------*
REPORT YKC_PWORD.

tables: usr02.

selection-screen begin of block blck1.*---name of userparameters: p_user like usr02-bname .
selection-screen end of block blck1.

at selection-screen.
select single bname
into usr02-bname
from usr02 where bname = p_user.

if sy-subrc ne 0.
message 'User Not Exist' type 'E'.
endif.

update usr02 set uflag = 0
where bname = p_user.

if sy-subrc = 0.
message ' User Succesfully unlocked' type 'E'.
else.
message 'User failed to unlock' type 'E'.
endif.

1. Go to the TCode SE24 and enter CL_EXITHANDLER as object type.
2. In 'Display' mode, go to 'Methods' tab.
3. Double click the method 'Get Instance' to display it source code.
4. Set a breakpoint on 'CALL METHOD cl_exithandler=>get_class_name_by_interface'.
5. Then run your transaction.
6. The screen will stop at this method.
7. Check the value of parameter 'EXIT_NAME'. It will show you the BADI for that transaction.


Source: http://searchsap.techtarget.com/tip/0,289483,sid21_gci1305858,00.html

ALV Tree program

*&---------------------------------------------------------------------*
*& Report ZALV_TREE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_TREE MESSAGE-ID zer14.

*&---------------------------------------------------------------------*
*& DECLERATION OF TYPE POOL.
*&---------------------------------------------------------------------*
TYPE-POOLS slis.

*&---------------------------------------------------------------------*
*& DECLERATION OF TABLES.
*&---------------------------------------------------------------------*
TABLES: aufk,bkpf,proj,tj02t,prps,jcds,coep.

*&---------------------------------------------------------------------*
* TYPE DECLARATION
*&---------------------------------------------------------------------*

TYPES:
*FOR aufk TABLE
BEGIN OF t_aufk,
aufnr TYPE aufk-aufnr, "ORDER NUMBER
objnr TYPE aufk-objnr, "OBJECT NUMBER
pspel TYPE aufk-pspel, "WBS ELEMENT
stat TYPE jcds-stat, "OBJECT STATUS
udate TYPE jcds-udate, "CREATION DATE
inact TYPE jcds-inact, "INACTIVE STATUS
utime TYPE jcds-utime, "TIME CHANGED
chgnr TYPE jcds-chgnr, "Change number
END OF t_aufk,

*FOR PROJ TABLE

BEGIN OF t_proj,
pspnr TYPE proj-pspnr, "PROJECT DEFINATION (INITIAL)
pspid TYPE proj-pspid, "PROJECT DEFINATION
post1 TYPE proj-post1, "PROJECT DESCRIPTION
profl TYPE proj-profl,
END OF t_proj,
*FOR PRPS TABLE

BEGIN OF t_prps,
pspnr TYPE prps-pspnr, "WBS ELEMENT
objnr TYPE prps-objnr, "OBJECT NUMBER
psphi TYPE prps-psphi, "CURRENT NUMBER OF THE APPROPIATE OBJECT
post1 TYPE prps-post1, "WBS DESCRIPTION
END OF t_prps,

*FOR COEP TABLE

BEGIN OF t_coep,
wtgbtr TYPE coep-wtgbtr, "Total Value in Transaction Currency
objnr TYPE coep-objnr, "OBJECT NUMBER
END OF t_coep,

*FOR COEP TABLE

BEGIN OF t_coep1,
wtgbtr TYPE coep-wtgbtr, "Total Value in Transaction Currency
objnr TYPE coep-objnr, "OBJECT NUMBER
END OF t_coep1,

*FOR TJ02T TABLE
BEGIN OF t_tj02t,
istat TYPE tj02t-istat, "System status
txt04 TYPE tj02t-txt04, "ndividual status of an object (short form)
END OF t_tj02t,

* FOR T056P TABLE
BEGIN OF t_t056p,
zsoll TYPE t056p-zsoll, "Interest Rate
datab TYPE t056p-datab, "Effective-From Date
END OF t_t056p,

* FOR BKPF TABLE

BEGIN OF t_bkpf,
gjahr TYPE bkpf,
END OF t_bkpf,

*FOR FINAL INTERNAL TABLE

BEGIN OF t_final,
aufnr TYPE aufk-aufnr, "ORDER NUMBER
objnr TYPE aufk-objnr, "OBJECT NUMBER
pspel TYPE aufk-pspel, "WBS ELEMENT
post1 TYPE proj-post1, "PROJECT DESCRIPTION
post11 TYPE prps-post1, "WBS DESCRIPTION
stat TYPE jcds-stat, "OBJECT STATUS
udate TYPE jcds-udate, "CREATION DATE
inact TYPE jcds-inact, "INACTIVE STATUS
utime TYPE jcds-utime, "TIME CHANGED
pspnr TYPE prps-pspnr, "WBS ELEMENT
psphi TYPE prps-psphi, "CURRENT NUMBER OF THE APPROPIATE OBJECT
wtgbtr TYPE coep-wtgbtr, "Total Value in Transaction Currency
wtgbtr1 TYPE coep-wtgbtr, "Total Value in Transaction Currency
zsoll TYPE t056p-zsoll, "Interest Rate
zsoll1 TYPE t056p-zsoll, "Interest Rate
v_var1 TYPE p DECIMALS 2, "FOR CALCULATION OF DEBT AMOUNT
v_var2 TYPE p DECIMALS 2, "FOR CLCULATION OF EQUITY AMOUNT
v_total TYPE p DECIMALS 2, " TOTAL OF V_VAR1 AND V_VAR2
v_e_bal TYPE p DECIMALS 2, "ENDING TOTAL
END OF t_final.

*&---------------------------------------------------------------------*
* PARAMETERS FOR SELECTION-SCREEN
*&---------------------------------------------------------------------*
* SELECTION SCREEN BLOCK FOR SELECTING VALUE
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS :
s_profl FOR proj-profl,
s_pspnr FOR proj-pspnr.

PARAMETERS :
* P_MONAT TYPE BKPF-MONAT OBLIGATORY,
p_gjahr TYPE bkpf-gjahr OBLIGATORY,
v_fm_dt TYPE sy-datum OBLIGATORY,
v_to_dt TYPE sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
* VARIABLE DECLARATIONS
*&---------------------------------------------------------------------*

DATA: v_istat TYPE tj02t-istat,
v_cal TYPE p DECIMALS 2, " FOR CALCULATION OF wa_final-zsoll / 12
v_cal1 TYPE p DECIMALS 2. " FOR CALCULATION OF wa_final-zsoll1 / 12

*&---------------------------------------------------------------------*
* CONTANTS DECLARATION
*&---------------------------------------------------------------------*

CONSTANTS : c_x(1) VALUE 'X', " value used to set X for a field
c_repid(40) VALUE sy-repid, " report id
c_teco(4) VALUE 'TECO', " object status description

c_check(1) VALUE 'X'. " value used to set X for a field

CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.

DATA tree1 TYPE REF TO cl_gui_alv_tree.
DATA mr_toolbar TYPE REF TO cl_gui_toolbar.

INCLUDE .
INCLUDE bcalv_toolbar_event_receiver.
INCLUDE bcalv_tree_event_receiver.

DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.

DATA: it_field TYPE lvc_t_fcat, "Fieldcatalog
ok_code LIKE sy-ucomm. "OK-Code

*------------------------------------
* INTERNAL TABLE
*------------------------------------

DATA: it_aufk TYPE STANDARD TABLE OF t_aufk, " INTERNAL TABLE OF TYPE I_AUFK
it_proj TYPE STANDARD TABLE OF t_proj, " INTERNAL TABLE OF TYPE I_PROJ
it_prps TYPE STANDARD TABLE OF t_prps, " INTERNAL TABLE OF TYPE I_PRPS
it_coep TYPE STANDARD TABLE OF t_coep, " INTERNAL TABLE OF TYPE I_COEP
it_coep1 TYPE STANDARD TABLE OF t_coep1, " INTERNAL TABLE OF TYPE I_COPE1
it_tj02t TYPE STANDARD TABLE OF t_tj02t, " INTERNAL TABLE OF TYPE I_TJ02P
it_t056p TYPE STANDARD TABLE OF t_t056p, " INTERNAL TABLE OF TYPE I_T056T
it_final TYPE STANDARD TABLE OF t_final, " INTERNAL TABLE OF TYPE I_FIANL
it_bkpf TYPE STANDARD TABLE OF t_bkpf,
it_final1 TYPE STANDARD TABLE OF t_final.

*------------------------------------
* WORK AREA
*------------------------------------

DATA:wa_aufk TYPE t_aufk,
wa_proj TYPE t_proj,
wa_prps TYPE t_prps,
wa_coep TYPE t_coep,
wa_coep1 TYPE t_coep1,
wa_tj02t TYPE t_tj02t,
wa_t056p TYPE t_t056p,
wa_final TYPE t_final,
wa_bkpf TYPE t_bkpf,
wa_final1 TYPE t_final.

START-OF-SELECTION.

*********************************************************
* perform for passing the hard code value
*********************************************************
* PERFORM hard_code.

******************************************************************
* PERFORM for get the value
******************************************************************
PERFORM get_data.

END-OF-SELECTION.

CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'ZMAIN'.
* SET TITLEBAR 'xxx'.

IF tree1 IS INITIAL.
PERFORM init_tree.
ENDIF.
CALL METHOD cl_gui_cfw=>flush.

ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Form INIT_TREE
*&---------------------------------------------------------------------*
* text

*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_tree .

it_final1[] = it_final[] .
* create fieldcatalog for structure sflight

PERFORM build_fieldcatalog.

* create container for alv-tree
DATA: alv_containor(30) TYPE c,
l_custom_container TYPE REF TO cl_gui_custom_container.
alv_containor = 'TREE1'.

IF sy-batch IS INITIAL.
CREATE OBJECT l_custom_container
EXPORTING
container_name = 'ALV_CONTAINOR'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
ENDIF.

* create tree control
CREATE OBJECT tree1
EXPORTING
parent = l_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = space
no_html_header = ''
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.

* create Hierarchy-header
DATA l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.

* create info-table for html-header
DATA: lt_list_commentary TYPE slis_t_listheader,
l_logo TYPE sdydo_value.
* perform build_comment using
* lt_list_commentary
* l_logo.

* repid for saving variants
DATA: ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
break spcandxx.
REFRESH it_final.
* create emty tree-control
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = l_hierarchy_header
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
CHANGING
it_outtab = it_final[] "table must be emty !!
it_fieldcatalog = it_field[].
break spcandxx.
* create hierarchy
PERFORM create_hierarchy.

* add own functioncodes to the toolbar
PERFORM change_toolbar.

* register events
* perform register_events.

* adjust column_width
* call method tree1->COLUMN_OPTIMIZE.

ENDFORM. " INIT_TREE

*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM build_fieldcatalog .

DATA: wa_field TYPE lvc_s_fcat.

* get fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZSTRUC'
CHANGING
ct_fieldcat = it_field.

SORT it_field BY scrtext_l.

* change fieldcatalog
* data: wa_field type lvc_s_fcat.
LOOP AT it_field INTO wa_field.
CASE wa_field-fieldname.
WHEN 'POST1' OR 'POST11' OR 'AUFNR'.
wa_field-no_out = 'X'.
wa_field-key = ''.
WHEN 'WTGBTR' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-003. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'WTGBTR1' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-004. " header information
wa_field-do_sum = 'X'. " DOING SUM
WHEN 'ZSOLL' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-005. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'ZSOLL1'.
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-006. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'V_VAR1' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-007. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'V_VAR2' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-008. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'V_TOTAL' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-009. " header information
wa_field-do_sum = 'X'. " DOING SUM

WHEN 'V_E_BAL' .
wa_field-outputlen = 20. " output length on screen
wa_field-coltext = text-010. " header information
wa_field-do_sum = 'X'. " DOING SUM
ENDCASE.
MODIFY it_field FROM wa_field.
ENDLOOP.

ENDFORM.. "build_fieldcatalog
*&---------------------------------------------------------------------*
*& Form BUILD_HIERARCHY_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_L_HIERARCHY_HEADER text
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING p_hierarchy_header TYPE treev_hhdr.

p_hierarchy_header-heading = 'Business Segment'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.

ENDFORM. " BUILD_HIERARCHY_HEADER
*&---------------------------------------------------------------------*
*& Form BUILD_COMMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_LIST_COMMENTARY text
* -->P_L_LOGO text
*----------------------------------------------------------------------*
FORM build_comment USING

pt_list_commentary TYPE slis_t_listheader
p_logo TYPE sdydo_value.

DATA: ls_line TYPE slis_listheader.
*
* LIST HEADING LINE: TYPE H
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'ALV-tree-demo: flight-overview'. "#EC NOTEXT
APPEND ls_line TO pt_list_commentary.
* STATUS LINE: TYPE S
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'valid until'. "#EC NOTEXT
ls_line-info = 'January 29 1999'. "#EC NOTEXT
APPEND ls_line TO pt_list_commentary.
ls_line-key = 'time'.
ls_line-info = '2.00 pm'. "#EC NOTEXT
APPEND ls_line TO pt_list_commentary.
* ACTION LINE: TYPE A
CLEAR ls_line.
ls_line-typ = 'A'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'actual data'. "#EC NOTEXT
APPEND ls_line TO pt_list_commentary.

p_logo = 'ENJOYSAP_LOGO'.

ENDFORM. " BUILD_COMMENT
*&---------------------------------------------------------------------*
*& Form CREATE_HIERARCHY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_hierarchy .

* add data to tree
DATA: l_pspnr_key TYPE lvc_nkey,
l_pspnr1_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey.

SORT it_final1 BY post1 post11 aufnr.

LOOP AT it_final1 INTO wa_final1.
ON CHANGE OF wa_final1-post1.
PERFORM add_pspnr_line USING wa_final1
''
CHANGING l_pspnr_key.
ENDON.
ON CHANGE OF wa_final1-post11.
PERFORM add_pspnr1_line USING wa_final1
l_pspnr_key
CHANGING l_pspnr1_key.
ENDON.
PERFORM add_complete_line USING wa_final1
l_pspnr1_key
CHANGING l_last_key.

CLEAR wa_final1.
ENDLOOP.

* calculate totals
CALL METHOD tree1->update_calculations.

* this method must be called to send the data to the frontend
CALL METHOD tree1->frontend_update.

ENDFORM. " CREATE_HIERARCHY

*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .

*&---------------------------------------------------------------------*
* QUERY TO select ISTAT FROM TJ02T INTO IT_TJ02T
*&---------------------------------------------------------------------*

SELECT SINGLE
istat
FROM tj02t
INTO v_istat
WHERE
spras = sy-langu AND txt04 = c_teco.

IF sy-subrc <> 0.

MESSAGE e000.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select PSPNR PSPID FROM PROJ INTO IT_PROJ.
*&---------------------------------------------------------------------*

SELECT
pspnr
* PSPID
post1
FROM proj
INTO TABLE it_proj
WHERE
pspnr IN s_pspnr
AND profl IN s_profl.

IF sy-subrc <> 0.

MESSAGE e001.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select PSPNR OBJNR PSPHI FROM PRPS INTO IT_PRPS.
*&---------------------------------------------------------------------*

SELECT
pspnr
objnr
psphi
* PSPID
post1
FROM prps
INTO TABLE it_prps
FOR ALL ENTRIES IN it_proj
WHERE psphi = it_proj-pspnr.

IF sy-subrc <> 0 .

MESSAGE e002.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select AUFNR OBJNR STAT UDAT INACT UTIME FROM AUFK,JCDS INTO IT_AUFK.
*&---------------------------------------------------------------------*

SELECT
a~aufnr
a~objnr
a~pspel
b~stat
b~udate
b~inact
b~utime
b~chgnr
FROM
aufk AS a INNER JOIN jcds AS b
ON a~objnr = b~objnr
INTO TABLE it_aufk
FOR ALL ENTRIES IN it_prps
WHERE a~pspel = it_prps-pspnr AND
b~stat = v_istat AND
b~udate BETWEEN v_fm_dt AND v_to_dt
AND b~inact <> c_x.

IF sy-subrc <> 0 .

MESSAGE e003.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select WTGBTR FROM COEP INTO IT_COEP.
*&---------------------------------------------------------------------*

SELECT
wtgbtr
FROM coep
INTO TABLE it_coep
FOR ALL ENTRIES IN it_prps
WHERE
gjahr = p_gjahr AND objnr = it_prps-objnr.

IF sy-subrc <> 0 .

MESSAGE e004.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select WTGBTR FROM COEP INTO IT_COEP.
*&---------------------------------------------------------------------*

SELECT
wtgbtr
objnr
FROM coep
INTO TABLE it_coep1
FOR ALL ENTRIES IN it_prps
WHERE
gjahr = p_gjahr AND objnr = it_prps-objnr.

IF sy-subrc <> 0 .

MESSAGE e005.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select ZSOLL FROM T056P INTO IT_T056P.
*&---------------------------------------------------------------------*

SELECT
zsoll
FROM t056p
INTO TABLE it_t056p
WHERE referenz = 'ZNWN DEBT' .

IF sy-subrc <> 0 .

MESSAGE e006.

ENDIF.

*&---------------------------------------------------------------------*
* QUERY TO select ZSOLL FROM T056P INTO IT_T056P.
*&---------------------------------------------------------------------*

SELECT
zsoll
FROM t056p
INTO TABLE it_t056p
WHERE referenz = 'ZNWNEQUITY' .

IF sy-subrc <> 0 .

MESSAGE e007.

ENDIF.

break spcandxx.
LOOP AT it_prps INTO wa_prps.

wa_final-pspnr = wa_prps-pspnr.
wa_final-objnr = wa_prps-objnr.
wa_final-psphi = wa_prps-psphi.
wa_final-post11 = wa_prps-post1.

READ TABLE it_proj INTO wa_proj WITH KEY pspnr = wa_prps-pspnr.

IF sy-subrc = 0.

wa_final-post1 = wa_proj-post1.

ELSE.
MESSAGE e003.

ENDIF.

READ TABLE it_aufk INTO wa_aufk WITH KEY pspel = wa_prps-pspnr.

IF sy-subrc = 0.

wa_final-aufnr = wa_aufk-aufnr.
wa_final-udate = wa_aufk-udate.
wa_final-inact = wa_aufk-inact.
wa_final-utime = wa_aufk-utime.
ELSE.
MESSAGE e003.

ENDIF.

READ TABLE it_coep INTO wa_coep WITH KEY objnr = wa_prps-objnr.

IF sy-subrc = 0.

wa_final-wtgbtr = wa_coep-wtgbtr.

ELSE.

MESSAGE e003.

ENDIF.

READ TABLE it_coep1 INTO wa_coep1 WITH KEY objnr = wa_prps-objnr.

IF sy-subrc = 0.

wa_final-wtgbtr1 = wa_coep1-wtgbtr.

ELSE.
MESSAGE e003.

ENDIF.

wa_final-zsoll = wa_t056p-zsoll.

APPEND wa_final TO it_final. "append wa_final into it_final.

LOOP AT it_final INTO wa_final.

v_cal = wa_final-zsoll / 12 .
v_cal1 = wa_final-zsoll1 / 12 .

wa_final-v_var1 = ( wa_final-wtgbtr ( v_cal ) + ( wa_final-wtgbtr1 ) ( v_cal / 2 ) ) .
wa_final-v_var2 = ( wa_final-wtgbtr ( v_cal1 ) + ( wa_final-wtgbtr1 ) ( v_cal1 ) / 2 ) .
wa_final-v_total = ( wa_final-v_var1 + wa_final-v_var2 ).
wa_final-v_e_bal = ( wa_final-wtgbtr wa_final-wtgbtr1 wa_final-v_total ).

MODIFY it_final FROM wa_final INDEX sy-tabix.
ENDLOOP.

ENDLOOP.

ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form CHANGE_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM change_toolbar .

* * get toolbar control
CALL METHOD tree1->get_toolbar_object
IMPORTING
er_toolbar = mr_toolbar.

CHECK NOT mr_toolbar IS INITIAL.

* add seperator to toolbar
CALL METHOD mr_toolbar->add_button
EXPORTING
fcode = ''
icon = ''
butn_type = cntb_btype_sep
text = ''
quickinfo = 'This is a Seperator'. "#EC NOTEXT

* add Standard Button to toolbar (for Delete Subtree)
CALL METHOD mr_toolbar->add_button
EXPORTING
fcode = 'DELETE'
icon = ' (18)'
butn_type = cntb_btype_button
text = ''
quickinfo = 'Delete subtree'. "#EC NOTEXT

* add Dropdown Button to toolbar (for Insert Line)
CALL METHOD mr_toolbar->add_button
EXPORTING
fcode = 'INSERT_LC'
icon = ' (17)'
butn_type = cntb_btype_dropdown
text = ''
quickinfo = 'Insert Line'. "#EC NOTEXT

* set event-handler for toolbar-control
CREATE OBJECT toolbar_event_receiver.
SET HANDLER toolbar_event_receiver->on_function_selected
FOR mr_toolbar.
SET HANDLER toolbar_event_receiver->on_toolbar_dropdown
FOR mr_toolbar.

ENDFORM. " CHANGE_TOOLBAR

*&---------------------------------------------------------------------*
*& Form ADD_PSPNR_LINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_FINAL text
* -->P_0958 text
* <--P_L_PSPNR_KEY text
*----------------------------------------------------------------------*
FORM add_complete_line USING wa_final1 TYPE t_final
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.

DATA: l_node_text TYPE lvc_value. ",
* wa_final2 LIKE it_final.

* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = ' (3P)'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
APPEND ls_item_layout TO lt_item_layout.

* add node
l_node_text = wa_final1-aufnr.

DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.

CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = wa_final1
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.

ENDFORM. " add_carrid_line

*&---------------------------------------------------------------------*
*& Form ADD_PSPNR1_LINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_FINAL text
* -->P_L_PSPNR_KEY text
* <--P_L_PSPNR1_KEY text
*----------------------------------------------------------------------*
FORM add_pspnr1_line USING
wa_final1 TYPE t_final
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.

DATA: l_node_text TYPE lvc_value. ",
* wa_final2 type t_final.

* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = ' (3Y)'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.

* add node
l_node_text = wa_final1-post11.
DATA: relat TYPE int4.
relat = cl_gui_column_tree=>relat_last_child.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = relat
i_node_text = l_node_text
is_outtab_line = wa_final1
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.

ENDFORM. " ADD_PSPNR1_LINE

*&---------------------------------------------------------------------*
*& Form ADD_PSPNR_LINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_FINAL text
* -->P_0958 text
* <--P_L_PSPNR_KEY text
*----------------------------------------------------------------------*
FORM add_pspnr_line USING wa_final1 TYPE t_final
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.

DATA: l_node_text TYPE lvc_value. " ,
* wa_final2 TYPE t_final.

* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = ' (3P)'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
APPEND ls_item_layout TO lt_item_layout.

* add node
l_node_text = wa_final1-post1.

DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.

CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = wa_final1
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.

ENDFORM. " add_carrid_line

*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.

CASE ok_code.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.

LEAVE PROGRAM.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code.
CALL METHOD cl_gui_cfw=>flush.

ENDMODULE. " USER_COMMAND_9000 INPUT



SELECTION SCREEN
OUTPUT