Alv OO program error Message no. 0K534 - abap

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.

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.

Checking if a report uses hierarchical ALV or not. How?

I found a way to export a hierarchical ALV with the help of this question. Unfortunately I don't know in advanced if the report uses hierarchical ALV or not.
If I apply the code of above answer to the report RFSKPL00, then I get an exception in cl_salv_bs_runtime_info=>get_data() here:
if t_data_line is requested.
import t_data_line to t_data_line from memory id cl_salv_bs_runtime_info=>c_memid_data_line.
if sy-subrc ne 0.
raise exception type cx_salv_bs_sc_runtime_info <=========
exporting
textid = 'ERROR'.
endif.
endif.
How can I check in ABAP if a report uses hierarchical ALV or not?
You can use TRY / CATCH / ENDTRY to prevent dumps based on catchable class based exceptions:
DATA lx_runtime_info TYPE REF TO cx_salv_bs_sc_runtime_info.
TRY.
cl_salv_bs_runtime_info=>get_data(
IMPORTING
t_data = <lt_data>
t_data_line = <lt_data_line>
).
CATCH cx_salv_bs_sc_runtime_info INTO lx_runtime_info.
DATA(lv_result) = lx_runtime_info->if_message~get_text( ).
DATA(lv_result_long) = lx_runtime_info->if_message~get_longtext( ).
ENDTRY.
(ST22 will always tell you which exception class you have to use.)
As all exception classes are subclasses (sub-subclasses, sub-sub-subclasses, etc.) of CX_ROOT, so you can use the methods get_text and get_longtext to get more information (implemented through interface if_message) about the problem.
To determine whether the ALV is a classic ALV or a hierarchical-sequential list :
IF cl_salv_bs_runtime_info=>get( )-structure_line IS INITIAL.
"---------------------
" classic ALV
"---------------------
cl_salv_bs_runtime_info=>get_data_ref(
IMPORTING r_data = DATA(lr_data) ).
ELSE.
"---------------------
" hierarchical-sequential list
"---------------------
cl_salv_bs_runtime_info=>get_data_ref(
IMPORTING r_data = lr_data
r_data_line = DATA(lr_data_line) ).
ENDIF.
I wanted the same information and the answer by Sandra didn't help me/didn't work, because the parameters just wouldn't fill. But cl_salv_bs_runtime_info has another function that solved my problem, get_metadata. It has a parameter is_hierseq that gets filled as expected.
DATA: lr_data TYPE REF TO data,
lr_data_line TYPE REF TO data.
FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE,
<lt_data_line> TYPE ANY TABLE.
" initialising runtime analysis
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_true
data = abap_true ).
* ALV grid / hierarchical output:
CALL TRANSACTION 'MB51'.
* Testing output mode using metadata
DATA(runtime_metadata) = cl_salv_bs_runtime_info=>get_metadata( ).
IF runtime_metadata-is_hierseq IS INITIAL.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data_descr = DATA(lr_data_descr) ).
CREATE DATA lr_data TYPE HANDLE lr_data_descr.
ASSIGN lr_data->* TO <lt_data>.
cl_salv_bs_runtime_info=>get_data( IMPORTING t_data = <lt_data> ).
ELSE. " hierarchical
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data_descr = lr_data_descr
r_data_line_descr = DATA(lr_data_line_descr) ).
CREATE DATA lr_data TYPE HANDLE lr_data_descr.
CREATE DATA lr_data_line TYPE HANDLE lr_data_line_descr.
ASSIGN lr_data->* TO <lt_data>.
ASSIGN lr_data_line->* TO <lt_data_line>.
cl_salv_bs_runtime_info=>get_data( IMPORTING t_data = <lt_data>
t_data_line = <lt_data_line> ).
ENDIF.
In the case of a simple SALV grid <lt_data> var contains the output, and in the case of a hierarchical ALV list the result will be in <lt_data_line> instead.

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

Function module to export local table to excel

I am working on a program in Business Warehouse that allows you to map out all of your process chains by following the hierarchy of parent to sub-chains by using the rspcchain table. As of right now I have it printing the output to the screen, but would like to export this output to excel instead. I have been unable to find a function module that serves this purpose, so any help would be greatly appreciated
note - after learning about the SALV classes available I changed the code to display the table differently.
REPORT Z_PC_VARIANT_MAPPING.
*Declaring types and variables
TYPES: BEGIN OF t_chains,
chain_id LIKE rspcchain-chain_id,
variant LIKE rspcchain-variante,
END OF t_chains.
DATA: lt_rspcchain TYPE STANDARD TABLE OF t_chains,
lwa_rspcchain TYPE t_chains,
o_alv TYPE REF TO cl_salv_table,
lx_msg TYPE REF TO cx_salv_msg.
TABLES: rspcchain.
*selection screen setup
SELECT-OPTIONS chain_id FOR rspcchain-chain_id.
SELECT-OPTIONS type FOR rspcchain-type.
*filling local table
SELECT chain_id variante
FROM rspcchain INTO TABLE lt_rspcchain
WHERE chain_id IN chain_id AND
type IN type AND
objvers = 'A'.
*original code to test printing output on screen
*LOOP AT lt_rspcchain INTO lwa_rspcchain.
* skip.
* WRITE lwa_rspcchain-chain_id.
* WRITE lwa_rspcchain-variant.
*ENDLOOP.
IF sy-subrc NE 0. "sy-subrc = return code
WRITE 'Data not found'.
ENDIF.
*loading data from local table into alv object table
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = lt_rspcchain ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
*calling display method to display table
o_alv->display( ).
You can use the SALV framework for this, it comes with a class to export whatever would be displayed to various formats, including .MHTML and .XML formats that are understood by Excel. The class CL_SALV_TABLE has a method TO_XML to support this; additionally, you might need the CL_SALV_BS_XML_UTILS to handle the transformations. See the report SALV_TEST_TABLE_DISPLAY_OR_XML for example coding.
You should look at the ABAP2XLSX project.
http://wiki.sdn.sap.com/wiki/display/ABAP/abap2xlsx
Not sure if all the necessary components exist in BW, but this is really the best solution for creating spreadsheets out of ABAP code that I have found.
You can try the following which will download a CSV file, which with the .xls extension opens flawlessly in Excel:
Convert lt_rspcchain to a csv internal table by calling SAP_CONVERT_TO_CSV_FORMAT
Figure out where the user wants to store the file by calling cl_gui_frontend_services=>file_save_dialog( )
Store the file by calling cl_gui_frontend_services=>gui_download( )
I assume you will be able to find how these work by experience or through Google.