Thursday, June 29, 2017

Sample code for EDITABLE ALV (Classical Approach)





*&---------------------------------------------------------------------*
*& Report YTEST_ALV_EDITABLE
*&
*&---------------------------------------------------------------------*
*& Developed by DEBESH
*& Aim : Make cell editable whereever pincode is empty
*&---------------------------------------------------------------------*


REPORT ytest_alv_editable.

TYPE-POOLS : slis.

TYPES : BEGIN OF ty_kna1,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
field_style TYPE lvc_t_styl, " For editing
END OF ty_kna1.

DATA: lt_kna1 TYPE STANDARD TABLE OF ty_kna1,
ls_kna1 TYPE ty_kna1,
lt_fieldcat TYPE lvc_t_fcat,
ls_fieldcat TYPE lvc_s_fcat,
ls_stylerow TYPE lvc_s_styl ,
lt_styletab TYPE lvc_t_styl ,
ls_layout TYPE lvc_s_layo.

** Data extraction
SELECT kunnr land1 name1 name2 ort01 pstlz FROM kna1
INTO CORRESPONDING FIELDS OF TABLE lt_kna1 UP TO 10 ROWS.

** Field catalog for ALV

IF sy-subrc IS INITIAL.

ls_fieldcat-fieldname = 'KUNNR'.
ls_fieldcat-scrtext_m = 'Customer Number'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
ls_fieldcat-key = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'LAND1'.
ls_fieldcat-scrtext_m = 'Location'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'NAME1'.
ls_fieldcat-scrtext_m = 'First Name'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'NAME2'.
ls_fieldcat-scrtext_m = 'Last Name'.


ls_fieldcat-col_pos = 0.


ls_fieldcat-outputlen = 10.


ls_fieldcat-emphasize = 'X'.





APPEND ls_fieldcat TO lt_fieldcat.


CLEAR ls_fieldcat-edit.


ls_fieldcat-fieldname = 'ORT01'.


ls_fieldcat-scrtext_m = 'City'.


ls_fieldcat-col_pos = 0.


ls_fieldcat-outputlen = 10.


ls_fieldcat-emphasize = 'X'.


ls_fieldcat-edit = 'X'. " Make coulmn Editable


APPEND ls_fieldcat TO lt_fieldcat.





CLEAR ls_fieldcat-edit.


ls_fieldcat-fieldname = 'PSTLZ'.


ls_fieldcat-scrtext_m = 'Post Code'.


ls_fieldcat-col_pos = 0.


ls_fieldcat-outputlen = 10.


ls_fieldcat-emphasize = 'X'.


APPEND ls_fieldcat TO lt_fieldcat.





IF sy-subrc <> 0.


MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno


WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.


ENDIF.


** Cell Editable


LOOP AT lt_kna1 INTO ls_kna1.


IF ls_kna1-pstlz <> space. " change condition according to your data


ls_stylerow-fieldname = 'ORT01' .


ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.


APPEND ls_stylerow TO ls_kna1-field_style.


MODIFY lt_kna1 FROM ls_kna1.


** code to update database can be inserted here


ENDIF.


ENDLOOP.


ls_layout-stylefname = 'FIELD_STYLE'.


a

IF sy-subrc <> 0.


MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno


WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.


ENDIF.





ENDIF.












https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ1ZzB6oqYiHAh-3rTK2Ceixup_r1rnwrymWHogkCyij9dNoIT9vDYx06Mkav3bYr_8fL1SyA1Y22mSIVgFSxUUvaol4lZrHfBdlIZdFsX5m1GOtTKHyEv1uRKzfv4EjeU4sF1NpfYauo/s400/alvoutput.png




Friday, May 26, 2017

SAP FI Configurations

Transaction SPRO (SAP Project Reference Object) is used by SAP consultants to configure and customize SAP solution and EASY ACCESS screen is used by end users for doing the transactions.

GL Accounting

