ABAP Select data from SAP table /BIC/CCOC2LIS_01_S261 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 /BIC/CCOC2LIS_01_S261 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 /BIC/CCOC2LIS_01_S261. 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 /BIC/CCOC2LIS_01_S261 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_/BIC/CCOC2LIS_01_S261 TYPE STANDARD TABLE OF /BIC/CCOC2LIS_01_S261,
      WA_/BIC/CCOC2LIS_01_S261 TYPE /BIC/CCOC2LIS_01_S261,
      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: </BIC/CCOC2LIS_01_S261> TYPE /BIC/CCOC2LIS_01_S261.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /BIC/CCOC2LIS_01_S261
*  INTO TABLE @DATA(IT_/BIC/CCOC2LIS_01_S2612).
*--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_/BIC/CCOC2LIS_01_S261 INDEX 1 INTO DATA(WA_/BIC/CCOC2LIS_01_S2612).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/BIC/CCOC2LIS_01_S261 ASSIGNING </BIC/CCOC2LIS_01_S261>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</BIC/CCOC2LIS_01_S261>-STORNO = 1.
</BIC/CCOC2LIS_01_S261>-WRTTP = 1.
</BIC/CCOC2LIS_01_S261>-VRSIO = 1.
</BIC/CCOC2LIS_01_S261>-SPMON = 1.
</BIC/CCOC2LIS_01_S261>-SPTAG = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/BIC/CCOC2LIS_01_S261-SPWOC, sy-vline,
WA_/BIC/CCOC2LIS_01_S261-SPBUP, sy-vline,
WA_/BIC/CCOC2LIS_01_S261-VBELN, sy-vline,
WA_/BIC/CCOC2LIS_01_S261-POSNR, sy-vline,
WA_/BIC/CCOC2LIS_01_S261-ETENR, sy-vline,
WA_/BIC/CCOC2LIS_01_S261-PERIV, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/BIC/CCOC2LIS_01_S261 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_/BIC/CCOC2LIS_01_S261 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_/BIC/CCOC2LIS_01_S261 INTO WA_/BIC/CCOC2LIS_01_S261. *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_/BIC/CCOC2LIS_01_S261_STR,
STORNO TYPE STRING,
WRTTP TYPE STRING,
VRSIO TYPE STRING,
SPMON TYPE STRING,
SPTAG TYPE STRING,
SPWOC TYPE STRING,
SPBUP TYPE STRING,
VBELN TYPE STRING,
POSNR TYPE STRING,
ETENR TYPE STRING,
PERIV TYPE STRING,
LIFNR TYPE STRING,
VSTEL TYPE STRING,
ROUTE TYPE STRING,
PSPDNR TYPE STRING,
PKUNRE TYPE STRING,
PKUNRG TYPE STRING,
PVRTNR TYPE STRING,
KDGRP TYPE STRING,
BZIRK TYPE STRING,
VKORG TYPE STRING,
SPARA TYPE STRING,
LFART TYPE STRING,
FAKSK TYPE STRING,
LIFSK TYPE STRING,
ABLAD TYPE STRING,
INCO1 TYPE STRING,
INCO2 TYPE STRING,
KUNNR TYPE STRING,
KUNAG TYPE STRING,
LSTEL TYPE STRING,
WADAT_IST TYPE STRING,
LFDAT TYPE STRING,
VBTYP TYPE STRING,
BUKRS TYPE STRING,
VRKME TYPE STRING,
MEINS TYPE STRING,
GEWEI TYPE STRING,
VOLEH TYPE STRING,
ERDAT TYPE STRING,
AEDAT TYPE STRING,
STADAT TYPE STRING,
UMVKZ TYPE STRING,
UMVKN TYPE STRING,
PSTYV TYPE STRING,
VGTYP TYPE STRING,
MATNR TYPE STRING,
MATKL TYPE STRING,
WERKS TYPE STRING,
LGORT TYPE STRING,
CHARG TYPE STRING,
PRODH TYPE STRING,
FAKSP TYPE STRING,
VGBEL TYPE STRING,
VGPOS TYPE STRING,
KOMKZ TYPE STRING,
LGNUM TYPE STRING,
LGTYP TYPE STRING,
LGPLA TYPE STRING,
POSAR TYPE STRING,
GSBER TYPE STRING,
VKBUR TYPE STRING,
VKGRP TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
KVGR1 TYPE STRING,
KVGR2 TYPE STRING,
KVGR3 TYPE STRING,
KVGR4 TYPE STRING,
KVGR5 TYPE STRING,
MVGR1 TYPE STRING,
MVGR2 TYPE STRING,
MVGR3 TYPE STRING,
MVGR4 TYPE STRING,
MVGR5 TYPE STRING,
WBSTA TYPE STRING,
KOSTA TYPE STRING,
KOQUA TYPE STRING,
APERDAT TYPE STRING,
KZVBR TYPE STRING,
ERNAM TYPE STRING,
ERZET TYPE STRING,
PS_POSID TYPE STRING,
LFIMG TYPE STRING,
NTGEW TYPE STRING,
BRGEW TYPE STRING,
VOLUM TYPE STRING,
LGMNG TYPE STRING,
ANZLI TYPE STRING,
ANZLIPOS TYPE STRING,
ETTYP TYPE STRING,
LIFSP TYPE STRING,
LDDAT TYPE STRING,
TDDAT TYPE STRING,
EDATU TYPE STRING,
WADAT TYPE STRING,
MBDAT TYPE STRING,
WLDATBE TYPE STRING,
VSMNG_L TYPE STRING,END OF T_EKKO_STR. DATA: WA_/BIC/CCOC2LIS_01_S261_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_/BIC/CCOC2LIS_01_S261_STR-STORNO sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WRTTP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VRSIO sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPMON sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPTAG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPWOC sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPBUP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VBELN sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-POSNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ETENR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PERIV sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LIFNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VSTEL sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ROUTE sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PSPDNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PKUNRE sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PKUNRG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PVRTNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KDGRP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-BZIRK sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VKORG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPARA sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LFART sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-FAKSK sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LIFSK sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ABLAD sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-INCO1 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-INCO2 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KUNNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KUNAG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LSTEL sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WADAT_IST sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LFDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VBTYP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-BUKRS sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VRKME sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MEINS sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-GEWEI sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VOLEH sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ERDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-AEDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-STADAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-UMVKZ sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-UMVKN sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PSTYV sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VGTYP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MATNR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MATKL sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WERKS sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LGORT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-CHARG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PRODH sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-FAKSP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VGBEL sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VGPOS sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KOMKZ sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LGNUM sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LGTYP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LGPLA sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-POSAR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-GSBER sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VKBUR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VKGRP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VTWEG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-SPART sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KVGR1 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KVGR2 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KVGR3 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KVGR4 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KVGR5 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MVGR1 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MVGR2 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MVGR3 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MVGR4 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MVGR5 sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WBSTA sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KOSTA sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KOQUA sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-APERDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-KZVBR sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ERNAM sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ERZET sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-PS_POSID sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LFIMG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-NTGEW sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-BRGEW sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VOLUM sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LGMNG sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ANZLI sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ANZLIPOS sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-ETTYP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LIFSP sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-LDDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-TDDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-EDATU sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WADAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-MBDAT sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-WLDATBE sy-vline
WA_/BIC/CCOC2LIS_01_S261_STR-VSMNG_L sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.