ABAP Select data from SAP table FAGL_FC_S_LIST_POST 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_FC_S_LIST_POST 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_FC_S_LIST_POST. 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_FC_S_LIST_POST 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_FC_S_LIST_POST TYPE STANDARD TABLE OF FAGL_FC_S_LIST_POST,
      WA_FAGL_FC_S_LIST_POST TYPE FAGL_FC_S_LIST_POST,
      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_FC_S_LIST_POST> TYPE FAGL_FC_S_LIST_POST.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FAGL_FC_S_LIST_POST
*  INTO TABLE @DATA(IT_FAGL_FC_S_LIST_POST2).
*--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_FC_S_LIST_POST INDEX 1 INTO DATA(WA_FAGL_FC_S_LIST_POST2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FAGL_FC_S_LIST_POST ASSIGNING <FAGL_FC_S_LIST_POST>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FAGL_FC_S_LIST_POST>-SELKEY = 1.
<FAGL_FC_S_LIST_POST>-MANDT = 1.
<FAGL_FC_S_LIST_POST>-LDGRP = 1.
<FAGL_FC_S_LIST_POST>-BUKRS = 1.
<FAGL_FC_S_LIST_POST>-BELNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FAGL_FC_S_LIST_POST-GJAHR, sy-vline,
WA_FAGL_FC_S_LIST_POST-BKTXT, sy-vline,
WA_FAGL_FC_S_LIST_POST-BLART, sy-vline,
WA_FAGL_FC_S_LIST_POST-BLDAT, sy-vline,
WA_FAGL_FC_S_LIST_POST-BUDAT, sy-vline,
WA_FAGL_FC_S_LIST_POST-XBLNR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FAGL_FC_S_LIST_POST 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_FC_S_LIST_POST 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_FC_S_LIST_POST INTO WA_FAGL_FC_S_LIST_POST. *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 BELNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-BELNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-BELNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-GJAHR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

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

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

*Conversion exit IMKEY, internal->external for field IMKEY CALL FUNCTION 'CONVERSION_EXIT_IMKEY_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-IMKEY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-IMKEY.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ABPSP, internal->external for field PS_PSP_PNR CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-PS_PSP_PNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-PS_PSP_PNR.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit FMCIS, internal->external for field FIPOS CALL FUNCTION 'CONVERSION_EXIT_FMCIS_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-FIPOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-FIPOS.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit AU132, internal->external for field WRBTR CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_FAGL_FC_S_LIST_POST-WRBTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_FC_S_LIST_POST-WRBTR.
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_FAGL_FC_S_LIST_POST_STR,
SELKEY TYPE STRING,
MANDT TYPE STRING,
LDGRP TYPE STRING,
BUKRS TYPE STRING,
BELNR TYPE STRING,
GJAHR TYPE STRING,
BKTXT TYPE STRING,
BLART TYPE STRING,
BLDAT TYPE STRING,
BUDAT TYPE STRING,
XBLNR TYPE STRING,
WAERS TYPE STRING,
HWAER TYPE STRING,
HWAE2 TYPE STRING,
HWAE3 TYPE STRING,
HWAE4 TYPE STRING,
HWAE5 TYPE STRING,
HWAE6 TYPE STRING,
HWAE7 TYPE STRING,
HWAE8 TYPE STRING,
HWAE9 TYPE STRING,
HWAE10 TYPE STRING,
CURT2 TYPE STRING,
CURT3 TYPE STRING,
CURTPV TYPE STRING,
CURTPB TYPE STRING,
CURTPC TYPE STRING,
CURTPD TYPE STRING,
CURTPE TYPE STRING,
CURTPF TYPE STRING,
CURTPG TYPE STRING,
TXT100 TYPE STRING,
BUZEI TYPE STRING,
BSCHL TYPE STRING,
UMSKZ TYPE STRING,
UMSKS TYPE STRING,
KOART TYPE STRING,
HKONT TYPE STRING,
KUNNR TYPE STRING,
LIFNR TYPE STRING,
ANLN1 TYPE STRING,
ANLN2 TYPE STRING,
GSBER TYPE STRING,
PARGB TYPE STRING,
PRCTR TYPE STRING,
PPRCTR TYPE STRING,
SEGMENT TYPE STRING,
PSEGMENT TYPE STRING,
AUFNR TYPE STRING,
IMKEY TYPE STRING,
KDAUF TYPE STRING,
KDPOS TYPE STRING,
KOSTL TYPE STRING,
KSTRG TYPE STRING,
NPLNR TYPE STRING,
APLZL TYPE STRING,
AUFPL TYPE STRING,
PAOBJNR TYPE STRING,
PS_PSP_PNR TYPE STRING,
VBUND TYPE STRING,
WERKS TYPE STRING,
FIPOS TYPE STRING,
FISTL TYPE STRING,
GEBER TYPE STRING,
VNAME TYPE STRING,
EGRUP TYPE STRING,
RECID TYPE STRING,
WRBTR TYPE STRING,
DMBTR TYPE STRING,
DMBE2 TYPE STRING,
DMBE3 TYPE STRING,
VSL TYPE STRING,
BSL TYPE STRING,
CSL TYPE STRING,
DSL TYPE STRING,
ESL TYPE STRING,
FSL TYPE STRING,
GSL TYPE STRING,
SHKZG TYPE STRING,
MWSKZ TYPE STRING,
VALUT TYPE STRING,
ZUONR TYPE STRING,
SGTXT TYPE STRING,END OF T_EKKO_STR. DATA: WA_FAGL_FC_S_LIST_POST_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_FC_S_LIST_POST_STR-SELKEY sy-vline
WA_FAGL_FC_S_LIST_POST_STR-MANDT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-LDGRP sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BUKRS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BELNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-GJAHR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BKTXT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BLART sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BLDAT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BUDAT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-XBLNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-WAERS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAER sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE2 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE3 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE4 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE5 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE6 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE7 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE8 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE9 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HWAE10 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURT2 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURT3 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPV sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPB sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPC sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPD sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPE sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPF sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CURTPG sy-vline
WA_FAGL_FC_S_LIST_POST_STR-TXT100 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BUZEI sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BSCHL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-UMSKZ sy-vline
WA_FAGL_FC_S_LIST_POST_STR-UMSKS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KOART sy-vline
WA_FAGL_FC_S_LIST_POST_STR-HKONT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KUNNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-LIFNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-ANLN1 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-ANLN2 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-GSBER sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PARGB sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PRCTR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PPRCTR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-SEGMENT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PSEGMENT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-AUFNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-IMKEY sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KDAUF sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KDPOS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KOSTL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-KSTRG sy-vline
WA_FAGL_FC_S_LIST_POST_STR-NPLNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-APLZL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-AUFPL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PAOBJNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-PS_PSP_PNR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-VBUND sy-vline
WA_FAGL_FC_S_LIST_POST_STR-WERKS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-FIPOS sy-vline
WA_FAGL_FC_S_LIST_POST_STR-FISTL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-GEBER sy-vline
WA_FAGL_FC_S_LIST_POST_STR-VNAME sy-vline
WA_FAGL_FC_S_LIST_POST_STR-EGRUP sy-vline
WA_FAGL_FC_S_LIST_POST_STR-RECID sy-vline
WA_FAGL_FC_S_LIST_POST_STR-WRBTR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-DMBTR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-DMBE2 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-DMBE3 sy-vline
WA_FAGL_FC_S_LIST_POST_STR-VSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-BSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-CSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-DSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-ESL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-FSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-GSL sy-vline
WA_FAGL_FC_S_LIST_POST_STR-SHKZG sy-vline
WA_FAGL_FC_S_LIST_POST_STR-MWSKZ sy-vline
WA_FAGL_FC_S_LIST_POST_STR-VALUT sy-vline
WA_FAGL_FC_S_LIST_POST_STR-ZUONR sy-vline
WA_FAGL_FC_S_LIST_POST_STR-SGTXT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.