Define FI enterprise structure
1.    Define Company
2.    Define Company Code
3.    Assign Company Code to Company
4.    Define Business Area
Define Ledger settings
5.    Define chart of accounts
6.    Assign company code to chart of accounts
7.    Define accounts group
8.    Define retained earnings account
Define Global settings
9.    Define fiscal year variant
10.  Assign fiscal year variant to company code

11.  Define posting period variant.
12.  Assign posting period variant to company code
13.  Define open or close posting periods

14.  Define field status variant
15.  Assign field status variant to company code
Define Document settings
16.  Define document types and number ranges
17.  Define tolerance group and assign it to users
18.  Define tax procedures and assign it to country
19.  Define global parameters

20.  Controlling area settings
21.  Create GLs

22.  Test a transaction


SAP FI Configuration Screenshots :



Vendor Master Data & Customer Master Data Configurations


Vendor Master Data & Customer Master Data ( FI ) by Debesh Swain on Scribd

Thursday, May 4, 2017

SAP Table Events

Recently someone asked me for an example about SAP Table events.
Guys here it is for your reference.



Table Events by Debesh Swain on Scribd

Thursday, April 27, 2017

SAP IDOC Part 2

It’s very long since I have worked something related to Idocs.  Recently while going through a presentation I came across some IDOC related terms and they sounded very new to me. So I thought its time to update my IDOC knowledge. Hope it will be helpful for you too.

As we all know all of the SAP components never lie on the same system because of many reasons like load balancing security issues. So we work in a distributed system environment. So sometimes there is a need to send some data from one SAP system to another SAP system.  Similarly data needs to flow from SAP system to Non SAP system.

For example:
A user places an order in Customer Portal so the same data needs to flow to the Distributor and the Manufacturer. And all might be using different ERP systems.

These systems send and accept data through some specified data container file and this is nothing but IDOC or intermediate document.

ALE supports distributed yet integrated process across several SAP systems.EDI is used for exchange of business document between systems of business partners. IDOC is the data container file which is used for data exchange by both EDI and ALE.

Example:
I have 2 SAP systems DEV1 and DEV2. I have two database tables YTEST_CUSTOMER and YTEST_CUSTITEM. These tables exist in both the systems DEV1 as well as DEV2.
Now my aim is to send data from  DEV1, to DEV2.

Procedure:

IDOC steps are very generic.

Sender system steps: OUTBOUND IDOC



1.       Create/Choose Segments  : WE31
Segments are nothing but the structures in which format we intend to send the data.
2.       Create IDOC type : WE30
IDOC type or Basic type holds the segments in a sequential manner
3.       Create Logical message : WE81
An IDOC type is always implemented in a logical message. WE82
4.       Define Logical system for both source and destination  :  SALE
Logical systems are nothing but symbolic system names that we intend to connect. Assign the logical systems to the respective clients.
5.       RFC Connection : SM59
The name should be same as destination system name. Give the server IP address and system number and check for connectivity.
6.       RFC port : WE21
7.       Create model view : BD64
Specify sender and receiver systems. Generate partner profile from environment. Or create using BD82 or WE20. Add the message type in source and destination logical system in the partner profile. Then distribute the model view.

So now through port following connection is established
Port ->destination system ->Message Type->Basic type ->Segments

8.       Write ABAP code at standalone report or specified points to create an IDOC. Same will be achieved though the function module ‘MASTER_IDOC_DISTRIBUTE’ followed by DB_COMMIT, DEQUEUE_ALL and COMMIT WORK.
9.       Check status of the generated IDOC from WE02
10.   If status is ready for dispatch (Status 30) then run report RSEOUT00 to send the IDOC (Status 03) . Else correct the errors till status is ready for dispatch.

Receiving system steps: INBOUND IDOC



1.       Create Segments, IDOC type, Message type, Sender logical system, RFC destination, Port and sender partner profile and add the message type to profile.
2.       Create a function module to read IDOC data based on segments and use the data for required data base operations.
3.       Assign FM to Logical message (message type and basic type)  WE57
4.       Define input method for FM : BD51
5.       Create Process code : WE42
Choose the function module, Assign Logical message to it.
6.       If all the settings are correct then once IDOC sent from sender system it comes to receiver system and can be viewed from WE02
7.       If errors are found and rectified then the same can be reprocessed through BD84
8.       There are other reports like RBDAPP01, RBDMANI2 for reprocessing inbound IDOC.
9.       To debug  the function module use WE19
10.   Correct and reprocess till status is 53 (Application Document posted)


