ABAP Select data from SAP table /BEV3/CHSNODETXT into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP /BEV3/CHSNODETXT table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /BEV3/CHSNODETXT. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the /BEV3/CHSNODETXT table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_/BEV3/CHSNODETXT TYPE STANDARD TABLE OF /BEV3/CHSNODETXT,
      WA_/BEV3/CHSNODETXT TYPE /BEV3/CHSNODETXT,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: </BEV3/CHSNODETXT> TYPE /BEV3/CHSNODETXT.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/BEV3/CHSNODETXT.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /BEV3/CHSNODETXT
  INTO TABLE IT_/BEV3/CHSNODETXT.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /BEV3/CHSNODETXT
*  INTO TABLE @DATA(IT_/BEV3/CHSNODETXT2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_/BEV3/CHSNODETXT INDEX 1 INTO DATA(WA_/BEV3/CHSNODETXT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/BEV3/CHSNODETXT ASSIGNING </BEV3/CHSNODETXT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</BEV3/CHSNODETXT>-NODE_ID = 1.
</BEV3/CHSNODETXT>-TYPE = 1.
</BEV3/CHSNODETXT>-KNOTENNAME = 1.
</BEV3/CHSNODETXT>-NODELEVEL = 1.
</BEV3/CHSNODETXT>-LINK = 1.
ENDLOOP.

LOOP AT IT_/BEV3/CHSNODETXT INTO WA_/BEV3/CHSNODETXT.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/BEV3/CHSNODETXT-COMPRES, sy-vline,
WA_/BEV3/CHSNODETXT-LEAF, sy-vline,
WA_/BEV3/CHSNODETXT-TLOCK, sy-vline,
WA_/BEV3/CHSNODETXT-PARENTNODE, sy-vline,
WA_/BEV3/CHSNODETXT-CHILDNODE, sy-vline,
WA_/BEV3/CHSNODETXT-NEXTNODE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/BEV3/CHSNODETXT you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/BEV3/CHSNODETXT TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/BEV3/CHSNODETXT INTO WA_/BEV3/CHSNODETXT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/BEV3/CHSNODETXT_STR,
NODE_ID TYPE STRING,
TYPE TYPE STRING,
KNOTENNAME TYPE STRING,
NODELEVEL TYPE STRING,
LINK TYPE STRING,
COMPRES TYPE STRING,
LEAF TYPE STRING,
TLOCK TYPE STRING,
PARENTNODE TYPE STRING,
CHILDNODE TYPE STRING,
NEXTNODE TYPE STRING,
VBKL TYPE STRING,
RI TYPE STRING,
VBIN TYPE STRING,
NLENGTH TYPE STRING,
COLOR TYPE STRING,
INTENSIV TYPE STRING,
KNOTENBEZ TYPE STRING,
TLENGTH TYPE STRING,
TCOLOR TYPE STRING,
TINTENSIV TYPE STRING,
TPOS TYPE STRING,
KIND TYPE STRING,
TEXT1 TYPE STRING,
TLENGTH1 TYPE STRING,
TCOLOR1 TYPE STRING,
TINTENSIV1 TYPE STRING,
TPOS1 TYPE STRING,
KIND1 TYPE STRING,
TEXT2 TYPE STRING,
TLENGTH2 TYPE STRING,
TCOLOR2 TYPE STRING,
TINTENSIV2 TYPE STRING,
TPOS2 TYPE STRING,
KIND2 TYPE STRING,
TEXT3 TYPE STRING,
TLENGTH3 TYPE STRING,
TCOLOR3 TYPE STRING,
TINTENSIV3 TYPE STRING,
TPOS3 TYPE STRING,
KIND3 TYPE STRING,
TEXT4 TYPE STRING,
TLENGTH4 TYPE STRING,
TCOLOR4 TYPE STRING,
TINTENSIV4 TYPE STRING,
TPOS4 TYPE STRING,
KIND4 TYPE STRING,
TEXT5 TYPE STRING,
TLENGTH5 TYPE STRING,
TCOLOR5 TYPE STRING,
TINTENSIV5 TYPE STRING,
TPOS5 TYPE STRING,
KIND5 TYPE STRING,
TEXT6 TYPE STRING,
TLENGTH6 TYPE STRING,
TCOLOR6 TYPE STRING,
TINTENSIV6 TYPE STRING,
TPOS6 TYPE STRING,
KIND6 TYPE STRING,
TEXT7 TYPE STRING,
TLENGTH7 TYPE STRING,
TCOLOR7 TYPE STRING,
TINTENSIV7 TYPE STRING,
TPOS7 TYPE STRING,
KIND7 TYPE STRING,
TEXT8 TYPE STRING,
TLENGTH8 TYPE STRING,
TCOLOR8 TYPE STRING,
TINTENSIV8 TYPE STRING,
TPOS8 TYPE STRING,
KIND8 TYPE STRING,
TEXT9 TYPE STRING,
TLENGTH9 TYPE STRING,
TCOLOR9 TYPE STRING,
TINTENSIV9 TYPE STRING,
TPOS9 TYPE STRING,
KIND9 TYPE STRING,
HIDE TYPE STRING,
FORCE_PLUS TYPE STRING,
HOTSPOT TYPE STRING,
HOTSPOT1 TYPE STRING,
HOTSPOT2 TYPE STRING,
HOTSPOT3 TYPE STRING,
HOTSPOT4 TYPE STRING,
HOTSPOT5 TYPE STRING,
HOTSPOT6 TYPE STRING,
HOTSPOT7 TYPE STRING,
HOTSPOT8 TYPE STRING,
HOTSPOT9 TYPE STRING,
NODISPLAY TYPE STRING,
MOREINFO TYPE STRING,END OF T_EKKO_STR. DATA: WA_/BEV3/CHSNODETXT_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/BEV3/CHSNODETXT_STR-NODE_ID sy-vline
WA_/BEV3/CHSNODETXT_STR-TYPE sy-vline
WA_/BEV3/CHSNODETXT_STR-KNOTENNAME sy-vline
WA_/BEV3/CHSNODETXT_STR-NODELEVEL sy-vline
WA_/BEV3/CHSNODETXT_STR-LINK sy-vline
WA_/BEV3/CHSNODETXT_STR-COMPRES sy-vline
WA_/BEV3/CHSNODETXT_STR-LEAF sy-vline
WA_/BEV3/CHSNODETXT_STR-TLOCK sy-vline
WA_/BEV3/CHSNODETXT_STR-PARENTNODE sy-vline
WA_/BEV3/CHSNODETXT_STR-CHILDNODE sy-vline
WA_/BEV3/CHSNODETXT_STR-NEXTNODE sy-vline
WA_/BEV3/CHSNODETXT_STR-VBKL sy-vline
WA_/BEV3/CHSNODETXT_STR-RI sy-vline
WA_/BEV3/CHSNODETXT_STR-VBIN sy-vline
WA_/BEV3/CHSNODETXT_STR-NLENGTH sy-vline
WA_/BEV3/CHSNODETXT_STR-COLOR sy-vline
WA_/BEV3/CHSNODETXT_STR-INTENSIV sy-vline
WA_/BEV3/CHSNODETXT_STR-KNOTENBEZ sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT1 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH1 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR1 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV1 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS1 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND1 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT2 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH2 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR2 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV2 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS2 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND2 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT3 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH3 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR3 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV3 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS3 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND3 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT4 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH4 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR4 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV4 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS4 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND4 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT5 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH5 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR5 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV5 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS5 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND5 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT6 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH6 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR6 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV6 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS6 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND6 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT7 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH7 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR7 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV7 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS7 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND7 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT8 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH8 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR8 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV8 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS8 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND8 sy-vline
WA_/BEV3/CHSNODETXT_STR-TEXT9 sy-vline
WA_/BEV3/CHSNODETXT_STR-TLENGTH9 sy-vline
WA_/BEV3/CHSNODETXT_STR-TCOLOR9 sy-vline
WA_/BEV3/CHSNODETXT_STR-TINTENSIV9 sy-vline
WA_/BEV3/CHSNODETXT_STR-TPOS9 sy-vline
WA_/BEV3/CHSNODETXT_STR-KIND9 sy-vline
WA_/BEV3/CHSNODETXT_STR-HIDE sy-vline
WA_/BEV3/CHSNODETXT_STR-FORCE_PLUS sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT1 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT2 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT3 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT4 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT5 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT6 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT7 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT8 sy-vline
WA_/BEV3/CHSNODETXT_STR-HOTSPOT9 sy-vline
WA_/BEV3/CHSNODETXT_STR-NODISPLAY sy-vline
WA_/BEV3/CHSNODETXT_STR-MOREINFO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.