How to display itab in ALV with dynamic layout variant? - abap

I am using the class CL_GUI_ALV_GRID and a dynpro screen to display an internal table via the ALV tool.
In my selection screen I have a dropdown list where the user can choose a layout variant for the displayed internal table. The layout variants are stored in the table LTDX.
Now, back to my question, how can I display the variants depending on the selection of the user?

You supply in the initial set_table_for_first_display method the is_variant parameter:
DATA: ls_variant TYPE disvariant.
CLEAR: ls_variant.
ls_variant-report = sy-repid.
ls_variant-variant = pa_varid. "<<< this is the name of the variant
CALL METHOD gro_alv100->set_table_for_first_display
EXPORTING
is_variant = ls_variant
...
EDIT: okay you did not accept the simple answer, so I will add the manual alternative:
FORM set_variant USING ps_variant TYPE disvariant.
DATA: lf_user_specific TYPE char1,
ls_stable TYPE lvc_s_stbl VALUE 'XX'.
CHECK ps_variant-variant IS NOT INITIAL.
lf_user_specific = boolc( ps_variant-variant(1) <> '/' ).
CALL FUNCTION 'LVC_VARIANT_SELECT'
EXPORTING
i_dialog = space
i_user_specific = lf_user_specific
i_default = space
it_default_fieldcat = gt_fcat
IMPORTING
et_fieldcat = gt_fcat
et_sort = gt_sort
et_filter = gt_filter
TABLES
it_data = gt_outtab
CHANGING
cs_variant = ps_variant
EXCEPTIONS
wrong_input = 1
fc_not_complete = 2
not_found = 3
program_error = 4
data_missing = 5
OTHERS = 6.
IF sy-subrc <> 0.
ENDIF.
gro_alv100->set_variant( EXPORTING is_variant = ps_variant ).
gro_alv100->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = gt_fcat ).
gro_alv100->set_sort_criteria( EXPORTING it_sort = gt_sort ).
gro_alv100->set_filter_criteria( EXPORTING it_filter = gt_filter ).
gro_alv100->refresh_table_display( EXPORTING is_stable = ls_stable i_soft_refresh = abap_false ).
ENDFORM.

Related

Add table rows to a TR programmatically?

I have a problem with adding rows of table to the transport request in programming way.
When i wrote down the transport request number i get the error:
You cannot use request EAMK913244
the code I use is
data lt_variable_changed type table of ztable_task2.
data: l_request type trkorr,
lt_e071 type tr_objects,
lt_e071k type tr_keys,
lv_tabkey type trobj_name,
ls_e071 type e071,
ls_e071k type e071k.
ls_e071-pgmid = 'R3TR'.
ls_e071-object = 'TABU'. "for table
ls_e071-obj_name = 'ZTABLE_TASK2'.
ls_e071-objfunc = 'K'.
append ls_e071 to lt_e071.
loop at lt_variable_changed into ls_variable.
lv_tabkey = ls_variable-num.
ls_e071k-pgmid = 'R3TR'.
ls_e071k-object = 'TABU'.
ls_e071k-objname = 'ZTABLE_TASK2'.
ls_e071k-mastertype = 'TABU'.
ls_e071k-mastername = 'ZTABLE_TASK2'.
ls_e071k-tabkey = lv_tabkey.
append ls_e071k to lt_e071k.
endloop.
call function 'TR_REQUEST_CHOICE'
exporting
iv_suppress_dialog = 'X'
iv_request = var_query
it_e071 = lt_e071
it_e071k = lt_e071k.
message 'Ok' type 'I'.
Screen from se01:
Thanks for help and good luck!
three function modules shall be used to transport changes
call function 'TR_ORDER_CHOICE_CORRECTION'
exporting
iv_category = 'CUST'
importing
ev_order = ev_request
ev_task = ev_task
exceptions
invalid_category = 1
no_correction_selected = 2
others = 3.
call function 'TR_OBJECTS_CHECK'
exporting
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
call function 'TR_OBJECTS_INSERT'
exporting
wi_order = lv_request
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
You can also use object-oriented approach for transporting tables.
This piece creates a customizing request and puts contents of a table in it:
DATA(instance) = cl_adt_cts_management=>create_instance( ).
TRY.
instance->insert_objects_in_wb_request( EXPORTING pgmid = 'R3TR'
object = 'TABU'
obj_name = CONV trobj_name( 'Z_TABLE' )
CHANGING trkorr = l_trkorr ).
CATCH cx_adt_cts_insert_error.
RETURN.
ENDTRY.
This piece uses ADT CTS classes and is very flexible. Despite the name wb_request this method is adaptive and will create workbench or customizing request depending on the objects passed.

Allow free text in ALV Grid cell with dropdown