When an outbound EDI or ALE is executed an IDOC is created. Data in it stored in character format instead of binary format.

An IDOC will have

1.       Control record holding direction, status, basic type, message type, partner ports which are maily for administrative purpose. Remains in EDID2, EDID4 and of type EDIDC.
2.       Data Records which holds the application data in segments. This is of type EDIDD.
3.       Status records holding the status information.  Type EDIDS.
·         IDOC message flows are configured in Distribution model (Sender & Receiver). Each connection on server is represented by recipient or Logical system. Each system is associated with a tRFC port which bound to RFC destination.
·         TRFC is used by ALE and File port is used by EDI.
·         IDOCs can’t be deleted but status can be changed through program RCL_IDOC_SET_STATUS.
·         Statuses are monitored in BD87.
·         Some important Message types: MATMAS, CREMAS, DEBMAS (material, vendor, customer).
·         Whole documentation after settings can be viewed from WE60


Step By Step Screen Shots:



Sample Outbound Program:


*&---------------------------------------------------------------------*
*& Report  YTEST_IDOC1
*&
*&---------------------------------------------------------------------*
***********************************************************************
* Developed By Debesh
***********************************************************************
* Generats an Idoc for Customer Data
***********************************************************************


REPORT ytest_idoc1.
TABLES : ytest_customer.
DATA : ls_ctrl_rec LIKE edidc, "Idoc Control Record
ls_segment1 LIKE zdev_customer,
ls_segment2 LIKE zdev_customeritem.

DATA : lt_customers TYPE STANDARD TABLE OF ytest_customer,
ls_customers TYPE ytest_customer.
DATA : lt_customeritem TYPE STANDARD TABLE OF ytest_custitem,
ls_customeritem TYPE ytest_custitem.

DATA : lt_edidd TYPE STANDARD TABLE OF edidd ,
ls_edidd TYPE edidd.
DATA : lt_comm_idoc TYPE STANDARD TABLE OF edidc,
ls_comm_idoc TYPE edidc .
"Generated Communication IDOc


CONSTANTS :
c_segment1 LIKE edidd-segnam VALUE 'ZDEV_CUSTOMER',
c_segment2 LIKE edidd-segnam VALUE 'ZDEV_CUSTOMERITEM'.

CONSTANTS: c_idoctp LIKE edidc-idoctp VALUE 'YDEV_SHOP'.



*** Selection Screen
SELECT-OPTIONS : cnumber FOR ytest_customer-cnumber .

PARAMETERS : c_mestyp LIKE edidc-mestyp DEFAULT 'YDEV_SHOPMSG', "Message Type
c_rcvprt LIKE edidc-rcvprt DEFAULT 'LS', "Partner type of receiver
c_logsys LIKE edidc-rcvprn DEFAULT 'YDEV_TRG',
c_rcvpor LIKE edidc-rcvpor DEFAULT 'YDEV_PORT',
c_sndprn LIKE edidc-sndprn DEFAULT 'YDEV_SRC',
c_sndprt LIKE edidc-sndprt DEFAULT 'LS'.
*Destination System

***START-OF-SELECTION
START-OF-SELECTION.
PERFORM generate_data_records.
PERFORM generate_control_record.
PERFORM send_idoc.



***********************************************************************

*&---------------------------------------------------------------------*
*& Form generate_data_records
*&---------------------------------------------------------------------*
FORM generate_data_records .
PERFORM get_customer.
PERFORM get_customer_item.
PERFORM arrange_data_records.
ENDFORM. " generate_data_records



*&---------------------------------------------------------------------*
*& Form GET_CUSTOMER
*&---------------------------------------------------------------------*
FORM get_customer.
SELECT *
FROM ytest_customer
INTO CORRESPONDING FIELDS OF TABLE lt_customers
WHERE cnumber IN cnumber.
IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'No Customers Found'.
ENDIF.
ENDFORM. " GET_CUSTOMER



