Why is the result of `cl_gui_textedit->get_textstream` empty? - abap

I'm using the ABAP standard class cl_gui_textedit to read text from a textarea on my selection screen. But the result after calling the method get_textstream on the instance is empty.
Minimal working example:
REPORT z_mwe_textarea_bug.
DATA lr_edit TYPE REF TO cl_gui_textedit.
DATA lr_docker TYPE REF TO cl_gui_docking_container.
PARAMETERS p_dummy TYPE string DEFAULT 'just for testing'. ""// <--- need this to show selection screen.
INITIALIZATION.
CREATE OBJECT lr_docker
EXPORTING
ratio = 60.
CREATE OBJECT lr_edit
EXPORTING
parent = lr_docker.
lr_docker->dock_at( EXPORTING side = cl_gui_docking_container=>dock_at_left ).
START-OF-SELECTION.
DATA lv_text_from_textarea TYPE string.
lr_edit->get_textstream( IMPORTING text = lv_text_from_textarea ). ""// <-- why is lv_text_from_textarea empty??

You (or I, answering my own question) have to call cl_gui_cfw=>flush( ) afterwards. Like this:
lr_edit->get_textstream( IMPORTING text = lv_text_from_textarea ). ""// <-- lv_text_from_textarea still empty
cl_gui_cfw=>flush( ). ""//<-- now it's not empty anymore.
Disclaimer: Found the answer on abapforum.de but removed all the useless (and german) discussions and added a minimal working example to my question.

Related

No data returned from class method to PBO

I want to return record of table from abap method, which is field of class
but nothing is returned to the variable in PBO
definition in class
data MS_ZORK_JG_SETTING type ZORK_JG_SETTING .
methods GET_MS_ZORK_JG_SETTING
returning
value(MS_ZORK_JG_SETTING) type ZORK_JG_SETTING .
MS_ZORK_JG_SETTING is a data type which contains data from ZORK_JG_SETTING transparent table, filled properly using other method, so there is a correct data in this variable
in pbo of the screen i wanted to assign returned value to variable of the same type as returned
MODULE pbo_0102 OUTPUT.
DATA: wa_jg_setting TYPE zork_jg_setting.
wa_jg_setting = go_bukrs_conf->get_ms_zork_jg_setting( ).
MOVE-CORRESPONDING wa_jg_setting TO zork_jg_setting.
ENDMODULE.
But wa_jg_setting is empty. Tell me why and how to repair that?
Place of invoking screen
DATA: go_bukrs_conf TYPE REF TO zork_cl_scr_bukrs_conf.
CREATE OBJECT go_bukrs_conf
EXPORTING
pa_bukrs = '3020'.
CALL SCREEN 102.
And get_ms_zork_jg_settings method. I am assigning a value of field to a formal parameter
method GET_MS_ZORK_JG_SETTING.
ms_zork_jg_setting = ms_zork_jg_setting."zwracana wartosc to pole/ atrybut
endmethod.
The line
ms_zork_jg_setting = ms_zork_jg_setting.
is useless, as you assign the value of the return parameter to itself.
Generally speaking, var = var is always non-sense.
Probably you want to do:
ms_zork_jg_setting = me->ms_zork_jg_setting.

How to add old HR INCLUDE into local class?

