ABAP Select data from SAP table FAGL_S_PERIOD_BLOCK 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 FAGL_S_PERIOD_BLOCK 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 FAGL_S_PERIOD_BLOCK. 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 FAGL_S_PERIOD_BLOCK 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_FAGL_S_PERIOD_BLOCK TYPE STANDARD TABLE OF FAGL_S_PERIOD_BLOCK, WA_FAGL_S_PERIOD_BLOCK TYPE FAGL_S_PERIOD_BLOCK, 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: <FAGL_S_PERIOD_BLOCK> TYPE FAGL_S_PERIOD_BLOCK. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FAGL_S_PERIOD_BLOCK. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FAGL_S_PERIOD_BLOCK INTO TABLE IT_FAGL_S_PERIOD_BLOCK. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FAGL_S_PERIOD_BLOCK * INTO TABLE @DATA(IT_FAGL_S_PERIOD_BLOCK2). *--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_FAGL_S_PERIOD_BLOCK INDEX 1 INTO DATA(WA_FAGL_S_PERIOD_BLOCK2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FAGL_S_PERIOD_BLOCK ASSIGNING <FAGL_S_PERIOD_BLOCK>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FAGL_S_PERIOD_BLOCK>-DRCRK = 1.
<FAGL_S_PERIOD_BLOCK>-TSLVT = 1.
<FAGL_S_PERIOD_BLOCK>-TSL01 = 1.
<FAGL_S_PERIOD_BLOCK>-TSL02 = 1.
<FAGL_S_PERIOD_BLOCK>-TSL03 = 1.
ENDLOOP. LOOP AT IT_FAGL_S_PERIOD_BLOCK INTO WA_FAGL_S_PERIOD_BLOCK. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FAGL_S_PERIOD_BLOCK-TSL04, sy-vline,
WA_FAGL_S_PERIOD_BLOCK-TSL05, sy-vline,
WA_FAGL_S_PERIOD_BLOCK-TSL06, sy-vline,
WA_FAGL_S_PERIOD_BLOCK-TSL07, sy-vline,
WA_FAGL_S_PERIOD_BLOCK-TSL08, sy-vline,
WA_FAGL_S_PERIOD_BLOCK-TSL09, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FAGL_S_PERIOD_BLOCK 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_FAGL_S_PERIOD_BLOCK 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_FAGL_S_PERIOD_BLOCK INTO WA_FAGL_S_PERIOD_BLOCK. *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_FAGL_S_PERIOD_BLOCK_STR,
DRCRK TYPE STRING,
TSLVT TYPE STRING,
TSL01 TYPE STRING,
TSL02 TYPE STRING,
TSL03 TYPE STRING,
TSL04 TYPE STRING,
TSL05 TYPE STRING,
TSL06 TYPE STRING,
TSL07 TYPE STRING,
TSL08 TYPE STRING,
TSL09 TYPE STRING,
TSL10 TYPE STRING,
TSL11 TYPE STRING,
TSL12 TYPE STRING,
TSL13 TYPE STRING,
TSL14 TYPE STRING,
TSL15 TYPE STRING,
TSL16 TYPE STRING,
HSLVT TYPE STRING,
HSL01 TYPE STRING,
HSL02 TYPE STRING,
HSL03 TYPE STRING,
HSL04 TYPE STRING,
HSL05 TYPE STRING,
HSL06 TYPE STRING,
HSL07 TYPE STRING,
HSL08 TYPE STRING,
HSL09 TYPE STRING,
HSL10 TYPE STRING,
HSL11 TYPE STRING,
HSL12 TYPE STRING,
HSL13 TYPE STRING,
HSL14 TYPE STRING,
HSL15 TYPE STRING,
HSL16 TYPE STRING,
KSLVT TYPE STRING,
KSL01 TYPE STRING,
KSL02 TYPE STRING,
KSL03 TYPE STRING,
KSL04 TYPE STRING,
KSL05 TYPE STRING,
KSL06 TYPE STRING,
KSL07 TYPE STRING,
KSL08 TYPE STRING,
KSL09 TYPE STRING,
KSL10 TYPE STRING,
KSL11 TYPE STRING,
KSL12 TYPE STRING,
KSL13 TYPE STRING,
KSL14 TYPE STRING,
KSL15 TYPE STRING,
KSL16 TYPE STRING,
OSLVT TYPE STRING,
OSL01 TYPE STRING,
OSL02 TYPE STRING,
OSL03 TYPE STRING,
OSL04 TYPE STRING,
OSL05 TYPE STRING,
OSL06 TYPE STRING,
OSL07 TYPE STRING,
OSL08 TYPE STRING,
OSL09 TYPE STRING,
OSL10 TYPE STRING,
OSL11 TYPE STRING,
OSL12 TYPE STRING,
OSL13 TYPE STRING,
OSL14 TYPE STRING,
OSL15 TYPE STRING,
OSL16 TYPE STRING,
MSLVT TYPE STRING,
MSL01 TYPE STRING,
MSL02 TYPE STRING,
MSL03 TYPE STRING,
MSL04 TYPE STRING,
MSL05 TYPE STRING,
MSL06 TYPE STRING,
MSL07 TYPE STRING,
MSL08 TYPE STRING,
MSL09 TYPE STRING,
MSL10 TYPE STRING,
MSL11 TYPE STRING,
MSL12 TYPE STRING,
MSL13 TYPE STRING,
MSL14 TYPE STRING,
MSL15 TYPE STRING,
MSL16 TYPE STRING,END OF T_EKKO_STR. DATA: WA_FAGL_S_PERIOD_BLOCK_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_FAGL_S_PERIOD_BLOCK_STR-DRCRK sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSLVT sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL01 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL02 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL03 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL04 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL05 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL06 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL07 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL08 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL09 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL10 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL11 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL12 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL13 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL14 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL15 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-TSL16 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSLVT sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL01 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL02 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL03 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL04 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL05 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL06 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL07 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL08 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL09 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL10 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL11 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL12 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL13 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL14 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL15 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-HSL16 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSLVT sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL01 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL02 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL03 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL04 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL05 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL06 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL07 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL08 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL09 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL10 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL11 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL12 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL13 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL14 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL15 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-KSL16 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSLVT sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL01 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL02 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL03 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL04 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL05 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL06 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL07 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL08 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL09 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL10 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL11 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL12 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL13 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL14 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL15 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-OSL16 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSLVT sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL01 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL02 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL03 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL04 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL05 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL06 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL07 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL08 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL09 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL10 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL11 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL12 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL13 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL14 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL15 sy-vline
WA_FAGL_S_PERIOD_BLOCK_STR-MSL16 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.