*&---------------------------------------------------------------------*
*& Form GET_CUSTOMER_ITEM
*&---------------------------------------------------------------------*
FORM get_customer_item.
SELECT *
FROM ytest_custitem
INTO CORRESPONDING FIELDS OF TABLE lt_customeritem.
IF sy-subrc NE 0.
MESSAGE i398(00) WITH 'No item found found'.
ENDIF.
ENDFORM. " GET_CUSTOMER_ITEM
*&---------------------------------------------------------------------*
*& Form generate_control_record
*&---------------------------------------------------------------------*
FORM generate_control_record .
ls_ctrl_rec-rcvpor = c_rcvpor. "Receiver Port
ls_ctrl_rec-mestyp = c_mestyp. "Message type
ls_ctrl_rec-idoctp = c_idoctp. "Basic IDOC type
ls_ctrl_rec-rcvprt = c_rcvprt. "Partner type of receiver
ls_ctrl_rec-rcvprn = c_logsys. "Partner number of receiver

ls_ctrl_rec-sndprt = c_sndprt. "Sender Partner type
ls_ctrl_rec-sndprn = c_sndprn. "Sender Partner Number
ENDFORM. " generate_control_record



*&---------------------------------------------------------------------*
*& Form send_idoc
*&---------------------------------------------------------------------*
FORM send_idoc.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = ls_ctrl_rec
TABLES
communication_idoc_control = lt_comm_idoc
master_idoc_data = lt_edidd
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 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.
ELSE.
* COMMIT WORK.
CALL FUNCTION 'DB_COMMIT'.
CALL FUNCTION 'DEQUEUE_ALL'.
COMMIT WORK.
LOOP AT lt_comm_idoc INTO ls_comm_idoc.
WRITE:/ 'IDoc Generated - ', ls_comm_idoc-docnum.
ENDLOOP.
ENDIF.
ENDFORM. " send_idoc



*&---------------------------------------------------------------------*
*& Form arrange_data_records
*&---------------------------------------------------------------------*
FORM arrange_data_records .
DATA: w_index1 LIKE sy-tabix,
w_index2 LIKE sy-tabix.
SORT lt_customers BY cnumber.
SORT lt_customeritem BY cnumber .

LOOP AT lt_customers INTO ls_customers.


CLEAR w_index1.
READ TABLE lt_customeritem INTO ls_customeritem WITH KEY cnumber = ls_customers-cnumber BINARY SEARCH.

IF sy-subrc = 0.
w_index1 = sy-tabix.
LOOP AT lt_customeritem INTO ls_customeritem FROM w_index1.
IF ls_customeritem-cnumber NE ls_customers-cnumber.
EXIT.
ENDIF.
ls_segment2-vgpos = ls_customeritem-vgpos.
ls_segment2-ntgew = ls_customeritem-ntgew.
ls_segment2-netwr = ls_customeritem-netwr.
ls_segment2-cnumber = ls_customeritem-cnumber.
ls_edidd-segnam = c_segment2.
ls_edidd-sdata = ls_segment2.
APPEND ls_edidd TO lt_edidd.
CLEAR ls_edidd.

CLEAR w_index2.
ls_segment1-cnumber = ls_customers-cnumber.
ls_segment1-name = ls_customers-name.
ls_segment1-contact = ls_customers-contact.
ls_edidd-segnam = c_segment1.
ls_edidd-sdata = ls_segment1.
APPEND ls_edidd TO lt_edidd.
CLEAR ls_edidd.
ENDLOOP.
ENDIF.

ENDLOOP.
ENDFORM. " arrange_data_records



Sample Inbound Function Module:


FUNCTION YTEST_IODC_RECEIVE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(INPUT_METHOD) TYPE BDWFAP_PAR-INPUTMETHD
*" REFERENCE(MASS_PROCESSING) TYPE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" REFERENCE(WORKFLOW_RESULT) TYPE BDWF_PARAM-RESULT
*" REFERENCE(APPLICATION_VARIABLE) TYPE BDWF_PARAM-APPL_VAR
*" REFERENCE(IN_UPDATE_TASK) TYPE BDWFAP_PAR-UPDATETASK
*" REFERENCE(CALL_TRANSACTION_DONE) TYPE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