I have set a dropdown list for an ALV Grid cell. The dropdow works fine, but it allows to enter values from the dropdown value list only. Is it possible to allow free text entry in the cell?
My ABAP code is:
Creating a value list:
DATA: lt_dropdown TYPE lvc_t_dral,
ls_dropdown TYPE lvc_s_dral.
data: ls_taba TYPE dd07v,
lt_taba TYPE STANDARD TABLE OF dd07v,
lt_tabb TYPE STANDARD TABLE OF dd07v.
CALL FUNCTION 'DD_DOMA_GET'
EXPORTING
DOMAIN_NAME = 'ZBC_TRADE_NETWORK'
LANGU = SY-LANGU
WITHTEXT = 'X'
TABLES
DD07V_TAB_A = lt_taba
DD07V_TAB_N = lt_tabb
EXCEPTIONS
ILLEGAL_VALUE = 1
OP_FAILURE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
return.
ENDIF.
loop at lt_taba into ls_taba.
ls_dropdown-handle = '1'.
ls_dropdown-int_value = ls_taba-domvalue_l.
ls_dropdown-value = ls_taba-ddtext.
APPEND ls_dropdown TO lt_dropdown.
endloop.
*method to display the dropdown in ALV
CALL METHOD go_grid->set_drop_down_table
EXPORTING
IT_DROP_DOWN_ALIAS = lt_dropdown.
Fill the field catalogue:
data: ls_fcat type lvc_s_fcat,
lt_fcat type lvc_t_fcat.
field-symbols: <lfs_fcat> type ls_fcat.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = gc_struct_name
changing
ct_fieldcat = lt_fcat
exceptions
others = 1.
loop at lt_fcat assigning <lfs_fcat>.
case <lfs_fcat>-fieldname.
when 'NETWORK'.
<lfs_fcat>-drdn_hndl = '1'.
<lfs_fcat>-drdn_alias = 'X'.
<lfs_fcat>-edit = abap_on.
endcase.
endloop.
Set ALV grid for display
go_grid->set_table_for_first_display(
exporting
i_save = lf_save
i_default = lf_default
is_variant = ls_vari
is_layout = ls_layo
it_toolbar_excluding = lt_excl
changing
it_outtab = <lfs_t_data>
it_fieldcatalog = lt_fcat
exceptions
others = 1
).
No. A drop-down field implies a fixed value set. If you want to have both a value catalog and a text editing facility, use a value help (F4 help) to implement the catalog access.

How to add 'save format' button to ALV screen?

I'm adding double ALV screens on the same form, it works pretty fine, but one of it lacks of necessary button.
CALL METHOD gr_alv->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = ls_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = gt_aufk[]
it_fieldcatalog = lv_fieldcat
it_filter = lt_filter
EXCEPTIONS
OTHERS = 1.
Where should i look at?
It's in the documentation:
If you use parameter I_SAVE, passing a layout structure with
IS_VARIANT is a required step.
You need to tell the ALV the key data for the layouts (program name, and if you have multiple lists per program, an additional handle):
...
CALL METHOD gr_alv->set_table_for_first_display
EXPORTING
i_save = 'A'
is_variant = VALUE disvariant( repid = sy-repid )
...

ALV keep IS_VARIANT after refrest_table_display

I use variant of layout for my ALV_GRID Like that :
FORM display_alv .
DATA: lr_event TYPE REF TO lcl_zcad_0004,
ls_varia TYPE disvariant.
IF gr_alvpl IS NOT BOUND.
PERFORM build_fieldcatalog.
PERFORM alv_clear_std_toolbar.
PERFORM build_alv_table.
IF gv_vmode EQ 'N'.
PERFORM alv_dragdrop.
ENDIF.
CREATE OBJECT gr_alvpl
EXPORTING
i_parent = gc_cnalv.
CREATE OBJECT lr_event.
gs_layou-sel_mode = 'D'.
gs_layou-ctab_fname = 'COLCL'.
gs_layou-cwidth_opt = 'A'.
SET HANDLER: lr_event->handle_toolbar FOR gr_alvpl,
lr_event->handle_ucomm FOR gr_alvpl,
lr_event->double_click FOR gr_alvpl.
IF gv_vmode EQ 'N'.
SET HANDLER: lr_event->on_drag FOR gr_alvpl,
lr_event->on_drop FOR gr_alvpl.
ENDIF.
ls_varia-report = sy-repid.
CALL METHOD gr_alvpl->set_table_for_first_display
EXPORTING
it_toolbar_excluding = gt_exctb
is_layout = gs_layou
i_save = 'A'
is_variant = ls_varia
CHANGING
it_outtab = gt_tbalv
it_fieldcatalog = gt_fldct.
* Calling the interactive toolbar method of ALV
CALL METHOD gr_alvpl->set_toolbar_interactive.
PERFORM maj_titre_alv.
ENDIF.
ENDFORM. " DISPLAY_ALV
As you can see I shall consider a display variant ls_varia, but later when I refresh the table, this display variant is lost!
When I click on certain buttons or triggers certain actions , I do a refresh my table like that :
FORM refresh_alv USING iv_rfalv TYPE xfeld.
DATA: ls_varia TYPE disvariant.
PERFORM build_fieldcatalog.
IF iv_rfalv EQ 'X'.
gr_alvpl->set_frontend_layout( gs_layou ).
CALL METHOD gr_alvpl->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = gt_fldct.
PERFORM maj_titre_alv.
gr_alvpl->get_variant( IMPORTING ES_VARIANT = ls_varia ).
gr_alvpl->set_variant( EXPORTING is_variant = ls_varia
i_save = 'A' ).
CALL METHOD gr_alvpl->refresh_table_display(
* is_stable = ls_stabl
i_soft_refresh = 'X'
).
gr_alvpl->set_variant( is_variant = ls_varia ).
ENDIF.
ENDFORM. " REFRESH_ALV
As you can see I am trying to retrieve the display variant and reallocate to my ALV but nothing , and this is not taken in consideration.
Thanks,
Best regards

