ABAP Select data from SAP table COCF_S_DYNF_SNCPIT 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 COCF_S_DYNF_SNCPIT 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 COCF_S_DYNF_SNCPIT. 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 COCF_S_DYNF_SNCPIT 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_COCF_S_DYNF_SNCPIT TYPE STANDARD TABLE OF COCF_S_DYNF_SNCPIT, WA_COCF_S_DYNF_SNCPIT TYPE COCF_S_DYNF_SNCPIT, 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: <COCF_S_DYNF_SNCPIT> TYPE COCF_S_DYNF_SNCPIT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_COCF_S_DYNF_SNCPIT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM COCF_S_DYNF_SNCPIT INTO TABLE IT_COCF_S_DYNF_SNCPIT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM COCF_S_DYNF_SNCPIT * INTO TABLE @DATA(IT_COCF_S_DYNF_SNCPIT2). *--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_COCF_S_DYNF_SNCPIT INDEX 1 INTO DATA(WA_COCF_S_DYNF_SNCPIT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_COCF_S_DYNF_SNCPIT ASSIGNING <COCF_S_DYNF_SNCPIT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<COCF_S_DYNF_SNCPIT>-VARIANT1 = 1.
<COCF_S_DYNF_SNCPIT>-VARIANT2 = 1.
<COCF_S_DYNF_SNCPIT>-VARIANT3 = 1.
<COCF_S_DYNF_SNCPIT>-VARIANT4 = 1.
<COCF_S_DYNF_SNCPIT>-VARIANT5 = 1.
ENDLOOP. LOOP AT IT_COCF_S_DYNF_SNCPIT INTO WA_COCF_S_DYNF_SNCPIT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_COCF_S_DYNF_SNCPIT-VARIANT6, sy-vline,
WA_COCF_S_DYNF_SNCPIT-VARIANT1_TEXT, sy-vline,
WA_COCF_S_DYNF_SNCPIT-VARIANT2_TEXT, sy-vline,
WA_COCF_S_DYNF_SNCPIT-VARIANT3_TEXT, sy-vline,
WA_COCF_S_DYNF_SNCPIT-VARIANT4_TEXT, sy-vline,
WA_COCF_S_DYNF_SNCPIT-VARIANT5_TEXT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_COCF_S_DYNF_SNCPIT 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_COCF_S_DYNF_SNCPIT 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_COCF_S_DYNF_SNCPIT INTO WA_COCF_S_DYNF_SNCPIT. *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_COCF_S_DYNF_SNCPIT_STR,
VARIANT1 TYPE STRING,
VARIANT2 TYPE STRING,
VARIANT3 TYPE STRING,
VARIANT4 TYPE STRING,
VARIANT5 TYPE STRING,
VARIANT6 TYPE STRING,
VARIANT1_TEXT TYPE STRING,
VARIANT2_TEXT TYPE STRING,
VARIANT3_TEXT TYPE STRING,
VARIANT4_TEXT TYPE STRING,
VARIANT5_TEXT TYPE STRING,
VARIANT6_TEXT TYPE STRING,
LAYOUT1 TYPE STRING,
LAYOUT2 TYPE STRING,
LAYOUT3 TYPE STRING,
LAYOUT4 TYPE STRING,
LAYOUT5 TYPE STRING,
LAYOUT6 TYPE STRING,
REPID1 TYPE STRING,
REPID2 TYPE STRING,
REPID3 TYPE STRING,
REPID4 TYPE STRING,
REPID5 TYPE STRING,
REPID6 TYPE STRING,
ROW1_HEIGHT TYPE STRING,
ROW2_HEIGHT TYPE STRING,
ROW3_HEIGHT TYPE STRING,
LIST1_WIDTH TYPE STRING,
LIST2_WIDTH TYPE STRING,
LIST3_WIDTH TYPE STRING,
LIST4_WIDTH TYPE STRING,
LIST5_WIDTH TYPE STRING,
LIST6_WIDTH TYPE STRING,
VIEW_TABSTRIP TYPE STRING,
VIEW_SPLCTRL TYPE STRING,
NO_TOOLBAR TYPE STRING,
AUTO_REFRESH TYPE STRING,
AUTO_TIME TYPE STRING,
TITLE_SIZE TYPE STRING,END OF T_EKKO_STR. DATA: WA_COCF_S_DYNF_SNCPIT_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_COCF_S_DYNF_SNCPIT_STR-VARIANT1 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT2 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT3 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT4 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT5 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT6 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT1_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT2_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT3_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT4_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT5_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VARIANT6_TEXT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT1 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT2 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT3 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT4 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT5 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LAYOUT6 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID1 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID2 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID3 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID4 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID5 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-REPID6 sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-ROW1_HEIGHT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-ROW2_HEIGHT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-ROW3_HEIGHT sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST1_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST2_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST3_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST4_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST5_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-LIST6_WIDTH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VIEW_TABSTRIP sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-VIEW_SPLCTRL sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-NO_TOOLBAR sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-AUTO_REFRESH sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-AUTO_TIME sy-vline
WA_COCF_S_DYNF_SNCPIT_STR-TITLE_SIZE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.