** Include File containing ALE constants
INCLUDE MBDCONWF.



data : ls_segment1 type ZDEV_CUSTOMER, "ty_seg1,
ls_segment2 type ZDEV_CUSTOMERITEM. "ty_seg2.


DATA : lT_ytest_customer TYPE STANDARD TABLE OF ytest_customer ,
ls_ytest_customer TYPE ytest_customer .

DATA : lT_ytest_custitem TYPE STANDARD TABLE OF ytest_custitem ,
ls_ytest_custitem TYPE ytest_custitem .



***********************************************************************
WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.
IF IDOC_CONTRL-MESTYP NE 'YDEV_SHOPMSG'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.

* Before reading a new entry, clear application buffer
LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.
CASE IDOC_DATA-SEGNAM.
WHEN 'ZDEV_CUSTOMER'.
ls_segment1 = IDOC_DATA-SDATA.
MOVE-CORRESPONDING ls_segment1 TO ls_ytest_customer.
mODIFY ytest_customer FROM ls_ytest_customer.
WHEN 'ZDEV_CUSTOMERITEM'.
ls_segment2 = IDOC_DATA-SDATA.
MOVE-CORRESPONDING ls_segment2 TO ls_ytest_custitem.

MODIFY Ytest_custITEM FROM ls_ytest_custITEM.

ENDCASE.
ENDLOOP.


IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = ls_ytest_customer-Cnumber.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = ls_ytest_customer-cnumber.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
ENDLOOP.




ENDFUNCTION.

IDOC status messages:


If outbound status (1-42)

1. 26 => Syntax error, check segment sequence and other names.

2. 30=>ready for dispatch, run RSEOUT00.



If Inbound Status (50-75)

1. 56=> IDOC with errors, check partner profiles.

2. Run RBDAPP01 after correction

3. Use BD84 to reprocess

4. 60 =>Check segments



51-> Application Document not posted

53->successful

32->manually edited

01->IDOC generated

64->Ready to transfer



IDOC XML Display:


IDOCs is stored in Hierarchical format so its easily gets converted to XML format.



*&---------------------------------------------------------------------*
*& Report YTEST_IDOC_DISPLAY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT YTEST_IDOC_DISPLAY.

PARAMETERS: p_idoc TYPE edidd-docnum.

DATA: o_idoc_xml TYPE REF TO cl_idoc_xml1.
DATA: gv_string TYPE string.
DATA: gt_string TYPE TABLE OF string.

*Create IDoc object
CREATE OBJECT o_idoc_xml
EXPORTING
docnum = p_idoc
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
WRITE: /'Error while creating idoc object'.
EXIT.
ENDIF.

*Get IDoc data as string
CALL METHOD o_idoc_xml->get_xmldata_as_string
IMPORTING
data_string = gv_string.

APPEND gv_string TO gt_string.

IF sy-subrc NE 0 OR o_idoc_xml IS INITIAL.
WRITE: /'Error while getting xml data as string'.
EXIT.
ENDIF.

*Download IDoc data as XML file
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'D:\idoc.xml'
TABLES
data_tab = gt_string.





Friday, March 31, 2017

Sample Code : ALV using factory class








Sample Code




*&---------------------------------------------------------------------*
*& Report YTEST220_ALV
*&
*&---------------------------------------------------------------------*
*&
*& By Debesh
*&---------------------------------------------------------------------*

report ytest220_alv.

include ytest220_alv_top. “ At the end
include ytest220_alv_form.

start-of-selection.

select kunnr
land1
name1
name2
ort01
pstlz
regio
sortl
stras
telf1
telfx
xcpdk
adrnr
from kna1 into table gt_kna1 where kunnr in so_kunnr.

if sy-subrc is initial.

if p_r3 is not initial.

call screen 0100.

endif.

endif.















