ABAP CALL TRANSACTION and fill variant field - abap

I used this bit of code the exact same way in a previous program and it worked. Now I am using it to apply to a transaction with a range available for the field I want to fill with the information clicked on the hotspot. It is not placing anything in the field when taken to ME2N view. Any suggestions?
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
IF rs_selfield-fieldname = 'EBELN'.
READ TABLE itab_usr INTO wa_usr INDEX rs_selfield-tabindex.
SET PARAMETER ID 'BES' FIELD wa_usr-ebeln.
CALL TRANSACTION 'ME2N'.
ENDIF.
ENDCASE.
ENDFORM.

What you're doing is basically writing something on the wall and then nudging the next person. It's up to the next person to decide whether they want to read whatever's written on the wall. The parameters area is just a global memory - perhaps the called program will do something about it, but unless it states so in its documentation, you can't rely on that.
In the case of ME2N, you may want to examine the transaction and find out that it simply calls the selection screen of a report, let's say RM06EN00. You may then want to look up the keyword SUBMIT and the relevant documentation about filling the selection screen of a called program.

You can find more information from here.
DATA : WA_FCAT TYPE LVC_S_FCAT,
IT_FCAT TYPE STANDARD TABLE OF LVC_S_FCAT,
OB_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
OB_GRID TYPE REF TO CL_GUI_ALV_GRID,
G_VARIANT LIKE DISVARIANT,
LT_DEMO_DATA TYPE TABLE OF ZDEMO_TABLE.
INITIALIZATION.
START-OF-SELECTION.
" GET DATA .
REFRESH LT_DEMO_DATA.
SELECT * INTO TABLE LT_DEMO_DATA FROM ZDEMO_TABLE.
PERFORM FIELDCAT.
CALL SCREEN 1001.
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO.
ENDCLASS.
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
METHOD HANDLE_HOTSPOT_CLICK .
PERFORM HOTSPOT_CLICK USING E_ROW_ID E_COLUMN_ID.
ENDMETHOD.
ENDCLASS.
FORM HOTSPOT_CLICK USING E_ROW TYPE LVC_S_ROW E_COLUMN_ID TYPE LVC_S_COL.
DATA : WA_DEMO TYPE ZDEMO_TABLE.
READ TABLE LT_DEMO_DATA INTO WA_DEMO INDEX E_ROW-INDEX.
SET PARAMETER ID 'MAT' FIELD WA_DEMO-MATNR.
CALL TRANSACTION 'MB51'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_1001 OUTPUT.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
SET TITLEBAR 'TITLE'.
IF G_VARIANT IS INITIAL.
G_VARIANT-REPORT = SY-REPID.
G_VARIANT-USERNAME = SY-UNAME.
ENDIF.
"Object creation for custom container exporting the name
CREATE OBJECT OB_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = 'ALV_GRID'.
CREATE OBJECT OB_GRID
EXPORTING
I_PARENT = OB_CUSTOM_CONTAINER.
CALL METHOD OB_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_VARIANT = G_VARIANT
I_DEFAULT = 'X'
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FCAT
IT_OUTTAB = LT_DEMO_DATA.
**** For Hotspot Event Handling
DATA: G_HANDLER TYPE REF TO LCL_EVENT_HANDLER.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR OB_GRID.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
ENDFORM.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_1001 INPUT.
IF SY-UCOMM = '&F03' OR SY-UCOMM = '&F12' OR SY-UCOMM = '&F15'.
FREE: OB_GRID.
REFRESH: LT_DEMO_DATA.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.

Related

Cannot create field catalog with REUSE_ALV_FIELDCATALOG_MERGE

