Can header text in Grid change line - header

I add a Gird column and want to display Data Name and Data Unit in in column header:
grid.addColumn("v1").setWidth("20%").setHeader("Data Name (Data Unit)").setSortable(false);
The text "Data Name (Data Unit)" is displayed in one line.
If I need to display Data Unit in a serperated line, how to modify the code? Following cases are failed:
grid.addColumn("v1").setWidth("20%").setHeader("Data Name \n(Data Unit)").setSortable(false);
grid.addColumn("v1").setWidth("20%").setHeader("Data Name \r(Data Unit)").setSortable(false);
grid.addColumn("v1").setWidth("20%").setHeader("Data Name <br>(Data Unit)").setSortable(false);
grid.addColumn("v1").setWidth("20%").setHeader("Data Name <br/>(Data Unit)").setSortable(false);

You could do something like:
.setHeader(new Html("<span>Data Name <br>(Data Unit)</span>"))

Maybe this help:
Div div = new Div();
div.setText("Data Name\n(Data Unit)");
div.getElement().setAttribute("style", "white-space: pre-wrap;");
grid.addColumn("v1").setWidth("20%").setHeader(div).setSortable(false);

Related

How to assign internal table into a structure and then to a field in ABAP

With the below code I can retrieve the content of the internal table t_t005e, however when put into the field wa_upload-region, only the first column of the data is retrieved, however I want to retrieve the third column data.
TYPES: BEGIN OF ty_upload,
" ...
region TYPE regio,
" ...
END OF ty_upload.
DATA: wa_upload TYPE ty_upload,
t_t005e TYPE STANDARD TABLE OF t005e.
READ TABLE t_t005e
INTO wa_upload-region
WITH KEY land1 = 'GB'
regio = 'YK'
counc = ''.
As a result, I have created a work area wa_t005e, with the same type as the lines of t_t005e.
I want to first read the internal table t_t005e into the work area wa_t005e, then to the field wa_upload-region.
Following is my work in progress:
DATA: wa_t005e TYPE t005e.
LOOP AT t_t005e INTO wa_t005e.
ASSIGN COMPONENT wa_t005e-regio OF STRUCTURE
wa_t005e TO <wa_upload-region>.
ENDLOOP.
How to get the data of wa_t005e-regio into the field wa_upload-region?
There is no way of reading the value of only one column from a table directly into one field of a structure, at least in systems pre-7.40. If you do have a 7.40 system, you can use a "table expression" like this:
TRY.
wa_upload-region = t_t005e[ land1 = 'GB' regio = 'YK' counc = '' ]-regio.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
In older system, you will have to read the whole table line into a structure, then you can just take the field from it, like this:
READ TABLE t_t005e INTO wa_t005e WITH KEY land1 = 'GB' regio = 'YK' counc = ''.
wa_upload-region = wa_t005e-regio.
If you want to use ASSIGN and the like, you can do that too. First you would read the table line into a structure again (in this case a field symbol to stay in theme). Then assign the needed component/field of the structure to a single-value field symbol.
DATA: t_upload TYPE STANDARD TABLE OF ty_upload,
t_t005e TYPE STANDARD TABLE OF t005e.
FIELD-SYMBOLS: <fs_upload> TYPE ty_upload,
<fs_t005e> TYPE t005e,
<region> TYPE regio. " or type any
SELECT *
FROM t005e
INTO CORRESPONDING FIELDS OF TABLE t_t005e.
READ TABLE t_t005e ASSIGNING <fs_t005e> WITH KEY land1 = 'GB' regio = 'YK' counc = ''.
ASSIGN COMPONENT 'REGIO' OF STRUCTURE <fs_t005e> TO <region>. " <---
*Other option: number of column
*ASSIGN COMPONENT 3 OF STRUCTURE <fs_t005e> TO <region>.
APPEND INITIAL LINE TO t_upload ASSIGNING <fs_upload>.
<fs_upload>-region = <region>.
WRITE <fs_upload>-region.
But is reading only one entry from the table really what you want to do? You didn't specify all keys of t005e in the READ statement. It would only select the first line that fits.

Map key-value to structure

I have a key-value internal table and want to fill an existing structure with it.
Example: 1st I get a key-value table that I create by reading data from two existing tables.
SELECT vals~attr_value, names~attr_name
FROM atst_attr AS vals
INNER JOIN tc_attr AS names
ON vals~tc_attr_id = names~tc_attr_id
WHERE vals~atst_id = #lv_atst_id
INTO TABLE #DATA(itab)
.
Now my itab looks like this:
itab:
name value
1. "field_a" "value_a"
2. "field_c" "value_c"
And my local structure (or workingarea as it is often called) is empty:
l_struc:
field_a: ""
field_b: ""
field_c: ""
Now I want to fill the structure, which is where I need help - I want the result to be:
l_struc:
field_a: "value_a"
field_b: ""
field_c: "value_c"
How can I automatically make the mapping from the name property to the name of the structure component happen and setting its value?
something like:
FIELD-SYMBOLS lv_field TYPE ANY.
LOOP AT itab
ASSIGNING FIELD-SYMBOL(<ls_itab>).
ASSIGN COMPONENT <ls_itab>-name
OF STRUCTURE l_struc
TO <lv_field>.
IF sy-subrc EQ 0.
<lv_field> = <ls_itab>-value.
ENDIF.
ENDLOOP.