*&---------------------------------------------------------------------*
*& Include YTEST220_ALV_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status '0100'.
set titlebar '0100'.

endmodule. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.

case sy-ucomm.
when 'BACK'.
refresh gt_kna1.
submit ytest220_alv via selection-screen.
when 'EXIT'.
leave program.
when others.

endcase.

endmodule. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module populate_alv OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module populate_alv output.

data : lo_container type ref to cl_gui_custom_container,
lo_splitter type ref to cl_gui_splitter_container,
lo_container1 type ref to cl_gui_container,
lo_container2 type ref to cl_gui_container,
lo_header type ref to cl_dd_document,
lo_colref type ref to cl_salv_columns_table,
lo_col type ref to cl_salv_column,
lo_funclist type ref to cl_salv_functions_list,
lo_event type ref to cl_salv_events_table.


if lo_container is initial.
******************************************************Create container.
create object lo_container
exporting
container_name = 'CC_CONTAINER'
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.

*********************************************************Split Container.
create object lo_splitter
exporting
parent = lo_container
rows = 2
columns = 1
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

************************************************************Get container.
************************************************************ HEADER

call method lo_splitter->get_container
exporting
row = 1
column = 1
receiving
container = lo_container1.


call method lo_splitter->set_row_height
exporting
id = 1
height = 10
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

create object lo_header.

call method lo_header->add_text
exporting
text = text-001
* sap_color = 'red'
* sap_fontsize = '5'
sap_emphasis = 'STRONG'
.

call method lo_header->display_document
exporting
parent = lo_container1
exceptions
html_display_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.


*************************************************************Get container.
************************************************************* Content
call method lo_splitter->get_container
exporting
row = 2
column = 1
receiving
container = lo_container2.
call method lo_splitter->set_row_height
exporting
id = 2
height = 80
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.


** Call Factory method to get ALV table reference

try.
call method cl_salv_table=>factory
exporting
list_display = if_salv_c_bool_sap=>false
r_container = lo_container2
importing
r_salv_table = gt_tabref
changing
t_table = gt_kna1.
catch cx_salv_msg .
endtry.

*********************************************************** SET COLUMN VISBILITY
lo_colref = gt_tabref->get_columns( ).
try.
lo_col ?= lo_colref->get_column( 'NAME2' ).
call method lo_col->set_visible
exporting
value = if_salv_c_bool_sap=>false.

catch cx_salv_not_found.

endtry.

********************************************************* To select multiple rows at a time

call method gt_tabref->get_selections
receiving
value = go_sel.
call method go_sel->set_selection_mode
exporting
value = if_salv_c_selection_mode=>row_column.

******************************************************** Get Functions
call method gt_tabref->get_functions
receiving
value = lo_funclist.
lo_funclist->set_all( abap_true ).

try.
call method lo_funclist->add_function
exporting
name = 'CC_DETAILS'
* ICON =
text = 'CC Details'
tooltip = 'Company Code Details'
position = if_salv_c_function_position=>right_of_salv_functions
.
catch cx_salv_existing .
catch cx_salv_wrong_call .
endtry.

call method gt_tabref->get_event
receiving
value = lo_event.
set handler lcl_event_handling=>handle_user_command for all instances.

******************************************************** Display Using alv table reference display table
call method gt_tabref->display.
else.
call method gt_tabref->refresh.
endif.

endmodule. " populate_alv OUTPUT
*&---------------------------------------------------------------------*
*& Form form_get_selected
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form form_get_selected .

data : ls_rows type int4.
data : ls_kna1 type ty_data.
data : lr_kunnr type range of kna1-kunnr,
lrs_kunnr like line of lr_kunnr.

call method gt_tabref->get_metadata.
* FREE go_sel.
call method gt_tabref->get_selections
receiving
value = go_sel.
gt_rows = go_sel->get_selected_rows( ).

loop at gt_rows into ls_rows.

read table gt_kna1 into ls_kna1 index ls_rows.
if sy-subrc is initial.
lrs_kunnr-sign = 'I'.
lrs_kunnr-option = 'EQ'.
lrs_kunnr-low = ls_kna1-kunnr.
append lrs_kunnr to lr_kunnr.
endif.
clear lrs_kunnr.
endloop.

