ABAP Select data from SAP table P06_T_DSN_CHCO_P20V01 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 P06_T_DSN_CHCO_P20V01 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 P06_T_DSN_CHCO_P20V01. 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 P06_T_DSN_CHCO_P20V01 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_P06_T_DSN_CHCO_P20V01 TYPE STANDARD TABLE OF P06_T_DSN_CHCO_P20V01,
      WA_P06_T_DSN_CHCO_P20V01 TYPE P06_T_DSN_CHCO_P20V01,
      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: <P06_T_DSN_CHCO_P20V01> TYPE P06_T_DSN_CHCO_P20V01.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM P06_T_DSN_CHCO_P20V01
  INTO TABLE IT_P06_T_DSN_CHCO_P20V01.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM P06_T_DSN_CHCO_P20V01
*  INTO TABLE @DATA(IT_P06_T_DSN_CHCO_P20V012).
*--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_P06_T_DSN_CHCO_P20V01 INDEX 1 INTO DATA(WA_P06_T_DSN_CHCO_P20V012).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_P06_T_DSN_CHCO_P20V01 ASSIGNING <P06_T_DSN_CHCO_P20V01>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<P06_T_DSN_CHCO_P20V01>-SECTN = 1.
<P06_T_DSN_CHCO_P20V01>-SEKEY = 1.
<P06_T_DSN_CHCO_P20V01>-ADKEY = 1.
<P06_T_DSN_CHCO_P20V01>-CHMOD = 1.
<P06_T_DSN_CHCO_P20V01>-CHSTA = 1.
ENDLOOP.

LOOP AT IT_P06_T_DSN_CHCO_P20V01 INTO WA_P06_T_DSN_CHCO_P20V01.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_P06_T_DSN_CHCO_P20V01-CHAGI, sy-vline,
WA_P06_T_DSN_CHCO_P20V01-CHNAT, sy-vline,
WA_P06_T_DSN_CHCO_P20V01-CHINT, sy-vline,
WA_P06_T_DSN_CHCO_P20V01-CHUMQ, sy-vline,
WA_P06_T_DSN_CHCO_P20V01-CHQTC, sy-vline,
WA_P06_T_DSN_CHCO_P20V01-CHMEX, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P06_T_DSN_CHCO_P20V01 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_P06_T_DSN_CHCO_P20V01 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_P06_T_DSN_CHCO_P20V01 INTO WA_P06_T_DSN_CHCO_P20V01. *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_P06_T_DSN_CHCO_P20V01_STR,
SECTN TYPE STRING,
SEKEY TYPE STRING,
ADKEY TYPE STRING,
CHMOD TYPE STRING,
CHSTA TYPE STRING,
CHAGI TYPE STRING,
CHNAT TYPE STRING,
CHINT TYPE STRING,
CHUMQ TYPE STRING,
CHQTC TYPE STRING,
CHMEX TYPE STRING,
CHALS TYPE STRING,
CHCOL TYPE STRING,
CHASI TYPE STRING,
CHSIR TYPE STRING,
CHNUM TYPE STRING,
CHMRE TYPE STRING,
CHTDF TYPE STRING,
CHSTE TYPE STRING,
CHCSP TYPE STRING,
CHPCS TYPE STRING,
CHDEB TYPE STRING,
CHQTR TYPE STRING,
CHCCL TYPE STRING,
CHRSA TYPE STRING,
CHSCA TYPE STRING,
CHSTP TYPE STRING,
CHPRO TYPE STRING,
CHFPP TYPE STRING,
CHNPO TYPE STRING,
CHQTT TYPE STRING,
CHTTP TYPE STRING,
CHCCS TYPE STRING,
CHCIB TYPE STRING,
CHCIM TYPE STRING,
CHNBI TYPE STRING,
CHIBO TYPE STRING,
CHIES TYPE STRING,
CHIBG TYPE STRING,
CHIBP TYPE STRING,
CHIBS TYPE STRING,
CHMTC TYPE STRING,
CHTSA TYPE STRING,
CHNRX TYPE STRING,
CHECH TYPE STRING,
CHCOH TYPE STRING,
CHGEN TYPE STRING,
CHSBO TYPE STRING,
CHCDP TYPE STRING,
CHDEI TYPE STRING,
CHCCF TYPE STRING,
CHROB TYPE STRING,
CHRIS TYPE STRING,
CHIEM TYPE STRING,
CHIEG TYPE STRING,
CHTAP TYPE STRING,
CHTPD TYPE STRING,END OF T_EKKO_STR. DATA: WA_P06_T_DSN_CHCO_P20V01_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_P06_T_DSN_CHCO_P20V01_STR-SECTN sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-SEKEY sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-ADKEY sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHMOD sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSTA sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHAGI sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHNAT sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHINT sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHUMQ sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHQTC sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHMEX sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHALS sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCOL sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHASI sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSIR sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHNUM sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHMRE sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHTDF sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSTE sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCSP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHPCS sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHDEB sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHQTR sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCCL sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHRSA sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSCA sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSTP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHPRO sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHFPP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHNPO sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHQTT sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHTTP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCCS sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCIB sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCIM sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHNBI sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIBO sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIES sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIBG sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIBP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIBS sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHMTC sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHTSA sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHNRX sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHECH sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCOH sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHGEN sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHSBO sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCDP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHDEI sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHCCF sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHROB sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHRIS sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIEM sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHIEG sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHTAP sy-vline
WA_P06_T_DSN_CHCO_P20V01_STR-CHTPD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.