Good Day Everyone,
There is this something i've been trying to exercise in abap and that is the Displaying of column datas in ALV by retrieving the values from excel file into an internal table. I've been trying to debug my program for quite some time now and i can't seem to solve the error it's been stating which is "Field symbol has not yet been assigned" please guide me. I already made some research on how to solve this short dump error but most of the other issues posted on the net is selected from some specific table with column fields. I was just wondering that maybe my case is a little bit different from others.
The function that retrieved the values from excel is properly working and i have no problem at all in displaying them.Below is the code i constructed.
TYPE-POOLS: truxs,
slis.
TYPES: BEGIN OF t_itab,
col1 TYPE char20,
col2 TYPE char20,
col3 TYPE char20,
col4 TYPE char20,
col5 TYPE char20,
END OF t_itab,
t_it_itab type STANDARD TABLE OF t_itab.
Data: gt_tab TYPE t_it_itab,
wa_tab TYPE t_itab,
g_numrows TYPE i.
PARAMETERS: p_fname TYPE c LENGTH 50.
INITIALIZATION.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_fname.
DATA: l_filename LIKE IBIPPARMS-PATH.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = '1000'
IMPORTING
FILE_NAME = l_filename
.
p_fname = l_filename.
START-OF-SELECTION.
DATA: lc_fname TYPE RLGRAP-FILENAME,
lt_tab TYPE TRUXS_T_TEXT_DATA.
lc_fname = p_fname.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_TAB_RAW_DATA = lt_tab
I_FILENAME = lc_fname
TABLES
I_TAB_CONVERTED_DATA = gt_tab
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
WRITE 'Error'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" Delete First Row / HEADER
DELETE gt_tab INDEX 1.
IF gt_tab[] is INITIAL.
MESSAGE 'No Record(s) found' TYPE 'I'.
EXIT.
ELSE.
PERFORM DisplayALv.
ENDIF.
FORM DISPLAYALV.
DATA: l_it_fcat type SLIS_T_FIELDCAT_ALV,
l_wa_fcat TYPE SLIS_FIELDCAT_ALV.
l_wa_fcat-fieldname = 'col1'.
l_wa_fcat-ref_tabname = 'gt_tab'.
l_wa_fcat-reptext_ddic = 'Column 1'.
l_wa_fcat-outputlen = '30'.
APPEND l_wa_fcat TO l_it_fcat.
CLEAR l_wa_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT = l_it_fcat
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = gt_tab[].
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.
ENDFORM.
Any tips, tricks and advice in my program would be highly sought. Thanks in Advance
You're using a type which is not defined in the data dictionary. This requires a different approach when creating the ALV fieldcat. Try this:
l_wa_fcat-fieldname = 'COL1'.
l_wa_fcat-inttype = 'C'.
l_wa_fcat-outputlen = '30'.
l_wa_fcat-text_fieldname = 'Column 1'.
l_wa_fcat-seltext_s = 'Column 1'.
Also make sure you enter the fieldname value with capitalized letters.
I'm no ABAP expert but I noticed 2 things in the code you posted:
you said the error is "Field symbol has not yet been assigned" but you have no field symbol in your code. Maybe it's used inside one of the function modules you call. If so, try to post the code where the error pops up;
you use gt_tab[] which, if I remember well, is the way to access the body of an internal table with header line. In your code gt_tab is not an internal table with header line, but you use it to store one with function 'TEXT_CONVERT_XLS_TO_SAP' ;
Try to post the code where the error is being generated.
Regards,
Sergiu
Related
I had a problem spliting data in rows, used the solution provided by horseyride in the following link
Splitting rows into separate rows on all columns in Power Query.
Basically I am loocking to separete a row as breaks there are.
Many thanks #horseyride. The solution works in a simular problem. However, it's poping up the following error:
Expression.Error: We cannot convert a value of type Table to type Text.
Details:
Value=[Table]
Type=[Type]
My table is this one:
let
Source = Pdf.Tables(File.Contents("C:\Users\gmall\OneDrive\EF personales\EF\Temporales\IBK_Sueldo_PEN.pdf"), [Implementation="1.3"]),
Table002 = Source{[Id="Table002"]}[Data],
TableTransform = Table.Combine(List.Transform(List.Transform(Table.ToRecords(Source),
(x) => List.Transform(Record.ToList(x),each Text.Split(_,"#(lf)"))),
each Table.FromColumns(_,Table.ColumnNames(Source))))
in
TableTransform
Please let me know how to solve this issue:
Expression.Error: We cannot convert a value of type Table to type Text.
Details:
Value=[Table]
Type=[Type]
You need to use Table002 in step3 since that is the prior step name, not Source, which was the prior step name in my other answer
let
Source = Pdf.Tables(File.Contents("C:\Users\gmall\OneDrive\EF personales\EF\Temporales\IBK_Sueldo_PEN.pdf"), [Implementation="1.3"]),
Table002 = Source{[Id="Table002"]}[Data],
TableTransform = Table.Combine(List.Transform(List.Transform(Table.ToRecords(Table002),
(x) => List.Transform(Record.ToList(x),each Text.Split(_,"#(lf)"))),
each Table.FromColumns(_,Table.ColumnNames(Table002))))
in
TableTransform
I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST
Despite of checking many questions relating error 13, I could not find answers to my problem, so I am giving a shot here:
I am building my code to save information from a userform, but first I am testing to see if mandatory textboxes are empty. Since I am using a 64 bits machine I have used Trevor Eyre´s CalendarForm.
However while testing the code I hit a problem with the empty textboxes that receives the dates from CalendarForms:
In this line:
Dim dteCompraDataOps As Date: dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
This part is highlighted and returns Runtime Error 13:
dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
When I check the values coming from empty TextBoxes I get:
dteCompraDataOps = "00:00:00"`
Which is correct since it should be treated as Date, but this:
Me.txtTesouro_Compra_DataOps.value = ""
Is coming as a string.
I did a little search and noticed that Date data types are tricky when the textbox they come from are empty.
I could find a solution: creating a Select Case to test the mandatory fields before declaring the variables but I would like o learn how to deal with the empty textboxes that are supposed to be empty.
Any chance you can shed some light into my conundrum?
Thanks in advance.
Cub4_RJ
There are two ways to handle this.
a) Check for Null:
With Me.txtTesouro_Compra_DataOps
If Not IsNull(.Value) Then
If IsDate(.Value) Then dteCompraDataOps = . Value
End if
End With
b) Introduce a new variable of Variant type which accepts everything (including nulls) and check it's value.
Dim rawData As variant
rawData = Me.txtTesouro_Compra_DataOps.Value
If Not IsNull(rawData) Then
If IsDate(rawData) Then dteCompraDataOps = rawData
End If
The problem with approach A, is that the value 123 is treated as a date, however option B will catch it.
I need to fill a cell with a data, separated by 'new line' symbol.
I've tried:
data: l_con_sepa TYPE c VALUE cl_abap_char_utilities=>newline.
...
CONCATENATE <gf_aufk>-tplnr " 6000000159 Korchagin AS 02.02.2017
<gf_aufk>-pltxt
l_con_sepa
<gf_aufk>-aufnr
INTO lv_str
SEPARATED BY space.
Tried to use CL_ABAP_CHAR_UTILITIES=>CR_LF. Tried to use "&" and "#" symbols. Tried to wrap lv_str with quotes. Nothing.
I either got symbols as is, or just a blank space insted of 'alt+enter' equivalent.
A simple experiment with Excel, namely creating a cell with Alt+Enter characters and saving it as a CSV file, shows that such a new line symbol is LF and not CR_LF. Moreover it is put there in double quotes.
So just use double quotes and CL_ABAP_CHAR_UTILITIES=>NEWLINE.
It must work with CSV. You did not specify what API you use to export your data to XLS format, so I cannot test it. If you do not mind putting those details in the question, please do so.
Assuming you use FM SAP_CONVERT_TO_XLS_FORMAT, there is even no need for double quotes.
REPORT YYY.
TYPES: BEGIN OF gty_my_type,
col1 TYPE char255,
col2 TYPE char255,
END OF gty_my_type,
gtty_my_type TYPE STANDARD TABLE OF gty_my_type WITH EMPTY KEY.
START-OF-SELECTION.
DATA(gt_string_table) = VALUE gtty_my_type(
(
col1 = 'aaa'
&& cl_abap_char_utilities=>newline
&& 'bbb'
&& cl_abap_char_utilities=>newline
&& 'ccc'
col2 = 'ddd'
)
).
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = 'D:\temp\abap.xlsx'
TABLES
i_tab_sap_data = gt_string_table
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ASSERT sy-subrc = 0.
The result looks like follows
I thought that it might be caused by CONCATENATE .. INTO .. SEPARATED BY space but it is not. Please execute the following program in order to check it out.
REPORT YYY.
TYPES: BEGIN OF gty_my_type,
col1 TYPE char255,
col2 TYPE char255,
END OF gty_my_type,
gtty_my_type TYPE STANDARD TABLE OF gty_my_type WITH EMPTY KEY.
DATA: gs_string TYPE gty_my_type.
DATA: gt_string_table TYPE gtty_my_type.
START-OF-SELECTION.
CONCATENATE 'aaa' cl_abap_char_utilities=>newline 'bbb' cl_abap_char_utilities=>newline 'ccc'
INTO gs_string-col1 SEPARATED BY space.
gs_string-col2 = 'ddd'.
APPEND gs_string TO gt_string_table.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = 'D:\temp\abap.xlsx'
TABLES
i_tab_sap_data = gt_string_table
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ASSERT sy-subrc = 0.
So the problem must be somewhere else. You are not showing us your whole code. Maybe you use some kind of a third party package to process your Excel files?
I don't remember if it's needed to add an "end of line" symbol.
Just append each line into a table and download the full table using FM SAP_CONVERT_TO_XLS_FORMAT.
An Excel table as data source may contain error values (#NA, #DIV/0), which could disturbe later some steps during the transformation process in Power Query.
Depending of the following steps, we may get no output but an error. So how to handle this cases?
I found two standard steps in Power Query to catch them:
Remove errors (UI: Home/Remove Rows/Remove Errors) -> all rows with an error will be removed
Replace error values (UI: Transform/Replace Errors) -> the columns have first to be selected for performing this operations.
The first possibility is not a solution for me, since I want to keep the rows and just replace the error values.
In my case, my data table will change over the time, means the column name may change (e.g. years), or new columns appear. So the second possibility is too static, since I do not want to change the script each time.
So I've tried to get a dynamic way to clean all columns, indepent from the column names (and number of columns). It replaces the errors by a null value.
let
Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
//Remove errors of all columns of the data source. ColumnName doesn't play any role
Cols = Table.ColumnNames(Source),
ColumnListWithParameter = Table.FromColumns({Cols, List.Repeat({""}, List.Count(Cols))}, {"ColName" as text, "ErrorHandling" as text}),
ParameterList = Table.ToRows(ColumnListWithParameter ),
ReplaceErrorSource = Table.ReplaceErrorValues(Source, ParameterList)
in
ReplaceErrorSource
Here the different three queries messages, after I've added two new column (with errors) to the source:
If anybody has another solution to make this kind of data cleaning, please write your post here.
let
src = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
cols = Table.ColumnNames(src),
replace = Table.ReplaceErrorValues(src, List.Transform(cols, each {_, "!"}))
in
replace
Just for novices like me in Power Query
"!" could be any string as substitute for error values. I initially thought it was a wild card.
List.Transform(cols, each {_, "!"}) generates the list of error handling by column for the main funcion:
Table.ReplaceErrorValues(table_with errors, {{col1,error_str1},{col2,error_str2},{},{}, ...,{coln,error_strn}})
Nice elegant solution, Sergei