if lr_kunnr is not initial.
select kunnr
bukrs
pernr
erdat
ernam
sperr
loevm
zuawa
busab
akont
from knb1 into table gt_knb1
where kunnr in lr_kunnr.

if sy-subrc is initial.
clear lr_kunnr.
call screen 200.
endif.

endif.


endform. " form_get_selected
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0200 output.
set pf-status '0200'.
set titlebar '0200'.
perform populate_alv2.
endmodule. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0200 input.

case sy-ucomm.
when 'BACK'.
refresh gt_knb1.
* IF gt_tabref2 IS BOUND.
* FREE gt_tabref2.
* ENDIF.

leave list-processing.
set screen 100.
when 'EXIT'.
leave program.
when others.

endcase.
endmodule. " USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*& Form populate_alv2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form populate_alv2 .

data : lo_containerr type ref to cl_gui_custom_container,
lo_splitter2 type ref to cl_gui_splitter_container,
lo_cont1 type ref to cl_gui_container,
lo_cont2 type ref to cl_gui_container,
lo_head2 type ref to cl_dd_document,
lo_colref2 type ref to cl_salv_columns_table,
lo_col2 type ref to cl_salv_column,
lo_funclist2 type ref to cl_salv_functions_list,
lo_event2 type ref to cl_salv_events_table.

if lo_containerr is initial.
******************************************************Create container.
create object lo_containerr
exporting
container_name = 'CC_CONTAINERR'
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.

*********************************************************Split Container.
create object lo_splitter2
exporting
parent = lo_containerr
rows = 2
columns = 1
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

************************************************************Get container.
************************************************************ HEADER

call method lo_splitter2->get_container
exporting
row = 1
column = 1
receiving
container = lo_cont1.


call method lo_splitter2->set_row_height
exporting
id = 1
height = 10
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

create object lo_head2.

call method lo_head2->add_text
exporting
text = text-002
* sap_color = 'red'
* sap_fontsize = '5'
sap_emphasis = 'STRONG'
.

call method lo_head2->display_document
exporting
parent = lo_cont1
exceptions
html_display_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.


*************************************************************Get container.
************************************************************* Content
call method lo_splitter2->get_container
exporting
row = 2
column = 1
receiving
container = lo_cont2.
call method lo_splitter2->set_row_height
exporting
id = 2
height = 80
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.


** Call Factory method to get ALV table reference
if gt_tabref2 is not initial.
gt_tabref2->refresh( ).
endif.

try.
call method cl_salv_table=>factory
exporting
list_display = if_salv_c_bool_sap=>false
r_container = lo_cont2
importing
r_salv_table = gt_tabref2
changing
t_table = gt_knb1.
catch cx_salv_msg .
endtry.

*********************************************************** SET COLUMN VISBILITY
lo_colref2 = gt_tabref2->get_columns( ).
try.
lo_col2 ?= lo_colref2->get_column( 'NAME2' ).
call method lo_col2->set_visible
exporting
value = if_salv_c_bool_sap=>false.

catch cx_salv_not_found.

endtry.

********************************************************* To select multiple rows at a time

call method gt_tabref2->get_selections
receiving
value = go_sel2.
call method go_sel2->set_selection_mode
exporting
value = if_salv_c_selection_mode=>row_column.

******************************************************** Get Functions
call method gt_tabref2->get_functions
receiving
value = lo_funclist2.
lo_funclist2->set_all( abap_true ).


******************************************************** Display Using alv table reference display table
call method gt_tabref2->refresh.
call method gt_tabref2->display.
else.
call method gt_tabref2->refresh.
endif.
endform. " populate_alv2

*&---------------------------------------------------------------------*
*& Include YTEST220_ALV_TOP
*&---------------------------------------------------------------------*
tables : kna1.


selection-screen begin of block b1 with frame.
select-options : so_kunnr for kna1-kunnr obligatory.
selection-screen end of block b1.