How to display list of attachments from Generic Object Services

I have a report that should display an attachment list from an object.
For instance, in transaction FI02 (maintenance of banks), the GOS toolbar has the menu Attachment List:
I want to display this list. What is the best way to display it?
REPORT zay_gos_demo.
DATA ls_appl_object TYPE gos_s_obj.
DATA lo_gos_api TYPE REF TO cl_gos_api.
DATA lt_attachment_list TYPE gos_t_atta.
DATA lt_role_filter TYPE gos_t_rol.
DATA ls_attachment TYPE gos_s_atta.
DATA ls_attachm_cont TYPE gos_s_attcont.
DATA ls_atta_key TYPE gos_s_attkey.
ls_appl_object-typeid = 'KNA1'.
ls_appl_object-instid = '0000000001'.
ls_appl_object-catid = 'BO'. "BO - BOR Object
"CL - Persistent Class
START-OF-SELECTION.
* create instance of GOS API providing unique application object
TRY.
lo_gos_api = cl_gos_api=>create_instance( ls_appl_object ).
* get attachment list for this object (if needed restrict selection
* by adding certain roles to filter table; initial table means: get
* attachments in all roles)
APPEND cl_gos_api=>c_attachment TO lt_role_filter.
APPEND cl_gos_api=>c_annotation TO lt_role_filter.
APPEND cl_gos_api=>c_website TO lt_role_filter.
lt_attachment_list = lo_gos_api->get_atta_list( lt_role_filter ).
CATCH cx_gos_api.
* error handling
ENDTRY.
I found other example and I want to test it:
REPORT zay_attachment_list_display.
DATA: go_attachments TYPE REF TO cl_gos_attachments,
g_att_container TYPE REF TO cl_gui_custom_container,
ls_object TYPE borident,
lo_bitem TYPE REF TO cl_sobl_bor_item.
ls_object-objtype = 'KNA1'.
ls_object-objkey = '0000000001'.
IF NOT go_attachments IS INITIAL.
CLEAR go_attachments.
ENDIF.
CREATE OBJECT g_att_container
EXPORTING
container_name = 'ATTS'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
* ADD your handling
ENDIF.
CREATE OBJECT lo_bitem
EXPORTING
is_bor = ls_object.
IF go_attachments IS INITIAL.
CREATE OBJECT go_attachments
EXPORTING
io_object = lo_bitem
ip_check_arl = 'X'
ip_check_bds = 'X'
io_container = g_att_container
* is_layout = ls_layout
* ip_mode = wf_mode
ip_notes = 'X'
ip_attachments = 'X'
ip_urls = 'X'.
ELSE.
go_attachments->set_container( g_att_container ).
ENDIF.
go_attachments->display( ).
I created a custom control in dynpro 0100 and I named it ATTS. I still can't get the attachment list of GOS. Did I miss something?
After weeks of searching and asking. it was really simple. just call the function GOS_ATTACHMENT_LIST_POPUP.
Example:
DATA: ls_object TYPE sibflporb,
save_request TYPE sgs_flag.
ls_object-instid = 'FR 1234567890'.
ls_object-typeid = 'BUS1011'.
ls_object-catid = 'BO'.
CALL FUNCTION 'GOS_ATTACHMENT_LIST_POPUP'
EXPORTING
is_object = ls_object
ip_mode = 'E' " Edit mode
IMPORTING
ep_save_request = save_request.
IF save_request = 'X'.
COMMIT WORK.
ENDIF.