Dynamic alv creation in dynamic tabstrip.
Hi,
I have already created tabstrip dynamically, now i need to create alv dynamically inside the dynamically created view container.. how can i embed the interface TABLE view of salv_wd_table in it dynamically.
Thanks and Regards
Tenzin
Hi,
Please check the below article 'Creating navigations and Embedding view at Run time'. This might be helpful for you.
[https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-technology/wd%20abap/creating%20navigations%20and%20embedding%20views%20at%20runtime%20-%20web%20dynpro%20abap.pdf]
Regards,
Manne.
Similar Messages
-
Help: Dynamic ALV from an dynamic Node
Hi Expart,
I have a question. I need to create an dynamic context node, and depending upon that dynamic context node, I need to create an dynamic ALV in the View. Is it possible to create two level of dynamic implimentation in case of ALV ?
if possibel in that case, can ayn one give some hint, how to create ? or some document link to help me out. Any kind of help is mostly welcome.
thanks in advance.
Regards
Satrajit.Yes it is possible.
To create the dynamic node you can use the method ADD_NEW_CHILD_NODE of the node info object. You can use a ddic structure/table or an RTTI instance to supply the information for the node attributes.
rootnode_info = wd_context->get_node_info( ).
* Create dynamic sub node name TEST1 of structure (tablename)
dyn_node_info = rootnode_info->add_new_child_node(
static_element_type = tablename
name = tablename ). " Web Dynpro: Name of Context Node
You can then bind to the dynamic context node like normal:
* get instance of new node
dyn_node = wd_context->get_child_node( name = tablename ).
* Bind internal table to context node
dyn_node->bind_table( <tab> ).
Then connect the dynamic context node to an ALV component usage:
* Connect to the component Usage of the ALV
if wd_this->wd_cpuse_alv( )->has_active_component( ) is initial.
wd_this->wd_cpuse_alv( )->create_component( ).
endif.
* Through the interface controller of the ALV Component set the DATA node dynamically
wd_this->wd_cpifc_alv( )->set_data( r_node_data = dyn_node ). -
WD4A Dynamic ALV Table with dynamic tables
Hi all,
first I want give you the information what I try to do.
I have an another WD4A application for administrative use in which I can assign certain tablefields to a certain user. You can say it's something like a customizing application.
In the next application (with my issues) I will display the tables for the user, but these tables are not the complete table.
I have a node in my context of the component controller which is bound to my ALV. I add during the runtime attributes to my node.
* .... coding ....declaration
* get the node
lr_node = wd_context->get_child_node( 'M_TABLE' ).
lr_node_info ?= lr_node->get_node_info( ).
* remove the attributes, if exists
lr_node_info->remove_dynamic_attributes( ).
* .... coding ....
* add attributes
LOOP AT l_t_m_table INTO l_s_m_table.
CLEAR ls_attribute.
* name of the attribute
MOVE l_s_m_table-NAME TO ls_attribute-NAME.
* DDIC type of the attribute
MOVE l_s_m_table-TYPE_NAME TO ls_attribute-TYPE_NAME.
* If the DDIC has a gen namespace like /B135/ replace the / with _
REPLACE ALL OCCURRENCES OF '/' IN ls_attribute-NAME WITH '_'.
* add the attribute
lr_node_info->add_attribute( EXPORTING
attribute_info = ls_attribute ).
ENDLOOP.
This coding works fine I get the columns in my ALV. Then I tried to fill my ALV table with data from a database table.
I created dynamicly an internal table with the following coding:
* Create dynamic table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = l_t_FLDCAT
IMPORTING
EP_TABLE = l_t_NEW_M_TABLE.
* assign the table
ASSIGN l_t_NEW_M_TABLE->* TO <M_TABLE>.
* structure of table
CREATE DATA l_s_NEW_M_TABLE LIKE LINE OF <M_TABLE>.
ASSIGN l_s_NEW_M_TABLE->* TO <l_s_m_table>.
* get data from database
SELECT * FROM (l_m_table) INTO CORRESPONDING FIELDS OF TABLE <M_table> WHERE OBJVERS = 'A'.
With this coding I get the data from the database and only the required fields that means I have e.g. an itab with columns1, columns3, columns4 from the database.
I also added e.g. these columns (columns1, columns3, columns4 from the database) to the node as attribute. Now it should be possible to bind the table to the structure with this coding:
lr_comp_usage_m = wd_this->wd_cpuse_usage_alv_M_table( ).
* create component if not active
IF lr_comp_usage_m->has_active_component( ) IS INITIAL.
lr_comp_usage_m->create_component( ).
else.
* set data if node exists
l_ref_interfacecontroller = wd_this->wd_cpifc_usage_alv_M_table( ).
l_ref_interfacecontroller->set_data( lr_node ).
endif.
* bind table
lr_node->bind_table( <M_TABLE> ).
Now, I get an error, which is caused by the table binding.
In ST22 I get:
Short text
Line types of an internal table and a work area not compatible.
What happened?
Error in the ABAP Application Program
The current ABAP program "CL_WDR_CONTEXT_NODE_VAL=======CP" had to be
terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
The statement
"INSERT wa INTO TABLE itab"
requires the lines of the internal table "TABLE" and the
work area " wa" to be compatible. Compatibility means
equivalence in the context of ABAP/4 type checking.
In this case, the condition is not satisfied because the internal table
"TABLE" has the line type "u" and the length 28, but the work area " wa"
has the type "C" and the length 2.
(If the work area " wa" is the header line of the internal
table "TABLE", the above inconsistency can arise if an internal
table t with the line type T1 is passed to a subroutine (FORM or
FUNCTION) as an actual parameter and the corresponding formal
parameter p is declared in the subroutine by "TABLES p STRUCTURE T2".
If then T1 and T2 are incompatible, the header line p
has the type T2 (specifed by STRUCTURE), but the internal
table p has the line type T1 (passed from the actual parameter)).
Source Code Extract
Line SourceCde
1 method if_wd_context_node~get_static_attributes_table .
2
3 field-symbols:
4 <element> like line of me->collection,
5 <static_attributes> type data,
6 <table> type index table.
7
8 * check whether elements are supllied or not
9 if me->elements_supplied = abap_false.
10 me->supply_elements( ).
11 endif.
12
13 clear table.
14
15 if me->table_ref is not initial.
16 assign me->table_ref->* to <table>.
17 table = <table>.
18 else.
19 loop at me->collection assigning <element> from from to to.
20 assign <element>->static_attributes->* to <static_attributes>.
error in line 21 insert <static_attributes> into table table.
22 endloop.
23 endif.
24
25 endmethod.
Any suggestions? Is it allowed to use bind_table() with a field symbol?
Another strange thing is that if I try the same with static itab and attributes during runtime it works, but only if the fields of the itab has the same name as the attributes, which means that I can not use itabs with fieldnames like /BI0/S_CUSTOMER and if I can not use them it's difficult to read data from database with SELECT * FROM ... INTO CORRESPONDING FIELDS OF TABLE itab.
Thanks in advance for your suggestions!
Best Regards,
MarcelHi Francois,
I solve it with the RTTI and the method
lr_node_info = lr_node_info->add_new_child_node(
name = 'Dynamic_TABLE'
IS_MANDATORY = ABAP_false
IS_MULTIPLE = ABAP_true
STATIC_ELEMENT_RTTI = lr_struct_descr
IS_STATIC = ABAP_false
I don't know why it doesn't work with adding attributes and binding the table after adding the attributes.
Anyway thanks for your help.
Best Regards,
Marcel -
Hello Experts,
Please suggest how to generate dynamic ALV title for dynamic alv output.
Scenario: My ALV output is dynamic based on custom table. We have maintained 10 fields in custom table. In selection screen one of the parameter is number.
If i enter 2 or more than 2 accordingly my fieldcatlog will be prepared with same fields. But it will be mulitiple based on selection screen.
I have achieved till this part, now i need to generate title for each set of 10 columns.
Best example:
ALV output:
Title 1 Title2 Title3
A B C D E F G H I J | A B C D E F G H I J | A B C D E F G H I J |
I hope you all understand my problem and i appreciate your answers....
Thanks
CrisDear,
Use the below report code to print your dynamic coloumn in alv grid.
below just go through the use of variable w_bom for text,u will use single varible w_bom but clear it b4
printing it again. on the conditional base header will come in w_bom and print in fieldcatalog.
operate all operation b4 putting the text in fieldcatalog.
jus go through the code and you may ask any clarificaiton regarading that.
loop at i_fldcat into x_fldcat WHERE
fieldname = 'IDNRK' or
fieldname = 'MAKTX' or
fieldname = 'MEINS' or
FIELDNAME = 'MENGE1' OR
FIELDNAME = 'MENGE2' OR
FIELDNAME = 'MENGE3' OR
FIELDNAME = 'MENGE4' OR
FIELDNAME = 'MENGE5' OR
FIELDNAME = 'MENGE6' OR
FIELDNAME = 'MENGE7' OR
FIELDNAME = 'MENGE8'.
if stlal-low ne ''.
if x_fldcat-fieldname = 'IDNRK'.
x_fldcat-seltext_l = 'Component'.
x_fldcat-outputlen = 25.
x_fldcat-reptext_ddic = 'Component'.
x_fldcat-inttype = c_c.
endif.
if x_fldcat-fieldname = 'MAKTX'.
x_fldcat-seltext_l = 'Component Description'.
x_fldcat-outputlen = 25.
x_fldcat-reptext_ddic = 'Component Description'.
x_fldcat-inttype = c_c.
endif.
if x_fldcat-fieldname = 'MEINS'.
x_fldcat-seltext_l = 'UOM'.
x_fldcat-reptext_ddic = 'UOM'.
x_fldcat-ddictxt = c_l.
endif.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE1'.
read table t_stas1 with key stlal = '01'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
X_FLDCAT-TECH = 'X'.
ELSE.
PERFORM VAR_BOM USING T_STAS1-STLAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE2'.
read table t_stas1 with key stlal = '02'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING T_STAS1-STLAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE3'.
read table t_stas1 with key stlal = '03'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING T_STAS1-STLAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE4'.
read table t_stas1 with key stlal = '04'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING T_STAS1-STLAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE5'.
read table t_stas1 with key stlal = '05'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING T_STAS1-STLAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
ENDIF.
endif.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE6'.
read table t_stas1 with key stlal = '06'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING 6.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
ENDIF.
endif.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE7'.
read table t_stas1 with key stlal = '07'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING 7.
if sy-subrc = 0.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
ENDIF.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE8'.
read table t_stas1 with key stlal = '08'.
if sy-subrc NE 0.
x_fldcat-no_out = 'X'.
ELSE.
PERFORM VAR_BOM USING 8.
if sy-subrc = 0.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
ENDIF.
endif.
ENDIF.
modify i_fldcat from x_fldcat index T_INDEX.
T_INDEX = T_INDEX + 1.
CLEAR X_FLDCAT.
ELSE.
if x_fldcat-fieldname = 'IDNRK'.
x_fldcat-seltext_l = 'Component'.
x_fldcat-reptext_ddic = 'Component'.
x_fldcat-inttype = c_c.
endif.
if x_fldcat-fieldname = 'MAKTX'.
x_fldcat-seltext_l = 'Component Description'.
x_fldcat-outputlen = 25.
x_fldcat-reptext_ddic = 'Component Description'.
x_fldcat-inttype = c_c.
endif.
if x_fldcat-fieldname = 'MEINS'.
x_fldcat-seltext_l = 'UOM'.
x_fldcat-reptext_ddic = 'UOM'.
x_fldcat-ddictxt = c_l.
endif.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE1'.
PERFORM VAR_BOM USING 1.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE2'.
PERFORM VAR_BOM USING 2.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE3'.
PERFORM VAR_BOM USING 3.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE4'.
PERFORM VAR_BOM USING 4.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
ENDIF.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE5'.
PERFORM VAR_BOM USING 5.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
ENDIF.
endif.
CLEAR T_BOM-STLST.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE6'.
PERFORM VAR_BOM USING 6.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
endif.
CLEAR T_BOM-STLST.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE7'.
PERFORM VAR_BOM USING 7.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
endif.
clear t_bom-STLST.
CLEAR W_BOM.
if x_fldcat-fieldname = 'MENGE8'.
PERFORM VAR_BOM USING 8.
if T_BOM-STKTX IS NOT INITIAL.
CONCATENATE '' T_BOM-STKTX INTO W_BOM separated BY SPACE.
IF T_BOM-STLST = '1'.
X_FLDCAT-EMPHASIZE = 'C511'.
ENDIF.
x_fldcat-seltext_l = W_BOM.
x_fldcat-reptext_ddic = W_BOM.
x_fldcat-ddictxt = c_l.
else.
X_FLDCAT-NO_OUT = 'X'.
X_FLDCAT-TECH = 'X'.
endif.
endif.
modify i_fldcat from x_fldcat index sy-tabix.
CLEAR X_FLDCAT.
endif.
endloop.
endform. " build_field_catalog
FORM VAR_BOM USING P_CNT.
if NOT stlal-low = ''.
LOOP AT T_BOM where stlal = t_stas1-stlal .
READ TABLE T_BOM with key stlal = t_stas1-stlal.
IF SY-SUBRC <> 0.
T_BOM-STKTX = ''.
clear t_bom.
exit.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT T_BOM .
READ TABLE T_BOM INDEX P_CNT.
IF SY-SUBRC <> 0.
T_BOM-STKTX = ''.
clear t_bom.
exit.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "VAR_BOM
form call_list_viewer.
delete T_FINAL where IDNRK eq ''.
data : T1_MAST like T_MAST occurs 0 with header line.
data : t_stas like STAS occurs 0 with header line.
data : t_stko like stko occurs 0 with header line.
clear : t_stas[],t_stas,t1_STPO,t1_STPO[],t_stko,t_stko[],t1_mast,
t1_mast[].
SELECT MATNR WERKS STLAN STLNR STLAL ANDAT
INTO CORRESPONDING FIELDS OF TABLE T1_MAST
FROM MAST WHERE MATNR = MATNR AND WERKS = WERKS
AND STLAN = STLAN AND STLAL IN STLAL.
if not T1_MAST[] is initial.
read table T1_MAST index 1.
select * from stas into table t_stas
where stlnr = T1_MAST-STLNR
and stlal in stlal
and STLTY NE 'D'.
endif.
IF NOT T1_MAST[] IS INITIAL.
SELECT STLTY STLNR STLKN STPOZ ANDAT IDNRK POSTP POSNR
MEINS MENGE FMENG POTX1 OBJTY STVKN
INTO CORRESPONDING FIELDS OF TABLE T1_STPO
FROM STPO
FOR ALL ENTRIES IN T1_MAST
WHERE STLNR = T1_MAST-STLNR
AND FMENG = 'X'.
ENDIF.
sort t_stas by STLAL STVKN.
sort t_stas by STLNR STLAL.
loop at T1_MAST.
loop at t_stas where STLNR = T1_MAST-STLNR
and STLAL = T1_MAST-STLAL.
LOOP AT T1_STPO where STLKN = t_stas-STLKN.
IF T1_MAST-STLAL = 01.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE1 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 02.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE2 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 03.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE3 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 04.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE4 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 05.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE5 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 06.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE6 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 07.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE7 = T1_STPO-MENGE.
ELSEIF T1_MAST-STLAL = 08.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE8 = T1_STPO-MENGE.
ENDIF.
read table T_FINAL with key MAKTX = T1_STPO-POTX1.
if sy-subrc ne 0.
APPEND T_FINAL.
clear T_FINAL.
elseif T1_MAST-STLAL = 08.
T_FINAL-MAKTX = T1_STPO-POTX1.
T_FINAL-MEINS = T1_STPO-MEINS.
T_FINAL-MENGE8 = T1_STPO-MENGE.
MODIFY T_FINAL FROM T_FINAL TRANSPORTING MENGE8
WHERE MAKTX = T1_STPO-POTX1.
clear T_FINAL.
endif.
endif.
endloop.
endloop.
clear : T_FINAL.
endloop.
sort T_FINAL by IDNRK descending.
*end 09.07.2007
*endded
Thanks and regards
vijay dwivedi -
Here's how to do ALV (OO) with dynamic fcat, int table and editable data
Hi everybody
Here's a more useful approach to ALV grid with OO using dynamic table, data NOT from DDIC, dynamic FCAT and how to get changed lines from the grid when ENTER key is pressed.
It's really not too dificult but I think this is more useful than the ever present SFLIGHT methods from the demos.
This also defines a subclass of cl_gui_alv_grid so you can access the protected attributes / methods of that class.
You don't need to add the class via SE24 -- done fron this ABAP.
When you run it click Edit for the first time.
After editing data press ENTER and the break point should bring you into the relevant method.
Code developed on NW2004S trial version but also works on rel 6.40 on a "Real" system.
The code should work without any changes on any system >=6.40.
All you need to do is to create a blank screen 100 via SE51 with a custom container on it called CCONTAINER1.
The rest of the code can just be uploaded into your system using the SE38 upload facility.
When running the program click on the EDIT button to enable the edit functionality of the grid.
Change your data and when you press ENTER you should get the break-point where you can see the original table and changed rows.
This program is actually quite general as it covers Dynamic tables, building a dynamic fcat where your table fields are NOT in the DDIC, intercepting the ENTER key via using an event, and accessing the protected attributes of the cl_gui_alv_grid by defining a subclass of this class in the abap.
I've seen various questions relating to all these functions but none in my view ever answers the questions in a simple manner. I hope this simple program will answer all these and show how using OO ALV is actually quite easy and people shouldn't be scared of using OO.
Have fun and award points if useful.
Cheers
Jimbo.
<b>PROGRAM zdynfieldcat.
Simple test of dynamic ITAB with user defined (not ddic) fields
Build dynamic fcat
use ALV grid to display and edit.
*When edit mode set to 1 toolbar gives possibility of adding and
*deleting rows.
*Define subclass of cl_gui_alv_grid so we can use protected attributes
*and methods.
Add event handler to intercept user entering data and pressing the
*ENTER key.
When enter key is pressed get actual value of NEW table (all rows)
rather than just the changed data.
*use new RTTI functionality to retrieve internal table structure
*details.
Create a blank screen 100 with a custom container called CCONTAINER1.
James Hawthorne
include <icon>.
define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
types: lt_rows type lvc_t_roid.
Note new RTTI functionality allows field detail retrieval
at runtime for dynamic tables.
data: wa_element type s_elements ,
wa_data type s_elements,
c_index type sy-index,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
field-symbols: <dyn_table> type standard table,
<actual_tab> type standard table,
<fs1> type ANY,
<FS2> TYPE TABLE.
data: grid_container1 type ref to cl_gui_custom_container.
class lcl_grid_event_receiver definition deferred.
data: g_event_receiver type ref to lcl_grid_event_receiver.
data: ls_modcell type LVC_S_MODI,
stab type ref to data,
sdog type s_elements. .
class lcl_grid_event_receiver definition.
public section.
methods:
handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed,
toolbar for event toolbar of cl_gui_alv_grid
importing e_object
e_interactive,
user_command for event user_command of cl_gui_alv_grid
importing e_ucomm.
endclass.
*implementation of Grid event-handler class
class lcl_grid_event_receiver implementation.
method handle_data_changed.
code whatever required after data entry.
various possibilites here as you can get back Cell(s) changed
columns or the entire updated table.
Data validation is also possible here.
perform check_data using er_data_changed.
endmethod.
Method for handling all creation/modification calls to the toolbar
method toolbar.
data : ls_toolbar type stb_button.
Define Custom Button in the toolbar
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
endmethod.
method user_command.
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform init_grid.
when 'UPDA'. "From Tool bar
perform refresh_disp.
perform update_table.
when 'EXIT'. "From Tool bar
leave program.
endcase.
endmethod.
endclass.
class zcltest definition inheriting from cl_gui_alv_grid.
define this as a subclass so we can access the protected attributes
of the superclass cl_gui_alv_grid
public section.
methods: constructor, disp_tab.
endclass.
need this now to instantiate object
as we are using subclass rather than the main cl_gui_alv_grid.
class zcltest implementation.
METHOD constructor.
CALL METHOD super->constructor
exporting i_appl_events = 'X'
i_parent = grid_container1.
endmethod.
method disp_tab.
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
break-point 1.
mt_outtab is the data table held as a protected attribute
in class cl_gui_alv_grid.
ASSIGN me->mt_outtab->* TO <outtab>. "Original data
do whatever you want with <outtab>
contains data BEFORE changes each time.
Note that NEW (Changed) table has been obtained already by
call to form check_data USING P_ER_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
Entered data is in table defined by <fs2>
In this method you can compare original and changed data.
Easier than messing around with individual cells.
do what you want with data in <fs2> validate / update / merge etc
endmethod.
endclass.
data :
ok_code like sy-ucomm,
save_ok like sy-ucomm,
i4 type int4,
Container Object [grid_container]
now created via method constructor
in the subclass zcltest.
Control Object [grid]
grid1 type ref to zcltest,
Event-Handler Object [grid_handler]
grid_handler type ref to lcl_grid_event_receiver.
start-of-selection.
call screen 100.
module status_0100 output.
now display it as grid
if grid_container1 is initial.
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
create object grid1.
break-point 1.
create object grid_handler.
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed for grid1.
perform create_dynamic_fcat.
perform create_dynamic_itab.
perform populate_dynamic_itab.
perform init_grid.
perform register_enter_event.
set off ready for input initially
i4 = 0.
call method grid1->set_ready_for_input
exporting
i_ready_for_input = i4.
endif.
endmodule.
module user_command_0100 input.
*PAI not needed in OO ALV anymore as User Commands are handled as events
*in method user_command.
*we can also get control if the Data entered and the ENTER is pressed by
*raising an event.
Control then returns to method handle_data_changed.
endmodule.
form create_dynamic_fcat.
get structure of our user table for building field catalog
Use the RTTI functionality
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
Build field catalog just use basic data here
colour specific columns as well
loop at lr_rtti_struc->components into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-lowercase = 'X'.
if c_index eq 2.
wa_it_fldcat-emphasize = 'C411'.
endif.
if c_index eq 3.
wa_it_fldcat-emphasize = 'C511'.
endif.
append wa_it_fldcat to it_fldcat .
endloop.
endform.
form create_dynamic_itab.
Create dynamic internal table and assign to field sysmbol.
Use dynamic field catalog just built.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
endform.
form populate_dynamic_itab.
load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
wa_element-anyfield1 = 'Tabbies'.
wa_element-anyfield2 = 'ger.shepards'.
wa_element-anyfield3 = 'White mice'.
wa_element-anyfield4 = 'Any old text'.
wa_element-anyfield5 = c_dec2.
append wa_element to <dyn_table>.
endform.
form check_data USING P_ER_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
Get altered data back
ASSIGN p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
ASSIGN STAB->* TO <FS2>.
LOOP AT <FS2> INTO sdog.
ALV grid display with altered data is now in <fs2>.
do any extra processing you want here
endloop.
now display new table
call method grid1->disp_tab.
endform.
form exit_program.
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
endform.
form refresh_disp.
call method grid1->refresh_table_display.
endform.
form update_table.
The dynamic table here is the changed table read from the grid
after user has changed it
Data can be saved to DB or whatever.
loop at <dyn_table> into wa_element.
do what you want with the data here
endloop.
switch off edit mode again for next function
i4 = 0.
call method grid1->set_ready_for_input
exporting
i_ready_for_input = i4.
endform.
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
exporting
i_ready_for_input = i4.
endform.
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
exporting
i_ready_for_input = i4.
endform.
form init_grid.
Enabling the grid to edit mode,
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
call method grid1->set_table_for_first_display
exporting
is_layout = struct_grid_lset
changing
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform.
form register_enter_event.
call method grid1->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
endform.</b>Hi there
IE7 doesn't give me the add new page option and I get 404 error when trying to access the "How to contribute" section.
I'll load up Firefox later (this browser usually works when IE7 doesn't always work properly).
I'll copy the stuff to the wiki when I've got the browser sorted out.
Cheers
jimbp -
Dynamic ALV and cl_abap_structdescr Create method
Hi
In the process of creation of Dynamic ALV, as I have char_name and char_descr fields, I have to use char_descr as column header of ALV because char_name which has entries something like DVS_******(that do not make any sense to user). I am facing 2 problems here using the scenario above.
1. char_descr contains characters like '[', ']', ' /', '.', space which are invalid characters for method cl_abap_structdescr=>create(). How to handle scenario like this?
2. assign (lv_value) to <value>.
if sy-subrc = 0.
<value> = ls_bapi_char_value-charvalue.
if <value> is assigned.
move ls_bapi_char_value-charvalue to <value>.
where-> concatenate '<table_dyn_wa>-' ls_bapi_char-char_descr into lv_value
<value> type any
<table_dyn_wa>- is dynamic table with structure created with cl_abap_tabledescr=>create( p_line_type = stru_type )
with above code for few fields data is being assigned and for few sy-subrc = 4. The table from where I am reading the field contains char_name associated with it and not char_descr. For the fields whose char_name and char_descr matches exactly, ALV displays data for it.
How to resolve the issue so that I could get all the data?
Let me know if further details are needed.
Thanks, in advance
Trupti
Edited by: TRUPTI KALLURWAR on Jul 9, 2010 7:08 PMHello Srikanth,
CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE( ) uses the GENERATE SUBROUTINE POOL technique to create the dynamic internal tables.
And as per the SAP documentation,
In an internal mode, a maximum of 36 temporary subroutine pools may be created.
Source: [http://help.sap.com/abapdocu_702/en/abapgenerate_subroutine_pool.htm]
Btw why are you crating 36 dynamic internal table? That's way too far-fetched even for the RTTC classes
BR,
Suhas -
I want to create dynamic ALV report
Hi great abapers,
I want to create dynamic ALV report.Please help me.
Regards,
BillaHi,
Please check the code below:
REPORT YMMR_PALLET_OVERVIEW MESSAGE-ID Y_MESSAGE_0001.
Short description:
To Display and sum up the Quantity of scanned materials on pallet for*
each Shipment number for the Packaging Materials. *
TYPE-POOLS : SLIS.
TABLES: YYLE0003. " Scanned SSCC No.
--Structure Declaration--
Structure for Shipment No. and Date.
TYPES : BEGIN OF T_VTTK_TAB ,
TKNUM LIKE VTTK-TKNUM, " Shipment number
ERDAT LIKE VTTK-ERDAT, " created Date
END OF T_VTTK_TAB .
Structure for Shipment No., Packaging Materials and Date.
TYPES: BEGIN OF T_ITAB2,
TKNUM LIKE YYLE0003-TKNUM, " Shipment number
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
QUANTITY TYPE P,
ERDAT LIKE YYLE0003-ERDAT, " created Date
COUNT TYPE I,
END OF T_ITAB2.
Structure for Shipment No. and Packaging Materials.
TYPES: BEGIN OF T_ITAB3,
TKNUM LIKE YYLE0003-TKNUM, " Shipment number
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
QUANTITY TYPE P, " Quantity
END OF T_ITAB3.
--Internal table Declaration--
*Internal tables for the above Declared structures
DATA: G_VTTK_TAB TYPE TABLE OF T_VTTK_TAB,
G_ITAB5_TAB TYPE TABLE OF T_ITAB2,
G_ITAB4_TAB TYPE TABLE OF T_ITAB3,
G_ITAB3_TAB TYPE TABLE OF T_ITAB2. "#EC NEEDED
*Internal table Holding Shipment No.and quantity
DATA: BEGIN OF G_TOTAL_TAB OCCURS 0 ,
TKNUM TYPE YYLE0003-TKNUM, " Shipment number
QUANTITY TYPE P,
COUNT TYPE I,
END OF G_TOTAL_TAB .
*Internal table for selection screen data
DATA: BEGIN OF G_SCANDATA_TAB OCCURS 0,
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
EXIDV TYPE EXIDV, " External Handling Unit
TKNUM LIKE YYLE0003-TKNUM, " Shipment number
QUANTITY LIKE YYLE0003-QUANTITY, " Quantity
END OF G_SCANDATA_TAB.
DATA: BEGIN OF ST_SCANDATA_TAB,
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
EXIDV TYPE EXIDV, " External Handling Unit
TKNUM LIKE YYLE0003-TKNUM, " Shipment number
QUANTITY LIKE YYLE0003-QUANTITY, " Quantity
END OF ST_SCANDATA_TAB.
DATA: BEGIN OF G_SCANDATA_COUNT_TAB OCCURS 0,
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
TKNUM LIKE YYLE0003-TKNUM, " Shipment number
QUANTITY LIKE YYLE0003-QUANTITY, " Quantity
COUNT TYPE I,
END OF G_SCANDATA_COUNT_TAB.
DATA: L_COUNT TYPE I.
*Internal table for Packaging Materials and quantity
DATA: BEGIN OF G_ITAB6_TAB OCCURS 0,
VHILM LIKE YYLE0003-VHILM, " Packaging Materials
QUANTITY TYPE P, " Quantity
END OF G_ITAB6_TAB.
*- Field catalog
DATA: L_ALV_CAT1_TAB TYPE TABLE OF LVC_S_FCAT.
--Work area Declaration--
DATA: WA_VTTK TYPE T_VTTK_TAB,
WA_ITAB3 TYPE T_ITAB2,
WA_ITAB5 TYPE T_ITAB2,
WA_ITAB4 TYPE T_ITAB3,
WA_ITAB1 LIKE G_SCANDATA_TAB,
WA_ALV_CAT1 LIKE LINE OF L_ALV_CAT1_TAB.
----Variable Defnition -
DATA: G_CUSTOM_CONTAINER_0100 TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
G_ALV_GRID_0100 TYPE REF TO CL_GUI_ALV_GRID,
G_CONTAINER_0100 TYPE SCRFNAME VALUE 'LIST',
G_MYLAYOUT TYPE LVC_S_LAYO, "#EC NEEDED
G_WA TYPE REF TO DATA.
DATA: G_VAR TYPE I, " No of records
G_VAR1 TYPE CHAR20. " Variable
--field symbols Declaration--
FIELD-SYMBOLS : <F_FS> TYPE TABLE,
<F_FS3> TYPE ANY,
<F_FS4> TYPE ANY,
<F_FS5> TYPE ANY,
<F_WA> TYPE ANY,
<F_FS15> TYPE ANY,
<F_FS16> TYPE SY-DATUM,
<F_FS2> TYPE T_ITAB2,
<F_FS6> TYPE ANY,
<F_FS7> TYPE ANY,
<F_FS12> TYPE ANY,
<F_FS13> TYPE ANY.
--Selection Parameters--
SELECTION-SCREEN: BEGIN OF BLOCK BLCK01 WITH FRAME TITLE TEXT-000.
"Select options
SELECT-OPTIONS :
S_TKNUM FOR YYLE0003-TKNUM , " Shipment number
S_YYREF FOR YYLE0003-YY_REFERENCE, " Packing reference
S_YYREFT FOR YYLE0003-YY_REFTP, " Reference type
S_EXIDV FOR YYLE0003-EXIDV, " External HU
S_MATNR FOR YYLE0003-MATNR, " Material number
S_VBELN FOR YYLE0003-VBELN, " SD number
S_POSNR FOR YYLE0003-POSNR, " Item number
S_LGTOR FOR YYLE0003-LGTOR, " Door for Wr Hs No
S_VHILM FOR YYLE0003-VHILM, " Packaging Mat
S_YYMEIN FOR YYLE0003-YY_MEINH, " Indicator for UOM
S_QUANTI FOR YYLE0003-QUANTITY, " Quantity
S_YCHECK FOR YYLE0003-YYCHECKED, " Destination_door
S_STATUS FOR YYLE0003-STATUS, " Packing status
S_STASHI FOR YYLE0003-STATUSSHIPTO, " Status on ship-to
S_LOADTR FOR YYLE0003-LOADTRUCK, " Load truck
S_ERDAT FOR YYLE0003-ERDAT , " Date
S_ERZET FOR YYLE0003-ERZET, " Entry time
S_AEDAT FOR YYLE0003-AEDAT, " Last changed on
S_ERNAM FOR YYLE0003-ERNAM, " Name of Person
S_AEZET FOR YYLE0003-AEZET, " Time last change
S_AENAM FOR YYLE0003-AENAM. " Name of person
SELECTION-SCREEN: END OF BLOCK BLCK01.
--INITIALIZATION--
INITIALIZATION.
Clear the variables and workarea
CLEAR :G_VAR,
G_VAR1,
WA_VTTK,
WA_ITAB3,
WA_ITAB5,
WA_ITAB4,
WA_ITAB1,
WA_VTTK,
WA_ITAB3,
WA_ITAB5,
WA_ITAB4,
WA_ITAB1.
--AT SELECTION-SCREEN--
AT SELECTION-SCREEN.
To validate the data entered in selection screen
PERFORM SUB_VALIDATE.
--START-OF-SELECTION--
START-OF-SELECTION.
*To fetch the data from table yyle0003
PERFORM GET_INPUT_DATA.
*To create the Dynamic Field Catalog
PERFORM GET_FIELDCAT.
To populate the data to final table
PERFORM GET_FINAL_DATA.
MODULE status_0100 OUTPUT *
MODULE STATUS_0100 OUTPUT.
*set title bar and PF status.
SET PF-STATUS 'ZVKS'.
SET TITLEBAR 'ZVKS'.
CHECK SY-UCOMM IS INITIAL.
SORT G_SCANDATA_TAB BY TKNUM VHILM.
*Create object for Custom container
CREATE OBJECT G_CUSTOM_CONTAINER_0100
EXPORTING
CONTAINER_NAME = G_CONTAINER_0100
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
*Create object for ALV grid
CREATE OBJECT G_ALV_GRID_0100
EXPORTING I_PARENT = G_CUSTOM_CONTAINER_0100.
G_MYLAYOUT-GRID_TITLE = 'Display Scanning data'.
*Call method for table Display
CALL METHOD G_ALV_GRID_0100->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = <F_FS>
IT_FIELDCATALOG = L_ALV_CAT1_TAB
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.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
User Interaction
MODULE USER_COMMAND_0100 INPUT.
CALL METHOD CL_GUI_CFW=>DISPATCH.
*To exit , back or cancel
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form get_input_data
This sub routine will get the data from yyle0003 table.
FORM GET_INPUT_DATA.
CONSTANTS: C_DOT TYPE C VALUE '.',
C_CHAR TYPE C VALUE 'D'.
CLEAR G_SCANDATA_TAB.
Get the data from yyle0003
SELECT VHILM " Packaging Materials
EXIDV " External Handling Unit
TKNUM " Shipment number
QUANTITY " Quantity
FROM YYLE0003
INTO TABLE G_SCANDATA_TAB
WHERE TKNUM IN S_TKNUM " Shipment number
AND YY_REFERENCE IN S_YYREF " Packing reference
AND YY_REFTP IN S_YYREFT " Reference type
AND EXIDV IN S_EXIDV " External Handling Unit
AND MATNR IN S_MATNR " Material number
AND VBELN IN S_VBELN " SD number
AND POSNR IN S_POSNR " Item number
AND LGTOR IN S_LGTOR " Door for warehouse No
AND VHILM IN S_VHILM " Packaging Materials
AND YY_MEINH IN S_YYMEIN " Indicator for UOM
AND QUANTITY IN S_QUANTI " Quantity
AND YYCHECKED IN S_YCHECK " Destination_door
AND STATUS IN S_STATUS " Packing status
AND STATUSSHIPTO IN S_STASHI " Status on ship-to
AND LOADTRUCK IN S_LOADTR " Load truck
AND ERDAT IN S_ERDAT " Date
AND ERZET IN S_ERZET " Entry time
AND AEDAT IN S_AEDAT " Last changed on
AND ERNAM IN S_ERNAM " Name of Person
AND AEZET IN S_AEZET " Time last change
AND AENAM IN S_AENAM. " Name of person
If VHILM contains any Decimal '.', replace it with D
LOOP AT G_SCANDATA_TAB.
REPLACE C_DOT WITH C_CHAR INTO G_SCANDATA_TAB-VHILM.
IF SY-SUBRC = 0.
MODIFY G_SCANDATA_TAB TRANSPORTING VHILM.
ENDIF.
CLEAR G_SCANDATA_TAB.
ENDLOOP.
*To get the Shipment No Creation date from VTTK.
SELECT TKNUM
ERDAT
FROM VTTK
INTO TABLE G_VTTK_TAB
WHERE TKNUM IN S_TKNUM.
SORT G_SCANDATA_TAB BY VHILM EXIDV. "TKNUM VHILM.
*To get the repeatition of Pacakaging material for each Shipment.
*--- to find the count of packaging materials under each shipment
LOOP AT G_SCANDATA_TAB.
READ TABLE G_SCANDATA_TAB INTO ST_SCANDATA_TAB INDEX SY-TABIX.
AT END OF EXIDV.
L_COUNT = L_COUNT + 1.
MOVE-CORRESPONDING ST_SCANDATA_TAB TO G_SCANDATA_COUNT_TAB.
G_SCANDATA_COUNT_TAB-COUNT = L_COUNT.
CLEAR: ST_SCANDATA_TAB, L_COUNT.
COLLECT G_SCANDATA_COUNT_TAB.
ENDAT.
CLEAR : G_SCANDATA_TAB.
ENDLOOP.
ENDFORM. " get_input_data
*& Form sub_validate
*This subroutine will validate the data eneterd in the selection screen
FORM SUB_VALIDATE.
*Varaiable declaration for Shipment number
DATA: L_TKNUM TYPE YYLE0003-TKNUM."#EC NEEDED " Shipment number
*- Condition will not qualify all primary key (IDENT)
SELECT TKNUM FROM YYLE0003 UP TO 1 ROWS
INTO L_TKNUM "wa_scandata
WHERE TKNUM IN S_TKNUM " Shipment number
AND YY_REFERENCE IN S_YYREF " Packing reference
AND YY_REFTP IN S_YYREFT " Reference type
AND EXIDV IN S_EXIDV " External Handling Unit
AND MATNR IN S_MATNR " Material number
AND VBELN IN S_VBELN " SD number
AND POSNR IN S_POSNR " Item number
AND LGTOR IN S_LGTOR " Door for warehouse No
AND VHILM IN S_VHILM " Packaging Materials
AND YY_MEINH IN S_YYMEIN " Indicator for UOM
AND QUANTITY IN S_QUANTI " Quantity
AND YYCHECKED IN S_YCHECK " Destination_door
AND STATUS IN S_STATUS " Packing status
AND STATUSSHIPTO IN S_STASHI " Status on ship-to
AND LOADTRUCK IN S_LOADTR " Load truck
AND ERDAT IN S_ERDAT " Date
AND ERZET IN S_ERZET " Entry time
AND AEDAT IN S_AEDAT " Last changed on
AND ERNAM IN S_ERNAM " Name of Person
AND AEZET IN S_AEZET " Time last change
AND AENAM IN S_AENAM. " Name of person
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE E987 . " No data found for these selection criterias
ENDIF.
ENDFORM. " sub_validate
*& Form get_fieldcat
Preparing Field catalog
FORM GET_FIELDCAT.
DATA: L_REF TYPE REF TO DATA,
L_I TYPE I. " Variable
CONSTANTS: C_CENTER TYPE C VALUE 'C'. " Center Justified
LOOP AT G_SCANDATA_TAB INTO WA_ITAB1.
MOVE-CORRESPONDING WA_ITAB1 TO WA_ITAB3.
APPEND WA_ITAB3 TO G_ITAB3_TAB.
MOVE-CORRESPONDING WA_ITAB1 TO WA_ITAB4.
COLLECT WA_ITAB4 INTO G_ITAB4_TAB.
*To sum up the qunatity field for each TKNUM.
AT END OF TKNUM.
SUM.
MOVE WA_ITAB1-TKNUM TO G_TOTAL_TAB-TKNUM.
MOVE WA_ITAB1-QUANTITY TO G_TOTAL_TAB-QUANTITY .
APPEND G_TOTAL_TAB.
CLEAR G_TOTAL_TAB.
ENDAT.
CLEAR : WA_ITAB1,
WA_ITAB3,
WA_ITAB4.
ENDLOOP.
*--- Begin of change - SKR.EXT - EBDK986377
SORT G_ITAB4_TAB BY TKNUM.
*--- End of change - SKR.EXT - EBDK986377
LOOP AT G_ITAB4_TAB INTO WA_ITAB4.
MOVE-CORRESPONDING WA_ITAB4 TO WA_ITAB5.
MOVE-CORRESPONDING WA_ITAB4 TO G_ITAB6_TAB.
*---- to get the count
READ TABLE G_SCANDATA_COUNT_TAB WITH KEY TKNUM = WA_ITAB5-TKNUM
VHILM = WA_ITAB5-VHILM.
IF SY-SUBRC EQ 0.
WA_ITAB5-COUNT = G_SCANDATA_COUNT_TAB-COUNT.
ENDIF.
APPEND WA_ITAB5 TO G_ITAB5_TAB.
COLLECT G_ITAB6_TAB.
ENDLOOP.
CLEAR : WA_ITAB3.
SORT G_ITAB4_TAB BY TKNUM VHILM.
DELETE ADJACENT DUPLICATES FROM G_ITAB4_TAB COMPARING VHILM.
*To get the Number of fields to be displayed
DESCRIBE TABLE G_ITAB4_TAB LINES G_VAR.
L_I = '3'.
*Field catalog
WA_ALV_CAT1-FIELDNAME = 'TKNUM'(002).
WA_ALV_CAT1-COL_POS = 1.
WA_ALV_CAT1-COLTEXT ='ShipmentNo.'.
APPEND WA_ALV_CAT1 TO L_ALV_CAT1_TAB.
CLEAR : WA_ALV_CAT1.
WA_ALV_CAT1-FIELDNAME = 'ERDAT'(003).
WA_ALV_CAT1-COL_POS = 2.
WA_ALV_CAT1-COLTEXT ='Creation_Date.'(005).
APPEND WA_ALV_CAT1 TO L_ALV_CAT1_TAB.
CLEAR : WA_ALV_CAT1.
Create field catalog for each of VHILM
LOOP AT G_ITAB4_TAB INTO WA_ITAB4.
IF G_VAR >= 1.
CONDENSE WA_ITAB4-VHILM NO-GAPS.
WA_ALV_CAT1-FIELDNAME = WA_ITAB4-VHILM. "l_fieldname.
WA_ALV_CAT1-COL_POS = L_I.
WA_ALV_CAT1-COLTEXT = WA_ITAB4-VHILM.
WA_ALV_CAT1-JUST = C_CENTER. "'C'.
APPEND WA_ALV_CAT1 TO L_ALV_CAT1_TAB.
CLEAR WA_ALV_CAT1.
L_I = L_I + 1.
ENDIF.
*TOTAL-last column in the field catalog
AT LAST.
WA_ALV_CAT1-FIELDNAME = 'TOTAL'(004).
WA_ALV_CAT1-COL_POS = L_I.
WA_ALV_CAT1-COLTEXT = 'TOTAL'(004).
WA_ALV_CAT1-JUST = C_CENTER. " 'C'.
APPEND WA_ALV_CAT1 TO L_ALV_CAT1_TAB.
CLEAR WA_ALV_CAT1.
ENDAT.
SORT L_ALV_CAT1_TAB BY FIELDNAME.
*Non of the field name should not get repeated
DELETE ADJACENT DUPLICATES FROM L_ALV_CAT1_TAB.
ENDLOOP.
SORT L_ALV_CAT1_TAB BY COL_POS.
*Creating Dynamic Internal table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = L_ALV_CAT1_TAB
IMPORTING
EP_TABLE = L_REF.
Assigning the Dynamic field Catalog to field symbol.
ASSIGN L_REF->* TO <F_FS>.
CREATE DATA G_WA LIKE LINE OF <F_FS>.
ASSIGN G_WA->* TO <F_WA>.
DELETE ADJACENT DUPLICATES FROM <F_FS> COMPARING ALL FIELDS.
ENDFORM. " get_fieldcat
*& Form display_data
FORM GET_FINAL_DATA.
*variable declaration
DATA: L_TOTAL TYPE I, " Row wise total
L_FILL TYPE I, " Count
L_TOT TYPE I. " Grand total
*To get the TOTAL qunatity in the last line of out put.
LOOP AT G_ITAB6_TAB.
CLEAR WA_ITAB5.
WA_ITAB5-TKNUM = 'TOTAL'(004).
WA_ITAB5-ERDAT = SPACE.
MOVE-CORRESPONDING G_ITAB6_TAB TO WA_ITAB5 .
LOOP AT G_SCANDATA_COUNT_TAB WHERE VHILM = G_ITAB6_TAB-VHILM.
WA_ITAB5-COUNT = WA_ITAB5-COUNT + G_SCANDATA_COUNT_TAB-COUNT.
ENDLOOP.
APPEND WA_ITAB5 TO G_ITAB5_TAB.
CLEAR WA_ITAB5.
ENDLOOP.
DESCRIBE TABLE G_ITAB5_TAB LINES L_TOT.
*>>>>>>>>
****To get total qunatity of all TKNUM
LOOP AT G_TOTAL_TAB .
L_TOTAL = L_TOTAL + G_TOTAL_TAB-QUANTITY.
ENDLOOP.
*>>>>>>>>
*To assign ERDAT to g_itab5_tab
LOOP AT G_ITAB5_TAB INTO WA_ITAB5 .
READ TABLE G_VTTK_TAB INTO WA_VTTK WITH KEY TKNUM = WA_ITAB5-TKNUM.
IF SY-SUBRC = 0.
WA_ITAB5-ERDAT = WA_VTTK-ERDAT.
MODIFY G_ITAB5_TAB FROM WA_ITAB5 TRANSPORTING ERDAT.
ENDIF.
ENDLOOP.
*Assigning value in each field to respective Field symbols.
LOOP AT G_ITAB5_TAB ASSIGNING <F_FS2>.
CLEAR G_TOTAL_TAB-QUANTITY.
ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <F_FS2> TO <F_FS6>.
ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <F_WA> TO <F_FS7>.
<F_FS7> = <F_FS6>.
CONDENSE <F_FS2>-VHILM NO-GAPS.
ASSIGN COMPONENT 'VHILM' OF STRUCTURE <F_FS2> TO <F_FS3>.
ASSIGN COMPONENT 5 OF STRUCTURE <F_FS2> TO <F_FS4>.
MOVE <F_FS3> TO G_VAR1.
ASSIGN COMPONENT G_VAR1 OF STRUCTURE <F_WA> TO <F_FS5>.
<F_FS5> = <F_FS4>.
ASSIGN COMPONENT 'ERDAT' OF STRUCTURE <F_FS2> TO <F_FS16>.
ASSIGN COMPONENT 'ERDAT' OF STRUCTURE <F_WA> TO <F_FS15>.
WRITE <F_FS16> TO <F_FS15> .
Inorder not to display the date '00/00/000',
if there is no DATE .
IF ( <F_FS15> CP '00/*' )
OR ( <F_FS15> CP '00.*' )
OR ( <F_FS15> CP '00-*' ).
<F_FS15> = SPACE.
ELSEIF ( <F_FS15> CO ' / /' )
OR ( <F_FS15> CO ' . .' )
OR ( <F_FS15> CO ' - -' ) .
<F_FS15> = SPACE.
ENDIF.
READ TABLE G_TOTAL_TAB WITH KEY TKNUM = <F_FS6>.
IF SY-SUBRC = 0.
ASSIGN G_TOTAL_TAB-QUANTITY TO <F_FS12>.
ASSIGN COMPONENT 'COUNT' OF STRUCTURE <F_FS2> TO <F_FS12>.
ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <F_WA> TO <F_FS13>.
<F_FS13> = <F_FS13> + <F_FS12>.
L_TOTAL = L_TOTAL + <F_FS12>.
ENDIF.
L_FILL = L_FILL + 1.
IF L_FILL = L_TOT.
ASSIGN L_TOTAL TO <F_FS12>.
ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <F_WA> TO <F_FS13>.
<F_FS13> = <F_FS12>.
ENDIF.
AT END OF <F_FS2>-TKNUM.
APPEND <F_WA> TO <F_FS>.
CLEAR <F_WA>.
ENDAT.
ENDLOOP.
CLEAR: <F_FS6>,
<F_FS7>,
<F_WA>.
*Call the screen where Custom container is defined
CALL SCREEN 0100.
ENDFORM. " display_data
Regards
Kannaiah -
Hi,
I am working on an a alv report.In the selection screen,if the fiscal period is input based on that the dates have to be calculated and have to be displayed as column headers in the o/p.This colum is dynamic and will change based on the values given in the selection screen.Now I need to populate the values for these dates under the corresponding columns respectively.
Can anyone tell me how can I achieve this?
Regards,
Hemacheck this.. sample code..
REPORT ztest_dynamic_code.
TYPES: BEGIN OF ty_data,
abc(3),
xyz(3),
pqr(3),
item1,
item2,
item3,
item4,
item5,
item6,
item7,
item8,
item9,
END OF ty_data.
DATA: BEGIN OF it_tab OCCURS 0,
abc(3),
xyz(3),
pqr(3),
item,
END OF it_tab.
DATA: it_fieldcatalog TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.
DATA: i_dyntab TYPE REF TO data. " To create dyn.Itab
DATA:
w_dref TYPE REF TO data,
ind(2) TYPE n,
w_data TYPE REF TO data,
w_text(5),
w_grid TYPE REF TO cl_gui_alv_grid.
DATA: grid TYPE REF TO cl_gui_alv_grid,
cont TYPE REF TO cl_gui_custom_container.
FIELD-SYMBOLS: <t_itab> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,<fs> TYPE ANY.
DATA: in TYPE i.
*Data population
it_tab-abc = 'ABC'.
it_tab-xyz = 'XYZ'.
it_tab-pqr = 'PQR'.
DO 9 TIMES.
in = in + 1.
it_tab-item = in.
APPEND it_tab.
ENDDO.
*Field cat population.
wa_fieldcat-fieldname = 'ABC'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'abc'.
APPEND wa_fieldcat TO it_fieldcatalog.
wa_fieldcat-fieldname = 'XYZ'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'XYZ'.
APPEND wa_fieldcat TO it_fieldcatalog.
wa_fieldcat-fieldname = 'PQR'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'pqr'.
APPEND wa_fieldcat TO it_fieldcatalog.
ind = 1.
DO 9 TIMES.
CONCATENATE 'ITEM' ind INTO wa_fieldcat-fieldname.
CONCATENATE 'ITEM' ind INTO wa_fieldcat-coltext.
wa_fieldcat-outputlen = 1.
APPEND wa_fieldcat TO it_fieldcatalog.
CLEAR wa_fieldcat .
ind = ind + 1.
ENDDO.
*-Dynamic Table creation
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = i_dyntab.
ASSIGN i_dyntab->* TO <t_itab>.
CREATE DATA w_data LIKE LINE OF <t_itab>.
ASSIGN w_data->* TO <fs_wa>.
SORT it_tab BY abc xyz pqr.
CLEAR ind.
ind = 4.
*-Final Internal table as per Requirement
LOOP AT it_tab.
ASSIGN COMPONENT 1 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-abc.
ASSIGN COMPONENT 2 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-xyz.
UNASSIGN <fs>.
ASSIGN COMPONENT 3 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-pqr.
UNASSIGN <fs>.
ASSIGN COMPONENT ind OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-item.
UNASSIGN <fs>.
ind = ind + 1.
AT END OF pqr.
APPEND <fs_wa> TO <t_itab>.
ind = 4.
CLEAR <fs_wa>.
ENDAT.
ENDLOOP.
*-Display
CALL SCREEN 100.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
DATA: layout TYPE lvc_s_layo.
CREATE OBJECT cont
EXPORTING
container_name = 'CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT grid
EXPORTING
i_parent = cont
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
grid->set_table_for_first_display(
EXPORTING
is_layout = layout
CHANGING
it_outtab = <t_itab>
it_fieldcatalog = it_fieldcatalog
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT -
Create deep structure to disable some cells in Dynamic ALV GRID
Hi,
I want to disable some cells in a Dynamic ALV Grid before calling "SET_tABLE_Display" Method.
I check the BCALV_EDIT_02, where some cells are grayed out by assign the CL_GUI_ALV_GRID-MC_STYLE_DISABLED to the field name.
But I want the same using Field symbol.
I'm creating Dynamic table and dynamic structure based on the Dynamic field catalog.
Example: <FT_TAB> TYPE STANDARD TABLE,
<FS_TAB> TYPE ANY,
DATA: INT_TAB is my dynamic table values.
For the INT_TAB internal table, I created dynamic Structure and dynamic field symbol table.
LOOP AT INT_TAB.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <FS_TAB> TO <F_VALUE>
<F_VALUE> = INT_TAB-MATNR.
APPEND <FS_TAB> TO <FT_TAB>
"Here is the problem occurs, I want to grayed out the MATNR value based on some condition.
ENDLOOP.
I would like to set the 'MATNR' value to be grayed out by passing the CL_GUI_ALV_GRID-MC_STYLE_DISABLED.
and update into <FT_TAB>( <FT_TAB> structure will have 2 structures)
Finally the fieldsymbol should have two structure ( <F_TAB> = DYNAMIC STRUCTURE + LVC_S_STYLE )
Display alv grid by passing <FT_TAB> to set_table_display method.
Thanks in advance,
Kumar.Hi,
I am not sure whether I really understand your request. Let me try to help.
> Example: <FT_TAB> TYPE STANDARD TABLE,
> <FS_TAB> TYPE ANY,
>
> DATA: INT_TAB is my dynamic table values.
>
>
> LOOP AT INT_TAB.
> ASSIGN COMPONENT 'MATNR' OF STRUCTURE <FS_TAB> TO <F_VALUE>
> <F_VALUE> = INT_TAB-MATNR.
> APPEND <FS_TAB> TO <FT_TAB>
Here <FT_TAB> must already be assigned to some internal table with a given (dynamic) structure. Did this happen before this piece of code?
What I would do is to create a dynamic table (see documentation to CREATE DATA) with MATNR and the STYLE field (LVC_T_STYL). See the documentation for CREATE DATA - creation of internal tables. When collection the field descriptions for that internal table I would also build the field catalogue for the ALV.
Then assign <FT_TAB> to that newly created internal table, <FS_TAB> to a newly created structure (same as a table line).
Move the MATNR to component 1 (or component 'MATNR') of the table and fill the style table according to your needs. Then insert the <FS_TAB> into <FT_TAB>.
Finally call the ALV SET_TABLE... method with your dynamic table and your field catalogue.
Regards,
Gerd Rother -
Problem in Data Display in Dynamic ALV Report
Hi all,
I am developing a Dynamic ALV report where I want display material batch (zjpack_base-charg) in column and Material (zjpack_base-matnr) & Qty (Zjpack_base-netwr) field row wise.My intention is to show report datewise for a material how many batch developed with there qty.I am sending you the code which i already wrote.Here column is developed batchwise but I am not able to show the qty against each batch.Please see my code and guide me how to display.
REPORT zdynamic_test .
*REPORT ztest_notepad.
*& Declarations
*Type-pools
TYPE-POOLS: slis.
*TABLES
TABLES: zjpack_base.
*Types
TYPES:
ty_fcat TYPE lvc_s_fcat,
ty_fcatalog TYPE slis_fieldcat_alv.
*Work areas
DATA:
wa_fcat TYPE ty_fcat,
wa_fcatalog TYPE ty_fcatalog.
*Internal tables
DATA:
it_fcat TYPE STANDARD TABLE OF ty_fcat,
it_fcatalog TYPE STANDARD TABLE OF ty_fcatalog.
*Type reference
DATA:
it_dyn_tab TYPE REF TO data,
wa_newline TYPE REF TO data.
*INTERNAL TABLE
DATA: BEGIN OF it_itab OCCURS 0.
INCLUDE STRUCTURE zjpack_base.
DATA: END OF it_itab.
*Filed symbols
FIELD-SYMBOLS:
<gt_table> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<l_field> TYPE ANY.
*Variables
DATA:
l_fieldname TYPE lvc_s_fcat-fieldname,
l_tabname TYPE lvc_s_fcat-tabname,
l_fieldtext TYPE lvc_s_fcat-seltext,
l_index TYPE char2.
"Selection-screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s11 .
SELECT-OPTIONS:s_matnr FOR zjpack_base-matnr.
SELECT-OPTIONS:s_charg FOR zjpack_base-charg.
SELECT-OPTIONS:s_fdate FOR zjpack_base-fdate .
SELECTION-SCREEN END OF BLOCK b1.
PARAMETERS:
p_colms TYPE i.
*& start-of-selection.
START-OF-SELECTION.
PERFORM select_data.
PERFORM build_fieldcat.
PERFORM create_dynamic_table.
DO 20 TIMES.
DO p_colms TIMES.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = sy-index.
ENDDO.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDDO.
LOOP AT it_itab.
l_index = sy-tabix.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = it_itab-matnr.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDLOOP.
LOOP AT it_fcat INTO wa_fcat.
PERFORM fieldcatalog1 USING: wa_fcat-fieldname
wa_fcat-tabname
wa_fcat-seltext.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZTEST_NOTEPAD'
it_fieldcat = it_fcatalog
TABLES
t_outtab = <gt_table>.
*& Form BUILD_FIELDCAT
FORM build_fieldcat .
CLEAR: l_fieldname,
l_tabname,
l_fieldtext,
l_index.
DO p_colms TIMES.
CLEAR l_index.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'Field' l_index INTO l_fieldtext.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
ENDDO.
ENDFORM. " BUILD_FIELDCAT
*& Form CREATE_DYNAMIC_TABLE
FORM create_dynamic_table .
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_dyn_tab.
ASSIGN it_dyn_tab->* TO <gt_table>.
Create dynamic work area and assign to FS
CREATE DATA wa_newline LIKE LINE OF <gt_table>.
ASSIGN wa_newline->* TO <fs_dyntable>.
ENDFORM. " CREATE_DYNAMIC_TABLE
*& Form FIELDCATALOG
FORM fieldcatalog USING field table f_txt.
wa_fcat-fieldname = field.
wa_fcat-tabname = table.
wa_fcat-seltext = f_txt.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. " FIELDCATALOG
*& Form FIELDCATALOG1
FORM fieldcatalog1 USING field table f_txt.
wa_fcatalog-fieldname = field.
wa_fcatalog-tabname = table.
wa_fcatalog-seltext_m = f_txt.
APPEND wa_fcatalog TO it_fcatalog.
CLEAR wa_fcatalog.
ENDFORM. " FIELDCATALOG1
*& Form SELECT_DATA
text
--> p1 text
<-- p2 text
FORM select_data .
DATA: v_srlno TYPE i.
SELECT matnr charg blqty
INTO CORRESPONDING FIELDS OF it_itab
FROM zjpack_base
WHERE matnr IN s_matnr
AND charg IN s_charg
AND fdate IN s_fdate.
COLLECT it_itab.
ENDSELECT.
v_srlno.
LOOP AT it_itab.
v_srlno = v_srlno + 1.
ENDLOOP.
CLEAR: l_fieldname,
l_tabname,
l_fieldtext,
l_index.
1st Field
l_index = sy-tabix.
CONCATENATE 'FIELD' '1' INTO l_fieldname.
l_fieldtext = 'MATNR'.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
Other fields
LOOP AT it_itab.
CLEAR l_index.
l_index = sy-tabix + 1.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'CHARG-' it_itab-charg INTO l_fieldtext.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
ENDLOOP.
Please guide me how my problem will solve.
Thanks & Regards
NirmalHi all, I am developing a Dynamic ALV report where I want display material batch (zjpack_base-charg) in column and Material (zjpack_base-matnr) & Qty (Zjpack_base-netwr) field row wise.My intention is to show report datewise for a material how many batch developed with there qty.I am sending you the code which i already wrote.Here column is developed batchwise but I am not able to show the qty against each batch.Please see my code and guide me how to display.
*& Report ZDYNAMIC_TEST *
REPORT zdynamic_test .
*REPORT ztest_notepad.
*& Declarations
*Type-pools
TYPE-POOLS: slis.
*TABLES
TABLES: zjpack_base.
*Types
TYPES:
ty_fcat TYPE lvc_s_fcat,
ty_fcatalog TYPE slis_fieldcat_alv.
*Work areas
DATA:
wa_fcat TYPE ty_fcat,
wa_fcatalog TYPE ty_fcatalog.
*Internal tables
DATA:
it_fcat TYPE STANDARD TABLE OF ty_fcat,
it_fcatalog TYPE STANDARD TABLE OF ty_fcatalog.
*Type reference
DATA:
it_dyn_tab TYPE REF TO data,
wa_newline TYPE REF TO data.
*INTERNAL TABLE
DATA: BEGIN OF it_itab OCCURS 0.
INCLUDE STRUCTURE zjpack_base.
DATA: END OF it_itab.
*Filed symbols
FIELD-SYMBOLS:
<gt_table> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<l_field> TYPE ANY.
*Variables
DATA:
l_fieldname TYPE lvc_s_fcat-fieldname,
l_tabname TYPE lvc_s_fcat-tabname,
l_fieldtext TYPE lvc_s_fcat-seltext,
l_index TYPE char2.
"Selection-screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s11 .
SELECT-OPTIONS:s_matnr FOR zjpack_base-matnr.
SELECT-OPTIONS:s_charg FOR zjpack_base-charg.
SELECT-OPTIONS:s_fdate FOR zjpack_base-fdate .
SELECTION-SCREEN END OF BLOCK b1.
PARAMETERS:
p_colms TYPE i.
*& start-of-selection.
START-OF-SELECTION.
PERFORM select_data.
PERFORM build_fieldcat.
PERFORM create_dynamic_table.
* DO 20 TIMES.
* DO p_colms TIMES.
* l_index = sy-index.
* CONCATENATE 'FIELD' l_index INTO l_fieldname.
* ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
* <l_field> = sy-index.
* ENDDO.
* INSERT <fs_dyntable> INTO TABLE <gt_table>.
* ENDDO.
LOOP AT it_itab.
l_index = sy-tabix.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = it_itab-matnr.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDLOOP.
LOOP AT it_fcat INTO wa_fcat.
PERFORM fieldcatalog1 USING: wa_fcat-fieldname
wa_fcat-tabname
wa_fcat-seltext.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZTEST_NOTEPAD'
it_fieldcat = it_fcatalog
TABLES
t_outtab = <gt_table>.
*& Form BUILD_FIELDCAT
FORM build_fieldcat .
* CLEAR: l_fieldname,
* l_tabname,
* l_fieldtext,
* l_index.
* DO p_colms TIMES.
* CLEAR l_index.
* l_index = sy-index.
* CONCATENATE 'FIELD' l_index INTO l_fieldname.
* CONCATENATE 'Field' l_index INTO l_fieldtext.
* l_tabname = '<GT_TABLE>'.
* PERFORM fieldcatalog USING: l_fieldname
* l_tabname
* l_fieldtext.
* ENDDO.
ENDFORM. " BUILD_FIELDCAT
*& Form CREATE_DYNAMIC_TABLE
FORM create_dynamic_table .
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_dyn_tab.
ASSIGN it_dyn_tab->* TO <gt_table>.
* Create dynamic work area and assign to FS
CREATE DATA wa_newline LIKE LINE OF <gt_table>.
ASSIGN wa_newline->* TO <fs_dyntable>.
ENDFORM. " CREATE_DYNAMIC_TABLE
*& Form FIELDCATALOG
FORM fieldcatalog USING field table f_txt.
wa_fcat-fieldname = field.
wa_fcat-tabname = table.
wa_fcat-seltext = f_txt.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. " FIELDCATALOG
*& Form FIELDCATALOG1
FORM fieldcatalog1 USING field table f_txt.
wa_fcatalog-fieldname = field.
wa_fcatalog-tabname = table.
wa_fcatalog-seltext_m = f_txt.
APPEND wa_fcatalog TO it_fcatalog.
CLEAR wa_fcatalog.
ENDFORM. " FIELDCATALOG1
*& Form SELECT_DATA
* text
* --> p1 text
* <-- p2 text
FORM select_data .
* DATA: v_srlno TYPE i.
SELECT matnr charg blqty
INTO CORRESPONDING FIELDS OF it_itab
FROM zjpack_base
WHERE matnr IN s_matnr
AND charg IN s_charg
AND fdate IN s_fdate.
COLLECT it_itab.
ENDSELECT.
* v_srlno.
* LOOP AT it_itab.
* v_srlno = v_srlno + 1.
* ENDLOOP.
CLEAR: l_fieldname,
l_tabname,
l_fieldtext,
l_index.
* 1st Field
* l_index = sy-tabix.
CONCATENATE 'FIELD' '1' INTO l_fieldname.
l_fieldtext = 'MATNR'.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
* Other fields
LOOP AT it_itab.
CLEAR l_index.
l_index = sy-tabix + 1.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'CHARG-' it_itab-charg INTO l_fieldtext.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
ENDLOOP.
ENDFORM. " SELECT_DATA -
hi friends,
how to create alv report in dynamically.
regards,
jaiHi,
Declare this in TOP:
* Declaration For ALV Used
*-- Global data definitions for ALV
*--- ALV Grid instance reference
DATA:v_alvgrid TYPE REF TO cl_gui_alv_grid,
v_alvgrid1 TYPE REF TO cl_gui_alv_grid.
*--- Name of the custom control added on the screen
DATA v_custom_control_name TYPE scrfname VALUE 'CONTAINER_100'.
*--- Custom container instance reference
DATA: v_container_100 TYPE REF TO cl_gui_custom_container,
v_container_200 TYPE REF TO cl_gui_custom_container.
*--- Field catalog table
DATA it_fieldcat TYPE lvc_t_fcat.
*---Layout Structure
DATA : wa_layout TYPE lvc_s_layo.
CONSTANTS: c_container_name_100(13) TYPE c VALUE 'CONTAINER_100',
c_container_name_200(13) TYPE c VALUE 'CONTAINER_200'.
*In PAI*
CALL METHOD v_alvgrid->check_changed_data.
<write code here>
CALL METHOD v_alvgrid->refresh_table_display.
HOPE THIS HELPS
Code Formatted by: Alvaro Tejada Galindo on Jan 1, 2008 10:16 AM -
Problem in Dynamic ALV - inserting values in proper field of a table.
Hi gurus,
As per the user requirement I need to create a dynamic alv report. The fields will be display according to the period entered.
I have already build the alv and it is working fine. But My questio is how can I append data into internal table in its proper field.
suppose I have enter period 1 to 3 in selection screen. Then my table structure will be
JAN | FEB | MAR
Upto this is is working fine, fields are generated dynamically , but how can I insert data only in perticular field.
like
itab-JAN = 001.
itab-FEB = 002.
itab-MAR = 003.
append itab
JAN | FEB | MAR
001 002 003
Please give me a solution of that. waiting for reply.hI,
loop at <dyn_table> assigning <wa>.
lv_count = 001.
*perform get_short_tet of month in a varibale say lv_var
assign component LV_VAR of structure <wa> to <dyn_field1>.
<dyn_field1> = lv_count.
lv_count = lv_count + 1.
endloop.
Regards,
mrunal
Edited by: Mrunal Shyamkant Patki on Nov 5, 2009 10:53 AM
Edited by: Mrunal Shyamkant Patki on Nov 5, 2009 10:54 AM -
Problem in print out of Dynamic ALV
Hi ,
I am using dynamic ALV to address a requirement. The ALV is working fine and the output is also coming corretly, even in spool.
But if the width of dynamic table exceeds a limit, then nothing is coming in the print out.
If anyone has faced similar problem or knows how to tackle this problem, please advise what can be done here.
Thanks,
SonalHi,
Can you try to increase field with to maximun as per your requirement.
Regards,
Sai -
Dynamic Table Creation & Fill Up
Hello,
Can anyone please guide where I can find examples for dynamic table creation (programmaticaly), with dynamic number of columns and rows, used to place inside text components (or whatever) to fill them with data.
All programmatic.
Using JSF, ADF BC
JDeveloper 10.1.3.1
Thanks
Message was edited by:
RJundiHi,
Meybe this article helps: http://technology.amis.nl/blog/?p=2306
Kuba -
Hi all
i try to put color in the dynamic alv, but i become a dump message
Runtime Errors OBJECTS_MOVE_NOT_SUPPORTED
Date and Time 28.10.2010 08:46:49
Short text
Conversion of type "h" to type "g" not supported.
What happened?
Error in the ABAP Application Program
The current ABAP program "SAPLSLVC" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
You attempted to move one data object to another.
This is not possible here because the conversion of a data object
of type "h" to type "g" is not supported.
my code implementation looks like
method validate_order_deli.
data ls_scol type lvc_s_scol.
data ls_colo type lvc_s_colo.
data ls_aoc_percent type zsd_aoc_percent.
data lf_deliv type lifmg.
data lf_db_percent type f.
data lf_calc_perc type f.
refresh et_color.
select single *
from zsd_aoc_percent
into corresponding fields of ls_aoc_percent
where acin = 'X'.
if sy-subrc <> 0.
exit.
endif.
lf_db_percent = ls_aoc_percent-percent.
* ls_scol-fname = if_fieldname.
ls_scol-fname = 'MATNR'.
if if_deliv <> 0.
me->calc_amour_unit(
exporting
if_matnr = if_matnr
if_amount = if_deliv
if_input = if_deliv_unit
if_output = if_order_unit
importing
ef_amount = lf_deliv
lf_calc_perc = ( lf_deliv * 100 ) / if_order.
if lf_calc_perc < lf_db_percent.
ls_colo-col = cl_gui_resources=>list_col_positive.
else.
ls_colo-col = cl_gui_resources=>list_col_negative.
endif.
ls_scol-color = ls_colo.
append ls_scol to et_color.
else.
exit.
endif.
endmethod. "validate_order_deli
method add_color_field.
data ls_fcat type lvc_s_fcat.
ls_fcat-fieldname = 'COLOR'.
ls_fcat-ref_field = 'COLTAB'.
ls_fcat-ref_table = 'CALENDAR_TYPE'.
append ls_fcat to ct_fcat.
endmethod. "add_color_field
ls_lvc_s_layo-cwidth_opt = 'X'.
ls_lvc_s_layo-ctab_fname = 'COLOR'.
i don't no, what's wrong...
thx for help*& Form generate_alv
* text
form generate_alv.
field-symbols <lt_any_table> type any table.
if lrf_gui_custom_container is initial.
create object lrf_gui_custom_container
exporting
container_name = lf_container.
create object lrf_gui_alvgrid
exporting
i_parent = lrf_gui_custom_container.
ls_lvc_s_layo-cwidth_opt = 'X'.
ls_lvc_s_layo-ctab_fname = 'COLOR'.
check sy-subrc = 0.
call method lrf_gui_alvgrid->set_table_for_first_display
exporting
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name = 'ZAM_CELL_COLOR'
* is_variant = ls_disvariant
* i_save = 'A'
* i_default = 'X'
is_layout = ls_lvc_s_layo
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
changing
it_outtab = <gt_table>
it_fieldcatalog = gt_dyn_fcat
* it_filter =
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.
endif.
endform. "generate_alv
*& Module STATUS_0100 OUTPUT
* text
module status_0100 output.
set pf-status 'ZAM_CELL_STATUS'.
set titlebar 'ZAM_CELL_TIT'.
perform generate_alv.
endmodule. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
module user_command_0100 input.
data lf_okcode type syucomm.
call method cl_gui_cfw=>dispatch.
lf_okcode = ok_code.
case lf_okcode.
when 'EXIT'.
set screen 0.
leave screen.
when 'CANCEL'.
leave program.
when 'BACK'.
set screen 0.
leave screen..
endcase.
endmodule. " USER_COMMAND_0100 INPUT
Maybe you are looking for
-
Itunes/quicktime will not install
I am trying to udgrade my intunes to the newest version (7.34) to add music to my 2nd genertaion ipod nano. The installer will not even open giving the error message of invalid drive J:/. I already tried changing my ipod's drvie letter to (k) but it
-
I pre-ordered shipment of the IPhone 5's 9/14 like many others, and now it pushed back to 10/5. How can I go to store and pick up at upgrade rate rather than paying full price?
-
While creating with holding tax certificate
dear all while printing with holding certificate getting error No data selected for printing please guide me how to solve this error Regards Babu.k
-
Concepts Oracle should look upon --1) Definition Security
Hi All, Recently i was working on implementing Application Designer definition security in one of PeopleSoft instance. Well, i read the peoplebooks, employed the past knowledge and found one severe drawback of using definition group and primary permi
-
Secondary Hard drive in a Envy dv7-7233nr Laptop
hello this laptop supports a secondary hard drive. I need to know where to get the right Mounting kit for it. I have the Hard drive i want to use and a cable i got on Ebay for it. now all i need is a Cradle /mounting kit. Please help. Thx