selection-screen begin of block b2 with frame.
parameters:p_r1 type c radiobutton group rg1 default 'X'.
parameters:p_r2 type c radiobutton group rg1 .
parameters:p_r3 type c radiobutton group rg1 .
selection-screen end of block b2 .

types: begin of ty_data,
kunnr type kunnr ,
land1 type land1_gp ,
name1 type name1_gp ,
name2 type name2_gp ,
ort01 type ort01_gp ,
pstlz type pstlz ,
regio type regio ,
sortl type sortl ,
stras type stras_gp ,
telf1 type telf1 ,
telfx type telfx ,
xcpdk type xcpdk ,
adrnr type adrnr ,
end of ty_data.

types: begin of ty_compdata,
kunnr type kunnr ,
bukrs type bukrs ,
pernr type pernr_d ,
erdat type erdat_rf ,
ernam type ernam_rf ,
sperr type sperb_b ,
loevm type loevm_b ,
zuawa type dzuawa ,
busab type busab ,
akont type akont ,
end of ty_compdata.

data : gt_kna1 type standard table of ty_data,
gt_knb1 type standard table of ty_compdata.
data : gt_tabref type ref to cl_salv_table,
gt_tabref2 type ref to cl_salv_table,
go_sel type ref to cl_salv_selections,
go_sel2 type ref to cl_salv_selections.
data: gt_rows type salv_t_row.

*----------------------------------------------------------------------*
* CLASS lcl_event_handling DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handling definition.
public section.
class-methods:
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm.
private section.
endclass. "lcl_event_handling DEFINITION

*----------------------------------------------------------------------*
* CLASS lcl_event_handling IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handling implementation.

method handle_user_command.
case e_ucomm.

when 'CC_DETAILS'.
perform form_get_selected.
endcase.
endmethod. "handle_user_command
endclass. "lcl_event_handling IMPLEMENTATION





*&---------------------------------------------------------------------*
*& Include YTEST220_ALV_TOP
*&---------------------------------------------------------------------*
TABLES : kna1.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS : so_kunnr FOR kna1-kunnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.




TYPES: BEGIN OF ty_data,
kunnr TYPE kunnr ,
land1 TYPE land1_gp ,
name1 TYPE name1_gp ,
name2 TYPE name2_gp ,
ort01 TYPE ort01_gp ,
pstlz TYPE pstlz ,
regio TYPE regio ,
sortl TYPE sortl ,
stras TYPE stras_gp ,
telf1 TYPE telf1 ,
telfx TYPE telfx ,
xcpdk TYPE xcpdk ,
adrnr TYPE adrnr ,
END OF ty_data.

TYPES: BEGIN OF ty_compdata,
kunnr TYPE kunnr ,
bukrs TYPE bukrs ,
pernr TYPE pernr_d ,
erdat TYPE erdat_rf ,
ernam TYPE ernam_rf ,
sperr TYPE sperb_b ,
loevm TYPE loevm_b ,
zuawa TYPE dzuawa ,
busab TYPE busab ,
akont TYPE akont ,
END OF ty_compdata.

DATA : gt_kna1 TYPE TABLE OF ty_data,
gt_knb1 TYPE STANDARD TABLE OF ty_compdata.
DATA : gt_tabref TYPE REF TO cl_salv_table,
gt_tabref2 TYPE REF TO cl_salv_table,
go_sel TYPE REF TO cl_salv_selections,
go_sel2 TYPE REF TO cl_salv_selections,
lo_container TYPE REF TO cl_gui_custom_container,
lo_containerr TYPE REF TO cl_gui_custom_container.
DATA: gt_rows TYPE salv_t_row.



*----------------------------------------------------------------------*
* CLASS lcl_event_handling DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handling DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
ENDCLASS. "lcl_event_handling DEFINITION

*----------------------------------------------------------------------*
* CLASS lcl_event_handling IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handling IMPLEMENTATION.

METHOD handle_user_command.
CASE e_ucomm.

WHEN 'CC_DETAILS'.
* PERFORM form_get_selected.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handling IMPLEMENTATION