I'm new to ABAP, and I'm trying to build a field catalog using the REUSE_ALV_FIELDCATALOG_MERGE function module. This function module exits with sy-subrc value 1 ("Inconsistent interface") and a message dialog appears saying that the field catalog couldn't be build.
My code is the same as the examples found online. Maybe I missed something.
My program consists of a TOP include, a FORMS include and the main module:
FORMS include:
FORM DISPLAY_WITH_ALV_LIST.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'it_report'
I_INCLNAME = sy-repid
CHANGING
CT_FIELDCAT = it_fldcat.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
IT_FIELDCAT = it_fldcat
TABLES
T_OUTTAB = it_report.
ENDFORM.
FORM ZSELECT.
SELECT VBELN ERDAT ERNAM
FROM VBAK
INTO CORRESPONDING FIELDS OF TABLE it_report
WHERE ERDAT IN S_ERDAT
AND ERNAM IN S_ERNAM.
ENDFORM.
TOP include:
TYPE-POOLS: slis.
TABLES VBAK.
DATA: BEGIN OF it_report OCCURS 0,
VBELN LIKE VBAK-VBELN,
ERDAT LIKE VBAK-ERDAT,
ERNAM LIKE VBAK-ERNAM,
END OF it_report.
DATA it_fldcat TYPE slis_t_fieldcat_alv.
Main module:
REPORT ZMLA_EXO1.
INCLUDE ZMLA_EXO1_TOP.
INCLUDE ZMLA_EXO1_SCREEN.
INCLUDE ZMLA_EXO1_FORM.
INITIALIZATION.
AT SELECTION-SCREEN.
START-OF-SELECTION.
PERFORM ZSELECT.
PERFORM DISPLAY_WITH_ALV_LIST.
END-OF-SELECTION.
I would advise using the "SALV" class. It's pretty straight forward, in your case it would look like this:
DATA: go_salv_table TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = go_salv_table
CHANGING
t_table = it_report.
go_salv_table->display( ).
If you still insist on using the function module (FM) REUSE_ALV_FIELDCATALOG_MERGE, and generate field catalog from internal table, then these conditions must be observed:
Your internal table with the data to be displayed has to be declared with the word "OCCURS" (not a must to use addition "WITH HEADER LINE").
Fields of the internal table have to be declared using "LIKE". It will not work if you use "TYPE" to declare the fields.
No line in your program should exceed 72 characters. Otherwise a short dump will be generated with the exception cx_sy_read_src_line_too_long since the FM has to scan your program code looking for the internal table definition.
In short, it's an old FM with a lot of problems.

ALV resfresh working fine in SE80 but not with Z tcode

I'm using this code to refresh my ALV-Grid:
CALL METHOD go_alv->refresh_table_display
EXPORTING
is_stable = is_stable.
go_alv is TYPE REF TO cl_gui_alv_grid.
is_stable is TYPE lvc_s_stbl and set like this:
is_stable-row = 'X'.
is_stable-col = 'X'.
This works with no problems when the Report is started in SE80. But when I open the Report using the T-Code I created for it in SE93, the Grid does get refreshed, but the is_stabale parameter is somehow ignored. As a result, the scroll position is reseted.
I tried playing around with the GUI Options in the TCODE, but it didn't work.
It behaves the same whatever it's started via a report or via a transaction code.
You can check by yourself with this little program, then create a transaction code running this program and check whether the problem still occurs. If not, then check what's different in your code. If you don't find any difference, simplify your code, or recreate a separate program and transaction code, etc., anything which can help you solve the issue.
TABLES sscrfields.
DATA go_alv TYPE REF TO cl_gui_alv_grid.
DATA gt_sflight TYPE TABLE OF sflight.
PARAMETERS dummy.
SELECTION-SCREEN FUNCTION KEY 1.
AT SELECTION-SCREEN OUTPUT.
sscrfields-functxt_01 = 'Refresh'.
IF go_alv IS INITIAL.
CREATE OBJECT go_alv
EXPORTING
i_parent = cl_gui_container=>screen0.
SELECT * FROM sflight INTO TABLE gt_sflight.
go_alv->set_table_for_first_display(
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING it_outtab = gt_sflight ).
ENDIF.
AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'FC01'.
DATA gs_sflight TYPE sflight.
MODIFY gt_sflight FROM gs_sflight TRANSPORTING price currency WHERE price <> 0.
DATA: ls_stbl TYPE lvc_s_stbl.
ls_stbl-col = abap_true.
ls_stbl-row = abap_true.
DATA: l_soft TYPE char01.
l_soft = abap_true. " do not recalculate totals
go_alv->refresh_table_display(
EXPORTING
is_stable = ls_stbl
i_soft_refresh = l_soft " default = false
EXCEPTIONS
finished = 1 ).
ENDIF.
AT SELECTION-SCREEN ON EXIT-COMMAND.
go_alv->free( ).
FREE go_alv.

