ABAP Select data from SAP table E1FMALE_FMIFIIT_CHG 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 E1FMALE_FMIFIIT_CHG 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 E1FMALE_FMIFIIT_CHG. 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 E1FMALE_FMIFIIT_CHG 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_E1FMALE_FMIFIIT_CHG TYPE STANDARD TABLE OF E1FMALE_FMIFIIT_CHG,
      WA_E1FMALE_FMIFIIT_CHG TYPE E1FMALE_FMIFIIT_CHG,
      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: <E1FMALE_FMIFIIT_CHG> TYPE E1FMALE_FMIFIIT_CHG.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM E1FMALE_FMIFIIT_CHG
*  INTO TABLE @DATA(IT_E1FMALE_FMIFIIT_CHG2).
*--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_E1FMALE_FMIFIIT_CHG INDEX 1 INTO DATA(WA_E1FMALE_FMIFIIT_CHG2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_E1FMALE_FMIFIIT_CHG ASSIGNING <E1FMALE_FMIFIIT_CHG>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1FMALE_FMIFIIT_CHG>-FMBELNR = 1.
<E1FMALE_FMIFIIT_CHG>-FIKRS = 1.
<E1FMALE_FMIFIIT_CHG>-FMBUZEI = 1.
<E1FMALE_FMIFIIT_CHG>-BTART = 1.
<E1FMALE_FMIFIIT_CHG>-RLDNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_E1FMALE_FMIFIIT_CHG-GJAHR, sy-vline,
WA_E1FMALE_FMIFIIT_CHG-STUNR, sy-vline,
WA_E1FMALE_FMIFIIT_CHG-ZHLDT, sy-vline,
WA_E1FMALE_FMIFIIT_CHG-GNJHR, sy-vline,
WA_E1FMALE_FMIFIIT_CHG-PERIO, sy-vline,
WA_E1FMALE_FMIFIIT_CHG-CFSTAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1FMALE_FMIFIIT_CHG 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_E1FMALE_FMIFIIT_CHG 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_E1FMALE_FMIFIIT_CHG INTO WA_E1FMALE_FMIFIIT_CHG. *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_E1FMALE_FMIFIIT_CHG_STR,
FMBELNR TYPE STRING,
FIKRS TYPE STRING,
FMBUZEI TYPE STRING,
BTART TYPE STRING,
RLDNR TYPE STRING,
GJAHR TYPE STRING,
STUNR TYPE STRING,
ZHLDT TYPE STRING,
GNJHR TYPE STRING,
PERIO TYPE STRING,
CFSTAT TYPE STRING,
CFSTATSV TYPE STRING,
CFCNT TYPE STRING,
OBJNRZ TYPE STRING,
TRBTR TYPE STRING,
FKBTR TYPE STRING,
FISTL TYPE STRING,
FONDS TYPE STRING,
FIPEX TYPE STRING,
FAREA TYPE STRING,
MEASURE TYPE STRING,
GRANT_NBR TYPE STRING,
BUS_AREA TYPE STRING,
PRCTR TYPE STRING,
WRTTP TYPE STRING,
VRGNG TYPE STRING,
BUKRS TYPE STRING,
STATS TYPE STRING,
TWAER TYPE STRING,
CFLEV TYPE STRING,
SGTXT TYPE STRING,
TRANR TYPE STRING,
CTRNR TYPE STRING,
USERDIM TYPE STRING,
FMVOR TYPE STRING,
HKONT TYPE STRING,
VOBUKRS TYPE STRING,
VOGJAHR TYPE STRING,
VOBELNR TYPE STRING,
VOBUZEI TYPE STRING,
KNGJAHR TYPE STRING,
KNBELNR TYPE STRING,
KNBUZEI TYPE STRING,
SKNTO TYPE STRING,
RDIFF TYPE STRING,
PAYFLG TYPE STRING,
PSOBT TYPE STRING,
MENGE TYPE STRING,
MEINS TYPE STRING,
VBUND TYPE STRING,
XREF3 TYPE STRING,
VREFBT TYPE STRING,
VREFBN TYPE STRING,
VRFORG TYPE STRING,
VRFPOS TYPE STRING,
VRFKNT TYPE STRING,
VRFTYP TYPE STRING,
VRFSYS TYPE STRING,END OF T_EKKO_STR. DATA: WA_E1FMALE_FMIFIIT_CHG_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_E1FMALE_FMIFIIT_CHG_STR-FMBELNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FIKRS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FMBUZEI sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-BTART sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-RLDNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-GJAHR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-STUNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-ZHLDT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-GNJHR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-PERIO sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-CFSTAT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-CFSTATSV sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-CFCNT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-OBJNRZ sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-TRBTR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FKBTR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FISTL sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FONDS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FIPEX sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FAREA sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-MEASURE sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-GRANT_NBR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-BUS_AREA sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-PRCTR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-WRTTP sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRGNG sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-BUKRS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-STATS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-TWAER sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-CFLEV sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-SGTXT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-TRANR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-CTRNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-USERDIM sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-FMVOR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-HKONT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VOBUKRS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VOGJAHR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VOBELNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VOBUZEI sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-KNGJAHR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-KNBELNR sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-KNBUZEI sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-SKNTO sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-RDIFF sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-PAYFLG sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-PSOBT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-MENGE sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-MEINS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VBUND sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-XREF3 sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VREFBT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VREFBN sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRFORG sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRFPOS sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRFKNT sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRFTYP sy-vline
WA_E1FMALE_FMIFIIT_CHG_STR-VRFSYS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.