ABAP Select data from SAP table IFMRKBVM 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 IFMRKBVM 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 IFMRKBVM. 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 IFMRKBVM 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_IFMRKBVM TYPE STANDARD TABLE OF IFMRKBVM,
      WA_IFMRKBVM TYPE IFMRKBVM,
      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: <IFMRKBVM> TYPE IFMRKBVM.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IFMRKBVM
*  INTO TABLE @DATA(IT_IFMRKBVM2).
*--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_IFMRKBVM INDEX 1 INTO DATA(WA_IFMRKBVM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IFMRKBVM ASSIGNING <IFMRKBVM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IFMRKBVM>-HHSTELLE = 1.
<IFMRKBVM>-NR_BEZEICH = 1.
<IFMRKBVM>-GRUPP_NR = 1.
<IFMRKBVM>-BEZEICH = 1.
<IFMRKBVM>-BESCHREIB1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IFMRKBVM-BESCHREIB2, sy-vline,
WA_IFMRKBVM-FICTR, sy-vline,
WA_IFMRKBVM-FOND, sy-vline,
WA_IFMRKBVM-WAERS, sy-vline,
WA_IFMRKBVM-HSART, sy-vline,
WA_IFMRKBVM-POTYP, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IFMRKBVM 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_IFMRKBVM 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_IFMRKBVM INTO WA_IFMRKBVM. *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 FIPEX, internal->external for field HHSTELLE CALL FUNCTION 'CONVERSION_EXIT_FIPEX_OUTPUT' EXPORTING input = WA_IFMRKBVM-HHSTELLE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFMRKBVM-HHSTELLE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit FMCIL, internal->external for field FIPUP CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_IFMRKBVM-FIPUP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFMRKBVM-FIPUP.
WRITE:/ 'New Value:', ld_input.

*Conversion exit FIPEX, internal->external for field BUDKZ CALL FUNCTION 'CONVERSION_EXIT_FIPEX_OUTPUT' EXPORTING input = WA_IFMRKBVM-BUDKZ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFMRKBVM-BUDKZ.
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_IFMRKBVM_STR,
HHSTELLE TYPE STRING,
NR_BEZEICH TYPE STRING,
GRUPP_NR TYPE STRING,
BEZEICH TYPE STRING,
BESCHREIB1 TYPE STRING,
BESCHREIB2 TYPE STRING,
FICTR TYPE STRING,
FOND TYPE STRING,
WAERS TYPE STRING,
HSART TYPE STRING,
POTYP TYPE STRING,
HIE_ID TYPE STRING,
PLEVL TYPE STRING,
FIPUP TYPE STRING,
HSTTEXT1 TYPE STRING,
HSTTEXT2 TYPE STRING,
HSTTEXT3 TYPE STRING,
OB_PLJ TYPE STRING,
OB_LFDJ TYPE STRING,
RE_VOR TYPE STRING,
RE_3 TYPE STRING,
RE_4 TYPE STRING,
ANS_PLJ1 TYPE STRING,
ANS_PLJ2 TYPE STRING,
ANS_PLJ3 TYPE STRING,
ANS_PLJ4 TYPE STRING,
VE_PLJ1 TYPE STRING,
VE_PLJ2 TYPE STRING,
VE_PLJ3 TYPE STRING,
VE_PLJ4 TYPE STRING,
SUM_VE TYPE STRING,
GES_E_A TYPE STRING,
BUD_BER TYPE STRING,
KORR TYPE STRING,
BEZIRK TYPE STRING,
EFICTR TYPE STRING,
BUDKZ TYPE STRING,
BSAMT TYPE STRING,
BTAMT TYPE STRING,
ERL_TEXT TYPE STRING,
FLG_SUMME TYPE STRING,
EINZELPLT1 TYPE STRING,
EINZELPLT2 TYPE STRING,
ABSCHNT1 TYPE STRING,
ABSCHNT2 TYPE STRING,
UABSCHT1 TYPE STRING,
UABSCHT2 TYPE STRING,
UABSCHT3 TYPE STRING,
XSNROL TYPE STRING,
PRAEFIX TYPE STRING,
GLD TYPE STRING,
EPL TYPE STRING,
ABSCHN TYPE STRING,
UABSCH TYPE STRING,
GRUPPE TYPE STRING,
HGR TYPE STRING,
GRP TYPE STRING,
UGR TYPE STRING,
MASS TYPE STRING,
HMASS TYPE STRING,
MASSN TYPE STRING,
UMASS TYPE STRING,
OBJ TYPE STRING,
PRUEFZ TYPE STRING,END OF T_EKKO_STR. DATA: WA_IFMRKBVM_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_IFMRKBVM_STR-HHSTELLE sy-vline
WA_IFMRKBVM_STR-NR_BEZEICH sy-vline
WA_IFMRKBVM_STR-GRUPP_NR sy-vline
WA_IFMRKBVM_STR-BEZEICH sy-vline
WA_IFMRKBVM_STR-BESCHREIB1 sy-vline
WA_IFMRKBVM_STR-BESCHREIB2 sy-vline
WA_IFMRKBVM_STR-FICTR sy-vline
WA_IFMRKBVM_STR-FOND sy-vline
WA_IFMRKBVM_STR-WAERS sy-vline
WA_IFMRKBVM_STR-HSART sy-vline
WA_IFMRKBVM_STR-POTYP sy-vline
WA_IFMRKBVM_STR-HIE_ID sy-vline
WA_IFMRKBVM_STR-PLEVL sy-vline
WA_IFMRKBVM_STR-FIPUP sy-vline
WA_IFMRKBVM_STR-HSTTEXT1 sy-vline
WA_IFMRKBVM_STR-HSTTEXT2 sy-vline
WA_IFMRKBVM_STR-HSTTEXT3 sy-vline
WA_IFMRKBVM_STR-OB_PLJ sy-vline
WA_IFMRKBVM_STR-OB_LFDJ sy-vline
WA_IFMRKBVM_STR-RE_VOR sy-vline
WA_IFMRKBVM_STR-RE_3 sy-vline
WA_IFMRKBVM_STR-RE_4 sy-vline
WA_IFMRKBVM_STR-ANS_PLJ1 sy-vline
WA_IFMRKBVM_STR-ANS_PLJ2 sy-vline
WA_IFMRKBVM_STR-ANS_PLJ3 sy-vline
WA_IFMRKBVM_STR-ANS_PLJ4 sy-vline
WA_IFMRKBVM_STR-VE_PLJ1 sy-vline
WA_IFMRKBVM_STR-VE_PLJ2 sy-vline
WA_IFMRKBVM_STR-VE_PLJ3 sy-vline
WA_IFMRKBVM_STR-VE_PLJ4 sy-vline
WA_IFMRKBVM_STR-SUM_VE sy-vline
WA_IFMRKBVM_STR-GES_E_A sy-vline
WA_IFMRKBVM_STR-BUD_BER sy-vline
WA_IFMRKBVM_STR-KORR sy-vline
WA_IFMRKBVM_STR-BEZIRK sy-vline
WA_IFMRKBVM_STR-EFICTR sy-vline
WA_IFMRKBVM_STR-BUDKZ sy-vline
WA_IFMRKBVM_STR-BSAMT sy-vline
WA_IFMRKBVM_STR-BTAMT sy-vline
WA_IFMRKBVM_STR-ERL_TEXT sy-vline
WA_IFMRKBVM_STR-FLG_SUMME sy-vline
WA_IFMRKBVM_STR-EINZELPLT1 sy-vline
WA_IFMRKBVM_STR-EINZELPLT2 sy-vline
WA_IFMRKBVM_STR-ABSCHNT1 sy-vline
WA_IFMRKBVM_STR-ABSCHNT2 sy-vline
WA_IFMRKBVM_STR-UABSCHT1 sy-vline
WA_IFMRKBVM_STR-UABSCHT2 sy-vline
WA_IFMRKBVM_STR-UABSCHT3 sy-vline
WA_IFMRKBVM_STR-XSNROL sy-vline
WA_IFMRKBVM_STR-PRAEFIX sy-vline
WA_IFMRKBVM_STR-GLD sy-vline
WA_IFMRKBVM_STR-EPL sy-vline
WA_IFMRKBVM_STR-ABSCHN sy-vline
WA_IFMRKBVM_STR-UABSCH sy-vline
WA_IFMRKBVM_STR-GRUPPE sy-vline
WA_IFMRKBVM_STR-HGR sy-vline
WA_IFMRKBVM_STR-GRP sy-vline
WA_IFMRKBVM_STR-UGR sy-vline
WA_IFMRKBVM_STR-MASS sy-vline
WA_IFMRKBVM_STR-HMASS sy-vline
WA_IFMRKBVM_STR-MASSN sy-vline
WA_IFMRKBVM_STR-UMASS sy-vline
WA_IFMRKBVM_STR-OBJ sy-vline
WA_IFMRKBVM_STR-PRUEFZ sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.