NetSuite sublist column order (suitescript 2)

Is there any way to add a sublist field via a user event script and define its column position? By default the field is added as the last column. It appears you can move form fields around, but can't change sublist column order.
We can able to edit sublist column postion.
But it can be vary based on your records either transaction or suitlet script or any other things just elaborate your question pls.
// For This Example we create a first Field
var field1 = form.addField({
id : 'textfield1',
type : serverWidget.FieldType.TEXT,
label : 'Text'
});
// For This Example we create a first Field
var field2 = form.addField({
id : 'textfield2',
type : serverWidget.FieldType.TEXT,
label : 'Text'
});
form.insertField({
field : field2,
nextfield : 'textfield1'
});

Change field length afterwards

TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS LIKE VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: wa_test LIKE it_test.
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF wa_test.
IF wa_test-BUKRS = 'xxxx'.
wa_test-BUKRS = 'XXXXX' "Problem occurs here as the BUKRS allow 4 value
APPEND wa_test TO it_test.
ENDIF.
Then I want to map the internal table to output as ALV table. Is they any way to change the field length afterwards?
Apart from multiple issues in your code, you can't. If you need something similar to that, add an additional field to the structure with whatever size you require and copy the values over.
If the objective is to output something to the screen that is different(or differently formatted) that what is stored internally(or in the database), then the use of a data element with a conversion exit maybe the way to go.
For an example, look at the key fields of table PRPS.
Expanding the answer of vwegert:
The MOVE-CORRESPONDINGcommand (and SELECT ... INTO CORRESPONDING FIELDS) don't need the same field type. The content is converted. So you could define a 5-character field in your internal structure and copy the BUKRS-value into this 5-character field:
TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS(5), "longer version of VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: tt_test TYPE STANDARD TABLE OF it_test.
* I would strongly recommend to set a filter!
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF it_test.
IF it_test-BUKRS = 'xxxx'.
it_test-BUKRS = 'XXXXX'.
APPEND it_test to tt_test.
ENDIF.
ENDSELECT.
A pitfall: When you use it with ALV you will loose the field description. (on the other side, the field description of the original field will not fit any longer the new field.)

What is the difference between like and like line of in ABAP?

I have one doubt. May I know what the difference between LIKE and LIKE LINE OF in ABAP is? I have seen somewhere that while declaring the work area they are declaring.
wa LIKE it_one
wa LIKE LINE OF it_one
LIKE LINE OF means that the variable will be of the table line type.
LIKE means that the variable will be exactly of the same type as the one sitting after this key word.
Example
TYPES: BEGIN OF t_my_example_structure,
my_example_field1 TYPE i,
my_example_field2 TYPE n,
END OF t_my_example_structure.
TYPES tt_my_example_structure TYPE STANDARD TABLE OF t_my_example_structure.
DATA: l_tab_my_example TYPE tt_my_example_structure.
* has structure of row of l_tab_my_example so in this case t_my_example_structure.
DATA: l_str_my_example LIKE LINE OF l_tab_my_example.
* is exactly the same table type as l_tab_my_example so in this case tt_my_example_structure.
DATA: l_tab_like_my_example LIKE l_tab_my_example.
* I use it often for LOOP AT <tab> ASSIGNING <fs>.
FIELD-SYMBOLS: <fs_str_my_example> LIKE LINE OF l_tab_my_example.
Well, the difference is when you pass table into subroutine with USING or TABLES.
In 1st case you will get a table without headerline, thus WA_LIKE will be a table too.
In 2nd case IT_DATA will be a table with headerline: this causes IT_DATA actually means IT_DATA as structure or IT_DATA[] as table, depending on context. Particulary, DATA ... LIKE IT_DATA will refer to headerline, and not entire internal table.
You may check this using a debugger:
DATA T_DATA TYPE STRING_TABLE.
PERFORM TEST_01 USING T_DATA.
PERFORM TEST_02 TABLES T_DATA.
FORM TEST_01 USING IT_DATA TYPE STRING_TABLE.
DATA : WA_LIKE LIKE IT_DATA "This is a Table
, WA_LINE LIKE LINE OF IT_DATA.
BREAK-POINT.
ENDFORM.
FORM TEST_02 TABLES IT_DATA TYPE STRING_TABLE.
DATA : WA_LIKE LIKE IT_DATA "This is a String
, WA_LINE LIKE LINE OF IT_DATA.
BREAK-POINT.
ENDFORM.