EKPO fields not updated after PROCESS_ITEM method set_data in ME21N

I'm trying to change field WEORA and BSTAE in ME21n through BADI me_process_po_cust, method PROCESS_ITEM. I have successfully changed the value in the screen, BUT when I saved the PO, table EKPO is not updated with the new value. Am I missing something? Do I need to commit?
DATA: ls_mepoitem_set TYPE mepoitem.
DATA: cl_po TYPE REF TO cl_po_header_handle_mm.
DATA: ls_mepoitem TYPE mepoitem.
FIELD-SYMBOLS: <fs_item> TYPE mepoitem.
ls_mepoitem = im_item->get_data( ).
ls_mepoitem_set = ls_mepoitem.
ls_mepoitem_set-bstae = '0004'.
ls_mepoitem_set-weora = abap_true.
ASSIGN ls_mepoitem_set TO <fs_item>.
CALL METHOD im_item->set_data( EXPORTING im_data = <fs_item> ).
cl_po ?= lm_poheader.
IF NOT cl_po->my_recheck_queue IS INITIAL.
CLEAR cl_po->my_recheck_queue.
ENDIF.
Please check if there is project enhancement implentation for PO which might be updating field values.
regards,
Umar Abdullha
I had the same mistake and I was able to resolve it by using the same code shown before in IF_EX_ME_PROCESS_PO_CUST->PROCESS_ITEM.
I had to call im_item->get_data( ) to get the data from the position and the set method work perfectly.

Crash "Field symbol has not yet been assigned" when calling REUSE_ALV_GRID_DISPLAY

While displaying an ALV I get a crash report when executing the program. To create an ALV I have followed a few tutorials and stuff and at the moment it looks like this:
TYPE-POOLS: slis.
*build field catalog
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
repid TYPE sy-repid.
REFRESH it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-reptext_ddic = 'Table ID'.
wa_fieldcat-fieldname = 'table_id'.
wa_fieldcat-tabname = 'lt_where_used_data_of_coll'.
wa_fieldcat-outputlen = '18'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-reptext_ddic = 'Table Description'.
wa_fieldcat-fieldname = 'table_description'.
wa_fieldcat-tabname = 'lt_where_used_data_of_coll'.
wa_fieldcat-outputlen = '40'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-reptext_ddic = 'Numer of Records Found'.
wa_fieldcat-fieldname = 'nr_of_records'.
wa_fieldcat-tabname = 'lt_where_used_data_of_coll'.
wa_fieldcat-outputlen = '30'.
APPEND wa_fieldcat TO it_fieldcat.
*pass data and field catalog to ALV function module
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repid
it_fieldcat = it_fieldcat
i_structure_name = 'lty_where_used_data_of_coll'
TABLES
t_outtab = lt_where_used_data_of_coll.
'lt_where_used_data_of_coll' is my local table that I have already filled with a working function earlier in my program. This function works and I have tested it and the table fills itself with data. My next step was displaying this data to the end user. The error report I receive when executing this program is:
Short text: Field symbol has not yet been assigned.
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 access an unassigned field symbol
(data segment "-1").
Trigger Location of Runtime Error:
Program SAPLSLVC
Include LSLVCF36
Row 3,273
Module type (FORM)
Module Name FILL_DATA_TABLE
I really don't know how to start finding my mistake. It seems like it runs bad when calling a function from ABAP itself.
Any help is much appreciated.
EDIT: As was suggested I implemented another way of displaying an ALV that can be found below. This way works fine and gives no errors. Question still remains why the older method does give me an error.
I replaced the entire block of code above with this:
DATA alv TYPE REF TO cl_salv_table. DATA message TYPE REF TO cx_salv_msg.
*initialize ALV
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = alv
CHANGING
t_table = lt_where_used_data_of_coll ).
CATCH cx_salv_msg INTO message.
" error handling
ENDTRY.
*display ALV
alv->display( ).
why the older method does give me an error
Field catalog names are case sensitive. Capitalize every fieldname and tabname value and see if the error's still there. Also make sure that the names match those of your internal table lt_where_used_data_of_coll

