ABAP Select data from SAP table CIFLFA1X 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 CIFLFA1X 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 CIFLFA1X. 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 CIFLFA1X 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_CIFLFA1X TYPE STANDARD TABLE OF CIFLFA1X,
      WA_CIFLFA1X TYPE CIFLFA1X,
      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: <CIFLFA1X> TYPE CIFLFA1X.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CIFLFA1X
*  INTO TABLE @DATA(IT_CIFLFA1X2).
*--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_CIFLFA1X INDEX 1 INTO DATA(WA_CIFLFA1X2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CIFLFA1X ASSIGNING <CIFLFA1X>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CIFLFA1X>-MANDT = 1.
<CIFLFA1X>-LIFNR = 1.
<CIFLFA1X>-ANRED = 1.
<CIFLFA1X>-BAHNS = 1.
<CIFLFA1X>-BBBNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CIFLFA1X-BBSNR, sy-vline,
WA_CIFLFA1X-BEGRU, sy-vline,
WA_CIFLFA1X-BRSCH, sy-vline,
WA_CIFLFA1X-BUBKZ, sy-vline,
WA_CIFLFA1X-DATLT, sy-vline,
WA_CIFLFA1X-DTAMS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CIFLFA1X 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_CIFLFA1X 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_CIFLFA1X INTO WA_CIFLFA1X. *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_CIFLFA1X_STR,
MANDT TYPE STRING,
LIFNR TYPE STRING,
ANRED TYPE STRING,
BAHNS TYPE STRING,
BBBNR TYPE STRING,
BBSNR TYPE STRING,
BEGRU TYPE STRING,
BRSCH TYPE STRING,
BUBKZ TYPE STRING,
DATLT TYPE STRING,
DTAMS TYPE STRING,
DTAWS TYPE STRING,
ERDAT TYPE STRING,
ERNAM TYPE STRING,
ESRNR TYPE STRING,
KONZS TYPE STRING,
KTOKK TYPE STRING,
KUNNR TYPE STRING,
LAND1 TYPE STRING,
LNRZA TYPE STRING,
LOEVM TYPE STRING,
NAME1 TYPE STRING,
NAME2 TYPE STRING,
NAME3 TYPE STRING,
NAME4 TYPE STRING,
ORT01 TYPE STRING,
ORT02 TYPE STRING,
PFACH TYPE STRING,
PSTL2 TYPE STRING,
PSTLZ TYPE STRING,
REGIO TYPE STRING,
SORTL TYPE STRING,
SPERR TYPE STRING,
SPERM TYPE STRING,
SPRAS TYPE STRING,
STCD1 TYPE STRING,
STCD2 TYPE STRING,
STKZA TYPE STRING,
STKZU TYPE STRING,
STRAS TYPE STRING,
TELBX TYPE STRING,
TELF1 TYPE STRING,
TELF2 TYPE STRING,
TELFX TYPE STRING,
TELTX TYPE STRING,
TELX1 TYPE STRING,
XCPDK TYPE STRING,
XZEMP TYPE STRING,
VBUND TYPE STRING,
FISKN TYPE STRING,
STCEG TYPE STRING,
STKZN TYPE STRING,
SPERQ TYPE STRING,
ADRNR TYPE STRING,
MCOD1 TYPE STRING,
MCOD2 TYPE STRING,
MCOD3 TYPE STRING,
GBORT TYPE STRING,
GBDAT TYPE STRING,
SEXKZ TYPE STRING,
KRAUS TYPE STRING,
REVDB TYPE STRING,
QSSYS TYPE STRING,
KTOCK TYPE STRING,
PFORT TYPE STRING,
WERKS TYPE STRING,
LTSNA TYPE STRING,
WERKR TYPE STRING,
PLKAL TYPE STRING,
DUEFL TYPE STRING,
TXJCD TYPE STRING,
SPERZ TYPE STRING,
SCACD TYPE STRING,
SFRGR TYPE STRING,
LZONE TYPE STRING,END OF T_EKKO_STR. DATA: WA_CIFLFA1X_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_CIFLFA1X_STR-MANDT sy-vline
WA_CIFLFA1X_STR-LIFNR sy-vline
WA_CIFLFA1X_STR-ANRED sy-vline
WA_CIFLFA1X_STR-BAHNS sy-vline
WA_CIFLFA1X_STR-BBBNR sy-vline
WA_CIFLFA1X_STR-BBSNR sy-vline
WA_CIFLFA1X_STR-BEGRU sy-vline
WA_CIFLFA1X_STR-BRSCH sy-vline
WA_CIFLFA1X_STR-BUBKZ sy-vline
WA_CIFLFA1X_STR-DATLT sy-vline
WA_CIFLFA1X_STR-DTAMS sy-vline
WA_CIFLFA1X_STR-DTAWS sy-vline
WA_CIFLFA1X_STR-ERDAT sy-vline
WA_CIFLFA1X_STR-ERNAM sy-vline
WA_CIFLFA1X_STR-ESRNR sy-vline
WA_CIFLFA1X_STR-KONZS sy-vline
WA_CIFLFA1X_STR-KTOKK sy-vline
WA_CIFLFA1X_STR-KUNNR sy-vline
WA_CIFLFA1X_STR-LAND1 sy-vline
WA_CIFLFA1X_STR-LNRZA sy-vline
WA_CIFLFA1X_STR-LOEVM sy-vline
WA_CIFLFA1X_STR-NAME1 sy-vline
WA_CIFLFA1X_STR-NAME2 sy-vline
WA_CIFLFA1X_STR-NAME3 sy-vline
WA_CIFLFA1X_STR-NAME4 sy-vline
WA_CIFLFA1X_STR-ORT01 sy-vline
WA_CIFLFA1X_STR-ORT02 sy-vline
WA_CIFLFA1X_STR-PFACH sy-vline
WA_CIFLFA1X_STR-PSTL2 sy-vline
WA_CIFLFA1X_STR-PSTLZ sy-vline
WA_CIFLFA1X_STR-REGIO sy-vline
WA_CIFLFA1X_STR-SORTL sy-vline
WA_CIFLFA1X_STR-SPERR sy-vline
WA_CIFLFA1X_STR-SPERM sy-vline
WA_CIFLFA1X_STR-SPRAS sy-vline
WA_CIFLFA1X_STR-STCD1 sy-vline
WA_CIFLFA1X_STR-STCD2 sy-vline
WA_CIFLFA1X_STR-STKZA sy-vline
WA_CIFLFA1X_STR-STKZU sy-vline
WA_CIFLFA1X_STR-STRAS sy-vline
WA_CIFLFA1X_STR-TELBX sy-vline
WA_CIFLFA1X_STR-TELF1 sy-vline
WA_CIFLFA1X_STR-TELF2 sy-vline
WA_CIFLFA1X_STR-TELFX sy-vline
WA_CIFLFA1X_STR-TELTX sy-vline
WA_CIFLFA1X_STR-TELX1 sy-vline
WA_CIFLFA1X_STR-XCPDK sy-vline
WA_CIFLFA1X_STR-XZEMP sy-vline
WA_CIFLFA1X_STR-VBUND sy-vline
WA_CIFLFA1X_STR-FISKN sy-vline
WA_CIFLFA1X_STR-STCEG sy-vline
WA_CIFLFA1X_STR-STKZN sy-vline
WA_CIFLFA1X_STR-SPERQ sy-vline
WA_CIFLFA1X_STR-ADRNR sy-vline
WA_CIFLFA1X_STR-MCOD1 sy-vline
WA_CIFLFA1X_STR-MCOD2 sy-vline
WA_CIFLFA1X_STR-MCOD3 sy-vline
WA_CIFLFA1X_STR-GBORT sy-vline
WA_CIFLFA1X_STR-GBDAT sy-vline
WA_CIFLFA1X_STR-SEXKZ sy-vline
WA_CIFLFA1X_STR-KRAUS sy-vline
WA_CIFLFA1X_STR-REVDB sy-vline
WA_CIFLFA1X_STR-QSSYS sy-vline
WA_CIFLFA1X_STR-KTOCK sy-vline
WA_CIFLFA1X_STR-PFORT sy-vline
WA_CIFLFA1X_STR-WERKS sy-vline
WA_CIFLFA1X_STR-LTSNA sy-vline
WA_CIFLFA1X_STR-WERKR sy-vline
WA_CIFLFA1X_STR-PLKAL sy-vline
WA_CIFLFA1X_STR-DUEFL sy-vline
WA_CIFLFA1X_STR-TXJCD sy-vline
WA_CIFLFA1X_STR-SPERZ sy-vline
WA_CIFLFA1X_STR-SCACD sy-vline
WA_CIFLFA1X_STR-SFRGR sy-vline
WA_CIFLFA1X_STR-LZONE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.