So I need to use the INCLUDES rpcblo00 and rpcbdt00 to get the type of infotype change (create, update, delete). Beforehand I used a subroutine that had no problem with the includes, but I cannot get them into a class for the life of me.
If I try to put the include into the method as described here (it's even about the same HR include), I get the following error (because of the minus in lo-key):
Syntax error: Names may only consist of the characters "A-Z", "0-9"
and "_". In addition, they may not begin with a number.
minimal reproducible example:
CLASS lcl_infotypaenderungen DEFINITION.
PUBLIC SECTION.
TYPES: tty_aenderungs_operationen TYPE STANDARD TABLE OF pc403.
METHODS:
constructor
IMPORTING is_aenderungs_kopf TYPE pldoc_key,
get_aenderungs_operationen
RETURNING value(rt_aenderungs_operationen) TYPE tty_aenderungs_operationen.
PRIVATE SECTION.
DATA: s_aenderungs_kopf TYPE pldoc_key,
t_aenderungs_operationen TYPE tty_aenderungs_operationen.
METHODS:
select_aenderungs_operationen.
ENDCLASS. "lcl_infotypaenderungen DEFINITION
*----------------------------------------------------------------------*
TYPE-POOLS: abap.
DATA: lo_infotypaenderungen TYPE REF TO lcl_infotypaenderungen,
lv_fehler TYPE sy-subrc,
lt_log_kopf TYPE pldoc_key_tab WITH HEADER LINE,
lt_log_felder TYPE TABLE OF hrinftylog_fields,
lt_infotyp_vorher TYPE prelp_tab,
lt_infotyp_nachher TYPE prelp_tab,
lt_aenderungs_operationen TYPE STANDARD TABLE OF pc403.
FIELD-SYMBOLS: <log_kopfzeile> TYPE pldoc_key.
*----------------------------------------------------------------------*
CALL FUNCTION 'HR_INFOTYPE_LOG_GET_LIST'
EXPORTING
tclas = 'A'
begda = '20190315'
endda = '20190315'
IMPORTING
subrc = lv_fehler
TABLES
infty_logg_key_tab = lt_log_kopf.
CLEAR lv_fehler.
SORT lt_log_kopf DESCENDING BY infty bdate btime pernr.
LOOP AT lt_log_kopf ASSIGNING <log_kopfzeile>.
CALL FUNCTION 'HR_INFOTYPE_LOG_GET_DETAIL'
EXPORTING
logged_infotype = <log_kopfzeile>
IMPORTING
subrc = lv_fehler
TABLES
infty_tab_before = lt_infotyp_vorher
infty_tab_after = lt_infotyp_nachher
fields = lt_log_felder.
CREATE OBJECT lo_infotypaenderungen
EXPORTING
is_aenderungs_kopf = <log_kopfzeile>.
REFRESH lt_aenderungs_operationen.
lt_aenderungs_operationen = lo_infotypaenderungen->get_aenderungs_operationen( ).
ENDLOOP.
*----------------------------------------------------------------------*
CLASS lcl_infotypaenderungen IMPLEMENTATION.
METHOD constructor.
me->s_aenderungs_kopf = is_aenderungs_kopf.
me->select_aenderungs_operationen( ).
ENDMETHOD. "constructor
METHOD select_aenderungs_operationen.
INCLUDE rpcblo00. """ <---
INCLUDE rpcbdt00. """ <---
lo-key-tclas = me->s_aenderungs_kopf-tclas.
lo-key-pernr = me->s_aenderungs_kopf-pernr.
lo-key-infty = me->s_aenderungs_kopf-infty.
lo-key-bdate = me->s_aenderungs_kopf-bdate.
lo-key-btime = me->s_aenderungs_kopf-btime.
lo-key-seqnr = me->s_aenderungs_kopf-seqnr.
IMPORT header TO me->t_aenderungs_operationen FROM DATABASE pcl4(la) ID lo-key.
ENDMETHOD. "select_aenderungs_operationen
METHOD get_aenderungs_operationen.
rt_aenderungs_operationen = me->t_aenderungs_operationen.
ENDMETHOD. "get_aenderungs_operationen
ENDCLASS. "lcl_infotypaenderungen IMPLEMENTATION
Anyone know a good solution? Thanks in advance
Edit: The includes have some declarations and a makro reading from a data cluster. Of course I could just put those directly into the method, but I would like to avoid that (for now I did that).
Alternatively, does someone know of a different way to get the change operation per infotype line?
If you use your class as a local one then the only way to use these includes is to put them at the very beginning of the program. The downside is of course that the variables there become global but unfortunately there is no other way to do that and for sure not if you want to use a global class after all (not sure if your minimal working example is just simplified to use a local class instead of global or not).
REPORT ZZZ.
INCLUDE rpcblo00. """ <---
INCLUDE rpcbdt00. """ <---
CLASS lcl_infotypaenderungen DEFINITION.
" ...
Thanks to Jagger I can make it work with a local class, but in case anyone later wonders how you need to change the include code to be able to use it in a global method, you basically just need to get rid of INCLUDE STRUCTURE declarations and exchange tables with a header line.
So
DATA BEGIN OF LO-KEY.
INCLUDE STRUCTURE PC400.
DATA END OF LO-KEY.
becomes
DATA: lo_key TYPE pc400.
And
DATA BEGIN OF BELEGE_00 OCCURS 100.
DATA:
SPLKZ(01) TYPE X,
FIELD(10) TYPE C,
FTYPE(04) TYPE C,
FLENG(03) TYPE N,
DECIM(02) TYPE N,
OLDDT(50) TYPE C,
NEWDT(50) TYPE C.
DATA END OF BELEGE_00.
becomes
TYPES: BEGIN OF ty_belege,
splkz(01) TYPE x,
field(10) TYPE c,
ftype(04) TYPE c,
fleng(03) TYPE n,
decim(02) TYPE n,
olddt(50) TYPE c,
newdt(50) TYPE c,
END OF ty_belege.
DATA: belege_00 TYPE STANDARD TABLE OF ty_belege.
The macro can stay the same (or I guess you could rewrite it).

Refresh ALV grid after deleting a row

So after I deleted a specific row in a database Table, it isn't removed on my screen. I have to end the programm and start it again to see the changes.
I've used alv->refresh( ). but this does not work for me. Is there a way to refresh the screen properly?
the refresh method has to have an importing parameter called is_stable. This structure has two fields (rwo and col) set both to 'X':
alv->refresh( is_stable = 'XX' ).
If the answer above doesn't work, you can use this method, it gets current ALV from global memory.
METHOD refresh_alv.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid, valid TYPE c.
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
ref_grid->check_changed_data(
IMPORTING
e_valid = valid ).
ENDIF.
IF valid IS NOT INITIAL.
ref_grid->refresh_table_display( ) .
ENDIF.
ENDMETHOD.

Single-line method calls with untyped parameters

Can I define an ABAP method where the RETURNING parameter and any IMPORTING parameters have a generic type but that can still be called in a single line as a functional method?
In other words I'd like to replace this:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_external_value
IMPORTING
output = lv_internal_value.
With:
lv_internal_value= zcl_conversion=>alpha_input( lv_external_value ).
Unfortunately the fact that Class Methods can't have an untyped returning parameter is preventing me from declaring the functional method's return value as type ANY or CLIKE. The accepted standard of creating generic method parameters seems to be to define them as TYPE REF TO DATA and dereference/assign them. But as far as I know that prevents me from calling the method in a single statement as I have to first assign the importing parameter and then dereference the returning parameter, resulting in the same or more lines of code than a simple FM call.
Is there a way around this?
Unfortunately, there is no other way to dereference data than to use the dereference operator, either in the form ->* for the full value segment, or in the form ->comp, if the data object is structured and has a component named comp (and, even worse, there are a lot of places in ABAP code where you would like to use a value from a derefenced data object but can't do it for internal reasons / syntax restrictions).
However, you could simply keep the data reference object retrieved by your method in a variable of the calling code and work with that variable (instead of using a field symbol or a variable for the derefenced value segment itself). Either generically, as a ref to data variable, or typed, using the CAST operator (new ABAP syntax).
Most things that can be done with a field-symbol, can also be done directly with a data reference as well.
Example: Working with a variable result of the expected return type:
data(result) = cast t000( cl=>m( ) ).
write result->mandt.
See here the full example:
report zz_new_syntax.
class cl definition.
public section.
class-methods m returning value(s) type ref to data.
endclass.
start-of-selection.
data(result) = cast t000( cl=>m( ) ).
write: / result->mandt. " Writes '123'.
class cl implementation.
method m.
s = new t000( mandt = '123' ).
endmethod.
endclass.
On ABAP NW Stack 7.4 you could just use parameters type STRING and then use the new CONV Operator to convert your actual input in string. Little ugly but should work.
lv_internal_value = CONV #(zcl_conversion=>alpha_input( CONV #(lv_external_value) )).

How do i get all ui elements of a view? (Web Dynpro ABAP)

I want to make the labels of an input field invisible when the input field is invisible.
I cant bind it to the same context because they are build dynamically.
Is there a way to get all view elements so i can loop over them and make the label invisible dynamically?
Here's some example action handler code which finds the label MYLABEL inside a container and hides it. It doesn't completely cover your use case, but I think it will get you started.
data view type ref to cl_wdr_view.
view ?= wd_this->wd_get_api( ).
data container type ref to cl_wd_uielement_container.
container ?= view->root_element.
data children type cl_wd_uielement=>tt_uielement.
children = container->get_children( ).
data element type ref to cl_wd_uielement.
loop at children into element.
data id type string.
id = element->get_id( ).
if id = `MYLABEL`.
element->set_visible( `01` ).
endif.
endloop.
Each view controller contains the method WDDOMODIFYVIEW with an initially empty implementation. Inside this method you have access to the whole UI element hierarcy and should be able to retrieve references to both the label and the input field and hide the lable in case the input field is hidden.
First, write a second program that will be responsible for calling your program using the SUBMIT ABAP instruction with the EXPORTING LIST TO MEMORY addition.
When you run this caller program it will call your program using the SUBIT, but instead of generating output on screen, system will send the output to system memory.
Later, in webdynpro or in any other program, you can call ABAP function LIST_FROM_MEMORY to retrieve your program's earlier output to an internal table.
Cheers!