ABAP Select data from SAP table FKK_OPBEW_FKKOP 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 FKK_OPBEW_FKKOP 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 FKK_OPBEW_FKKOP. 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 FKK_OPBEW_FKKOP 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_FKK_OPBEW_FKKOP TYPE STANDARD TABLE OF FKK_OPBEW_FKKOP,
      WA_FKK_OPBEW_FKKOP TYPE FKK_OPBEW_FKKOP,
      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: <FKK_OPBEW_FKKOP> TYPE FKK_OPBEW_FKKOP.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FKK_OPBEW_FKKOP
*  INTO TABLE @DATA(IT_FKK_OPBEW_FKKOP2).
*--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_FKK_OPBEW_FKKOP INDEX 1 INTO DATA(WA_FKK_OPBEW_FKKOP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FKK_OPBEW_FKKOP ASSIGNING <FKK_OPBEW_FKKOP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FKK_OPBEW_FKKOP>-OPBEL = 1.
<FKK_OPBEW_FKKOP>-OPUPK = 1.
<FKK_OPBEW_FKKOP>-RLDNR = 1.
<FKK_OPBEW_FKKOP>-BWDAT = 1.
<FKK_OPBEW_FKKOP>-CURTP = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FKK_OPBEW_FKKOP-BWVAR, sy-vline,
WA_FKK_OPBEW_FKKOP-FBZAE, sy-vline,
WA_FKK_OPBEW_FKKOP-BUKRS, sy-vline,
WA_FKK_OPBEW_FKKOP-HWTYP, sy-vline,
WA_FKK_OPBEW_FKKOP-GSBER, sy-vline,
WA_FKK_OPBEW_FKKOP-SEGMENT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FKK_OPBEW_FKKOP 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_FKK_OPBEW_FKKOP 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_FKK_OPBEW_FKKOP INTO WA_FKK_OPBEW_FKKOP. *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 OPBEL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKK_OPBEW_FKKOP-OPBEL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKK_OPBEW_FKKOP-OPBEL.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

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

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

*Conversion exit EXCRT, internal->external for field KURSF CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_FKK_OPBEW_FKKOP-KURSF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKK_OPBEW_FKKOP-KURSF.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ALPHA, internal->external for field PRCTR_MIG CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKK_OPBEW_FKKOP-PRCTR_MIG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKK_OPBEW_FKKOP-PRCTR_MIG.
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_FKK_OPBEW_FKKOP_STR,
OPBEL TYPE STRING,
OPUPK TYPE STRING,
RLDNR TYPE STRING,
BWDAT TYPE STRING,
CURTP TYPE STRING,
BWVAR TYPE STRING,
FBZAE TYPE STRING,
BUKRS TYPE STRING,
HWTYP TYPE STRING,
GSBER TYPE STRING,
SEGMENT TYPE STRING,
PRCTR TYPE STRING,
LDGRP TYPE STRING,
VKONT TYPE STRING,
GPART TYPE STRING,
HKONT TYPE STRING,
FWBEL TYPE STRING,
FWBEL_INV TYPE STRING,
FWBEL_VA TYPE STRING,
FWBEL_VA_INV TYPE STRING,
UBETR TYPE STRING,
VBETR TYPE STRING,
BDIFF TYPE STRING,
WAERS TYPE STRING,
STOFLG TYPE STRING,
BETRH_VA TYPE STRING,
BDIFF_VA TYPE STRING,
SIMUL TYPE STRING,
LAUFD TYPE STRING,
LAUFI TYPE STRING,
BETRW TYPE STRING,
BETRH TYPE STRING,
BETR2 TYPE STRING,
BETR3 TYPE STRING,
OPUPZ TYPE STRING,
XRAGL TYPE STRING,
KURSF TYPE STRING,
FAEDN TYPE STRING,
OPUPW TYPE STRING,
AUGST TYPE STRING,
BUDAT TYPE STRING,
AUGDT TYPE STRING,
AUGBL TYPE STRING,
AUGBD TYPE STRING,
AUGWA TYPE STRING,
AUGBT TYPE STRING,
INFOZ TYPE STRING,
GSBER_MIG TYPE STRING,
SEGMT_MIG TYPE STRING,
PRCTR_MIG TYPE STRING,
BWBER TYPE STRING,
HWAER TYPE STRING,END OF T_EKKO_STR. DATA: WA_FKK_OPBEW_FKKOP_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_FKK_OPBEW_FKKOP_STR-OPBEL sy-vline
WA_FKK_OPBEW_FKKOP_STR-OPUPK sy-vline
WA_FKK_OPBEW_FKKOP_STR-RLDNR sy-vline
WA_FKK_OPBEW_FKKOP_STR-BWDAT sy-vline
WA_FKK_OPBEW_FKKOP_STR-CURTP sy-vline
WA_FKK_OPBEW_FKKOP_STR-BWVAR sy-vline
WA_FKK_OPBEW_FKKOP_STR-FBZAE sy-vline
WA_FKK_OPBEW_FKKOP_STR-BUKRS sy-vline
WA_FKK_OPBEW_FKKOP_STR-HWTYP sy-vline
WA_FKK_OPBEW_FKKOP_STR-GSBER sy-vline
WA_FKK_OPBEW_FKKOP_STR-SEGMENT sy-vline
WA_FKK_OPBEW_FKKOP_STR-PRCTR sy-vline
WA_FKK_OPBEW_FKKOP_STR-LDGRP sy-vline
WA_FKK_OPBEW_FKKOP_STR-VKONT sy-vline
WA_FKK_OPBEW_FKKOP_STR-GPART sy-vline
WA_FKK_OPBEW_FKKOP_STR-HKONT sy-vline
WA_FKK_OPBEW_FKKOP_STR-FWBEL sy-vline
WA_FKK_OPBEW_FKKOP_STR-FWBEL_INV sy-vline
WA_FKK_OPBEW_FKKOP_STR-FWBEL_VA sy-vline
WA_FKK_OPBEW_FKKOP_STR-FWBEL_VA_INV sy-vline
WA_FKK_OPBEW_FKKOP_STR-UBETR sy-vline
WA_FKK_OPBEW_FKKOP_STR-VBETR sy-vline
WA_FKK_OPBEW_FKKOP_STR-BDIFF sy-vline
WA_FKK_OPBEW_FKKOP_STR-WAERS sy-vline
WA_FKK_OPBEW_FKKOP_STR-STOFLG sy-vline
WA_FKK_OPBEW_FKKOP_STR-BETRH_VA sy-vline
WA_FKK_OPBEW_FKKOP_STR-BDIFF_VA sy-vline
WA_FKK_OPBEW_FKKOP_STR-SIMUL sy-vline
WA_FKK_OPBEW_FKKOP_STR-LAUFD sy-vline
WA_FKK_OPBEW_FKKOP_STR-LAUFI sy-vline
WA_FKK_OPBEW_FKKOP_STR-BETRW sy-vline
WA_FKK_OPBEW_FKKOP_STR-BETRH sy-vline
WA_FKK_OPBEW_FKKOP_STR-BETR2 sy-vline
WA_FKK_OPBEW_FKKOP_STR-BETR3 sy-vline
WA_FKK_OPBEW_FKKOP_STR-OPUPZ sy-vline
WA_FKK_OPBEW_FKKOP_STR-XRAGL sy-vline
WA_FKK_OPBEW_FKKOP_STR-KURSF sy-vline
WA_FKK_OPBEW_FKKOP_STR-FAEDN sy-vline
WA_FKK_OPBEW_FKKOP_STR-OPUPW sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGST sy-vline
WA_FKK_OPBEW_FKKOP_STR-BUDAT sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGDT sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGBL sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGBD sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGWA sy-vline
WA_FKK_OPBEW_FKKOP_STR-AUGBT sy-vline
WA_FKK_OPBEW_FKKOP_STR-INFOZ sy-vline
WA_FKK_OPBEW_FKKOP_STR-GSBER_MIG sy-vline
WA_FKK_OPBEW_FKKOP_STR-SEGMT_MIG sy-vline
WA_FKK_OPBEW_FKKOP_STR-PRCTR_MIG sy-vline
WA_FKK_OPBEW_FKKOP_STR-BWBER sy-vline
WA_FKK_OPBEW_FKKOP_STR-HWAER sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.