ABAP Select data from SAP table COPC_S_ACCT_GROUP_ITEM 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 COPC_S_ACCT_GROUP_ITEM 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 COPC_S_ACCT_GROUP_ITEM. 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 COPC_S_ACCT_GROUP_ITEM 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_COPC_S_ACCT_GROUP_ITEM TYPE STANDARD TABLE OF COPC_S_ACCT_GROUP_ITEM,
      WA_COPC_S_ACCT_GROUP_ITEM TYPE COPC_S_ACCT_GROUP_ITEM,
      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: <COPC_S_ACCT_GROUP_ITEM> TYPE COPC_S_ACCT_GROUP_ITEM.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM COPC_S_ACCT_GROUP_ITEM
*  INTO TABLE @DATA(IT_COPC_S_ACCT_GROUP_ITEM2).
*--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_COPC_S_ACCT_GROUP_ITEM INDEX 1 INTO DATA(WA_COPC_S_ACCT_GROUP_ITEM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_COPC_S_ACCT_GROUP_ITEM ASSIGNING <COPC_S_ACCT_GROUP_ITEM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<COPC_S_ACCT_GROUP_ITEM>-CHECK_BOX = 1.
<COPC_S_ACCT_GROUP_ITEM>-CELLTAB = 1.
<COPC_S_ACCT_GROUP_ITEM>-MANDT = 1.
<COPC_S_ACCT_GROUP_ITEM>-PLVAR = 1.
<COPC_S_ACCT_GROUP_ITEM>-OTYPE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_COPC_S_ACCT_GROUP_ITEM-OBJID, sy-vline,
WA_COPC_S_ACCT_GROUP_ITEM-ISTAT, sy-vline,
WA_COPC_S_ACCT_GROUP_ITEM-BEGDA, sy-vline,
WA_COPC_S_ACCT_GROUP_ITEM-ENDDA, sy-vline,
WA_COPC_S_ACCT_GROUP_ITEM-LANGU, sy-vline,
WA_COPC_S_ACCT_GROUP_ITEM-SEQNR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_COPC_S_ACCT_GROUP_ITEM 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_COPC_S_ACCT_GROUP_ITEM 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_COPC_S_ACCT_GROUP_ITEM INTO WA_COPC_S_ACCT_GROUP_ITEM. *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.

*Conversion exit ISOLA, internal->external for field LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_COPC_S_ACCT_GROUP_ITEM-LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_COPC_S_ACCT_GROUP_ITEM-LANGU.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field HKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_COPC_S_ACCT_GROUP_ITEM-HKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_COPC_S_ACCT_GROUP_ITEM-HKONT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit AC132, internal->external for field MINIM CALL FUNCTION 'CONVERSION_EXIT_AC132_OUTPUT' EXPORTING input = WA_COPC_S_ACCT_GROUP_ITEM-MINIM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_COPC_S_ACCT_GROUP_ITEM-MINIM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit AU132, internal->external for field MINAB CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_COPC_S_ACCT_GROUP_ITEM-MINAB IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_COPC_S_ACCT_GROUP_ITEM-MINAB.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_COPC_S_ACCT_GROUP_ITEM_STR,
CHECK_BOX TYPE STRING,
CELLTAB TYPE STRING,
MANDT TYPE STRING,
PLVAR TYPE STRING,
OTYPE TYPE STRING,
OBJID TYPE STRING,
ISTAT TYPE STRING,
BEGDA TYPE STRING,
ENDDA TYPE STRING,
LANGU TYPE STRING,
SEQNR TYPE STRING,
OTJID TYPE STRING,
INFTY TYPE STRING,
AEDTM TYPE STRING,
UNAME TYPE STRING,
REASN TYPE STRING,
HISTO TYPE STRING,
ITXNR TYPE STRING,
SHORT TYPE STRING,
STEXT TYPE STRING,
GDATE TYPE STRING,
MC_SHORT TYPE STRING,
MC_STEXT TYPE STRING,
MC_SEARK TYPE STRING,
BUKRS TYPE STRING,
HBKID TYPE STRING,
HKTID TYPE STRING,
ZLSCH TYPE STRING,
WAERS TYPE STRING,
CHAIN TYPE STRING,
RP_TEXT TYPE STRING,
XPORE TYPE STRING,
GSBER TYPE STRING,
HKONT TYPE STRING,
BANKN TYPE STRING,
BKONT TYPE STRING,
REFZL TYPE STRING,
DTAAI TYPE STRING,
BNKN2 TYPE STRING,
MINIM TYPE STRING,
MINAB TYPE STRING,
BNKACC_NO TYPE STRING,END OF T_EKKO_STR. DATA: WA_COPC_S_ACCT_GROUP_ITEM_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_COPC_S_ACCT_GROUP_ITEM_STR-CHECK_BOX sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-CELLTAB sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MANDT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-PLVAR sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-OTYPE sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-OBJID sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-ISTAT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BEGDA sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-ENDDA sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-LANGU sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-SEQNR sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-OTJID sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-INFTY sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-AEDTM sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-UNAME sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-REASN sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-HISTO sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-ITXNR sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-SHORT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-STEXT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-GDATE sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MC_SHORT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MC_STEXT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MC_SEARK sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BUKRS sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-HBKID sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-HKTID sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-ZLSCH sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-WAERS sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-CHAIN sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-RP_TEXT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-XPORE sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-GSBER sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-HKONT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BANKN sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BKONT sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-REFZL sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-DTAAI sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BNKN2 sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MINIM sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-MINAB sy-vline
WA_COPC_S_ACCT_GROUP_ITEM_STR-BNKACC_NO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.