Alv OO program error Message no. 0K534

Everytime i hit enter or any command button the program prompt an error message.
base on this thread http://scn.sap.com/thread/65856 i should declare my internal table
globally on top include.
Even though i already added all variable globally still the error is the same.
Top Include.
data: gr_data type ref to data.
data: la_data type ref to data.
field-symbols: <gt_data> type standard table.
Classs Declaration
me->get_data( CHANGING c_data = <f_tab> ). " Fetch Dynamic Data
METHOD get_data.
GET REFERENCE OF c_data INTO la_data.
move la_data TO gr_data.
assign gr_data->* to <gt_data>.
me->display( ).
assign gr_data->* to <gt_data>.
IF gc_custom_container is initial.
CREATE OBJECT gc_custom_container
EXPORTING
container_name = gv_mycontainer.
ENDIF.
if table is not bound.
try.
"// Create ALV Instance
cl_salv_table=>factory(
exporting
r_container = gc_custom_container
container_name = 'TC_MIXING'
importing
r_salv_table = table
changing
t_table = <gt_data>
).
catch cx_salv_msg. "#EC NO_HANDLER
endtry.
"// Setup ALV Attributes
functions = table->get_functions( ).
functions->set_all( abap_true ).
columns = table->get_columns( ).
columns->set_optimize( abap_true ).
try.
column = columns->get_column( 'MANDT' ).
column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found.
endtry.
"// Dispalay ALV Model
table->display( ).
else.
table->refresh( ).
endif.
ENDMETHOD.
and another question:
how to create structure dynamically base on field-symbol. is this possible?
ls_testvar like line of <f_tab>.
thanks and regards,
Mapet
Question two is possible, with some usage of runtime type services.
Take a look at runtime type services.
se24
CL_ABAP_CLASSDESCR Run Time Type Services
CL_ABAP_DATADESCR Run Time Type Services
CL_ABAP_ELEMDESCR Run Time Type Services
CL_ABAP_INTFDESCR Run Time Type Services
CL_ABAP_OBJECTDESCR Run Time Type Services
CL_ABAP_REFDESCR Run Time Type Services
CL_ABAP_STRUCTDESCR Run Time Type Services
CL_ABAP_TABLEDESCR Run Time Type Services
CL_ABAP_TYPEDESCR Run Time Type Services
You can get the type of the fieldsymbol and create a structure based on it, perhaps You have to iterate through fieldsymbol, if it is composed type and add each component.
I agree, you should not pass a field symbol to the changing parameter for the table data! Use a global or static table. You should also use a typed table instead of data and create your field catalog in design time. This improves the performance a lot.
Cheers
Your table variable holding the ALV must be declared globally as well.
cl_salv_table=>factory(
exporting
r_container = gc_custom_container
container_name = 'TC_MIXING'
importing
r_salv_table = table
changing
t_table = <gt_data>
).
You should separate data retrieving from your displaying code like this:
START-OF-SELECTION.
gr_class->get_data( ).
CALL SCREEN 2000.
PBO:
gr_class->display.
Your display method:
METHOD display IMPLEMENTATION.
IF me->gr_container IS NOT BOUND.
gr_table->display( ).
ELSE.
gr_table->refresh( ).
ENDIF.