Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using field symbols to access a table control

Former Member
0 Kudos

Hi expert:

We need to access a table control (in trx BP, identification tab). We are programing an event (FCODE, enter key) with a module pool where we have to access the table control.

The code we are using:

TYPES: BEGIN OF i_tablecontrol_line.

INCLUDE STRUCTURE DFKKBPTAXNUM.

TYPES: END OF i_tablecontrol_line.

DATA: l_tabla(34),

i_tc type standard table of i_tablecontrol_line.

FIELD-SYMBOLS

<i_tc> TYPE ANY." TABLE.

l_tabla = '(SAPLBUPA_BUTX_DIALOG)DFKKBPTAXNUM'.

"SAPLBUPA_BUTX_DIALOG is the program

"DFKKBPTAXNUM is the table control

ASSIGN (l_tabla) TO <i_tc>.

i_tc[] = <i_tc>.

In this point <i_tc> shows the structure but only the header and it's empty.

During debugging (SAPLBUPA_BUTX_DIALOG)DFKKBPTAXNUM isn't unknown. Neither (SAPLBUPA_BUTX_DIALOG)DFKKBPTAXNUM-TAXTYPE (the field we need) or

(SAPLBUPA_BUTX_DIALOG)DFKKBPTAXNUM-TAXTYPE(01). But as said before they are empty even when data has been provided in the trx's dympro.

Ty

4 REPLIES 4

Former Member
0 Kudos

hi

good

Using a Field Symbol

To assign the contents of the current loop line to a field symbol, specify <result> as follows:

LOOP AT <itab> ASSIGNING <FS> <conditions>.

In each loop pass, the field symbol <FS> points to the table entry read in that pass. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.

The end of the loop does not affect the field symbol, that is, after ENDLOOP it is still assigned to the same line as in the final loop pass. If no table entries are processed in the loop, because the table is entry, or no line meets the condition <condition>, the field symbol is not changed.

For further information about assigning table lines to field symbols, refer to Access Using Field Symbols.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm

-


some part of the code where use the field-symbol to access the table control just go through this hope this ll help you

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <TABLE> LINES <TC>-LINES.

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

IF <MARK_FIELD> = 'X'.

DELETE <TABLE> INDEX SYST-TABIX.

IF SY-SUBRC = 0.

<TC>-LINES = <TC>-LINES - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " FCODE_DELETE_ROW

&----


*& Form COMPUTE_SCROLLING_IN_TC

&----


  • text

----


  • -->P_TC_NAME name of tablecontrol

  • -->P_OK ok code

----


FORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME

P_OK.

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_TC_NEW_TOP_LINE TYPE I.

DATA L_TC_NAME LIKE FELD-NAME.

DATA L_TC_LINES_NAME LIKE FELD-NAME.

DATA L_TC_FIELD_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <LINES> TYPE I.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.

ASSIGN (L_TC_LINES_NAME) TO <LINES>.

*&SPWIZARD: is no line filled? *

IF <TC>-LINES = 0.

*&SPWIZARD: yes, ... *

L_TC_NEW_TOP_LINE = 1.

ELSE.

*&SPWIZARD: no, ... *

CALL FUNCTION 'SCROLLING_IN_TABLE'

EXPORTING

ENTRY_ACT = <TC>-TOP_LINE

ENTRY_FROM = 1

ENTRY_TO = <TC>-LINES

LAST_PAGE_FULL = 'X'

LOOPS = <LINES>

OK_CODE = P_OK

OVERLAPPING = 'X'

IMPORTING

ENTRY_NEW = L_TC_NEW_TOP_LINE

EXCEPTIONS

  • NO_ENTRY_OR_PAGE_ACT = 01

  • NO_ENTRY_TO = 02

  • NO_OK_CODE_OR_PAGE_GO = 03

OTHERS = 0.

ENDIF.

*&SPWIZARD: get actual tc and column *

GET CURSOR FIELD L_TC_FIELD_NAME

AREA L_TC_NAME.

IF SYST-SUBRC = 0.

IF L_TC_NAME = P_TC_NAME.

*&SPWIZARD: et actual column *

SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.

ENDIF.

ENDIF.

*&SPWIZARD: set the new top line *

<TC>-TOP_LINE = L_TC_NEW_TOP_LINE.

ENDFORM. " COMPUTE_SCROLLING_IN_TC

&----


*& Form FCODE_TC_MARK_LINES

&----


  • marks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM FCODE_TC_MARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME.

&SPWIZARD: EGIN OF LOCAL DATA----


DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: mark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = 'X'.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

&----


*& Form FCODE_TC_DEMARK_LINES

&----


  • demarks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: demark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = SPACE.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

thanks

mrutyun^

0 Kudos

Thank you.

Your answer result to be quite helpful. I'd some problems to determine the name of the table control and it's table (i'm quite fish : ( )

I've tried to give you 10 points but the site gives me an error. I'll try few more times...

Tyvm again

Former Member
0 Kudos

Perhaps the table has been declared WITH HEADER LINE ??

0 Kudos

It's done. Here is the code if someone needs it in the future:

FIELD-SYMBOLS <TC> TYPE ANY.
FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.
FIELD-SYMBOLS <WA>.
FIELD-SYMBOLS <MARK_FIELD>.
FIELD-SYMBOLS <MARK_FIELD2>.
FIELD-SYMBOLS <CAMPO_BUSQ1>.

*Name of the table control (TC). I found it looking into the standar trx's code.
DATA: nombre_tablecontrol(50).
nombre_tablecontrol = '(SAPLBUPA_BUTX_DIALOG)TCTRL_BPTAX'.
ASSIGN (nombre_tablecontrol) TO <TC>.

*Same for the table with the values of the TC. Also in the standar
DATA: nombre_tabla(50).
nombre_tabla = '(SAPLBUPA_BUTX_DIALOG)GT_BPTAX[]'. "Beware []
ASSIGN (nombre_tabla) TO <TABLE>.

*The field into the TC we need.
DATA: campo_busqueda(50).
campo_busqueda = '(SAPLBUD0)BUS000FLDS-BU_SORT1_TXT'.

*I think next is easy to understand. Important how to get the fields.ASSIGN 
* COMPONENT

LOOP AT <TABLE> ASSIGNING <WA>.
   ASSIGN COMPONENT 'TAXTYPE' OF STRUCTURE <WA> TO <MARK_FIELD>.

   IF <MARK_FIELD> EQ 'ES1'. 
       ASSIGN COMPONENT 'TAXNUM' OF STRUCTURE <WA> TO <MARK_FIELD2>.
       ASSIGN (campo_busqueda) TO <CAMPO_BUS[code]

Q1>.

<CAMPO_BUSQ1> = <MARK_FIELD2>.

ENDIF.

ENDLOOP.[/code]