ABAP Select data from SAP table ICORDCSTC1 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 ICORDCSTC1 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 ICORDCSTC1. 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 ICORDCSTC1 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_ICORDCSTC1 TYPE STANDARD TABLE OF ICORDCSTC1, WA_ICORDCSTC1 TYPE ICORDCSTC1, 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: <ICORDCSTC1> TYPE ICORDCSTC1. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_ICORDCSTC1. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM ICORDCSTC1 INTO TABLE IT_ICORDCSTC1. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM ICORDCSTC1 * INTO TABLE @DATA(IT_ICORDCSTC12). *--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_ICORDCSTC1 INDEX 1 INTO DATA(WA_ICORDCSTC12). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_ICORDCSTC1 ASSIGNING <ICORDCSTC1>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<ICORDCSTC1>-KOKRS = 1.
<ICORDCSTC1>-AUFNR = 1.
<ICORDCSTC1>-KSTAR = 1.
<ICORDCSTC1>-VERSN = 1.
<ICORDCSTC1>-CURTYPE = 1.
ENDLOOP. LOOP AT IT_ICORDCSTC1 INTO WA_ICORDCSTC1. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_ICORDCSTC1-FISCPER, sy-vline,
WA_ICORDCSTC1-FISCVAR, sy-vline,
WA_ICORDCSTC1-REFBN, sy-vline,
WA_ICORDCSTC1-RFPOS, sy-vline,
WA_ICORDCSTC1-LOEKZ, sy-vline,
WA_ICORDCSTC1-MEASTYPE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ICORDCSTC1 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_ICORDCSTC1 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_ICORDCSTC1 INTO WA_ICORDCSTC1. *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 ALPHA, internal->external for field AUFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-AUFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-AUFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KSTAR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-KSTAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-KSTAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VERSN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-VERSN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-VERSN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit PERI7, internal->external for field FISCPER CALL FUNCTION 'CONVERSION_EXIT_PERI7_OUTPUT' EXPORTING input = WA_ICORDCSTC1-FISCPER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-FISCPER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REFBN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-REFBN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-REFBN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWG CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_ICORDCSTC1-SWG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-SWG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_ICORDCSTC1-MEINH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-MEINH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit REFBT, internal->external for field REFBT CALL FUNCTION 'CONVERSION_EXIT_REFBT_OUTPUT' EXPORTING input = WA_ICORDCSTC1-REFBT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-REFBT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VBUND CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-VBUND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-VBUND.
WRITE:/ 'New Value:', ld_input.
*Conversion exit BEKNZ, internal->external for field BEKNZ CALL FUNCTION 'CONVERSION_EXIT_BEKNZ_OUTPUT' EXPORTING input = WA_ICORDCSTC1-BEKNZ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-BEKNZ.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_ICORDCSTC1-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field GRANT_NBR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-GRANT_NBR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-GRANT_NBR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PGRANT_NBR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-PGRANT_NBR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-PGRANT_NBR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field LINEAR_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_ICORDCSTC1-LINEAR_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-LINEAR_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSP, internal->external for field PROID CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_ICORDCSTC1-PROID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-PROID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EQUNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICORDCSTC1-EQUNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-EQUNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TPLNR, internal->external for field TPLNR CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_ICORDCSTC1-TPLNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICORDCSTC1-TPLNR.
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_ICORDCSTC1_STR,
KOKRS TYPE STRING,
AUFNR TYPE STRING,
KSTAR TYPE STRING,
VERSN TYPE STRING,
CURTYPE TYPE STRING,
FISCPER TYPE STRING,
FISCVAR TYPE STRING,
REFBN TYPE STRING,
RFPOS TYPE STRING,
LOEKZ TYPE STRING,
MEASTYPE TYPE STRING,
VTDETAIL TYPE STRING,
VTSTAT TYPE STRING,
VTYPE TYPE STRING,
WAERS TYPE STRING,
SWG TYPE STRING,
SMEG TYPE STRING,
MEINH TYPE STRING,
BUDAT TYPE STRING,
LIFNR TYPE STRING,
REFBT TYPE STRING,
RFKNT TYPE STRING,
RFTRM TYPE STRING,
RFART TYPE STRING,
HRKFT TYPE STRING,
VBUND TYPE STRING,
PARGB TYPE STRING,
BEKNZ TYPE STRING,
UNAME TYPE STRING,
BLDAT TYPE STRING,
BUKRS TYPE STRING,
MATNR TYPE STRING,
MATKL TYPE STRING,
SGTXT TYPE STRING,
DABRZ TYPE STRING,
UPDMOD TYPE STRING,
OBJNR TYPE STRING,
GEBER TYPE STRING,
PGEBER TYPE STRING,
FKBER TYPE STRING,
PFKBER TYPE STRING,
GRANT_NBR TYPE STRING,
PGRANT_NBR TYPE STRING,
FIKRS TYPE STRING,
BUDGET_PD TYPE STRING,
PBUDGET_PD TYPE STRING,
START_POINT TYPE STRING,
END_POINT TYPE STRING,
LINEAR_LENGTH TYPE STRING,
LINEAR_UNIT TYPE STRING,
PROID TYPE STRING,
ILART TYPE STRING,
EQUNR TYPE STRING,
TPLNR TYPE STRING,END OF T_EKKO_STR. DATA: WA_ICORDCSTC1_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_ICORDCSTC1_STR-KOKRS sy-vline
WA_ICORDCSTC1_STR-AUFNR sy-vline
WA_ICORDCSTC1_STR-KSTAR sy-vline
WA_ICORDCSTC1_STR-VERSN sy-vline
WA_ICORDCSTC1_STR-CURTYPE sy-vline
WA_ICORDCSTC1_STR-FISCPER sy-vline
WA_ICORDCSTC1_STR-FISCVAR sy-vline
WA_ICORDCSTC1_STR-REFBN sy-vline
WA_ICORDCSTC1_STR-RFPOS sy-vline
WA_ICORDCSTC1_STR-LOEKZ sy-vline
WA_ICORDCSTC1_STR-MEASTYPE sy-vline
WA_ICORDCSTC1_STR-VTDETAIL sy-vline
WA_ICORDCSTC1_STR-VTSTAT sy-vline
WA_ICORDCSTC1_STR-VTYPE sy-vline
WA_ICORDCSTC1_STR-WAERS sy-vline
WA_ICORDCSTC1_STR-SWG sy-vline
WA_ICORDCSTC1_STR-SMEG sy-vline
WA_ICORDCSTC1_STR-MEINH sy-vline
WA_ICORDCSTC1_STR-BUDAT sy-vline
WA_ICORDCSTC1_STR-LIFNR sy-vline
WA_ICORDCSTC1_STR-REFBT sy-vline
WA_ICORDCSTC1_STR-RFKNT sy-vline
WA_ICORDCSTC1_STR-RFTRM sy-vline
WA_ICORDCSTC1_STR-RFART sy-vline
WA_ICORDCSTC1_STR-HRKFT sy-vline
WA_ICORDCSTC1_STR-VBUND sy-vline
WA_ICORDCSTC1_STR-PARGB sy-vline
WA_ICORDCSTC1_STR-BEKNZ sy-vline
WA_ICORDCSTC1_STR-UNAME sy-vline
WA_ICORDCSTC1_STR-BLDAT sy-vline
WA_ICORDCSTC1_STR-BUKRS sy-vline
WA_ICORDCSTC1_STR-MATNR sy-vline
WA_ICORDCSTC1_STR-MATKL sy-vline
WA_ICORDCSTC1_STR-SGTXT sy-vline
WA_ICORDCSTC1_STR-DABRZ sy-vline
WA_ICORDCSTC1_STR-UPDMOD sy-vline
WA_ICORDCSTC1_STR-OBJNR sy-vline
WA_ICORDCSTC1_STR-GEBER sy-vline
WA_ICORDCSTC1_STR-PGEBER sy-vline
WA_ICORDCSTC1_STR-FKBER sy-vline
WA_ICORDCSTC1_STR-PFKBER sy-vline
WA_ICORDCSTC1_STR-GRANT_NBR sy-vline
WA_ICORDCSTC1_STR-PGRANT_NBR sy-vline
WA_ICORDCSTC1_STR-FIKRS sy-vline
WA_ICORDCSTC1_STR-BUDGET_PD sy-vline
WA_ICORDCSTC1_STR-PBUDGET_PD sy-vline
WA_ICORDCSTC1_STR-START_POINT sy-vline
WA_ICORDCSTC1_STR-END_POINT sy-vline
WA_ICORDCSTC1_STR-LINEAR_LENGTH sy-vline
WA_ICORDCSTC1_STR-LINEAR_UNIT sy-vline
WA_ICORDCSTC1_STR-PROID sy-vline
WA_ICORDCSTC1_STR-ILART sy-vline
WA_ICORDCSTC1_STR-EQUNR sy-vline
WA_ICORDCSTC1_STR-TPLNR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.